Advertisement

Finding Camera Front

Started by August 11, 2014 02:12 AM
1 comment, last by iHakan4s 10 years, 5 months ago

I just tried to find front position of the camera. Rotation based and I've tried this method: (OpenGL)


x = x +- cos(ry * M_PI / 180.0) * sin(rx * M_PI / 180.0);
y = y +- cos(rx * M_PI / 180.0) * sin(ry * M_PI / 180.0);
z = z +- sin(ry * M_PI / 180.0) * cos(rx * M_PI / 180.0) ;

It doesn't work very properly.

(+- means I tried both + and - operator )

x,y,z : Camera position

rx,ry,rz: Camera rotation

I searched like 'Find Camera Front'. What can I do to make this code works properly.

Assume Y+ points forward and Z+ points upwards, and you have your rotations in radians ( I see you already convert them, so that won't be an issue ).

In this scenario, rx would mean the pitch, rz would mean the yaw, and ry would mean the roll. Now, to get the vector (vx,vy,vz) facing in the camera's direction:


vx =  cos(rz) * sin(rx);
vy = -sin(rz) * sin(rx);
vz =  cos(rx);

vy is negated so increasing rz would rotate counter-clockwise. You could just not-negate it if that's not the desired behaviour.

As you can see, ry ( the roll ) is not included - a vector is just a direction, but not a full transformation, so it doesn't include it.

Advertisement

Thanks, it worked.

This topic is closed to new replies.

Advertisement