R3 rotation arround an arbitrary axis...

Started by
2 comments, last by WhatEver 23 years, 2 months ago
Does anyone know how to do this. I read the Dian Grubber artical but I don''t undertsnad those formulas, much less implimenting it in OpenGL. I want to use the method so I can start using bones in my models.
Advertisement
First you need to know how to multiply matrices, or at least know how to do it in openGL. But assuming that you already know how to do that, here is how you rotate around an arbitrary axis given by a vector

(note: this assumes the vector has a length of one)

angle = the amout of rotation (usually in radians)
v = vector that is rotated around
c = cos(angle);
s = sin(angle);
matrix[0][0] = (v.x * v.x) * (1.0f - c) + c
matrix[0][1] = (v.y * v.x) * (1.0f - c) + (v.z * s)
matrix[0][2] = (v.z * v.x) * (1.0f - c) - (v.y * s)
matrix[0][3] = 0
matrix[1][0] = (v.x * v.y) * (1.0f - c) - (v.z * s)
matrix[1][1] = (v.y * v.y) * (1.0f - c) + c
matrix[1][2] = (v.z * v.y) * (1.0f - c) + (v.x * s)
matrix[1][3] = 0
matrix[2][0] = (v.x * v.z) * (1.0f - c) + (v.y * s)
matrix[2][1] = (v.y * v.z) * (1.0f - c) - (v.x * s)
matrix[2][2] = (v.z * v.z) * (1.0f - c) + c
matrix[2][3] = 0
matrix[3][0] = 0
matrix[3][1] = 0
matrix[3][2] = 0
matrix[3][3] = 1

then you multiply the vertices by this matrix and poof you''ve just rotated an object around an arbitrary axis.
There might be an easyer way to do it in opengl but i dont know enough to help you there.
hope that helps
Wow, I''ll give it a try in OpenGL. Thank you =D

Does anyone here know how to push this into the OpenGL matrix?

Do all matrices get multiplied by each other, even the Transformation matrix?

I''m learning .
Nevermind...

This seem easy enough

void glMultMatrixf(
const GLfloat *m
);

I''m gonna have some fun with this...oh yeah...bones here I come!!!!!

This topic is closed to new replies.

Advertisement