For this lab, you will be modeling and animating entire solar system, using coordinate transformations. Mostly you will be making judicious use of Translations, Scalings, and Rotations
, to work in different frames.
$ cd [~]$ ssh-add Enter passphrase for /home/ghopper1/.ssh/id_rsa: Identity added: /home/ghopper1/.ssh/id_rsa (/home/ghopper1/.ssh/id_rsa) [~]$ cd ~/cs40/ [labs]$ git clone git@github.swarthmore.edu:CS40-F18/lab04-YOURUSERNAME-YOURPARTNERNAME.git ./lab04
[04]$ cd ~/cs40/lab04 [04]$ ln -s /usr/local/doc/textures/ dataMake a build directory in your lab04 directory and run
cmake
, and make
.
[04]$ cd ~/cs40/lab04 [04]$ mkdir build [04]$ cd build [build]$ cmake .. [build]$ make -j8 [build]$ ./lab4
If you expect to see textures, but you don't, or if your program crashes, you may have forgotten to add the symlink above before building. You can manually add it to your build directory.
cd ~/cs40/lab04/build ln -s /usr/local/doc/textures/ data
solarData.txt
in your lab04
folder contains some basic info about our solar system (and Pluto, which was disqualified as a planet, but is thinking about a comeback). The information contains the radius of each object (in thousands of km), the distance from the sun ($a$, in millions of km), the period of rotation around the sun ($\tau$, in earth years), the eccentricity of the elliptical orbit, and the inclination of the orbit with respect to a plane through the center of the sun. You should use this information to model a solar system as a collection of rotating spheres.
You can parse this data file using code similar to that in MyPanelOpenGL::parsePlanets
.
You must create a planet class or planet struct to organize necessary planet info. I have provided a sample class in planet.h/.cpp
, but feel free to modify this or write a completely separate data structure.
You must draw and animate the sun and at least the first eight planets listed. Feel free to express you opinions on Pluto in your final lab. All planets should revolve in the same direction around the sun, but not at the same rate. You may assume the planets revolve in circular orbits, but the eccentricity is given if you want to model elliptical orbits.
All planets should spin about their axis according to the time of day. The tilt column of SolarData.txt
describes the tilt of the planet's axis with respect to the $\hat{y}$-axis of the sun. Planets should revolve around this tilted axis. You will likely want a way to speed up and slow down time so you can observe spinning and orbiting as desired.
Assign a texture to each of the planets. You may want to add these parameters to the data file, so you can refresh them without recompiling.
You must model at least one moon around one of the planets. You can choose the size of the moon, radius of orbit, and period of rotation, or consult a source for reasonable defaults. You can use the same moon texture for all moons, use a separate fragment shader, or modify your fragment shader to support textured and non-textured spheres.
Add keyboard controls to pan and zoom. You can decide how this is implemented. You should modify the m_view
matrix when you do this.
You can use the Sphere
class to model the planets. Note, you do not need to create multiple Sphere
instances. You can reuse the same VBO and apply different transforms to the shader before drawing each planet.
Work incrementally. Get your data file parser working and then print out the info each planet to ensure you parsed the data correctly. Make subtle adjustments to the m_view
matrix using QMatrix4x4::ortho
, or until you understand what you are looking out and how the scene is effected.
Explore the MatrixStack class and try some examples in PaintGL with multiple objects.
You can use any of the QMatrix4x4 methods. Methods like translate
, rotate
and scale
, modify an existing matrix, by multiplying it on the right
.
Each planet/moon can have its own uniform model
matrix in the vertex shader. You should probably only use one view
matrix for the entire system.
Use the Square
to help orient you if you find yourself getting lost.
Use a QTimer to animate. Do not try to maintain a global 'time'. Instead, each time the QTimer triggers, consider that $\Delta_t$ time has elapsed in the solar system. Pass this $\Delta$ to each planet so they can update their spin and rotation appropriately.