I am currently making a three-d skeleton system but the z rotation gives me weird results. The program takes the angles and subdivides the angle into sub-angles, then adds the sub-angles to the existing angle. The angle is added too the previous angle as so.
positionthreedslist[positionsthreeds.objnum-1].anglez[xcntt]=positionthreedslist[positionsthreeds.objnum-1].anglez[xcntt]+transbetweenz*numberoftimes;
next the code calls ROTATESPRITETZ2. The function ROTATESPRITETZ2 rotates the object and it children about the z axis. After the user is not pressing the mouse then it makes a animation from a previous frame to current frame as so.
void THREEDCLASS::ROTATESPRITETZ2(int spritechildx,float angle,int curframe)
{
n3dx=positionthreedslist[spritechildx-1].distancex*dbCos(angle)-positionthreedslist[spritechildx-1].distancey*dbSin(angle);
n3dy=positionthreedslist[spritechildx-1].distancex*dbSin(angle)+positionthreedslist[spritechildx-1].distancey*dbCos(angle);
n3dx=dbObjectPositionX(positionsthreeds.objnum)+n3dx;
n3dy=dbObjectPositionY(positionsthreeds.objnum)+n3dy;
dbPositionObject(spritechildx,n3dx,n3dy,dbObjectPositionZ(positionthreedslist[spritechildx-1].objnum));
dbZRotateObject(spritechildx,dbObjectAngleZ(positionsthreeds.objnum));
positionthreedslist[spritechildx-1].xpossprite[curframe]=n3dx;
positionthreedslist[spritechildx-1].ypossprite[curframe]=n3dy;
positionthreedslist[spritechildx-1].anglez[curframe]=dbObjectAngleZ(spritechildx);
}
this works for rotation about the y, and x axis
void THREEDCLASS::ROTATESPRITETY2(int spritechildx,float angle,int curframe)
{
n3dx=positionthreedslist[spritechildx-1].distancex*dbCos(angle)-positionthreedslist[spritechildx-1].distancez*dbSin(angle);
n3dz=positionthreedslist[spritechildx-1].distancex*dbSin(angle)+positionthreedslist[spritechildx-1].distancez*dbCos(angle);
n3dx=dbObjectPositionX(positionsthreeds.objnum)+n3dx;
n3dz=dbObjectPositionZ(positionsthreeds.objnum)+n3dz;
dbPositionObject(spritechildx,n3dx,dbObjectPositionY(positionthreedslist[spritechildx-1].objnum),n3dz);
dbYRotateObject(spritechildx,dbObjectAngleY(positionsthreeds.objnum));
positionthreedslist[spritechildx-1].xpossprite[curframe]=n3dx;
positionthreedslist[spritechildx-1].zpossprite[curframe]=n3dz;
positionthreedslist[spritechildx-1].angley[curframe]=dbObjectAngleY(spritechildx);
}
Right know I am only rotating about the x and y axis which seems too work fine.
ok, I found this on the web:
z' = z*cos q - x*sin q
x' = z*sin q + x*cos q
y' = y
(cos q 0 -sin q 0)
Ry(q) = (0 1 0 0)
(sin q 0 cos q 0)
(0 0 0 1)
-------------------------------------------
y' = y*cos q - z*sin q
z' = y*sin q + z*cos q
x' = x
(1 0 0 0)
Rx(q) = (0 cos q sin q 0)
(0 -sin q cos q 0)
(0 0 0 1)
-------------------------------------------
x' = x*cos q - y*sin q
y' = x*sin q + y*cos q
z' = z
( cos q sin q 0 0)
Rz (q) = (-sin q cos q 0 0)
( 0 0 1 0)
( 0 0 0 1)
--------------------------------------------
Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.