What this means is that drags left, right, up, and down will always move the cube in the direction that we expect. This delta will be used to rotate our accumulated rotation matrix. Every frame, calculate the delta between the last position of the pointer, and the current position of the pointer.One easy way to work around this problem is to keep a second matrix around that will store all of the accumulated rotations. If you rotate left and right from a point of zero rotation, the cube will rotate as you expect, but what if you then rotate it up or down 180 degrees? Trying to rotate the cube left or right will now rotate it in the opposite direction! The main problem with the simple way of rotating is that the object is being rotated in relation to itself, instead of in relation to the user’s point of view. How to make the rotation appear relative to the user’s point of view. We could also rotate an object around the Z axis if we wanted it to spin around. To rotate an object up or down, we rotate it around the X-axis, and to rotate an object left or right, we rotate it around the Y axis. Here is example pseudocode: tIdentity(modelMatrix) This is the easiest way to rotate an object based on touch movement. In this article, I’ll take a look at a simple way to rotate an object based on the touch events, and how to work around the main drawback of this method. Rotating an object in 3D is a neat way of letting your users interact with the scene, but the math can be tricky to get right.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |