How to realize gluLookAt in OpenGL ES 2.0 on Tizen

How to realize gluLookAt in OpenGL ES 2.0 on Tizen

BY 24 Aug 2015 Native Application Development

In OpenGL ES 1.1, we have an convient tool gluLookAt() to set the view point in the world coordination. But this has been deprecated in OpenGL ES 2.0.

Adjust the position and direction of camera will see different faces or parts of the objects on the device screen. Below is a picture to illustrate this.

 

 

In fact, there is a transforming matrix can reprensent the camera’s position and direction and where it lookat, we could done this by ourselves, just following the algorithm in gluLookAt(). Below are fake codes for the transfroming of view.

Matrix4 GetLookAtMatrix(Vector3 eye, Vector3 at, Vector3 up){
    Vector3 forward, side;
    forward = at - eye;
    normalize(forward);
    side = cross(forward, up);
    normalize(side);
    up = cross(side, forward);

    Matrix4 res = Matrix4(
                          side.x, up.x, -forward.x, 0,
                          side.y, up.y, -forward.y, 0,
                          side.z, up.z, -forward.z, 0,
                          0, 0, 0, 1);
    translate(res, Vector3(0 - eye));
    return res;
}

 

You can find the codes for Tizen in the code snippet

set lookat matrix in OpenGL ES 2.0

Written by