P
P
Pavel Efimov2016-03-20 13:41:06
Programming
Pavel Efimov, 2016-03-20 13:41:06

How to rotate an object by a specific angle in OpenGL?

So far, I can only rotate using glRotatef(theta, 0.1f, 0.1f, 0.0f);
I would like to learn how to rotate at a certain angle, something like this https://vk.com/videos57033099?z=video57033099_1714...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2016-03-20
@neon3

You need to learn how to apply geometric transformations to the input geometries (the vertices of your meshes).
In any case, this happens by calculating and using rotation matrices. For a mathematical background, google operations with matrices and vectors (linear algebra, computational geometry).
How to do this specifically in OpenGL depends on the API version you are using. If this is an "old" OpenGL, for example, version 2.0, then there is glRotate and other functions for operating with world and view transformation matrices. If this is OpenGL 3.0 and later, then read about vertex shaders and vertex transformations in shaders.

D
Denis Zagaevsky, 2016-03-20
@zagayevskiy

glRotatef(angle, x, y, z); rotates by angle around a vector (x, y, z). If you want to rotate about a specific axis, specify the rotation vector as follows: (1, 0, 0) - this is, for example, about the x-axis.

A
asd111, 2016-03-20
@asd111

Learn matrices and quaternions.
Roughly speaking, multiplication by a matrix is ​​a rotation.
I'm not good with quaternions. But the principle is approximately the same, it is necessary to multiply or the type of that will be a turn))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question