# please check my converted transformation from 2d

This topic is 3537 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi This is from the steering behavior code that I transformed to 3d. Can you guys check if i have done it right? Because I'm not getting the correct behavior. THere's 2 function, here is the first:
inline Vector2D PointToLocalSpace(const Vector2D &point,
Vector2D &AgentSide,
Vector2D &AgentPosition)
{

//make a copy of the point
Vector2D TransPoint = point;

//create a transformation matrix
C2DMatrix matTransform;

double Ty = -AgentPosition.Dot(AgentSide);

//create the transformation matrix
matTransform._31(Tx);           matTransform._32(Ty);

//now transform the vertices
matTransform.TransformVector2Ds(TransPoint);

return TransPoint;
}


And here's my 3d version:
        Vector3 PointToLocalSpace(Vector3 point, Vector3 forward, Vector3 right, Vector3 position)
{
//make a copy of the point
Vector3 TransPoint = point;

//create a transformation matrix
Matrix mat = Matrix.Identity;

float Tx = Vector3.Dot(position, forward);
float Ty = Vector3.Dot(position, right);

//create the transformation matrix
mat.M11 = right.X;
mat.M12 = right.Y;
mat.M13 = right.Z;

mat.M21 = 0.0f;
mat.M22 = 1.0f;
mat.M23 = 0.0f;

mat.M31 = forward.X;
mat.M32 = forward.Y;
mat.M33 = forward.Z;

mat.M41 = Tx; mat.M43 = Ty;
mat.M42 = 0.0f;

//now transform the vertices
TransPoint = Vector3.Transform(TransPoint, mat);

return TransPoint;
}


Here's the other one.
//--------------------- VectorToWorldSpace --------------------------------
//
//  Transforms a vector from the agent's local space into world space
//------------------------------------------------------------------------
inline Vector2D VectorToWorldSpace(const Vector2D &vec,
const Vector2D &AgentSide)
{
//make a copy of the point
Vector2D TransVec = vec;

//create a transformation matrix
C2DMatrix matTransform;

//rotate

//now transform the vertices
matTransform.TransformVector2Ds(TransVec);

return TransVec;
}


Here's mine
        Vector3 VectorToWorldSpace(Vector3 vec, Vector3 forward)
{
//make a copy of the point
Vector3 TransVec = vec;

Matrix matRot = Matrix.Identity;

if (forward == Vector3.Zero)
{
forward.X = 1.0f;
}
matRot = Matrix.CreateLookAt(Vector3.Zero, forward, Vector3.Up);
matRot = Matrix.Transpose(matRot);

//now transform the vertices
TransVec = Vector3.Transform(TransVec, matRot);

return TransVec;
}


thanks so much for your time. [Edited by - mickeyren on January 16, 2009 8:39:21 PM]

##### Share on other sites
Perhaps these functions does the same thing:

// Convert from point in local to world
Vector3 newTarget = Vector3.Transform(wanderTarget, entity.matWorld);

// Convert from point in world to local
Matrix invert = Matrix.Invert(entity.matWorld);
Vector3 LocalPos = Vector3.Transform(obstacles.sphere.Center, invert);

// Convert vector in local to world space
Matrix invertOrient = Matrix.Invert(entity.matRot);
invertOrient = Matrix.Transpose(invertOrient );
SeeringForce = Vector3.Transform(SteeringForce, invertOrient );

Should those be correct?

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632644
• Total Posts
3007625
• ### Who's Online (See full list)

There are no registered users currently online

×