Rotate a body manually screws up collision detection/distance grids

Topics: User Forum
Aug 30, 2009 at 12:33 PM

 

        public bool Intersect(Geom geom, ref Vector2 point)
        {
            //Lookup the geometry's distancegrid
            DistanceGridData gridData = _distanceGrids[geom.id];

            Feature feature;
            return gridData.Intersect(ref point, out feature);
        }
I;m new - but i did search the web to find an anser.
I know i;m not supposed to change anything manually, but I have to rotate a body + geom, before I even need the phsysics simulator.
Now I apply pi to the Body.Rotation, and on the next swoop of collision detection, I end up in the code above me (distancegrid.cs);
The given key was not present in the dictionary.  How can I force this distance grid dictionary to recalculate after i change the rotation to a body?
tx

Coordinator
Aug 30, 2009 at 12:38 PM

The rotation is automatically handled and the distance grid is the same no matter the rotational value of the geometry. The problem seems to be that the distance grid is not present for the specified geometry. Do you use the GeomFactory for all geometries or do you create geometries yourself?

Aug 30, 2009 at 12:52 PM

First - I;m sure it;s me; the engine seems impressive, and I am really enjoying to get to know it. Incredible work you guys do.

I;m using the Geometry factory for everything; yes, as I only have one method of creating objects; I;m in a sandbox, so only two objects present.

I;m currently dynamically scaling and roting my objects, and do so by just disposing the old geometry and body, and creating new ones.

(I added -5 to the geometry, as the squares leave some dead space between them, when stacked onto eachother) 

 

protected virtual void CreateObject ( int width, int height, Vector2 position )
		{
			if ( Body != null ) Body.Dispose ( );
			if ( Geometry != null ) Geometry.Dispose ( );
			texture2D = DrawingHelper.CreateRectangleTexture ( graphicsDevice, width, height, color, borderColor );
			origin = new Vector2 ( texture2D.Width / 2f, texture2D.Height / 2f );
			Body = BodyFactory.Instance.CreateRectangleBody ( physicsSimulator, width, height, 1 );
			Geometry = GeomFactory.Instance.CreateRectangleGeom ( physicsSimulator, Body, width - 5, height - 5 );
			Position = position;
		}
Aug 30, 2009 at 12:53 PM

Ooh,

I solved it; I was calling the createobject again, after applying the rotation. But there is no need, as i don;t scale or change the dimensions. Just manipulate the rotation.

 

Tx

 

Coordinator
Aug 30, 2009 at 12:54 PM

Glad you figured it out.