2
votes

What I am attempting to do is set up a relative coordinate system. What it does is take in the XYZ coordinates of point A. Then it should translate that position over point B to get the position of point C, point B can rotate and translate on all three axes, but point A only translates, doesn't rotate.

Basically whats happening is you have 2 rectangles, one with the lower left hand corner being at the origin, and one with the lower left hand corner being point B. If at the top right corner of the first rectangle is Point A, then at the top right corner of the second rectangle is Point C, and no matter how that second rectangle rotates or translates, then point C will always be on the top right corner of the second rectangle. But if point A moved to say the lower right hand corner, then Point C would always be at the lower right corner of the second rectangle.

I have tried multiple times to evaluate the correct expression and what I came up with I thought was close. I had some variations of:

X': Xcos(pitch) - Zcos(pitch) + Xcos(yaw) + Ysin(yaw) + X.pointB

Y': Ycos(yaw) + Xsin(yaw) + Ycos(roll) + Zsin(roll) + Y.pointB

Z': Ysin(roll) + Zcos(roll) + Xsin(pitch) + Zcos(pitch) + Z.pointB

Where the XYZ's in the equation are the coordinates of point A, The Pitch, Yaw, and Rolls are the angles (in degrees) of the second rectangle.

1
A diagram would explain better than a hundred words :)Ani
Yes, it is hard to follow your presentation. Try stepping back and explaining in completely different terms: what is it that you're trying to accomplish?comingstorm
In a game I have a character on a stationary platform, and then on an identical platform is a projection of that actor. That identical platform will be able to move in all directions, as well as rotate on all axes. But that projection should still remain in the same location relative to the player. I can only define the projection's location using XYZ and trig, so what I need to do is convert the XYZ of the player to XYZ coordinates relative to the second platform. The transformation part is simple, I just add the XYZ of the player to the platform's XYZ, but the rotation is more difficult.Josiahms

1 Answers

3
votes

The usual way to represent rotation and translation together is to use homogeneous coordinate vectors and 4x4 transformation matrices. Multiplying a vector by the matrix performs the rotation and translation at the same time; and multiplying two matrices gives you a new matrix that performs the two operations in sequence, which is what you want for your problem. This is basic computer graphics math (but it is useful for geometry and physics as well...).

It may seem redundant or even wasteful to represent your vectors and matrices this way, but it makes the math and the programming simpler. Once you understand how the math works, and have working code, you can go back and optimize away redundant data if you want; however, you may find it isn't worth the effort.


The formulas from your question won't work -- you need to decide what order you want to apply the yaw, pitch and roll, generate appropriate X-, Y-, and Z- rotation matrices, and multiply them together in that order (the link gives you examples of the individual rotation matrices as well as the combined rotation matrix).

The translation matrix is much simpler than computing the rotation matrix. Multiplying translation matrices basically just adds the translation vectors together, but when rotations come into the picture, you see the advantage of the system: the order of translations and rotations matters, and matrices make it easy to get things right every time.


Finally, to actually solve your problem:

  • compute the combined rotation/translation matrix for your character on the stationary platform. (ideally, you should use this matrix to draw the original character)
  • compute the combined rotation/translation matrix for the "projected" platform (which can also be used to draw the projected platform)
  • multiply the two matrices together to determine the correct matrix for the "projected" character

Note that the only trigonometry needed is taking the sin() and cos() of the original roll/pitch/yaw angles.