Professional Documents
Culture Documents
Sphere, Cylinder, and Cone
Sphere, Cylinder, and Cone
Earth Plane
HOMOGENEOUS COORDINATES
MATRIX REPRESENTATION OF 3D
OpenGL
TRANSFORMATIONS Transformations
1 0 0 dx d x 0 0 0 1 0 0 0
0 0 0
1 0 d y dy 0 0 cos sin 0
T S R
0 0 1 dz 0 0 dz 0 x
0 sin cos 0
0 0 0 1 0 0 0 1
0 0 0 1
COMPOSITION OF 3D TRANS
Solar
Solar system:
System
I M
I I I I
a) Before b) After c) Before d) After
glPushMatrix() glPushMatrix() glPopMatrix() glPopMatrix()
I M N
a) Call DrawRobot() b) Call DrawRobot() the 2nd time b) Call DrawRobot() the 3rd time
the first time M=R()T(A)R()T(-A)T(B)R( )T(-B) N =MM
Float matrix[4][4];
Often, a sphere is at the center of the coordinates
myLoadIdentity();
transDrawSphere(); //sun
myRotatef(e,0,1,0); myTranslatef(E, 0, 0);
transDrawSphere(); //earth
myRotatef(m,0,1,0); myTranslatef(M, 0, 0);
transDrawSphere(); //moon
Copyright @ 2002 by Jim X. Chen:
jchen@cs.gmu.edu
.7.
Transformation and Viewing
myPushMatrix();
myScalef(4,4,4);
transDrawSphere(); //sun
myPopMatrix();
myLoadIdentity();
myRotatef(e,0,1,0); myTranslatef(E, 0, 0);
myPushMatrix();
myScalef(2,2,2);
transDrawSphere(); //earth
myPopMatrix();
myRotatef(m,0,1,0); myTranslatef(M, 0, 0);
transDrawSphere(); //moon
Copyright @ 2002 by Jim X. Chen:
jchen@cs.gmu.edu
.8.
Transformation and Viewing
An OpenGL Implementation
glMatrixMode (GL_MODELVIEW);
……
glLoadIdentity ();
glPushMatrix();
glScalef(4,4,4);
Sphere(); //sun, matrix multi. automatic in OpenGL
glPopMatrix();
glRotatef(e,0,1,0); glTranslatef(E, 0, 0);
glPushMatrix();
glScalef(2,2,2);
Sphere(); // earth, transformation implied
glPopMatrix();
glRotatef(m,0,1,0); glTranslatef(M, 0, 0);
Sphere(); //moon, again …
Copyright @ 2002 by Jim X. Chen:
jchen@cs.gmu.edu
.9.
Transformation and Viewing
Mnew = Ry(-b)Rz(-a)Ry(m)Rz(a)Ry(b)M
Copyright @ 2002 by Jim X. Chen:
jchen@cs.gmu.edu
.10.
Jogl implementation
gl.glPushMatrix();
gl.glRotatef(earthAngle, 0.0f, 1.0f, 0.0f); // around the "sun"; proceed angle
gl.glRotatef(tiltAngle, 0.0f, 0.0f, 1.0f); // tilt between the center and y axis
gl.glTranslatef(0.0f, earthDistance, 0.0f);
gl.glPushMatrix();
gl.glScalef(WIDTH/20, WIDTH/20, WIDTH/20);
drawSphere();
gl.glPopMatrix();
Generalized
Solar System
Cone Earth
Cone Lab and Lighting
Sphere
HW: Optional
Draw a cone, a cylinder, and a sphere that move and collide in the
moon’s trajectory in the generalized solar system.