How to set the (local) rotation of ofNode

Hello! ITrying to get hang of moving things around in oF. After their position has been set, I want to rotate some ofSpherePrimitives (whose mesh I’m also altering).

If I do this:
//…calculations for position, color, etc.
sphere.setPosition(x, y, z);
ofRotateZRad(-angleI * m_rotation);
ofRotateXRad(-angleJ * m_rotation);

… The spheres aren’t rotated around their own center, but seemingly around 0,0,0, acting as a parent.

If I instead do:
sphere.setPosition(x, y, z);
sphere.rotateRad(angleI, ofVec3f(0, 0, 1));
sphere.rotateRad(angleJ, ofVec3f(1, 0, 0));

…the spheres DO rotate around their own center. However, they keep getting rotated every frame, whereas I want them to just stay at the same rotation. I guess I could do the above in setup(), but then I can’t dynamically change the amount of spheres (since that involves recalculating their positions and angles).

Also, on a related note. When using methods like rorateRad(), do I need to multiply values by PI, or can I just put in numbers in the range of 0 - 6?

Hi, I’m currently solving a similar problem. You might want to use setOrientation() method, you will just have to figure out the euler/quaternion rotation!

1 Like

Hey, thanks for your reply. Yeah, I’ve tried that method and it seems to have an overload that takes an euler as a vec3

sphere.setOrientation(ofVec3f(angleI, 0, angleJ));

but it doesn’t do anything.

well if you keep on calling that on every frame it will certainly will keep on rotating. Just call it when you need to rotate. It is a cumulative method, it adds to whatever rotation there is.
Otherwise, you can use sphere.setOrientation which will set it to a specific orientation. I prefer using quaternions as the euler angles have some inherent issues.

glm::vec3 axis(0, 1 , 0);// the axis around which you want to rotate
glm::quat q = glm::angleAxis(ofDegToRad(degrees), axis);


yes, it takes angles in radians , so you dont need to multiply by PI.