PDA

View Full Version : Need help with perspecive problem



TheBlackAdder
09-25-2006, 10:27 AM
Make a perspective picture of a 10 unit cube with
the diagonal vertices (0,0,0) and (10, 10, 10).
First make a front perspective view of the cube.
The Eye Point (View Point = Camera Position) is positioned in (20, 5,
5) and the View Plane goes through the origin of the world coordinate
system. In a front perspective the View plane and a set of faces (or two
main directions) are parallel to each other.
Find the position of the Point of Interest (=Principal Point, At-point).
Identify the individual transformations in the Viewing Transformation
(column notation). Calculate the concatenated 4x4 viewing transformation.
Calculate the Eye Coordinates [xe, ye, ze, 1] for each vertex of the
cube.

Use OpenGL to make perspective pictures of the 10-unit
cube with the diagonal vertices (0,0,0) and (10, 10, 10) from part 2.
Make a front perspective using the code below.
The eye point is (20., 5., 5.).

Make an X-perspective from the same eye point. The View Plane goes
through the Yw-axis.

Use
-gluPerspective
-gluLookAt
to set up the view frustum and the eye point, at-point, and up vector.
The parameter fovy=45 and up = (upx,upy,upz) = (0,1,0). Choose
reasonably values for the rest of the parameters.


I know it sounds like i am too lazy to make it myself, but i have really spent a lot of time trying to figure out how to make this problem, and i have difficulties. So if somebody could help me with an openGL implementation i would be most thankful.
Thank you very much in advance and best regards...
------------------------------------------------------------------------


#include <stdlib.h>
#include <GL/glut.h>


int main (int argc, char** argv);
void initgl(void);

void display (void);
void axis (void);
void reshape (int w, int h);

int main (int argc, char** argv) {

glutInit (&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Exercise 02501-03");
initgl ();
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutMainLoop ();
return 0;
}


void initgl (void) {
glClearColor (0., 0., 0., 0.);
glShadeModel (GL_FLAT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-6., 6., -6., 6., -6., 6.);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}

void reshape (int w, int h) {
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (-6., 6., -6., 6., -6., 6.);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}


void display (void) {

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (1.,1.,1.);
glPushMatrix ();

/*Tranformations
*/
glutWireCube (1.);

glPopMatrix ();

axis();
glFlush ();

}


void axis (void) {
/*Plot part of axis and an auxiliary line*/
GLfloat v0[] = {0., 0., 0.};
GLfloat vx[]= {4., 0., 0.};
GLfloat vy[]= {0, 4., 0.};
GLfloat vz[]= {0., 0., 4.};

GLfloat v0x1[] = {1., 0., 0.};
GLfloat vyx1[] = {1., 3., 0.};

glPushAttrib(GL_CURRENT_BIT);
glColor3f (1., 0., 0.);
glBegin (GL_LINES);
glVertex3fv (v0);
glVertex3fv (vx);
glEnd ();

glBegin (GL_LINES);
glVertex3fv (v0);
glVertex3fv (vy);
glEnd ();

glBegin (GL_LINES);
glVertex3fv (v0);
glVertex3fv (vz);
glEnd ();

glBegin (GL_LINES);
glVertex3fv (v0x1);
glVertex3fv (vyx1);
glEnd ();
glPopAttrib();
}