Coordinator
Jan 4, 2010 at 1:30 PM
Edited Jan 5, 2010 at 8:19 AM

Hi EvilNando,
this is a feature I have on my TODOList ;)
but there is a workaround to get an almost accurate result.
you need the following methods of the geometry you are colliding with:
GetNearestPointOnEdge()
GetEdgePathValueFromPoint()
GetPositionFromEdgePath()
the first method gives you a point on the outline of the shape which is the closest point to the passed position (for example the bottom of a wheel of your car).
pass the result to the second method. that method will give you a relative distance from the start of the shape.
Now add a very bit to the result and pass it to the third method. It will return another Vector2.
The difference between the result of the first method and the result of the last method is the tangent vector. to get the normal, you just need to turn the vector: (x, y) => (y, x)
Vector2 GetNormal(Drawing geo, Vector2 testPoint)
{
const float STEP = 0.001f;
Vector2 closePoint = geo.GetNearestPointOnEdge(testPoint);
float pathPosition = geo.GetEdgePathValueFromPoint(closePoint);
Vector2 nextPoint = geo.GetPositionFromEdgePath(pathPosition + STEP);
Vector2 tangent = nextPoint  closePoint;
return new Vector2(tangent.Y, tangent.X);
}
I hope this is what you need.
If you have two wheels you may calculate the tangent by subtracting the NearestPointOnEdge of the one wheel from the other...
please note: all this doesn't work with Splines yet.
