# How to rotate something around a fixed point WebGL

I have created a simple robot in webgl with cubes and now i want to rotate one "leg" around a point. But the leg is rotating around its origin. I want to rotate it around the point that connects with the body. I dont understand how to do it. How i am supposed to use translations and rotations outside of a push/pop when these translations will change the center of the world for the cubes i want to draw later on?? A little help would be appreciated. Thanks.

• This is a common task in manipulating 3D scenes that has been discussed several times. It may be helpful to review existing answers to see if they can get you on the right track. Commented Mar 26, 2017 at 15:42
• I checked them but still im confused. Do you have any experience about this? Thanks in advance. Commented Mar 26, 2017 at 21:22
• The abstract is that you apply a translation transformation to the center of rotation, then the rotation transformation and then the inverse of the translation transformation you did before. Also, you want to rotate the object first, then place it on the world. And finally if you express the transformations as matrices, you can combine them by matrix multiplication (that way you don't need push and pop). Btw, if want to direct a message to somebody use "@" and the name, that way that person gets a notification. Commented Mar 26, 2017 at 22:44

One way is using a matrIx stack

https://webglfundamentals.org/webgl/lessons/webgl-2d-matrix-stack.html

Basically you need to translate the object so it's center point is at the origin, rotate, then translate it back

push();
rotateY(frameCount*0.01);
translate(-100, 0, 0);
sphere(10);
pop();


This is literally your entire code, this is literally ALL you need, that link in the other answer is almost entirely useless. This code will do the job.

• This answer could benefit from an explanation of what the code you posted does.
– user35344
Commented Jan 5, 2018 at 10:21