Project description: using C++ to implement the OpenGL GLUT to implement a simple planetary system in the solar system. It will involve some mathematical foundation of 3d graphics technology, 3d coordinate system in OpenGL, illumination model in OpenGL, and keyboard event processing of GLUT.
OpenGL includes many rendering functions, but they are designed to be independent of any windowing system or operating system. Therefore, it does not contain functions to create open Windows or read the time from the keyboard or mouse, or even the most basic display window function, so it is completely impossible to create a complete graphics program using OpenGL alone. And most programs need to interact with the user (responding to keyboard and mouse actions, etc.). GLUT provides this convenience.
GLUT is an acronym for The OpenGL Utility Toolkit. GLUT is a tool library that handles calls and I/O operations with the underlying operating system. With GLUT, you can mask some of the details of the underlying OPERATING system GUI implementation. Using only the GLUT API, you can create application Windows, handle mouse and keyboard events, and so on across platforms.
In the whole celestial system, they are all one Star. Planets and stars can be distinguished only by whether they have parent nodes. Secondly, for different planets, they usually have their own materials, and different materials will show whether they shine or not, thus we have a preliminary object model. Therefore, we can divide the planets into stars that can rotate and orbit around a certain point, planets with special materials, and planets that can give off light.
I. Programming model assumptions:
Planets move in circular orbits;
The rotation speed remains the same;
Each time you refresh your drawing, assume that a day has passed.
Two, the overall idea:
Initialize a planet object.
Initialization of OpenGL engine, onDraw and onUpdate;
Planets should be responsible for their own properties, devolution, and transform correlation drawing, so provide a draw draw() method when designing planets’ classes;
The planet should also handle its own rotation and revolution of the update display, so when designing the planet class should also provide an update method update();
Call the draw() method of the planet in onDraw();
If you have a problem with C/C++ one item is a warm one (● ‘◡’ ●). A full item: one item for free and a live programme.
Call the update() method of the planet in onUpdate();
Adjust the display throughout the solar system on the onKeyboard().
3. Each planet has the following properties:
Color color
Radius of revolution RADIUS
Rotation speed selfSpeed
Revolution speed Speed
Distance from the center of the sun
Orbiting planet parentStar
Current rotation Angle of alphaSelf
The current revolution Angle alpha
So there are the following classes:
In the solar system, the solar system is obviously made up of planets; And, for the solar system, the view refresh after the motion of the planets in the solar system should be completed by the solar system. Therefore, the SolarSystem class can be designed as follows:
The basic framework of the program: main.cpp
The framework and ideas of this experiment come from the experimental building, and the operation effect is shown in the figure below:
prompt
Single buffering, is to execute all the drawing instructions in the window, is directly on the window drawing, such drawing efficiency is relatively slow, if the use of single buffering, and computer processing performance is not enough, the screen will appear flashing.
Double buffering, drawing instructions will be completed in a buffer, drawing here is very fast, after the completion of drawing instructions, and then through the exchange of instructions to complete the graphics immediately displayed on the screen, so as to avoid the incomplete drawing, high efficiency.
Double buffer is mainly divided into foreground buffer and background buffer, foreground buffer that we say see the screen, background buffer is maintained in memory, invisible to the user. With double buffering, all drawing takes place in the background, and when the drawing is complete, the results are copied to the screen.
The advantage of this is that if we let the drawing operation operate with the graphics card in real time, when the drawing task is complex, the IO operation will also become complex, resulting in low performance. Double buffering will only swap the buffer will be completed after the drawing results directly sent to the graphics card for rendering, IO significantly reduced.