Actually, I found a copy of Matlab running around…
I have set up all the basic rotation matrix using symbols (RotX,RotY,RotZ) and had a look at the product (actually, I had done it already by hand but I wanted to check… It’s so easy to make a mistake after the first product !).
Then, the resulting matrix was pretty easy to use but you always have this problem of :
a=sin b does not mean b=asin(a).
The real thing is :
a=sin b means b=asin(a) or b=pi-asin(a) !
That is why you need the cos (and not the absolute value of the cos !).
Then, I remembered this atan2 function that basically uses both sin and cos to find in which quadrant of the unit circle the angle is… Then you have your result between -pi and pi !!!
When you look at the matrix, you can see how easy it is to use atan2…
The first “if” statement simply avoids your X and Z to jump from 0 to 180 when you rotate around Y (just comment those lines and you will see the result !).
That is because atan2(y,x) will give two different results when y=0 :
if x>0, atan2=0;
if x<0, atan2=180;
I am using degrees but atan2 gives radians…
So, all in all, that is a good mix that does exactly what I want !!!
I now have an OpenGL MFC framework that works like 3DS Max : I can select/translate/rotate/scale objects exactly like in 3DS…
When you select an object, the axes appear and stay the same size wherever the view point is… Things like that !
The main problems I had and solved were :
- How to have non-scaling objects ? These are these objects that always have the same size independantly of the view point (in 3DS, this is used for axes/lights/cameras).
- How to rotate an object by offset or absolute position around X,Y,Z…
- How to do spherical billboards (that was for the letters X,Y and Z on the axes). I could not use the technique that was explained in the previous topic (I am not drawing a quad but a WYSIWYG font !).
Although these things seemed quite easy to solve, they were not (at all)…
I am sorry I can not post the whole source code of the application as this frame work is used to develop various programs for my company… But of course, I am always ready to help with “how to do it” and even post some snippet…
And Bob, if you are interested in trying this frame work (the frame work alone does nothing except display some objects you can play with !), please tell me and I’ll send you an executable…
Sorry for this huge post but I thought some people could be interested in the problems I solved in the past 2 weeks (I know spherical billboard is mentioned at least once a month here !).
Best regards.
Eric