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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Mar 26, 2017 at 15:42
  • \$\begingroup\$ I checked them but still im confused. Do you have any experience about this? Thanks in advance. \$\endgroup\$ Commented Mar 26, 2017 at 21:22
  • \$\begingroup\$ 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. \$\endgroup\$
    – Theraot
    Commented Mar 26, 2017 at 22:44

2 Answers 2


One way is using a matrIx stack


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

translate(-100, 0, 0);

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .