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

1 / 12
About This Presentation
Title:

OpenGL 3D and Animation for Simulating a Solar System

Description:

I have multiple systems of planets and moons (you only need 1 planet and 1 ... Objects can occlude (block visibility) one another, we need a depth buffer to ... – PowerPoint PPT presentation

Number of Views:369
Avg rating:3.0/5.0
Slides: 13
Provided by: AdamS81
Category:

less

Transcript and Presenter's Notes

Title: OpenGL 3D and Animation for Simulating a Solar System


1
OpenGL 3D and AnimationforSimulating a Solar
System
  • Assignment 3
  • CMPS 160

2
Demo
  • My code is in 3 files main.cc systems.h
    systems.cc
  • 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)

3
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?

4
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

5
Complex Hidden State
  • For a simple sun, earth, moon simulation we need
    to track
  • Sun
  • earths orbital rotation state
  • Earth
  • earths axial rotation state
  • moons orbital rotation state
  • Moon
  • moons 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!

6
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 dont 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()

7
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()

8
Camera vs Object Motion
  • OpenGL doesnt make a distinction here, but you
    should.
  • Scene is rendered from eyes frame of reference.
  • Simulation is run from the suns frame of
    reference.
  • Use gluLookAt() or other functions to move the
    simulated worlds origin with respect to the eye
    before drawing the world. This has same logical
    effect as moving the eye within the world.

9
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 cameras
    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 youll need its state
    back later.

10
Complex Hierarchical Drawing Using the Current
State Variables(easier viewing on your own
computer)
arm_length
  • glPushMatrix()
  • drawTower(tower_height)
  • glTranslate(0,tower_height,0)
  • glRotate(arm_angle,1,0,0)
  • drawControlBox()
  • drawArm(arm_length)
  • glTranslate(0,0,arm_length)
  • glPushMatrix()
  • glRotate(pulley_angle,0,1,0)
  • drawPulley()
  • glPopMatrix()
  • glTranslate(-cable_length,0,0)
  • drawBarrel()
  • glPopMatrix()
  • glPushMatrix()
  • glTranslate(first_barrel,0,0)
  • for(I0 Ilt4 I)
  • drawBarrel()

pulley_angle
arm_angle
cable_length
tower_height
firsrt_barrel
barrel_spacing
11
I still dont 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 http//www.cs.virginia.edu/gfx/C
    ourses/2004/Intro.Spring.04/Lectures/lecture04.ppt

12
Base Code
  • You write main.cc from scratch this time
    (really!). Copying the old main.cc is fine, but
    youll 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 suns lighting at the current origin
Write a Comment
User Comments (0)
About PowerShow.com