Jump to content
  • Advertisement
Sign in to follow this  

Simple matrix maths...

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the current location of an object (a xyz vector) and the current rotation of the object (xyz vector x = pitch (0-360) etc). How can i "move" the position. I was trying: Translate identity matrix by the position of the object. Rotate this by rotation matrices (yaw, pitch then roll) Translate this by the amount to move by. Here is the .net code..
public void Move(float x, float y, float z)
	Matrix Movemat = new Matrix();
	Matrix Translate = new Matrix();
	Matrix Rotate = new Matrix();

	Translate = Matrix.Translation(Position);
	Rotate = Matrix.RotationYawPitchRoll(Rotation.X, Rotation.Y, Rotation.Z);
	Movemat = Matrix.Translation(x, y, z);

	Matrix Final = new Matrix();

	Final = (Translate * Rotate) * Movemat;

	Position.X = Final.M14;
	Position.Y = Final.M24;
	Position.Z = Final.M34;

Share this post

Link to post
Share on other sites

How can i "move" the position.

have you tried the + and - operators on your position?

really if you want a serious answer youll have to make clear what it is you want to do precisely.

Share this post

Link to post
Share on other sites

Final = Rotate * Translate * Movemat;

Position.X = Final.M41;
Position.Y = Final.M42;
Position.Z = Final.M43;

- If you have the position and heading of the object, you wouldn't rotate after translating. If you did it in that order, the object wouldn't be in the original position when you came to do the new translation.
Ie, rotate then translate to the original spot, then translate to the final spot.

- I dont know what Matrix functions you're using - but if its the directX ones, they take radians (your question specifies your angles in degress)

- Also, note that a 4D matrix usually has the position on the bottom row, not the right column (which you had).

- And finally, if you just sum matrices, although the positions would be correct, the angles would change (into incorrect values). You would only sum vectors (afaik)

[Edited by - Wyzfen on September 27, 2004 8:19:31 AM]

Share this post

Link to post
Share on other sites
Looks like the order of the matrices is backwards to me. Matrix multiplication is not commutative, i.e. AB!=BA as a general rule. So (Translate*Rotate)*Movemat!=Movemat*(Rotate*Translate). It is associative though so Movemat*(Rotate*Translate)=(Movemat*Rotate)*Translate. Since it looks like the last column is your translation vector you want (Movemat*Rotate)*Translate. Look at the Translate*[0 0 0 1]^T. The product is the last column of Translate. [0 0 0 1]*Translate on the other hand is the last row of Translate.

You shouldn't place your position into a matrix. Rather just use T*p where p is your position vector and T is your composite transform matrix. That is what the last column is. Calculating the rest of the columns is just a waste of resources. When you are transforming hundreds of vertices of an object and doing that for lots of objects doing four times the work required starts adding up.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!