Title: Computer Graphics 5
1Computer Graphics 5
23D Elementary Shapes
- The glut library contains several functions for
drawing basic 3D primitives. These are listed
below. All of the following objects are centered
at the origin -
- glutWireCube(GLdouble size)
- glutSolidCube(GLdouble size)
- glutWireSphere(GLdouble radius, GLint nSlices,
GLint nStacks) - glutSolidSphere(GLdouble radius, GLint nSlices,
GLint nStacks)
3glutWireSphere
- This approximates a sphere with a set of
polygons. The number of polygons determines the
"niceness" of the approximation. nSlices is the
number of subdivisions around the z-axis. nStacks
is the number of bands along the z axis. - Large values for nSlices and nStacks produce more
accurate representations (at the cost of slower
graphics). - Small values for nSlices and nStacks produce
poorer representations (with the benefit of
faster graphics).
43D Elementary Shapes
- glutWireTetrahedron() // 4 faced pyramid
- glutSolidTetrahedron()
- glutWireOctahedron() // 8 faced solid
- glutSolidOctahedron()
- glutWireDodecahedron() // 12 faced solid
- glutSolidDodecahedron()
- glutWireIcosahedron() // 20 faced solid
- glutSolidIcosahedron()
53D Elementary Shapes
- glutWireTorus(GLdouble innerRadius, GLdouble
outerRadius, GLint nSlices, GLint rings) - glutSolidTorus(GLdouble innerRadius, GLdouble
outerRadius, GLint nSlices, GLint rings) - glutWireTeapot(GLdouble size)
- glutSolidTeapot(GLdouble size)
- glutWireCone(GLdouble baseRadius, GLdouble
height, GLint nSlices, GLint nStacks) - glutSolidCone(GLdouble baseRadius, GLdouble
height, GLint nSlices, GLint nStacks)
6lab07.cpp
include ltmath.hgt include ltstdio.hgt include
ltstdlib.hgt include ltGL/glut.hgt GLint N4 GLint
mouseX 0 GLint mouseY 0 GLint mouseState
0 GLint mouseButton 0 GLint shape1,
model2 GLfloat size2.0 GLfloat xTheta0.,
yTheta0., zTheta0., thetaDelta.125 GLfloat
scale1.0, scaleDelta1.01 void
myAxis(void) int i glColor3f(0.98, .04,
.70) glBegin(GL_LINES)
for(i0 iltN i) glVertex2f(-size2.0isi
ze/N, -size) glVertex2f(-size2.0isize/N,
size) glVertex2f(-size, -size2.0isize/N)
glVertex2f(size, -size2.0isize/N) glEnd()
void myDraw(void) glColor3f(.98, .625,
.12) if(model1) glutWireCube(1.0) else
if(model2) glutSolidCube(1.0) else
if(model3) glutWireSphere(1.0, 10, 10) else
if(model4) glutSolidSphere(1.0, 10, 10) else
if(model5) glutWireTeapot(1.0) else
if(model6) glutSolidTeapot(1.0)
7lab07.cpp
void myDisplay(void) static int i0 glClear(G
L_COLOR_BUFFER_BIT) glLoadIdentity() glRotatef
(xTheta, 1.0, 0.0, 0.0) glRotatef(yTheta, 0.0,
1.0, 0.0) glRotatef(zTheta, 0.0, 0.0,
1.0) glScalef(scale, scale, scale) myDraw()
glFlush() glutSwapBuffers() void
myReshape(int width, int height) glClearColor
(.75, .75, .75, 0.0) glViewport(0,0,width,height
) glMatrixMode(GL_PROJECTION) glLoadIdentity()
glOrtho(-size, size, -size, size, -size,
size) glMatrixMode(GL_MODELVIEW)
void glutMouse(int btn, int state, int x, int
y) if(btnGLUT_LEFT_BUTTON state
GLUT_DOWN) mouseStatestate mouseButtonbt
n mouseXx mouseYy else
if(btnGLUT_LEFT_BUTTON state GLUT_UP)
mouseState-1 else if(btnGLUT_MIDDLE_BU
TTON state GLUT_DOWN) mouseStatestat
e mouseButtonbtn mouseXx mouseYy
8lab07.cpp
else if(btnGLUT_MIDDLE_BUTTON state
GLUT_UP) mouseState-1 else
return glutPostRedisplay() void
glutMotion(int x, int y) if(mouseButton
GLUT_LEFT_BUTTON mouseState GLUT_DOWN)
yTheta - (mouseX - x)/10. xTheta -
(mouseY - y)/10. else if(mouseButton
GLUT_MIDDLE_BUTTON mouseState GLUT_DOWN)
if(mouseY!y) scale scale
pow(scaleDelta, (mouseY - y)/10.) else
return
mouseX x mouseY y glutPostRedisplay()
void myMenu(int id) if(id 7)
exit(1) else model id glutPostRedisplay()
9lab07.cpp
void main(int argc, char argv) int shape_subm
enu glutInit(argc,argv) glutInitDisplayMode
(GLUT_DOUBLE GLUT_RGB) glutInitWindowSize(500,
500) glutInitWindowPosition(0,0) glutCreateWin
dow("lab07") glutReshapeFunc(myReshape) glutDi
splayFunc(myDisplay) glutMouseFunc(glutMouse)
glutMotionFunc(glutMotion) glutCreateMenu(myMen
u) glutAddMenuEntry("WireCube",
1) glutAddMenuEntry("SolidCube",
2) glutAddMenuEntry("WireSphere",
3) glutAddMenuEntry("SolidSphere",
4) glutAddMenuEntry("WireTeapot",
5) glutAddMenuEntry("SolidTeapot",
6) glutAddMenuEntry("Quit", 7) glutAttachMenu(
GLUT_RIGHT_BUTTON) glutMainLoop()
10glutCreateMenu
- glutCreateMenu creates a new pop-up menu.
- int glutCreateMenu(void (func)(int value))
- Parameters
- func The callback function for the menu that is
called when a menu entry from the menu is
selected. - The value passed to the callback is determined
by the value for the selected menu entry. -
11glutAddMenuEntry
- glutAddMenuEntry adds a menu entry to the bottom
of the current menu. - void glutAddMenuEntry(char name, int value)
- Parameters
- name ASCII character string to display in the
menu entry. - value Value to return to the menus callback
function if the menu entry is selected.
12glutAttachMenu
- glutAttachMenu attaches a mouse button for the
current window to the identifier of the current
menu - void glutAttachMenu(int button)
- Parameters
- button The button to attach a menu
13Projection, ModelView matrix
- There are three different 4x4 matrices used by
OpenGL to produce an image. - Projection matrix - used to "project" a 3D image
onto a 2D plane to create an image - ModelView matrix - used to transform objects and
the camera to create the desired scene and view. - Commands like glTranslate, glRotate, and glScale
modify the active matrix. It is the programmer's
responsibility to make sure the appropriate
matrix is "active." The active matrix is
determined by calls to glMatrixMode().
14glMatrixMode
- The glMatrixMode function specifies which matrix
is the current matrix. - void glMatrixMode( GLenum mode )
- Parameters
- mode The matrix stack that is the target for
subsequent matrix operations. The mode parameter
can assume one of three values - GL_MODELVIEW Applies subsequent matrix
operations to the modelview matrix stack. - GL_PROJECTION Applies subsequent matrix
operations to the projection matrix stack. - GL_TEXTURE Applies subsequent matrix
operations to the texture matrix stack.
15OpenGL transformation functions
- OpenGL maintains a 4x4 transformation matrix that
is multiplied by every (x,y,z) value sent to
glVertex().This is sometimes referred to as the
CT (current transformation, active matrix). - The CT can be modified by the following
functions - glLoadIdentity()
- glTranslatefd(dx, dy, dz)
- glScalefd(sx, sy, sz)
- glRotatefd(angleInDegrees, axisXvalue,
axisYvalue, axisZvalue)
16Specifics
- The glLoadIdentity() function is unique. It
replaces the CT with an identity matrix. This has
the effect of starting transformations "from
unity". - The arguments to these functions can be float or
double data types. The last letter of the
function name determines the data type of the
arguments. - For example
- glTranslatef(3.0, 4.0, 1.2) // floating point
data - glTranslated(3.0, 4.0, 1.2) // double precision
data -
17Specifics
- To translate along one axis while leaving the
other axis values unchanged, use a value of zero
for the unaffected axes. - For example, the following function call moves
along the Y axis 6 units glTranslatef(0.0, 6.0,
0.0) - To scale along one axis while leaving the other
axis values unchanged, use a value of one for the
unaffected axes. - For example, the following call scales only
along the Z axis by a factor of 3 glScalef(1.0,
1.0, 3.0)
18Specifics
- To rotate about one of the coordinate system
axes, specify the appropriate vector. - For example
- glRotatef(20.0, 1.0, 0.0, 0.0) // rotates about
the X axis - glRotatef(20.0, 0.0, 1.0, 0.0) // rotates about
the Y axis - glRotatef(20.0, 0.0, 0.0, 1.0) // rotates about
the Z axis
19Specifics
- For the glTranslate, glRotate, and glScale
functions, each builds a 4x4 transformation
matrix using the supplied arguments and then
multiplies it times the CT (current transform).
For example, the glTranslatef function might look
something like the following -
- void glTranslatef(float dx, float dy, float dz)
- GLfloat m44
- 1.0, 0.0, 0.0, dx ,
- 0.0, 1.0, 0.0, dy ,
- 0.0, 0.0, 1.0, dz ,
- 0.0, 0.0, 0.0, 1.0
- CT CTm // pseudocode
-
20Facts about transformations
- Given a sequence of elementary transformations
that together form a single complex
transformation, if you change the order of the
elementary transformations, you get a different
complex transformation - There is typically more than one sequence of
transformations that will produce the same
effect, but often one sequence is easier to
create than the others. - The multiplication of the matrices is always
(CTm), not (mCT), so the order of the function
calls must be in reverse order from the
"conceptual" ordering of the transformations.
21Specifics
- If you want to
- translate a point by (-2, 5, 0),
- then rotate it by 20 degrees about the Z axis,
- then scale it by a factor of 2 along the X axis,
- the function calls would be
- glLoadIdentity() // always start with the
identity matrix - glScalef(2.0, 1.0, 1.0) // Conceptually, this
happens 3rd - glRotatef(20.0, 0.0, 0.0, 1.0) // Conceptually,
this happens 2nd - glTranslatef(-2.0, 5.0, 0.0) // Conceptually,
this happens 1st - drawObject()
22Specifics
- The transformations caused by glRotate,
glTranslate, and glScale are applied to the CT
(current transform). They will accumulate
continually unless you reset the matrix back to
the Identity matrix. If you want to start a new
set of transformations, then call
glLoadIdentity(). - Example
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity() // start a new sequence of
transforms - glTranslatef(-3.0, -4.0, 0.0)
- glRotatef(90.0, 1.0, 0.0, 0.0)
- drawObject1()
- glLoadIdentity() // start a new sequence of
transforms - glTranslatef(4.0, 2.0, 1.0)
- glScalef(2.0, 1.0, 1.0)
- drawObject2()
23Example 1
- Draw a wall of a building containing 5 arched
windows, spaced 10 units apart. Assume the arched
window is defined around the origin and is 4
units wide
24Example 1
- 1) reset the matrix
- 2) drawWindow
- 3) translate 8 on X, 5 on Y
- 4) reset the matrix
- 5) drawWindow
- 6) translate 18 on X, 5 on Y
- 7) reset the matrix
- 8) drawWindow
- 9) translate 28 on X, 5 on Y
- 10) reset the matrix
- 11) drawWindow
- 12) translate 38 on X, 5 on Y
- 13) reset the matrix
- 14) drawWindow
- 15) translate 48 on X, 5 on Y
- glLoadIdentity()
- glTranslatef(8.0, 5.0, 0.0)
- drawWindow()
- glLoadIdentity()
- glTranslatef(18.0, 5.0, 0.0)
- drawWindow()
- glLoadIdentity()
- glTranslatef(28.0, 5.0, 0.0)
- drawWindow()
- glLoadIdentity()
- glTranslatef(38.0, 5.0, 0.0)
- drawWindow()
- glLoadIdentity()
- glTranslatef(48.0, 5.0, 0.0)
- drawWindow()
25Example 1
- 1) reset the matrix
- 2) drawWindow
- 3) translate 10 on X, 0 on Y
- 4) drawWindow
- 5) translate 10 on X, 0 on Y
- 6) drawWindow
- 7) translate 10 on X, 0 on Y
- 8) drawWindow
- 9) translate 10 on X, 0 on Y
- 10) drawWindow
- 11) translate 8 on X, 5 on Y
- glLoadIdentity()
- glTranslatef(8.0, 5.0, 0.0)
- drawWindow()
- glTranslatef(10.0, 0.0, 0.0)
- drawWindow()
- glTranslatef(10.0, 0.0, 0.0)
- drawWindow()
- glTranslatef(10.0, 0.0, 0.0)
- drawWindow()
- glTranslatef(10.0, 0.0, 0.0)
- drawWindow()
26lab08.cpp
include ltmath.hgt include ltstdio.hgt include
ltstdlib.hgt include ltGL/glut.hgt GLint N12 GLfloa
t size60.0 void myAxis(void) int i glColor3
f(.98, .04, .70) glBegin(GL_LINES) for(i0
iltN i) glVertex2f(-size2.0isize/N,
-size) glVertex2f(-size2.0isize/N,
size) glVertex2f(-size, -size2.0isize/N)
glVertex2f(size, -size2.0isize/N) glEnd()
glColor3f(.25, .25, .25) glBegin(GL_LINES)
glVertex2f(0, -size) glVertex2f(0, size)
glVertex2f(-size, 0) glVertex2f(size,
0) glEnd() void drawWindow(void) glBegin(G
L_POLYGON) glVertex3f(-3., 0.,
0.) glVertex3f(3., 0., 0.) glVertex3f(3., 8.,
0.) glVertex3f(2.954423, 8.520945,
0.) glVertex3f(2.819078, 9.026060,
0.) glVertex3f(2.598076, 9.500000,
0.) glVertex3f(2.298133, 9.928363,
0.) glVertex3f(1.928363, 10.298133,
0.) glVertex3f(1.500000, 10.598076,
0.) glVertex3f(1.026060, 10.819078,
0.) glVertex3f(.520945, 10.954423,
0.) glVertex3f(0.000000, 11.000000,
0.) glVertex3f(-.520945, 10.954423,
0.) glVertex3f(-1.026060, 10.819078,
0.) glVertex3f(-1.500000, 10.598076, 0.)
27lab08.cpp
glVertex3f(-1.928363, 10.298133,
0.) glVertex3f(-2.298133, 9.928363,
0.) glVertex3f(-2.598076, 9.500000,
0.) glVertex3f(-2.819078, 9.026060,
0.) glVertex3f(-2.954423, 8.520945,
0.) glVertex3f(-3., 8., 0.) glEnd() void
myDisplay(void) glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity() myAxis() glColor3f(.25,
.25, .12) drawWindow() glColor3f(.98, .625,
.12) for(int j0 jlt5 j)
glLoadIdentity() glTranslatef(810.0j, 5.0,
0.0) drawWindow() glFlush()
glutSwapBuffers() void myReshape(int width,
int height) glClearColor (.75, .75, .75,
0.0) glViewport(0,0,width,height) glMatrixMode
(GL_PROJECTION) glLoadIdentity() glOrtho(-size
, size, -size, size, -size, size) glMatrixMode(G
L_MODELVIEW) void main(int argc, char
argv) glutInit(argc,argv) glutInitDisplayMod
e (GLUT_DOUBLE GLUT_RGB) glutInitWindowSize(50
0,500) glutInitWindowPosition(0,0) glutCreateW
indow("lab08") glutReshapeFunc(myReshape) glut
DisplayFunc(myDisplay) glutMainLoop()
28Exercise 1
- glLoadIdentity()
- glTranslatef(10.0, 0.0, 0.0)
- glRotatef(theta, 0.0, 0.0, 1.0)
- glutWireSphere(1.0, 10, 10)
- glLoadIdentity()
- glRotatef(theta, 0.0, 0.0, 1.0)
- glTranslatef(10.0, 0.0, 0.0)
- glutWireSphere(1.0, 10, 10)
29Example 2
- Transform the triangle from its current location
(left) to the new location and orientation shown
on right.
30Example 2
- 1) drawTriangle
- 2) rotate 90 degrees about Z
- 2) translate 10 units along Y
- glLoadIdentity()
- glTranslatef(0.0, 10.0, 0.0)
- glRotatef(90.0, 0.0, 0.0, 1.0)
- drawTriangle()
31Example 2
- 1) drawTriangle
- 2) translate 10 units along X
- 3) rotate 90 degrees about Z
- glLoadIdentity()
- glRotatef(90.0, 0.0, 0.0, 1.0)
- glTranslatef(10.0, 0.0, 0.0)
- drawTriangle()
32Example 2
- 1) drawTriangle
- 2) rotate -90 degrees about Z
- 3) translate -10 along Y
- 4) rotate 180 degrees about Z
- glLoadIdentity()
- glRotatef(180.0, 0.0, 0.0, 1.0)
- glTranslatef(0.0, -10.0, 0.0)
- glRotatef(-90.0, 0.0, 0.0, 1.0)
- drawTriangle()
33lab09.cpp
include ltmath.hgt include ltstdio.hgt include
ltstdlib.hgt include ltGL/glut.hgt GLint N6 GLfloa
t size30.0 void myAxis(void) int i glColor
3f(.98, .04, .70) glBegin(GL_LINES) for(i0
iltN i) glVertex2f(-size2.0isize/N,
-size) glVertex2f(-size2.0isize/N,
size) glVertex2f(-size, -size2.0isize/N)
glVertex2f(size, -size2.0isize/N) glEnd()
glColor3f(.25, .25, .25)
glBegin(GL_LINES) glVertex2f(0,
-size) glVertex2f(0, size) glVertex2f(-size,
0) glVertex2f(size, 0) glEnd() void
drawTriangle(void) glBegin(GL_POLYGON) glColo
r3f(.0, .0, 1.0) glVertex3f(-5., -5.,
0.) glColor3f(.0, .0, 1.0) glVertex3f(5.,
-5., 0.) glColor3f(1.0, .0, .0)
glVertex3f(0., 5., 0.) glEnd()
34lab09.cpp
void myDisplay(void) glClear(GL_COLOR_BUFFER_B
IT) glLoadIdentity() myAxis() glLoadIdentity
() glTranslatef(0.0, 10.0, 0.0) glRotatef(90.0
, 0.0, 0.0, 1.0) drawTriangle() glFlush() gl
utSwapBuffers() void myReshape(int width, int
height) glClearColor (.75, .75, .75,
0.0) glViewport(0,0,width,height) glMatrixMode
(GL_PROJECTION) glLoadIdentity() glOrtho(-size
, size, -size, size, -size, size) glMatrixMode(G
L_MODELVIEW)
void main(int argc, char argv) glutInit(argc
,argv) glutInitDisplayMode (GLUT_DOUBLE
GLUT_RGB) glutInitWindowSize(500,500) glutInit
WindowPosition(0,0) glutCreateWindow("lab09")
glutReshapeFunc(myReshape) glutDisplayFunc(myDis
play) glutMainLoop()
35Exercise 2
- From lab09
- Find another sequence of transformations that
will produce the same effect
36Matrix Stack
- Problem Matrix multiplication is
computationally expensive. - The multiplication of two 4x4 matrices requires
64 multiples and 48 additions - Solution Avoid duplicate matrix multiplication
by saving transformations that will be needed
again. - A stack is a good way to store a series of
transformations for later use
37OpenGL implementation
- OpenGL maintains a stack that can hold a minimum
of 32 matrices. The matrix at the top of the
stack is always the CT (Current Transform) - The following two commands manipulate the matrix
stack - glPushMatrix()
- glPopMatrix()
38OpenGL implementation
- Assuming that the stack is implemented as an
array, these two functions look like the
following pseudocode - // The stack begins with an Identity matrix on
top - int stackTop 1
- Matrix4x4 Identity 1, 0, 0, 0,0, 1, 0,
0,0, 0, 1, 0,0, 0, 0, 1 - Matrix4x4 MatrixStack32 Identity, 0
- void glPushMatrix(void)
-
- MatrixStackstackTop MatrixStackstackTop-1
- stackTop
-
- void glPopMatrix(void)
-
- stackTop--
-
- // The CT (current transform) is always
MatrixStackstacktop-1
39Matrix Stack
Statements stack0 stack1
glLoadIdentity() glRotatef(xTheta, 1.0, 0.0, 0.0) glRotatef(yTheta, 0.0, 1.0, 0.0) glRotatef(zTheta, 0.0, 0.0, 1.0) glScalef(scale, scale, scale) glutWireSphere(3.0, 10, 10) glRotatef(theta, 0., 0., 1.) glTranslatef(20., 0., 0.) glutWireSphere(1.0, 10, 10) glPushMatrix() glRotatef(theta, 0., 0., 1.) glTranslatef(5., 0., 0.) glutWireSphere(.5, 10, 10) glPopMatrix() glRotatef(theta, 0., 0., 1.) glTranslatef(-5., 0., 0.) glutWireSphere(.5, 10, 10) M0 I M0 M0Rx, xTheta M0 M0Ry, yTheta M0 M0Rz, zTheta M0 M0Sscale, scale, scale M0 M0 M0Rz, theta M0 M0Tx, 20. M0 M0 M0 M0 M0 M0 M0 M0Rz, theta M0 M0Tx,,5. M0 - - - - - - - - - M1 M0 M1 M1Rz, theta M1 M1Tx,,5. M1 - - - -
40lab10.cpp
include ltmath.hgt include ltstdio.hgt include
ltstdlib.hgt include ltGL/glut.hgt bool idleFlag
1 GLint N6 GLint mouseX 0 GLint mouseY
0 GLint mouseState 0 GLint mouseButton 0
GLfloat size30.0, theta0.0 GLfloat xTheta0.,
yTheta0., zTheta0., thetaDelta.125 GLfloa
t scale1.0, scaleDelta1.01
void myAxis(void) int i glColor3f(.98, .04,
.70) glutWireCube(size2.0) glBegin(GL_LINES)
for(i0 iltN i) glVertex2f(-size2.0i
size/N, -size) glVertex2f(-size2.0isize/N,
size) glVertex2f(-size, -size2.0isize/N)
glVertex2f(size, -size2.0isize/N) glEnd()
glColor3f(.25, .25, .25) glBegin(GL_LINES)
glVertex2f(0, -size) glVertex2f(0,
size) glVertex2f(-size, 0) glVertex2f(size,
0) glEnd()
41lab10.cpp
void myDisplay(void) glClear(GL_COLOR_BUFFER_B
IT) glLoadIdentity() glRotatef(xTheta, 1.0,
0.0, 0.0) glRotatef(yTheta, 0.0, 1.0,
0.0) glRotatef(zTheta, 0.0, 0.0,
1.0) glScalef(scale, scale, scale) myAxis()
glColor3f(.98, .625, .12) glutWireSphere(3.0,
10, 10) glRotatef(theta, 0., 0.,
1.) glTranslatef(20., 0., 0.) glutWireSphere(1
.0, 10, 10) glPushMatrix() glRotatef(theta,
0., 0., 1.) glTranslatef(5., 0.,
0.) glutWireSphere(.5, 10, 10) glPopMatrix()
glRotatef(theta, 0., 0., 1.)
glTranslatef(-5., 0., 0.) glutWireSphere(.5,
10, 10) glFlush() glutSwapBuffers() void
myReshape(int width, int height) glClearColor
(.75, .75, .75, 0.0) glViewport(0,0,width,height
) glMatrixMode(GL_PROJECTION) glLoadIdentity()
glOrtho(-size, size, -size, size, -size,
size) glMatrixMode(GL_MODELVIEW) void
myIdle(void) theta0.5 glutPostRedisplay()
42lab10.cpp
void myMouse(int btn, int state, int x, int
y) if(btnGLUT_LEFT_BUTTON state
GLUT_DOWN) mouseStatestate mouseButtonb
tn mouseXx mouseYy else
if(btnGLUT_LEFT_BUTTON state GLUT_UP)
mouseState-1 else if(btnGLUT_RIGHT_BUT
TON state GLUT_DOWN) mouseStatestate
mouseButtonbtn mouseXx mouseYy
else if(btnGLUT_RIGHT_BUTTON state
GLUT_UP) mouseState-1 else
if(btnGLUT_MIDDLE_BUTTON state
GLUT_DOWN) xThetayThetazTheta0. scale1.
0 else return if(idleFlag
stateGLUT_DOWN) glutIdleFunc(NULL) else
if(idleFlag stateGLUT_UP) glutIdleFunc(myI
dle) glutPostRedisplay()
43lab10.cpp
void myMotion(int x, int y) if(mouseButton
GLUT_LEFT_BUTTON mouseState GLUT_DOWN)
yTheta - (mouseX - x)/1. xTheta -
(mouseY - y)/1. else if(mouseButton
GLUT_RIGHT_BUTTON mouseState GLUT_DOWN)
if(mouseY!y) scale scale
pow(scaleDelta, (mouseY - y)/1.) else
return mouseX x mouseY y glutPostRedispl
ay() void myKeyboard(unsigned char theKey, int
x, int y) switch (theKey) case ' '
idleFlag!idleFlag
if(idleFlag) glutIdleFunc(myIdle) else
glutIdleFunc(NULL) break case 27
exit(-1) // esc key glutPostRedisplay() vo
id main(int argc, char argv) glutInit(argc,a
rgv) glutInitDisplayMode (GLUT_DOUBLE
GLUT_RGB) glutInitWindowSize(500,500) glutInit
WindowPosition(0,0) glutCreateWindow("lab09")
glutReshapeFunc(myReshape) glutDisplayFunc(myDis
play) glutMouseFunc(myMouse) glutMotionFunc(m
yMotion) glutKeyboardFunc(myKeyboard) glutMain
Loop()
44Homework 4.
- In two weeks
- Draw a house with more than 2 windows and 2
doors. - Rotate the house depend on the mouse movement
while left mouse button are pressed.