Code:
public static function RayCast( body:b2Body , startPos:b2Vec2 , endPos:b2Vec2 ):b2Vec2
{
var lambda:Number = 1.0;
var normal:b2Vec2;
var segment:b2Segment = new b2Segment;
segment.p1 = startPos;
segment.p2 = endPos;
var shape:b2Shape = body.GetShapeList(); //get first shape
var hit:Boolean = TestSegment( body.GetXForm() , &lambda, &normal, segment, 1 ); //This is C++ and I can't convert it... what is &?
if (hit)
{
trace(hit);
//return (1 - lambda) * segment.p1 + lambda * segment.p2;
}
return null;
}//RayCast(
{
var lambda:Number = 1.0;
var normal:b2Vec2;
var segment:b2Segment = new b2Segment;
segment.p1 = startPos;
segment.p2 = endPos;
var shape:b2Shape = body.GetShapeList(); //get first shape
var hit:Boolean = TestSegment( body.GetXForm() , &lambda, &normal, segment, 1 ); //This is C++ and I can't convert it... what is &?
if (hit)
{
trace(hit);
//return (1 - lambda) * segment.p1 + lambda * segment.p2;
}
return null;
}//RayCast(
Here is my work in progress code. The goal is to use the startPos, endPos and other data to return a b2Vec2 which contains the exact position of the intersection so I can draw a shadow there at the end of the ray, under the player's feet.
So far the problem is converting from the manual example, which is in C++. It is hurting my head and there seems to be no AS3 version I can learn from. Forgive me for not knowing C++ well enough to convert it. The manual example is here: http://www.box2d.org/wiki/index.php?title=TestSegment
I hope someone can convert that simple example in the manual to AS3 code, then I will be able to do the rest of the work I believe...
Any help guys?