Hello,
in monogame i have a world matrix
WorldMatrix= Matrix.CreateWorld(Vector3.Zero,Vector3.Forward,Vector3.Up)
that is used for the BasicEffect
then it can be transformed and rotated by Matrix.CreateTranslation and CreateRotationX&Y&Z
so newWorldMatrix = WorldMatrix * Trans * RotX * RotY * RotZ
Trans transforms the WorldMatrix to desired posithion “newOrigin”
while RotX * RotY * RotZ create Pitch, yaw, and roll rotation
and if i have a position “globalPos” vector from the WorldMatrix
how to calculate the equivalent of that position vector from the newWorldMatrix in it’s xyz directions
for an example if globalPos = (1,1,1) and newOrigin(0.1,1.1,0) and the rotation matrices has rotated the local world axis 90d around Y clockwise
the relativePos is (1,-0.1,-0.9)
this what i could come up with
public static Vector3 GetRelativePosition(int i, Vector3 globalPos)
{
List<Bone> BonesA = BonesList();
Transform3D boneTransform = new Transform3D();
boneTransform.rotOrder = rotOrder;
boneTransform.position = new Vector3D(BonesA[i].Translation);
boneTransform.setRotationInRad(new Vector3D(BonesA[i].Rotation));
boneTransform.scale = new Vector3D(BonesA[i].Scale);
Vector3D newOrigin = boneTransform.getGlobalOrigin();
Matrix3D parentTrans = Matrix3D.generateTranslationMatrix(newOrigin.X, newOrigin.Y, newOrigin.Z);
Matrix3D parentRot = boneTransform.getGlobalRotation();
Matrix3D boneWorld = Matrix3D.CreateWorld(new Vector3D(0, 0, 0), new Vector3D(0, 0, -1), new Vector3D(0, 1, 0)) * parentTrans * parentRot;
Vector3D relativePos = Matrix3D.matrixTimesVector3D(boneWorld, new Vector3D(globalPos.X - newOrigin.X, globalPos.Y - newOrigin.Y, globalPos.Z - newOrigin.Z));
return new Vector3((float)relativePos.X, (float)relativePos.Y, (float)relativePos.Z);
}
for more context my editor draws a skeletal hierarchy transform
Transform3D calculates the global position of every object/bone using the relative position from the hierarchy
using getGlobalOrigin() and getGlobalRotation() to calculate the position and orientation of the any opject relative to it’s parent
Matrix3D and Victor3D works in a similar way to XNA Matrix and Victor3
i want t be able to calculate the relative position from the global position so i can add more bones and position them at the global position
I cant really wrap my head around the requerd math to do this , thanks
the example upove should look like this
the new opject is drawn at (1,1,1) while it’s relative position is (1,-0.1,-0.9)