Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help with the Camera viewing

chang23chang23 Posts: 1Member
I am a beginner and i have recently started learning opengl .

so,please help me with the camera viewing and especially with gluPerspective ,i am having a lot of problems because of that.....

I had written a program that creates the image of the universe .i had created the orbits of the planets in the x-z plane and i wanna see it from upward i.e. from a point about h height from the x-z plane ..
this is my code -

#include
#include
#include
#include
#include

using namespace std;

void render(){
glClearColor(0.0,0.0,1.0,1.0);
// glEnable(GL_DEPTH_TEST);
}

GLfloat xrot = 360.0f,yrot = 0.0f,zrot = 0.0f;
void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0.0f,0.0f,-100.0f);
GLfloat x,z,angle,y = 0.0f;
glPushMatrix();
glRotatef(yrot,0.0,1.0,0.0);
glColor3f(1.0,1.0,0.0);
glutSolidSphere(7.0f,20,20);
glBegin(GL_POINTS);
for (angle = 0.0f;angle <= 3.1415f*2.0f*3.0f; angle += 0.08f){
glColor3f(1.0,0.0,0.0);
x = 30.0f*sin(angle);
z = 30.0f*cos(angle);
// y = 30.0f*cos(4 * angle);
// if (x < 5.0f && x > 5.0f )
glVertex3f(x,y,z);
x = 50.0f*sin(angle);
z = 50.0f*cos(angle);
glColor3f(0.0,0.0,0.0);
glVertex3f(x,y,z);

}
glEnd();
glTranslatef(-30.0f,00.0f,0.0f);
glColor3f(0.0,0.0,0.0);
glutSolidSphere(3.0f,20,20);
// glLoadIdentity();

glPopMatrix();
glRotatef((yrot),0.0,-1.0,0.0);
glTranslatef(-50.0f,00.0f,0.0f);
glColor3f(1.0,1.0,1.0);
glutSolidSphere(3.0f,20,20);

glLoadIdentity();
glutSwapBuffers();

}
void update(int x){
yrot += 0.75f;
glutPostRedisplay();
glutTimerFunc(33,update,0);
}
void reshape(int w,int h){
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// glTranslatef(0.0,10.0,-100.0);
// glRotatef(90,1,0,0);

// gluLookAt(0,0,0,0,0,-100, 1,0,0);
gluPerspective(90.0,w/h,1.0,200.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char **argv){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(800,600);
glutCreateWindow("chang");
render();
glutDisplayFunc(draw);
glutTimerFunc(1,update,0);
glutReshapeFunc(reshape);
glutMainLoop();
}

someone plese help me this ..
and also if u can explain me some about gluPerspective then it would be a lot more helpful...
Sign In or Register to comment.