# How to calculate/structure/define rotation vector for OpenGL / WebGL

I am trying to define the buffer data for WebGL and want to have in there something that encodes the fact that an object might be rotating. So it makes me think of angular momentum. So if you have something like that, like the angular momentum or some other rotation "vector" or something, you could use that to calculate a rotation matrix, and then go from there.

The problem is I don't know what that rotation thing is, angular momentum or something else. I keep searching rotation vector, but I'm not sure that's it. Wondering if you have any suggestions on how to have rotation encoded (the rotation force), before it is in a matrix form. This is just for 2D rotation.

• Hi, I've seen some of your previous questions, and while what you're asking is possible, I feel like there is a problem in your workflow that might be easier to solve. Do you have access to the 3dsMax source files for your scene? – Jay Mar 15 '19 at 8:47

In 2D it suffices to track a single angle value.

If you want to animate rotation over time, you can include both an angle and an angular velocity, both signed scalars.

float currentAngle = initialAngle + time * angularVelocity;

float s = sin(currentAngle);
float c = cos(cutrentAngle);


In tandem with a local scale vector $$\ \vec S\$$ and translation vector $$\ \vec T \$$, your transformation matrix can be...

$$\begin{bmatrix}S_x \cdot c & -S_y \cdot s & T_x \\S_x \cdot s & S_y \cdot c & T_y \\ 0 & 0 & 1\end{bmatrix}$$

(Or, if you multiply your vectors on the other side, use the transpose of this instead)

Because this entails re-computing trig functions every time you construct this matrix, it's also common to pre-compute the matrix and set it as a shader uniform or buffer input rather than reconstruct it from the angle in every shader invocation, where practical.