0
\$\begingroup\$

I'm coding a VR application that allows the user to point the controller at an object (there's a "laser" the extends from the front of the controller and is used in hit testing) and adjust its position, orientation, and scale. When pointing at an object, the trigger allows the user to drag the object around the room, left or right on the joystick causes the object to rotate around its local y-axis, and up or down on the joystick adjusts scale (around the point on the object where the laser hits).

In isolation, I am able to get all of the operations to work correctly. However, when I attempt to combine them all or have multiple consecutive operations things go wrong. For example, if I scale the object, it then doesn't track with the laser when translating. Or when I translate the object, it no longer rotates around the center of the object or scales around the point that the laser hits.

My current approach is this:

On each update: if first update: Save the objects current transform Save the hit location (where on the object the laser hit) Create a transform for the current operation (i.e. if scaling, translate the hit point to the origin, adjust the scale, and then translate back to the hit point) Multiply the previous transform by the new transform, and apply it to the object 

I feel like I'm fundamentally misunderstanding how to iteratively apply transformations. Is this the correct approach? Or do I need to keep track of separate translations/rotations/scales and combine them at the end?

Edit - I am now keeping track of rotation, translation, and scale separately, and then combining them to get the final transformation matrix:

m = translation * rotation * scale

However, when I do multiple operations I start to see the object jump. For example:

  1. Scale the object from 1x to 2x around the center point of the object - so a translation (to the center point) * scale * -translation.
  2. Translate the object on the y-axis by 10.
  3. Scale the object from 2x to 3x (again around the center).

As soon as the second scale occurs, the object jumps on the y-axis. I believe this is because I am now essentially applying a scale from 1x to 3x around a point that has been translated by 10 on the y-axis.

Again, I feel like I have a fundamental misunderstanding as to how to apply multiple consecutive transformations to an object.

\$\endgroup\$
2
  • \$\begingroup\$ "Do I need to keep track of separate translation/rotation/scale and combine them at the end?" yes - see this past Q&A explaining how game engines store the source translation, rotation, and scale components of a transformation as the source of truth, and re-generate the transformation matrix from those values when they've been changed. \$\endgroup\$ Commented Apr 10 at 19:48
  • \$\begingroup\$ Thank you for the reply! I've implemented a system where rotation, translation, and scale are stored separately and then combined to form the final transformation matrix. However, I'm now seeing objects jump when I do consecutive operations. Please see the question edit. \$\endgroup\$ Commented May 9 at 22:12

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.