Solar System OpenGL v1.0.0
Loading...
Searching...
No Matches
main.cpp File Reference

Main entry point for the Solar System simulation application. More...

#include <iostream>
#include <cmath>
#include <GL/glut.h>
#include "stb_image.h"
#include "textures.h"
#include "planet_radii.h"
#include "orbit_radii.h"
#include "planet_speeds.h"
#include "texture_loader.cpp"
#include "mouse_handler.cpp"
#include "keyboard_handler.cpp"

Macros

#define GL_SILENCE_DEPRECATION
 

Functions

void printCommandMenu ()
 Prints the command menu for user instructions.
 
void init ()
 Initializes OpenGL settings and loads textures.
 
void drawTexturedSphere (GLuint texture, float radius)
 Draws a textured sphere with the given texture and radius.
 
void drawOrbit (float radius)
 Draws an orbit with the given radius.
 
void drawSun (bool withLighting)
 Draws the sun with optional lighting.
 
void drawSaturnRing (float innerRadius, float outerRadius)
 Draws Saturn's rings.
 
void drawPlanet (GLuint texture, float orbitRadius, float orbitSpeed, float planetRadius, const char *name, bool hasRing=false, float innerRingRadius=0.0f, float outerRingRadius=0.0f)
 Draws a planet with the specified parameters.
 
void display ()
 Displays the current frame.
 
void reshape (int w, int h)
 Handles window resizing events.
 
void update (int value)
 Updates the simulation state.
 
int main (int argc, char **argv)
 Main entry point for the application.
 

Variables

GLuint sunTexture
 
GLuint mercuryTexture
 
GLuint venusTexture
 
GLuint earthTexture
 
GLuint marsTexture
 
GLuint jupiterTexture
 
GLuint saturnTexture
 
GLuint saturnRingTexture
 
GLuint uranusTexture
 
GLuint neptuneTexture
 
float rotationAngle = 0.0
 

Detailed Description

Main entry point for the Solar System simulation application.

This file contains the main function and the core rendering logic for the Solar System simulation, including initialization, drawing, and updating the scene. It also handles user input via keyboard and mouse.

Macro Definition Documentation

◆ GL_SILENCE_DEPRECATION

#define GL_SILENCE_DEPRECATION

Function Documentation

◆ display()

void display ( )

Displays the current frame.

This function clears the color and depth buffers, sets up the camera view, and draws all celestial bodies based on the current state. It also handles the selection of individual planets or the entire solar system.

◆ drawOrbit()

void drawOrbit ( float radius)

Draws an orbit with the given radius.

Parameters
radiusThe radius of the orbit.

This function draws a circular orbit using line loops, representing the path on which a planet revolves around a star.

◆ drawPlanet()

void drawPlanet ( GLuint texture,
float orbitRadius,
float orbitSpeed,
float planetRadius,
const char * name,
bool hasRing = false,
float innerRingRadius = 0.0f,
float outerRingRadius = 0.0f )

Draws a planet with the specified parameters.

Parameters
textureThe texture to apply to the planet.
orbitRadiusThe radius of the planet's orbit around the sun.
orbitSpeedThe speed of the planet's orbit.
planetRadiusThe radius of the planet.
nameThe name of the planet (for logging purposes).
hasRingIf true, a ring is drawn around the planet (default is false).
innerRingRadiusThe inner radius of the ring (default is 0.0f).
outerRingRadiusThe outer radius of the ring (default is 0.0f).

This function draws a planet with the specified texture and radius, and optionally draws a ring around the planet if specified.

◆ drawSaturnRing()

void drawSaturnRing ( float innerRadius,
float outerRadius )

Draws Saturn's rings.

Parameters
innerRadiusThe inner radius of the rings.
outerRadiusThe outer radius of the rings.

This function draws Saturn's rings as a series of textured disks. The transparency and spacing of the disks create the appearance of rings.

◆ drawSun()

void drawSun ( bool withLighting)

Draws the sun with optional lighting.

Parameters
withLightingIf true, lighting effects are enabled; otherwise, they are disabled.

This function draws the sun using the sun texture. It also applies a rotation based on the current rotation angle. Lighting effects are applied if specified.

◆ drawTexturedSphere()

void drawTexturedSphere ( GLuint texture,
float radius )

Draws a textured sphere with the given texture and radius.

Parameters
textureThe texture to apply to the sphere.
radiusThe radius of the sphere.

This function draws a textured sphere using the specified texture and radius, representing a celestial body.

◆ init()

void init ( )

Initializes OpenGL settings and loads textures.

This function sets up OpenGL settings, such as enabling texture mapping and depth testing. It also loads textures for all celestial bodies and prints the command menu.

◆ main()

int main ( int argc,
char ** argv )

Main entry point for the application.

Parameters
argcThe number of command-line arguments.
argvThe command-line arguments.
Returns
0 on successful execution.

This function initializes GLUT, sets up the window, and registers callback functions for display, reshape, keyboard, and mouse events. It then enters the GLUT main loop.

◆ printCommandMenu()

void printCommandMenu ( )

Prints the command menu for user instructions.

This function prints a menu of commands to the console, providing users with information on how to control the simulation using keyboard and mouse inputs.

◆ reshape()

void reshape ( int w,
int h )

Handles window resizing events.

Parameters
wThe new width of the window.
hThe new height of the window.

This function adjusts the viewport and projection matrix when the window is resized to ensure the correct aspect ratio and perspective.

◆ update()

void update ( int value)

Updates the simulation state.

Parameters
valueUnused parameter for timer function.

This function updates the rotation angle for animation and schedules the next update call. It also checks if the simulation is paused or running.

Variable Documentation

◆ earthTexture

GLuint earthTexture

◆ jupiterTexture

GLuint jupiterTexture

◆ marsTexture

GLuint marsTexture

◆ mercuryTexture

GLuint mercuryTexture

◆ neptuneTexture

GLuint neptuneTexture

◆ rotationAngle

float rotationAngle = 0.0

◆ saturnRingTexture

GLuint saturnRingTexture

◆ saturnTexture

GLuint saturnTexture

◆ sunTexture

GLuint sunTexture

◆ uranusTexture

GLuint uranusTexture

◆ venusTexture

GLuint venusTexture