0

Hello world ! I am beginner in openGL and really facing difficulties while learning it. I have a question and getting confused about the usage of GL_PROJECTIOn and GL_MODELVIEW and also about glLoadIdentity(). I am struggling, this concept has consumed several hours of mine. So from World, anyone who can remove my confusion where these concepts are used.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by pcgamer2008
0

A simple way to think about it is that GL_PROJECTION is to camera and GL_MODELVIEW is to world objects.

So if you use glTranslatef() in projection mode then you will be moving your viewing position or camera. And if you translate in modelview then you are moving the drawing point for objects.

glLoadIdentity() just takes the view that you passed into glMatrixMode() and loads it as the current matrix.

0

Thanks SFUO ! Now I understood the concept....can you help me in the below code ?:-
I stuck in a step for screen boundation for ball which is moving in counter clockwise direction..
How to apply screen boundation with coordinate system...Plzzz help me in this code...

if(posx<=1.0-radius && posy<=0.5)  // RIGHT EDGE RESTRICTION
{
dx=(1.0-radius)-posx;   // +
dy=0.5-posy;     // +
glColor3f(1.0,0.0,1.0);   // COLOUR OF THE BALL
} 
else
    if(posx>=0.5 && posy<=(1.0-radius))  // TOP EDGE RESTRICTION
    {
    dx=0.5-posx;   // -     
    dy=(1.0-radius)-posy;   // +
    glColor3f(1.0,1.0,0.0);   // COLOUR OF THE BALL
    } 
    else
        if(posx>=0.0+radius && posy>=0.5)  // LEFT EDGE RESTRICTION
        {
        dx=(0.0+radius)-posx;  //  -
        dy=(0.5-posy); //  -
        glColor3f(0.0,1.0,1.0);   // COLOUR OF THE BALL
        } 
       else
            if(posx<=0.5 && posy>=0.0+radius)
            {
            dx=0.5-posx;    // +
            dy=(0.0+radius)-posy;   // - 
            glColor3f(1.0,1.0,1.0);   // COLOUR OF THE BALL
            }

dis=sqrt(dx*dx+dy*dy);  // Distance between Ball and Wall
speedx=dx/(dis*100);    // Normalizing x
speedy=dy/(dis*100);    // Normalizing y
posx+=speedx*v1;
posy+=speedy*v1;

glBegin(GL_POLYGON);
for (float angle = 0;angle<360;angle+=5)
{
    float xc=sin(angle*PI/180) * radius;
    float yc=cos(angle*PI/180) * radius;
    glVertex3f(xc+posx, yc+posy ,0.0f);
}
glEnd();
glFlush();
glutSwapBuffers();

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.