Hi I'm trying to make a camera to point to an object and then move toward him...problem is pointCamera points imediatly to the object so I created a little function that gets the lowest turn angle and then turns the camera to the object, I also created a function that after turning the camera moves the camera toward the object! Now I'm looking for a way of combining the two functions so that the camera moves while it turns...For that I'm calculating the angle between the camera and the object and then move foward, but my results are a bit bad I'm sending the code I've made so far:
float anguloAux = dbWrapValue(this->angle);
float left = 360.0f-anguloAux;
float xx = pow(dbObjectPositionX(obj)-dbCameraPositionX(),2);
//float yy = pow(dbObjectPositionY(obj)-dbCameraPositionY(),2);
float zz = pow(dbObjectPositionZ(obj)-dbCameraPositionZ(),2);
float dist = sqrt(xx + zz);
do
{
anguloAux = dbWrapValue(dbWrapValue(dbATANFULL(dbCameraPositionX()-dbObjectPositionX(obj),dbCameraPositionZ()-dbObjectPositionZ(obj))-dbCameraAngleY()));
xx = pow(dbObjectPositionX(obj)-dbCameraPositionX(),2);
//yy = pow(dbObjectPositionY(obj)-dbCameraPositionY(),2);
zz = pow(dbObjectPositionZ(obj)-dbCameraPositionZ(),2);
dist = sqrt(xx + zz);
char str[128];
sprintf(str,"Angulo: %f Dist: %f",anguloAux,dist);
dbText(0,60,str);
if(dist>=2.0f)
{
updateCameraAngle(-90,0,0);
dbMoveCamera(.10);
updateCameraAngle(90,0,0);
updateCameraAngle(0,1.0,0);
}
dbSync();
}
while( dist>=2.0);
void Camera::updateCameraAngle(float ax,float ay,float az)
{
this->ax = dbWrapValue(this->ax+ax);
this->ay = dbWrapValue(this->ay+ay);
this->az = dbWrapValue(this->az+az);
dbRotateCamera(this->id,this->ax,this->ay,this->az);
}