# Change of coordinates with glFrustum

I am trying to use glFrustum for a perspective projection and as I understand glFrustum like glOrtho can be used to modify the mapping of our desired coordinate system to real screen coordinates (as read in Blue book). So, if I do

``````
glFrustum(-1,1,-1,1,1,1000);

``````

, it changes the coordinates to
_left = -1, right = 1, bottom = -1, top = 1 _in the form of cartesian coordinates.

I tried to draw a simple room (with 2 side walls) in this coordinate system by calling the following function in my draw method and it comes out drawing appropriately on the screen.

``````
void drawRoomWalls(){
//Left wall
glVertex3f(-1.0, 1.0, 0.0);
glVertex3f(-1.0, 1.0, -0.4);
glVertex3f(-1.0, -1.0, -0.4);
glVertex3f(-1.0, -1.0, 0.0);
glEnd();

//Right wall
glVertex3f(1.0, 1.0, 0.0);
glVertex3f(1.0, 1.0, -0.4);
glVertex3f(1.0, -1.0, -0.4);
glVertex3f(1.0, -1.0, 0.0);
glEnd();
}

``````

The function was called as follows:

``````
glMatrixMode(GL_PROJECTION);
glFrustum(1.0, -1.0, -1.0, 1.0, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0, 0, -1.0);
drawRoomWalls();

``````

Subsequently, I tried to do an off-axis projection (by taking mouse as input instead of user’s head). The code is as follows:

``````
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

double fov, near, far;
float aspectRatio;

near = 1.0f; far = 1000.0f;  aspectRatio = ofGetWidth()/ofGetHeight();
fov = tan(DEG_TO_RAD * 30/2); //tan accepts angle in radians. tan of the half of the fov angle
fov = 0.5; //taken constant for now

double msX = (double)ofGetMouseX();
double msY = (double)ofGetMouseY();
double scrWidth = (double)ofGetWidth();
double scrHeight = (double)ofGetHeight();

headX = (msX / scrWidth) - 0.5;
headY = ((scrHeight - msY) / scrHeight) - 0.5;

glMatrixMode(GL_PROJECTION);
glFrustum( near * (-fov * aspectRatio + headX),
near * (fov * aspectRatio + headX),
near,
far);

leftValue = near * (-fov * aspectRatio + headX); //for printing out on screen
rightValue = near * (fov * aspectRatio + headX); //for printing out on screen
bottomValue = near * (-fov + headY); //for printing out on screen
topValue = near * (fov + headY); //for printing out on screen

glMatrixMode(GL_MODELVIEW);