3d soft engine - is my rotation correct?

writing my own 3d rendering engine and, after finishing my triangle rasterizing algo i noticed something unusual -

i'm using windows timer() for the framerate to call a simple routine that rotates and renders my aa triangle. my triangle class has functions for rotate x, rotate y, and rotate z.

i've used povray et c. for almost two decades and done a bit of 3d rotation in c++ before for a 3d perlin noise > sphere terrain generator, so i thought i was "conceptually empowered to handle 3d".

when i apply one rotate function, the output is very predictable - the triangle sweeps around the selected axis. (it's positioned away from the pole and so passes through a roughly toroidal region of space).

next i applied two rotate functions, eg. a rotate x then a rotate y. i was anticipating that if i used non-harmonically related rate values (i've done a lot of audio coding and have my favourite "inharmonic" ratios) then the triangle would spin "like your typical 3d spinning wireframed cube demo rotation", but instead it locks into a single, repeating orbit tilted according to the ratio of the two rates.. eg. if the rates are the same then it is 45 degrees between the two poles.

this sort of makes sense to me, since the two rotations i guess describe a vector, and perhaps a constant rotation vector always indicates a fixed orbit.. but i was expecting that it would spin the triangle around so that it could be viewed from many angles, if you see what i mean.


so, is my implementation right and my preconception wrong, or the other way around?

i am not using quaternions for rotation, i haven't bothered to fully absorb the concept yet as sequential application of 2d rotations worked fine in povray and my previous 3d implementations..
Last edited on
So your rotation works basically like this?
1
2
3
4
while (1){
    triangle = rotate_y(rotate_x(triangle, ratex), ratey);
    render(triangle);
}
I would expect that will yield a very strange path.

To get something like a triangle that rotates in place you should do
1
2
3
4
5
6
7
8
9
10
initial_triangle = /*...*/;
//initial_triangle should have its corners about the origin.
double anglex = 0, angley = 0;
while (1){
    triangle = rotate_y(rotate_x(initial_triangle, anglex), angley);
    anglex += ratex;
    angley += ratey;
    triangle = displace(triangle, center_of_screen);
    render(triangle);
}
helios tyvm for saving me hours of semi-conscious labour, you're very right, it needs a state vector :p

i think i'd vaguely contemplated this at some half asleep moment..
Topic archived. No new replies allowed.