opengl 3d and animation for simulating a solar system l.
Skip this Video
Loading SlideShow in 5 Seconds..
OpenGL 3D and Animation for Simulating a Solar System PowerPoint Presentation
Download Presentation
OpenGL 3D and Animation for Simulating a Solar System

Loading in 2 Seconds...

play fullscreen
1 / 12

OpenGL 3D and Animation for Simulating a Solar System - PowerPoint PPT Presentation

  • Uploaded on

OpenGL 3D and Animation for Simulating a Solar System. Assignment 3 CMPS 160. Demo. My code is in 3 files: systems.h 364 lines of non-base code I have multiple systems of planets and moons (you only need 1 planet and 1 moon to get credit). New Concepts.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'OpenGL 3D and Animation for Simulating a Solar System' - jacoba

An Image/Link below is provided (as is) to download presentation

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.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
  • My code is in 3 files: systems.h
  • 364 lines of non-base code
  • I have multiple systems of planets and moons (you only need 1 planet and 1 moon to get credit)
new concepts
New Concepts
  • 3 dimensional world
  • Complex hidden state
  • Full screen animation
  • Multiple frames of reference
  • Camera vs Object Motion

How do these changes affect my design compared to the 2D painting program?

3d world
3D World
  • 3 parameters (x,y,z), duh - glVertex3f(…)
  • Using perspective projection instead of orthographic - gluPerspective(…)
  • Objects can occlude (block visibility) one another, we need a depth buffer to figure out when this is happening - glutInitDisplayMode(…) with GLUT_DEPTH, glEnable(GL_DEPTH_TEST), glClear(..) with GL_DEPTH_BUFFER_BIT
complex hidden state
Complex Hidden State

For a simple sun, earth, moon simulation we need to track…


earth’s orbital rotation state


earth’s axial rotation state

moon’s orbital rotation state


moon’s axial rotation state

AND on top of that we need up update this state using some constants for the rate of each rotation and the amount of time that has passed before we draw the scene each time!

full screen animation
Full Screen Animation
  • In painting assignment we only drew one picture. This program should draw new pictures over and over as fast as it can.
  • All painting goes in the display callback
  • Add an idle callback that tells GLUT to git’ drawin’ again - glutPostRedisplay()
  • We don’t want the user to watch us drawing so we draw to a back buffer while user looks at front, then swap them when we are ready to show them the new picture - glutSwapBuffers() -- implicitly flushes
  • We want to take up the whole screen -- use glutFullScreen() after glutCreateWindow(…)
multiple frames of reference the important part of this assignment
Multiple Frames of Reference(the important part of this assignment)
  • Earth rotates around the sun
  • Earth rotates around its own axis
  • The Moon rotates around Earth
  • The Moon rotates around its own axis
  • OpenGL does all of the hard math for you as long as you tell it what frame you want to work in - glTranslate, glRotate, glPushMatrix, glPopMatrix, glScale…
  • Ideally, you can do the whole assignment without sin() and cos()
camera vs object motion
Camera vs Object Motion
  • OpenGL doesn’t make a distinction here, but you should.
  • Scene is rendered from eye’s frame of reference.
  • Simulation is run from the sun’s frame of reference.
  • Use gluLookAt(…) or other functions to move the simulated world’s origin with respect to the eye before drawing the world. This has same logical effect as moving the eye within the world.
camera setup
Camera Setup
  • In your reshape callback reset the projection matrix to be a perspective projection with the appropriate aspect ratio, nothing more.
  • In your display callback, the first thing change to the modelview matrix should be the camera’s transformation (with gluLook at), after that everything (the solar system) you draw will be relative to the shifted origin so it looks correct from the eye point. Save the modelview matrix anytime you think you’ll need its state back later.
complex hierarchical drawing using the current state variables easier viewing on your own computer





Complex Hierarchical Drawing Using the Current State Variables(easier viewing on your own computer)

















for(I=0; I<4; I++) {












i still don t really feel like i understand opengl in general
“I still don’t really feel like I understand OpenGL in general”
  • At other schools there are whole classes on OpenGL or at least a few lecture sessions about it
  • cmps160 is more concept-based, you only learn to program with OpenGL in the lab.
  • I learned OpenGL myself from examples and documentation. However, if you learn best through colorful PowerPoint presentations, here is a good starter covering everything up through this assignment:
base code
Base Code
  • You write from scratch this time (really!). Copying the old is fine, but you’ll still have to make some major changes to the contents of your callbacks.
  • We provide two functions (in helper.h) to make your solar system pretty if you desire:
  • helperSetupLighting() -- call this in main after you have registered the callbacks
  • helperPlaceLight() -- call this when you are drawing the scene in the display callback -- places the sun’s lighting at the current origin