Again in having problems since i need relative positions.
I'm working in a dinamyc camera controlled by the user with the second stick of the playstation2 joypad.
Right now i can read the position of the stick but if i apply those values directly to the position of the car the values are apply in real world coordinates. And so the camera it not well aligned with the car.
I mean, having:
SSX ( second stick x value)
SSY ( second stick y value)
CAR (NAME OF THE MAIN ELEMENT OF THE CAR)
How can i get the desired effect?
I have made a new function to do this but it's not working properly. Really it's a hack of another function.
Here it goes:
Code:
void raydium_camera_follow_element_name(char *name, GLfloat tension,GLfloat dx,GLfloat dy)
{
//put in the headers
GLfloat basetension;
//vars
GLfloat *pos;
GLfloat mpos[3];
GLfloat *vel;
GLfloat cam[3];
basetension=2.f;
// get element position
pos=raydium_ode_element_pos_get_name(name);
vel=raydium_ode_element_linearvelocity_get_name(name);
// get position of camera in world coords
raydium_ode_element_RelPointPos_name(name,-1,0,0,cam);
// correct z pos (always at top of the car, for example)
cam[2]=pos[2]+0.4;
mpos[0]=pos[0]+vel[0];
mpos[1]=pos[1]+vel[1];
mpos[2]=pos[2]+vel[2];
//raydium_camera_replace();
raydium_camera_smooth(cam[0]-dx*2,cam[1]-dy,cam[2],mpos[1],-mpos[2],mpos[0],
70-(vel[0]+vel[1]+vel[2]),0,raydium_frame_time*tension/0.5);
}