Hi guys I'm stuck on a rotation problem, the thing is I'm building a 3d menu problem, since I'm using limbs I need to point them always to the camera, but since I can have X or Y angle rotations I can't seam to achieve a perfect solution. See the code below and the pic to see what I want..
#include "DarkGDK.h"
#define StartObj 4
#define EndObj 10
float getDist(float,float,float,float, float ,float);
void rotateOn(float,float,float);
void setupMenu(int,int,float,float,float);
int focusObj = 4;
float cameraX = 0.0f;
float camAngleX = 270.0f;
float camAngleY = 270.0f;
void DarkGDK ( void )
{
dbSetDisplayMode (1024,768,32);
dbSetWindowPosition(dbScreenWidth()/2-dbScreenWidth()/3,dbScreenHeight()/2-dbScreenHeight()/3);
dbAutoCamOff();
dbSetAmbientLight(50);
dbSyncOn();
dbSyncRate(60);
dbSetGlobalCollisionOff();
dbBackdropOn();
dbColorBackdrop(0);
//Mars
dbLoadImage("Teste\MarsTexture.jpg",1,1);
//Menu IMG
dbLoadImage("Teste\test.dds",3,1);
//Mars
dbMakeObjectSphere(4,5,100,100);
dbTextureObject(4,0,1);
dbSetObjectFilter(4,2);
dbFadeObject(4,120);
//Menu
setupMenu(5,EndObj,0.0f,0.0f,5.0f);
dbTextureObject(5,0,3);
dbSetObjectTransparency(5,1);
dbPositionCamera(0,dbObjectPositionX(focusObj),dbObjectPositionY(focusObj),dbObjectPositionZ(focusObj)+dbObjectSize(4)*3.0f);
dbPointCamera(0,dbObjectPositionX(focusObj),dbObjectPositionY(focusObj),dbObjectPositionZ(focusObj));
while (LoopGDK() )
{
dbSetCursor(0,0);
dbPrint((double)dbObjectPositionX(5));
dbPrint((double)dbObjectPositionY(5));
dbPrint((double)dbObjectPositionZ(5));
//dbPrint((double)dbScreenFPS());
if(dbUpKey()==1)
dbPositionObject(5,dbObjectPositionX(5),dbObjectPositionY(5)+.125f,dbObjectPositionZ(5));
if(dbDownKey()==1)
dbPositionObject(5,dbObjectPositionX(5),dbObjectPositionY(5)-.125f,dbObjectPositionZ(5));
if(dbLeftKey()==1)
dbPositionObject(5,dbObjectPositionX(5)-.125f,dbObjectPositionY(5),dbObjectPositionZ(5));
if(dbRightKey()==1)
dbPositionObject(5,dbObjectPositionX(5)+.125f,dbObjectPositionY(5),dbObjectPositionZ(5));
if(strcmp(dbInKey(),"a")==0)
{
//dbRotateObject(5,dbObjectAngleX(5),dbObjectAngleY(5)+.5f,dbObjectAngleZ(5));
dbTurnObjectLeft(5,.5f);
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,0.0f,dbLimbAngleY(5,i)+.5f,0.0f);
//dbRotateLimb(5,i,0.0f,180.0f-dbObjectAngleY(5),0.0f);
}
if(strcmp(dbInKey(),"d")==0)
{
/* dbRotateObject(5,dbObjectAngleX(5),dbObjectAngleY(5)-.5f,dbObjectAngleZ(5));
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,0.0f,180.0f-dbObjectAngleY(5),0.0f);*/
dbTurnObjectRight(5,.5f);
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,0.0f,dbLimbAngleY(5,i)-.5f,0.0f);
}
if(strcmp(dbInKey(),"w")==0)
{
/*dbRotateObject(5,dbObjectAngleX(5)-.25f,dbObjectAngleY(5),dbObjectAngleZ(5));
//dbXRotateObject(5,dbObjectAngleX(5)-.25f);
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,360.0f-dbObjectAngleX(5),0.0f,0.0f);*/
dbPitchObjectUp(5,.5f);
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,dbLimbAngleX(5,i)+.5f,0.0f,0.0f);
}
if(strcmp(dbInKey(),"s")==0)
{
dbPitchObjectDown(5,.5f);
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,dbLimbAngleX(5,i)-.5f,0.0f,0.0f);
/* //dbXRotateObject(5,dbObjectAngleX(5)+.25f);
dbRotateObject(5,dbObjectAngleX(5)+.25f,dbObjectAngleY(5),dbObjectAngleZ(5));
for(int i=1;i<=EndObj;i++)
dbRotateLimb(5,i,360.0f-dbObjectAngleX(5),0.0f,0.0f);*/
}
dbSync();
}
}
void setupMenu(int id,int limbNumber,float x,float y,float z)
{
float dist = 1.0f;
float angle = 0.0f;
dbMakeObjectPlain(id,0.3f,0.3f);
//dbHideLimb(id,0);
dbPositionObject(id,dbCameraPositionX(),dbCameraPositionY(),dbCameraPositionZ());
dbLockObjectOn(id);
dbPositionObject(id,x,y,z);
dbMakeObjectPlain(101,.5f,.5f);
dbMakeMeshFromObject(1,101);
for(int limbID = 1;limbID<=limbNumber;limbID++)
{
angle += 360.0f/limbNumber;
dbAddLimb(id,limbID,1);
dbOffsetLimb(id,limbID,dist*dbCos(angle),0.0f,dist*dbSin(angle));
}
}
EDIT: I decide to change my aproach to the problem