Well, before I answer your questions the code below is a working OpenGL program that uses the standard GL rotation,translate and scale commands as well as the LookAt command.
For xyz points I tend towards the struct command so something like this could suffice.
struct coords
{
int x;
int y;
int z;
};
You could then create variables as follows:
coords campos,camview,camup;
coords c1,c2;
campos.x = 0
campos.y = 0
campos.z = -100
Could be used to initialise the camera position and then used in the glLookAt command or the initial translate command as follow:
glLookAt(campos.x,campos.y,campos.z,0,0,0,0,1,0)
glTranslated(campos.x,campos.y,campos.z);
But it you are supposed to be using your own methods then it may be just the case that you have to use your existing code and find out the value ranges to use and why… trial and error may well help you out there…
Tina
Example GLUT Program
#include <GL/glut.h>
char glMode;
float rotx=0.0,xrot=0;
void drawCenteredSquare(int width,int height)
{
//Center the Square on the x,y axis points sent to the routine
glBegin(GL_QUADS);
glVertex2d(-width/2,-height/2);
glVertex2d(-width/2, height/2);
glVertex2d( width/2, height/2);
glVertex2d( width/2,-height/2);
glEnd();
}
void drawSquare(int width,int height)
{
glBegin(GL_QUADS);
glVertex2d(0, 0);
glVertex2d(0, height);
glVertex2d(width,height);
glVertex2d(width,0);
glEnd();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (glMode == ‘O’) gluOrtho2D(0,w, 0,h);
if (glMode == ‘P’) gluPerspective(45,1,1,1000);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0,0.0,0.0,0.0);
glLoadIdentity();
glutPostRedisplay();
}
void Draw3DScene()
{
glPushMatrix();
glColor3ub(255,255,255);
glRotatef(rotx,1,0,0); // Rotate on the x-axis
drawSquare(10,10);
glScalef(0.5,2.0,1.0); // Scale Object half its width,twice its height and the same depth
glTranslated(5,5,0); // Move the view 5 pixels up and across
drawSquare(10,10);
rotx+=0.5;
glPopMatrix();
glPushMatrix();
glTranslatef(0,0,-50);
glRotatef(xrot,1,0,0);
glBegin(GL_TRIANGLES);
glColor3f(1,0,0); glVertex3f(0,1,1);
glColor3f(0,1,0); glVertex3f(1,0,2);
glColor3f(0,0,1); glVertex3f(-1,0,2);
glColor3f(0,0,1); glVertex3f(-1,0,2);
glColor3f(0,1,0); glVertex3f(1,0,2);
glColor3f(1,0,1); glVertex3f(0,0,0);
glColor3f(1,0,0); glVertex3f(0,1,1);
glColor3f(0,0,1); glVertex3f(-1,0,2);
glColor3f(1,0,1); glVertex3f(0,0,0);
glColor3f(1,0,0); glVertex3f(0,1,1);
glColor3f(0,1,0); glVertex3f(1,0,2);
glColor3f(1,0,1); glVertex3f(0,0,0);
glEnd();
xrot++;
glPopMatrix();
}
void Draw2DScene()
{
glPushMatrix();
glColor3ub(255,255,255);
glTranslated(50,50,0);
glRotatef(rotx,0,1,0);
drawSquare(100,100);
rotx++;
glPopMatrix();
}
void display ()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(0,0,-100,0,0,0,0,1,0); // place camera 100 pixel back with y being up
// or
//glTranslated(0,0,-100); // place view 100 pixels into the screen
if (glMode==‘P’) Draw3DScene();
if (glMode==‘O’) Draw2DScene();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
/--------------------
- The main routine: *
--------------------/
int main (int argc, char **argv)
{
glMode = ‘P’;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow(“Simple GLUT Program”);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}