Hi I'm having a few problem with the limb rotation, I need to rotate an object and at the same time rotate and offset its limb, so that it always shows is face to the camera. I've already made those functions my problem is that when the rotation is turn off, the offset changes accordingly to the angle of the light, problem is when I turn on the rotation, the offset it's not any more sync with the angle.
bool updateCamFlag = false;
float dist = 0.0f;
float scaleX = 0.0f;
float scaleY = 0.0f;
float cameraX = 0.0f;
void update_planets(int);
float distObjCam(float ,float ,float );
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);
dbLoadImage("Teste\\MarsMap_2500x1250.jpg",4,1);
dbLoadImage("Teste\\Earth1.dds",5,1);
dbLoadImage("Teste\\starmap.jpg",6,1);
dbLoadImage("FX\\marsHalo256.bmp",7,1);
dbLoadImage("FX\\earthHalo256.bmp",8,1);
//Mars
dbMakeObjectSphere(4,5,100,100);
dbTextureObject(4,0,4);
dbHideLight (0);
dbMakeLight(1);
dbSetLightRange(1,5000);
dbColorLight(1,dbRGB(255,255,255) );
dbPositionLight (1,80.0f,0.0f,5.0f);
dbSetSpotLight(1,360.0f,0.0f);
int obj = 4;
cameraX=-45.0f;
float zoom=dbObjectSize(obj)*3.0f;
dbSetCurrentCamera(0);
while (LoopGDK() )
{
dbSetCursor(0,0);
dbPrint((float)dbScreenFPS());
dbPrint((float)dbWrapValue(cameraX));
dbPrint((float)3 * dbSin(dbWrapValue(cameraX)));
dbPositionCamera(0,dbObjectPositionX(obj),dbObjectPositionY(obj),dbObjectPositionZ(obj)+zoom);
dbPointCamera(0,0.0f,0.0f,0.0f);
/*if(dbLeftKey()==1)
cameraX+=.75f;
if(dbRightKey()==1)
cameraX-=.75f;*/
cameraX= dbWrapValue(cameraX+.55f);
dbPositionLight (1, dbSin(cameraX)*zoom +dbObjectPositionX(1),0.0f,dbCos(cameraX)*zoom+dbObjectPositionZ(1));
dbSetLightToObjectPosition (1,2);
if(dbUpKey()==1)
dbRotateLimb(obj,1,dbLimbAngleX(obj,1)+.75f,0,0);
if(dbDownKey()==1)
dbRotateLimb(obj,1,dbLimbAngleX(obj,1)-.75f,0,0);
if(strcmp(dbInKey(),"s")==0)
{
zoom+=.25f;
//para n se estar sempre a calcular a distancia
updateCamFlag = true;
}
if(strcmp(dbInKey(),"w")==0 && zoom > dbObjectSize(obj)*3.0f)
{
zoom-=.25f;
//para n se estar sempre a calcular a distancia
updateCamFlag = true;
}
update_planets(4);
dbSync();
}
}
void update_planets(int focus)
{
//HALO Scale Adjust
if(updateCamFlag)
{
dist = distObjCam(dbObjectPositionX(focus),dbObjectPositionY(focus),dbObjectPositionZ(focus));
float m = (0.0f - dbObjectSize(focus)*3.0f)/(143.0f - 135.0f);
float b = -m * 143.0f;
scaleX = (dist - b )/ m;
m = (0.0f - dbObjectSize(focus)*3.0f)/(105.0f - 101.5f);
b = -m * 105.0;
scaleY = (dist - b )/ m;
dbScaleLimb(focus,1,scaleX,scaleY,100.0f);
updateCamFlag = false;
}
//Planet & Halo Rotation
dbYRotateObject(focus,dbWrapValue(dbObjectAngleY(focus)+.2f));
dbRotateLimb(focus,1,dbWrapValue(360.0f-dbCameraAngleX()),dbWrapValue(180.0f+dbCameraAngleY()-dbObjectAngleY(focus)),dbCameraAngleZ());
//Halo Position Adjust
float offset = dbObjectSize(focus)/15.0f;
dbOffsetLimb(focus,1, offset* dbSin(cameraX),0,offset* dbCos(cameraX));
}
float distObjCam(float x,float y,float z)
{
float x1 = pow((dbCameraPositionX() - x),2);
float y1 = pow((dbCameraPositionY() - y),2);
float z1 = pow((dbCameraPositionZ() - z),2);
return sqrt(x1 + y1 + z1);
}