Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a simple 3D game with plane in space. With c++ (win32). But the plane rotation is not realistic. The code I am using for the rotation is the following:

point3D AxisRotation(point3D point,point3D Rotation){
float sx = Sin(Rotation.x*PI/180);
float cx = Cos(Rotation.x*PI/180);
float sy = Sin(Rotation.y*PI/180);
float cy = Cos(Rotation.y*PI/180);
float sz = Sin(Rotation.z*PI/180);
float cz = Cos(Rotation.z*PI/180);
float xy,xz, yx,yz, zx,zy;
xy = cx*point.y - sx*point.z;
xz = sx*point.y + cx*point.z;
yz = cy*xz - sy*point.x;
yx = sy*xz + cy*point.x;
zx = cz*yx - sz*xy;
zy = sz*yx + cz*xy;
point.x = zx;
point.y = zy;
point.z = yz;
return point;}

The axis of the rotation needs to be (Roll,Yaw,Pitch). Does anyone know the code or the math for it ? Thank you. Dave

share|improve this question

migrated from Jul 13 '11 at 2:07

This question came from our site for professional and enthusiast programmers.

For your convenience you might want to look into using matrices for your transformations. It will allow you to simplify your code. With respect to your question, have a look at this resource – Bart Jul 9 '11 at 11:35
Your question is unclear. Are you trying to determine the axis of rotation generated by this code? Or are you trying to write code which will rotate a point by a given angle around a given axis? – Beta Jul 9 '11 at 13:23
im trying to write code which will rotate a point by a given angle. but the rotation needs to be an airplane rotation .. there is a differents rotation codes who made for different things.. im trying to do a rotation that will be similar to Fighter like this-> with giving the point position in - X Y Z ... and the angles by Roll Yaw Pitch and will return the new X Y Z position also thanks for caring :P – Dave Jul 9 '11 at 14:06
@Dave Then look at the resource I provided. – Bart Jul 9 '11 at 15:20
yes.. i was taking a look at the resource.. and i coded it.. but still there is a problem with the 3D rotation moving .. you can take a look at the game -> when your pressing UP ARROW key also the name of this rotation is Euler angles and people using it for camera rotation – Dave Jul 9 '11 at 15:47

Try this: (You'll need to call this three times, once for Roll, Yaw, and Pitch). This should work, I've used it in my own game, and it has been unit-tested. Of course, if your vector/point class has its overloaded operators defined differently then it may not give similar results. Here is my vector implementation (as of a few months ago).

point3D RotatePointAroundAxis( const point3D& axis, const float
                               radians, const point3D& point )
    float matrix[3][3];

    float sn = sinf(radians);
    float cs = cosf(radians);

    float xSin = axis.x * sn;
    float ySin = axis.y * sn;
    float zSin = axis.z * sn;  
    float oneMinusCS = 1.0f - cs;
    float xym = axis.x * axis.y * oneMinusCS;
    float xzm = axis.x * axis.z * oneMinusCS;
    float yzm = axis.y * axis.z * oneMinusCS;

    matrix[0][0] = (axis.x * axis.x) * oneMinusCS + cs;
    matrix[0][1] = xym + zSin;
    matrix[0][2] = xzm - ySin;
    matrix[1][0] = xym - zSin;
    matrix[1][1] = (axis.y * axis.y) * oneMinusCS + cs;
    matrix[1][2] = yzm + xSin;
    matrix[2][0] = xzm + ySin;
    matrix[2][1] = yzm - xSin;
    matrix[2][2] = (axis.z * axis.z) * oneMinusCS + cs;

    return point3D
        matrix[0][0] * point.x + matrix[0][1] * point.y + matrix[0][2] * point.z,

        matrix[1][0] * point.x + matrix[1][1] * point.y + matrix[1][2] * point.z,

        matrix[2][0] * point.x + matrix[2][1] * point.y + matrix[2][2] * point.z

If you're trying to rotate an entire plane then I suspect you have a rotation matrix, if you're using DirectX you could use something like D3DXMatrixRotationRollYawPitch(&mRotation, rotation.y, rotation.x, rotation.z); I'm not sure if that's the exact function name.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.