General axis rotation is very simple with quaternions.

Please log in or register to post a reply.

To make myself clearer, you just a) create the quaternion b) declare
the rotation c) convert it to a matrix and Ive got it?

@rouncer

Can someone give me the simple implementation then? :) please?

http://topmost.se/personal/programming/3dmath.zip

There you go.

It’s pretty much a vanilla C++ implementation of vector, matrix and quaternion mathematics. What’s special about this implementation is the matrix class, which is OpenGL compatible, and that vectors are multiplied by matrices, not the other way around.

Thanks everyone. Maybe if I was a genius like you .oisyn…

```
void set_rot_axis(float a, vector axis)
{
axis.normalize();
float c=(float)Math.cos(a);
float s=(float)Math.sin(a);
float t=1.0f-(float)Math.cos(a);
this.m[0][0]=(t*axis.x*axis.x)+c;this.m[1][0]=t*axis.x*axis.y+s*axis.z;this.m[2][0]=t*axis.x*axis.z-s*axis.y;this.m[3][0]=0;
this.m[0][1]=t*axis.x*axis.y-s*axis.z;this.m[1][1]=t*axis.y*axis.y+c;this.m[2][1]=t*axis.y*axis.z+s*axis.x;this.m[3][1]=0;
this.m[0][2]=t*axis.x*axis.y+s*axis.y;this.m[1][2]=t*axis.y*axis.z-s*axis.x;this.m[2][2]=t*axis.z*axis.z+c;this.m[3][2]=0;
this.m[0][3]=0;this.m[1][3]=0;this.m[2][3]=0;this.m[3][3]=1;
}
```

Thank you drive through. lol

When it comes to rotating things decently, you have to have the general axis rotate, you cant do anything with skeletons without it.

I downloaded that math library anyway, probably proove useful. thanks.

@rouncer

Maybe if I was a genius like you .oisyn…

Well I’m certainly no genius, but I also wasn’t being a smug either if perhaps that’s what you think :)

No, I was serious. Everyone with a *bit* of math skills, which I
assume you have *at least* given the projects that you undertake, should
be able to write down what actually happens to all the 4 components of
the quaternions in the equation. In the end, you want to have them as

r = q * p * q-1

r.x = p.x * … + p.y * … + p.z * … + p.w * …

r.y = …

r.z = …

r.w = …

And hey, that looks exactly like a vector-matrix multiplication, with p being the vector input, the coefficients of the components of p being the matrix you actually want to know, and r being the vector result.

Naturally, if you have written this down you still want to take an existing implementation because an error would be hard to track down :), but I find that these kinds of things really help you understand the mathematical constructs you actually use but have always been abstracted away because you were using prefab textbook functions B). And when you learn how things work, you’ll learn to use those functions better and more efficiently.

Im actually serious when I call you a genius.

It doesnt matter how full on a guy gets into technical details, hes always too modest to say hes quite good at what he does, in fact, better than a lot of others.

Everythings easy in the end, its just a matter of how much you managed to pack inside your head to date, which makes you a genius or not… and you sir are a damn genius!

That truly is amazing. thankyou.

- Upcoming Multiplatform Game Program...
- Our first game - looking for feedbacks
- Network Emulation Tool
- Trouble with accessing GLSL array
- Fiction
- Game Programming Patterns: Bytecode
- Interactive WebGL Water Demo
- Skeletal Animation Tutorial with GP...
- Unreal Engine 4
- Microsoft xbox one selling poorly

I read on the internet that this can be accomplished by a few x y and z rotations and a couple of translations.

An algorithm (see Figure 1):

(1) translate space so that the rotation axis passes through the origin

(2) rotate space about the $ z$ -axis so that the rotation axis lies in the $ xz$ -plane

(3) rotate space about the $ y$ -axis so that the rotation axis lies along the $ z$ -axis

(4) perform the desired rotation by $ \theta$ about the $ z$ -axis

(5) apply the inverse of step (3)

(6) apply the inverse of step (2)

(7) apply the inverse of step (1)

So I could just go and type that in and just see if it works, because I cant really understand it… But I was wondering, does anyone have some C code that does this I can convert into my program- Just so I can be sure its going to work?