Difference between Camera.translate and Matrix.preTranslate or Matrix.postTranslate?

We use Camera to do 3D transformations in canvas. Usually we rotate the camera and get its Matrix, and then translate it. But the camera also has translate . The results of using the methods are different.

My question is: What is the difference between Camera.translate and Matrix.preTranslate or Matrix.postTranslate?

+6
source share
2 answers

The reason they exist is because matrix multiplication must be performed in a certain order to achieve the correct result (as you already know).

The sequence of translations / turns / scales is performed in the reverse order as they are entered.

So, if you do something like this:

Camera.rotate(15, 0, 0); Camera.scale(.5f, .5f, .5f); Camera.translate(70, 70, 70); 

You first translate 70.70.70, then scale it by 50% in all directions, then rotate it 15 degrees around the X axis.

So Matrix has pre and post translate (well, pre and post all), because maybe you want to actually rotate it 15 degrees first, then translate it, and then finally scale it.

So the answers to pre and post are translated. Now the reason the camera has a direct rotation and translation is for people who know how it works already (for example, me!), So I never use Matrix or Camera, because I can just perform my rotations and translations directly on canvas. You can take too long, as long as you know that translations, scales and rotations are performed in the reverse order.

Also, if you know what I told you, it gives you more strength. You can make a sequence of 10 matrices without surrounding them in several Matrix objects for each of them (for example, you want to make a swing motion that swings out and rotates around the center to simulate centrifugal force). This needs to be done with a few rotations and translations (surrounded by many Matrix objects being passed to each other), but if you know how each translation works, you can simply do a series of .translate () ,. rotate (), and .scale ( )

This information is especially useful if you have ever done 3D graphics, because when these matrices give people headaches.

Hope this helps!

+4
source

The result will be visually the same if you do not touch the canvas, but rotate the camera 90 degrees or hold the camera still, but rotate the canvas, which it looks at -90 degrees.

+1
source

All Articles