Академический Документы
Профессиональный Документы
Культура Документы
package Box2D.Collision.Shapes{
import Box2D.Common.Math.*;
import Box2D.Common.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Common.b2internal;
use namespace b2internal;
/**
* An edge shape.
* @private
* @see b2EdgeChainDef
*/
public class b2EdgeShape extends b2Shape
{
/**
* Returns false. Edges cannot contain points.
*/
public override function TestPoint(transform:b2Transform, p:b2Vec2) :
Boolean{
return false;
}
/**
* @inheritDoc
*/
public override function RayCast(output:b2RayCastOutput,
input:b2RayCastInput, transform:b2Transform):Boolean
{
var tMat:b2Mat22;
var rX: Number = input.p2.x - input.p1.x;
var rY: Number = input.p2.y - input.p1.y;
return false;
}
/**
* @inheritDoc
*/
public override function ComputeAABB(aabb:b2AABB, transform:b2Transform) :
void{
var tMat:b2Mat22 = transform.R;
//b2Vec2 v1 = b2Mul(transform, m_v1);
var v1X:Number = transform.position.x + (tMat.col1.x * m_v1.x +
tMat.col2.x * m_v1.y);
var v1Y:Number = transform.position.y + (tMat.col1.y * m_v1.x +
tMat.col2.y * m_v1.y);
//b2Vec2 v2 = b2Mul(transform, m_v2);
var v2X:Number = transform.position.x + (tMat.col1.x * m_v2.x +
tMat.col2.x * m_v2.y);
var v2Y:Number = transform.position.y + (tMat.col1.y * m_v2.x +
tMat.col2.y * m_v2.y);
if (v1X < v2X) {
aabb.lowerBound.x = v1X;
aabb.upperBound.x = v2X;
} else {
aabb.lowerBound.x = v2X;
aabb.upperBound.x = v1X;
}
if (v1Y < v2Y) {
aabb.lowerBound.y = v1Y;
aabb.upperBound.y = v2Y;
} else {
aabb.lowerBound.y = v2Y;
aabb.upperBound.y = v1Y;
}
}
/**
* @inheritDoc
*/
public override function ComputeMass(massData:b2MassData, density:Number) :
void{
massData.mass = 0;
massData.center.SetV(m_v1);
massData.I = 0;
}
/**
* @inheritDoc
*/
public override function ComputeSubmergedArea(
normal:b2Vec2,
offset:Number,
xf:b2Transform,
c:b2Vec2):Number
{
// Note that v0 is independant of any details of the specific edge
// We are relying on v0 being consistent between multiple edges of the
same body
//b2Vec2 v0 = offset * normal;
var v0:b2Vec2 = new b2Vec2(normal.x * offset, normal.y * offset);
//b2Vec2 e1 = v1 - v0;
//b2Vec2 e2 = v2 - v0;
//return 0.5f * b2Cross(e1, e2);
return 0.5 * ( (v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x -
v0.x) );
}
/**
* Get the distance from vertex1 to vertex2.
*/
public function GetLength(): Number
{
return m_length;
}
/**
* Get the local position of vertex1 in parent body.
*/
public function GetVertex1(): b2Vec2
{
return m_v1;
}
/**
* Get the local position of vertex2 in parent body.
*/
public function GetVertex2(): b2Vec2
{
return m_v2;
}
/**
* Get a core vertex in local coordinates. These vertices
* represent a smaller edge that is used for time of impact
* computations.
*/
public function GetCoreVertex1(): b2Vec2
{
return m_coreV1;
}
/**
* Get a core vertex in local coordinates. These vertices
* represent a smaller edge that is used for time of impact
* computations.
*/
public function GetCoreVertex2(): b2Vec2
{
return m_coreV2;
}
/**
* Get a perpendicular unit vector, pointing
* from the solid side to the empty side.
*/
public function GetNormalVector(): b2Vec2
{
return m_normal;
}
/**
* Get a parallel unit vector, pointing
* from vertex1 to vertex2.
*/
public function GetDirectionVector(): b2Vec2
{
return m_direction;
}
/**
* Returns a unit vector halfway between
* m_direction and m_prevEdge.m_direction.
*/
public function GetCorner1Vector(): b2Vec2
{
return m_cornerDir1;
}
/**
* Returns a unit vector halfway between
* m_direction and m_nextEdge.m_direction.
*/
public function GetCorner2Vector(): b2Vec2
{
return m_cornerDir2;
}
/**
* Returns true if the first corner of this edge
* bends towards the solid side.
*/
public function Corner1IsConvex(): Boolean
{
return m_cornerConvex1;
}
/**
* Returns true if the second corner of this edge
* bends towards the solid side.
*/
public function Corner2IsConvex(): Boolean
{
return m_cornerConvex2;
}
/**
* Get the first vertex and apply the supplied transform.
*/
public function GetFirstVertex(xf: b2Transform): b2Vec2
{
//return b2Mul(xf, m_coreV1);
var tMat:b2Mat22 = xf.R;
return new b2Vec2(xf.position.x + (tMat.col1.x * m_coreV1.x +
tMat.col2.x * m_coreV1.y),
xf.position.y + (tMat.col1.y * m_coreV1.x +
tMat.col2.y * m_coreV1.y));
}
/**
* Get the next edge in the chain.
*/
public function GetNextEdge(): b2EdgeShape
{
return m_nextEdge;
}
/**
* Get the previous edge in the chain.
*/
public function GetPrevEdge(): b2EdgeShape
{
return m_prevEdge;
}
/**
* @private
*/
public function b2EdgeShape(v1: b2Vec2, v2: b2Vec2){
super();
m_type = e_edgeShape;
m_prevEdge = null;
m_nextEdge = null;
m_v1 = v1;
m_v2 = v2;
m_cornerDir1 = m_normal;
m_cornerDir2.Set(-m_normal.x, -m_normal.y);
}
/**
* @private
*/
b2internal function SetPrevEdge(edge: b2EdgeShape, core: b2Vec2, cornerDir:
b2Vec2, convex: Boolean): void
{
m_prevEdge = edge;
m_coreV1 = core;
m_cornerDir1 = cornerDir;
m_cornerConvex1 = convex;
}
/**
* @private
*/
b2internal function SetNextEdge(edge: b2EdgeShape, core: b2Vec2, cornerDir:
b2Vec2, convex: Boolean): void
{
m_nextEdge = edge;
m_coreV2 = core;
m_cornerDir2 = cornerDir;
m_cornerConvex2 = convex;
}
};