ang_rotate(ANGLE* angle1, ANGLE* angle2)
ang_add(ANGLE* angle1, ANGLE* angle2)
Rotates an Euler angle by another Euler angle, in order to rotate an object or
view
about its local axes, rather than the X Y Z axis of the world coordinate system. This is mostly used for rotating aircraft or spaceship about their own axes, rather than the world axes.
ang_rotate rotates angle1 by angle2,
ang_add
rotates angle2 by angle1. The result is always
stored in angle1, which can also be an entity or view pan angle.
Parameters:
angle1 - pan/tilt/roll Euler angle to be modified
angle2 - pan/tilt/roll Euler angle used for rotation.
Speed:
mediumExamples (lite-C):
// An entity rotates about its vertical axis, regardless of its orientation in space
function ent_rotatepan(ENTITY* ent)
{
while(1) {
ang_rotate(ent.pan,vector(5*time_step,0,0));
wait(1);
}
}
// A camera is hunting a target and turns with it, keeping the target always in the middle of the view.
function chase_camera(ENTITY* ent)
{
// calculate the camera view's direction angle to the target
var cam_dist[3] = {-200,-100,-100}; // xyz distance vector from the camera to the target
var cam_ang[3] = {0,0,0}; // direction angle of the camera to the target.
vec_to_angle(cam_ang,cam_dist);
while (1)
{
// place the camera at the right position to the target
vec_diff(camera.x,nullvector,cam_dist);
vec_rotate(camera.x,ent.pan);
vec_add(camera.x,ent.x);
// Set the camera angles to the camera view direction
vec_set(camera.pan,cam_ang);
// and rotate it about the target angle
ang_add(camera.pan,ent.pan);
wait(1);
}
}
See also:
pan, tilt, roll,
vec_to_angle, vec_rotate, c_rotate
► latest
version online