Example #1
0
bool gob::Contains(const pt3d& globalPt, bool inclusive) {
  if (inclusive)
    return Shape()->Box().ContainsInclusively(globalPt << WorldPos());
  else
    return Shape()->Box().ContainsExclusively(globalPt << WorldPos());
}
Example #2
0
//------------------------------------------------------
//	create a transformed shape from a body shape
//------------------------------------------------------
TPtr<TLMaths::TShape> TLPhysics::GetShapeFromBodyShape(b2Fixture& BodyShape,const TLMaths::TTransform& Transform)
{
	//	gr: I figured the accurate/fast verison would transform by box2d. 
	//		but if we use the box2D transform, then it's out of date if the
	//		node is disabled(body frozen) and the transform[on the node] is changed as the
	//		body's transform cannot be changed until it's enabled (body is unfrozen). 

	//	gr: change this to use box2D when ENABLED and use our node transform when DISABLED.
//#define TRANSFORM_BY_BOX2D

//	b2Body& Body = *BodyShape.GetBody();
	b2Shape* pBodyShape = BodyShape.GetShape();
	
	if ( !pBodyShape )
	{
		TLDebug_Break("Fixture missing shape");
		return NULL;
	}

	if ( BodyShape.GetType() == b2_polygonShape )
	{
		b2PolygonShape& PolyShape = static_cast<b2PolygonShape&>( *pBodyShape );

#ifdef TRANSFORM_BY_BOX2D
		const b2XForm& Bodyxf = Body.GetXForm();
#endif

		//	get a list of the points
		TFixedArray<float2,100> Points;
		for ( s32 p=0;	p<PolyShape.GetVertexCount();	p++ )
		{
			#ifdef TRANSFORM_BY_BOX2D
				//	transform by bodys transform
				b2Vec2 WorldPos = b2Mul( Bodyxf, PolyShape.GetVertex(p) );

				//	gr: transform by ourtransform for scale? or instead of the box2d one? as box2d lacks scale
				float2 WorldPos2( WorldPos.x, WorldPos.y );
			#else
				//	transform by OUR transform
				float2 WorldPos2( PolyShape.GetVertex(p).x, PolyShape.GetVertex(p).y );
				Transform.Transform( WorldPos2 );
			#endif

			Points.Add( WorldPos2 );
		}

		//	create shape
		return new TLMaths::TShapePolygon2D( Points );
	}
	else if ( BodyShape.GetType() == b2_circleShape )
	{
		b2CircleShape& CircleShape = static_cast<b2CircleShape&>( *pBodyShape );

		#ifdef TRANSFORM_BY_BOX2D
			//	transform by bodys transform to put shape in world space
			const b2XForm& Bodyxf = Body.GetXForm();
			b2Vec2 WorldPos = b2Mul( Bodyxf, CircleShape.m_p );
		#else
			//	transform by OUR transform
			float2 WorldPos( CircleShape.m_p.x, CircleShape.m_p.y );
			Transform.Transform( WorldPos );
		#endif

		//	make circle
		TLMaths::TSphere2D Circle( float2( WorldPos.x, WorldPos.y ), CircleShape.m_radius );
		return new TLMaths::TShapeSphere2D( Circle );
	}
	else if ( BodyShape.GetType() == b2_edgeShape )
	{
		b2EdgeShape& EdgeShape = static_cast<b2EdgeShape&>( *pBodyShape );
	
		//	make line
		#ifdef TRANSFORM_BY_BOX2D
			//	transform by bodys transform to put shape in world space
			const b2XForm& Bodyxf = Body.GetXForm();
			b2Vec2 v1 = b2Mul( Bodyxf, EdgeShape.GetVertex1() );
			b2Vec2 v2 = b2Mul( Bodyxf, EdgeShape.GetVertex2() );
			TLMaths::TLine2D Line( float2( v1.x, v1.y ), float2( v2.x, v2.y ) );
		#else
			//	transform by OUR transform
			const b2Vec2& v1 = EdgeShape.GetVertex1();
			const b2Vec2& v2 = EdgeShape.GetVertex2();
			TLMaths::TLine2D Line( float2( v1.x, v1.y ), float2( v2.x, v2.y ) );
			Line.Transform( Transform );
		#endif
			
		return new TLMaths::TShapeLine2D( Line );
	}
	else
	{
		TLDebug_Break("Invalid body shape");
	}

	return NULL;
}
Example #3
0
pt3d gob::Center() const {
  return Shape()->Box().Center() * WorldPos();
}