200 likes | 301 Views
Three Dimension Viewing. glMatrixMode(GL_PROJECTION); //make the projection matrix current glLoadIdentity(); // start with a unit matrix gluPerspective(viewAngle,aspectRatio, N, F) // load the appropriate values fig.7-4. Building camera in a program. class Camera{ private: Point3 eye;
E N D
glMatrixMode(GL_PROJECTION); //make the projection matrix current glLoadIdentity(); // start with a unit matrix gluPerspective(viewAngle,aspectRatio, N, F) // load the appropriate values fig.7-4
Building camera in a program class Camera{ private: Point3 eye; Vector3 u,v,n; double viewAngle, aspect, nearDist, farDist; // view volume shape void setModelviewMatrix(); // tell OpenGL where the camera is public: Camera(); // default constructor void set(Point3 eye, Point3 look, Vector3 up); // like gluLookAt() void roll(float angle); // roll it void pitch(float angle); // increase pitch void yaw(float angle); // yaw it void slide(float delU, float delV, float delN); // slide it void setShape(float vAng, float asp, float nearD, float farD); };
7.4.1 (x*,y*)=(N* (Px/-Pz), N* (Py/-Pz))
Center in origin, E=5 in Z Center in (1,1,1), E=5 in Z
7.4.3. Straight lines project as straight lines: the parametric form point A(Ax,Ay,Az) direction vector c=(cx,cy,cz) P(t) = A + ct
Parallel projection orthogonal and oblique Orthogonal, the projection direction Is parallel to n Oblique not parallel to n
Oblique projection 7.13
void Camera:: setOblique(Vector3 d,..others..) {// establish camera for oblique projections glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(l,r,b,t,n,f); // set the projection matrix if(d.z == 0.0) return; // for orthographic projections float m[16]; // space for a 4 by 4 matrix for(int i = 0; i < 16; i++) // start with identity matrix m[i] = (i%5 == 0)? 1.0 : 0.0;// identity matrix m[8] = -d.x/d.z; // add the shear terms m[9] = -d.y/d.z; glMultMatrixf(m); // postmultiply it by m }