简体   繁体   中英

How to rotate an object in processing according to yaw, pitch and roll values

I am trying to rotate an object which was imported as .obj file according to pitch and roll values.

I actually achieved this with this code

object.rotateX(ConvertToRadians(pitch));

object.rotate(ConvertToRadians(roll), 0, 0, 1); // This line is basically the same thing with rotateZ function. I used it because rotateZ gives a weird error.

However, when new pitch and roll values arrive with the socket connection and I use these lines of code. It adds to the previous rotation. To give an example, when the object is rotated around X-axis for 30 degrees and I try to make it rotate to 10 degrees. It rotates it to 40 degrees.

I tried saving the previous rotation and undoing it before giving the new rotation with this line

pieta.rotateX(ConvertToRadians(pitch-prevpitch));

It seems to work partially but after some time the original position (pitch=0 and roll = 0 is not flat anymore. It tilts to some angle. I don't know the reason). I think resetting the object's position to the original will work.

How can I achieve my aim?

This is my full code if you want to recreate it Project File

Use resetMatrix() to setup a completely new matrix in every frame:

object.resetMatrix();
object.rotateX(ConvertToRadians(pitch));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM