# Starting a fire

Hello!

I'm working on a simulation of how fire will spread in a room with different types of materials. I've made a field which keeps track of points in space with a given temperature. I've made a crude algorithm for temperature distribution in this field and now I need to initiate fire effects when the temperature is "right". I'm thinking of a way to find the shortest distance from an arbitrary point to a spatial, but I'm kinda stuck at the moment.

I've thought about making spheres or boxes for all the points and check for collisions with the room, but I imagine there should be a better solution for it.

Thanks in advance for any thoughts or tips…

Using collisions does not seem a good approach.

You can get the distance between a Spatial and a point quite easily:

``` float distance = mySpatial.getWorldTranslation().distance(myVector3f); ```

Is there a possibilty, that fire travels along a texture, or is only burning on this texture?

I thought of something like oil

DarkPhoenixX said:

Is there a possibilty, that fire travels along a texture, or is only burning on this texture?
I thought of something like oil

I'm not sure if I understand the question.. But the fire should indeed spread across planes that are flammable.
Quote:
You can get the distance between a Spatial and a point quite easily:

Thank you for that, but that will return the distance between the center of the wall and the point. I'm looking for the shortest distance possible from that plane to a point in the room. Maybe I have to calculate this myself?

DarkPhoenixX:

I think perhaps I get the idea. It should spread from point to point, yeah. Meaning only the black points will "catch fire". A discrete distribution, not continuous.

Here's what I'm thinking:

A point in the room reaches, say, 1000 Kelvin and is very close to a wall made of wood. Let's say this is close/warm enough for the wall to catch fire. I have to get the shortest distance from this point to the wall and the actual point on the wall that will catch fire.

I think I've worked out some solution now that hopefully will work. I'm gonna make Rays pointing along the unit axes (negative and positive direction) on my points and find intersections using intersectsWhere() on a Triangle level.

It's the best I can come up with right now

I wonder if Marching Cubes would work…

(that was my first thought on this problem)

My room is on fire now, but the flames spread in a pretty non-realistic way at the moment. I have a lot of work ahead

Quote:
I wonder if Marching Cubes would work...

(that was my first thought on this problem)
Thank you for the tip, I'm gonna take a look at this!

hmm, I am just gonna spew some code here; I think it will help though:

```              private final Triangle tempTriangle = new Triangle( new Vector3f(), new Vector3f(), new Vector3f() );              private final Vector3f[] tempTriVerticies = new Vector3f[ 3 ];                          for( Integer triIndex : mesh.getTriangleCount() ) {                     // Get a single triangle and set the world transformations                     mesh.getTriangle( triIndex, tempTriVerticies );                     setTriVerticies( tempTriangle, tempTriVerticies, mesh );                     if( ray.intersect( tempTriangle ) ){                                                // get the exact location (in World coordinates) of the intersection                         ray.intersectWhere( tempTriangle, worldLocation );                     }              } ```

```     private void setTriVerticies( Triangle triangle, Vector3f[] verts, TriMesh mesh ) {         for( int i = 0; i < verts.length; ++i ){             mesh.localToWorld( verts[i], triangle.get( i ) );         }         triangle.calculateCenter();     } ```

It did help. Thanks, basixs.