OpenGL: Simple Use. Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop Set camera pose with gluLookAt() Camera position specified in world coordinates Render polygons of model
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
glBegin (GL_LINE_LOOP);
for (j=0; j<10; j++) {
angle = 2*M_PI*j/10;
glVertex2f (cos(angle), sin(angle));
}
glEnd();
glBegin(GL_QUADS);
glVertex3f(-1, 1, 0);
glVertex3f(-1, -1, 0);
glVertex3f(1, -1, 0);
glVertex3f(1, 1, 0);
glEnd();
float v1[3], v2[3], v3[3], v4[3];
...
glBegin(GL_TRIANGLES);
glVertex3fv(v1); glVertex3fv(v2); glVertex3fv(v3);
glVertex3fv(v1); glVertex3fv(v3); glVertex3fv(v4);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glVertex3fv(v0);
glVertex3fv(v1);
glVertex3fv(v2);
glVertex3fv(v3);
glVertex3fv(v4);
glVertex3fv(v5);
glEnd();
v2
v4
v0
v5
v1
v3
E
BAD
OK
B
B
D
A
A
C
C
glNormal3f(Nx, Ny, Nz);
glVertex3fv(v0);glVertex3fv(v1);glVertex3fv(v2);
glNormal3f(N0x, N0y, N0z); glVertex3fv(v0);
glNormal3f(N1x, N1y, N1z); glVertex3fv(v1);
glNormal3f(N2x, N2y, N2z); glVertex3fv(v2);
glColor3f(0.1, 0.5, 1.0);
glVertex3fv(v0); glVertex3fv(v1); glVertex3fv(v2);
glColor3f(1, 0, 0); glVertex3fv(v0);
glColor3f(0, 1, 0); glVertex3fv(v1);
glColor3f(0, 0, 1); glVertex3fv(v2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX, eyeY, eyeZ,
lookX, lookY, lookZ, upX, upY, upZ);
eye[XYZ]: camera position in world coordinates
look[XYZ]: a point centered in camera’s view
up[XYZ]: a vector defining the camera’s vertical
2
X 2,Y 0.5
scaling matrix
(x’, y’)
(x, y)
x’ = x cos() - y sin()
y’ = x sin() + y cos()
x = r cos (f)
y = r sin (f)
x’ = r cos (f + )
y’ = r sin (f + )
Trig Identity…
x’ = r cos(f) cos() – r sin(f) sin()
y’ = r sin(f) sin() – r cos(f) cos()
Substitute…
x’ = x cos() - y sin()
y’ = x sin() + y cos()
(x’, y’)
(x, y)
f
= -(90° - ) = - 90 °
p: The point to be rotated about A by
Ry : Rotate about Y by
Rx : Rotate about X by
Rz : Rotate about Z by
Rx -1: Undo rotation about X by
Ry-1: Undo rotation about Y by
p’ = Ry-1 Rx -1 Rz Rx Ry p
Rx : Rotate about X by
Rx -1: Undo rotation about X by
Rx : Rotate about X by
Rx -1: Undo rotation about X by
Rx : Rotate about X by
Rx -1: Undo rotation about X by
glMatrixMode(GL_PERSPECTIVE);
glLoadIdentity();
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(…);
glTranslate(…);
glScale(…);
/* Draw the object...*/
glMatrixMode(GL_PERSPECTIVE);
glLoadIdentity();
glTranslate(…);
glScale(…);
gluPerspective(…);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(…);
/* Draw the object...*/
glMatrixMode (MODELVIEW);
glLoadIdentity();
glMultMatrix(N);
glMultMatrix(M);
glMultMatrix(L);
glBegin(POINTS);
glVertex3f(v);
glEnd();
Modelview matrix successively contains:
I(dentity), N, NM, NML
The transformed vertex is:
NMLv = N(M(Lv))
Wrong
Right
R(45)
T(-3), R(45), T(3)
OpenGL
T(3)
R(45)
T(-3)
draw_wheel( );
for (j=0; j<5; j++) {
glPushMatrix ();
glRotatef(72.0*j, 0.0, 0.0, 1.0);
glTranslatef (3.0, 0.0, 0.0);
draw_bolt ( );
glPopMatrix ( );