SlideShare a Scribd company logo
#include "windows.h"
#include <glglut.h>
#define sunRaduis 0.4
#define earthRaduis 0.08
#define moonRaduis 0.018
GLfloat rotationSpeed = 0.07;
GLfloat daysInYear = 365;
GLfloat year = 0.0; //in degrees
GLfloat day = 0.0;
GLfloat moonAroundEarth = 0.0;
GLfloat moonItsSelf = 0.0;
GLfloat earthOrbitRadius = 1.2;
GLfloat moonOrbitRadius = 0.2;
GLfloat moonAroundEarthRate = 1 * rotationSpeed;
GLfloat moonRotationItselfRate = 1.0 * rotationSpeed;
GLfloat dayRate = 5.0 * rotationSpeed;
GLfloat yearRate = daysInYear / 360.0 * dayRate * rotationSpeed;
void drawSolarSystem()
{
glPushMatrix();
gluLookAt(0.0,0.0,-3.0,0.0,0.0,1.0,0.0,-3.0,0.0);
//Drawing the sun.
glColor3f(1,0,0);
glutSolidSphere(sunRaduis,40,40);
glPushMatrix();
glRotatef(year,0.0,0,1.0); //rotation for earth around
y-axis
glTranslatef(earthOrbitRadius,0.0,1.0); //
translation for earth around y-axis
glRotatef(-year,0.0,0,1.0); //rotation for earth around
y-axis
//EARTH
glPushMatrix();
//color earth
glColor3f(0.0,0.0,1);
//Drawing earth
glutSolidSphere(earthRaduis,10,10);
glPopMatrix();
// rotation for moon.
glRotatef(moonAroundEarth,0.0,0.0,1.0);
// translation for moon.
glTranslatef(moonOrbitRadius,0.2,0.2); //we took along x-axis and y-axis
// around earth rotation.
glRotatef(-moonAroundEarth,0.0,0.0,1.0);
glColor3f(1,1,1);
// drawing moon
glutSolidSphere(moonRaduis,20,20);
glPopMatrix();
glPopMatrix();
}
void Initialization()
{
glClearColor(0.0,0.0,0.0,0.0);
glClearDepth(10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void displayFunc()
{
glClear(GL_COLOR_BUFFER_BIT);
//now going to drawSolarSystem() function
drawSolarSystem();
glFlush();
glutSwapBuffers();
}
void reshapeFunc(int x, int y)
{
if (y == 0 || x==0) return;
glLoadIdentity();
gluPerspective(45,(GLdouble)x/(GLdouble)y,0.5,200.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y);
//now going to displayFunc() function
displayFunc();
}
void idleFunc(void)
{
// idle event call back,here we increase the values and redisply .
day = day + dayRate;
year= year + yearRate;
moonItsSelf = moonItsSelf + moonRotationItselfRate;
moonAroundEarth = moonAroundEarth + moonAroundEarthRate;
//now going to displayFunc() function
displayFunc();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800,800);
glutCreateWindow("Sun,Earth,Moon = ROTATION ");
Initialization();
glutDisplayFunc(displayFunc);
glutReshapeFunc(reshapeFunc);
glutIdleFunc(idleFunc);
glutMainLoop();
return 0;
}

More Related Content

Viewers also liked

Proyecto de las tic
Proyecto de las ticProyecto de las tic
Proyecto de las tic
Marcela Perez
 
Nation State dan Khilafah
Nation State dan KhilafahNation State dan Khilafah
Nation State dan Khilafah
Alat_Survey_Pemetaan
 
Uznemejdarbiba riebinuvsk 012012
Uznemejdarbiba riebinuvsk 012012Uznemejdarbiba riebinuvsk 012012
Uznemejdarbiba riebinuvsk 012012
Neils Balgalis
 
Tecnotaaller
TecnotaallerTecnotaaller
Tecnotaaller
tali44
 
Ultimo formato magola
Ultimo formato magolaUltimo formato magola
Ultimo formato magola
magola1
 
An inquiry based project for stem
An inquiry based project for stemAn inquiry based project for stem
An inquiry based project for stem
Laura Bradford
 
Gif and images
Gif and imagesGif and images
Gif and images
macraildr
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cpp
Robi Parvez
 
Relative Clauses
Relative ClausesRelative Clauses
Relative Clauses
Seemeen Khan Yousufzai
 

Viewers also liked (10)

Proyecto de las tic
Proyecto de las ticProyecto de las tic
Proyecto de las tic
 
Nation State dan Khilafah
Nation State dan KhilafahNation State dan Khilafah
Nation State dan Khilafah
 
Uznemejdarbiba riebinuvsk 012012
Uznemejdarbiba riebinuvsk 012012Uznemejdarbiba riebinuvsk 012012
Uznemejdarbiba riebinuvsk 012012
 
Tecnotaaller
TecnotaallerTecnotaaller
Tecnotaaller
 
Ultimo formato magola
Ultimo formato magolaUltimo formato magola
Ultimo formato magola
 
An inquiry based project for stem
An inquiry based project for stemAn inquiry based project for stem
An inquiry based project for stem
 
Gif and images
Gif and imagesGif and images
Gif and images
 
Ass day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cppAss day2 1_checkerboard...copy in cpp
Ass day2 1_checkerboard...copy in cpp
 
Relative Clauses
Relative ClausesRelative Clauses
Relative Clauses
 
วังชิ้น
วังชิ้นวังชิ้น
วังชิ้น
 

Ass day2 3_sun_moon_earth

  • 1. #include "windows.h" #include <glglut.h> #define sunRaduis 0.4 #define earthRaduis 0.08 #define moonRaduis 0.018 GLfloat rotationSpeed = 0.07; GLfloat daysInYear = 365; GLfloat year = 0.0; //in degrees GLfloat day = 0.0; GLfloat moonAroundEarth = 0.0; GLfloat moonItsSelf = 0.0; GLfloat earthOrbitRadius = 1.2; GLfloat moonOrbitRadius = 0.2; GLfloat moonAroundEarthRate = 1 * rotationSpeed; GLfloat moonRotationItselfRate = 1.0 * rotationSpeed; GLfloat dayRate = 5.0 * rotationSpeed; GLfloat yearRate = daysInYear / 360.0 * dayRate * rotationSpeed; void drawSolarSystem() { glPushMatrix(); gluLookAt(0.0,0.0,-3.0,0.0,0.0,1.0,0.0,-3.0,0.0); //Drawing the sun. glColor3f(1,0,0); glutSolidSphere(sunRaduis,40,40); glPushMatrix(); glRotatef(year,0.0,0,1.0); //rotation for earth around y-axis glTranslatef(earthOrbitRadius,0.0,1.0); // translation for earth around y-axis glRotatef(-year,0.0,0,1.0); //rotation for earth around y-axis //EARTH glPushMatrix(); //color earth glColor3f(0.0,0.0,1); //Drawing earth glutSolidSphere(earthRaduis,10,10); glPopMatrix(); // rotation for moon. glRotatef(moonAroundEarth,0.0,0.0,1.0); // translation for moon. glTranslatef(moonOrbitRadius,0.2,0.2); //we took along x-axis and y-axis // around earth rotation. glRotatef(-moonAroundEarth,0.0,0.0,1.0); glColor3f(1,1,1); // drawing moon glutSolidSphere(moonRaduis,20,20); glPopMatrix(); glPopMatrix(); } void Initialization() { glClearColor(0.0,0.0,0.0,0.0); glClearDepth(10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();
  • 2. } void displayFunc() { glClear(GL_COLOR_BUFFER_BIT); //now going to drawSolarSystem() function drawSolarSystem(); glFlush(); glutSwapBuffers(); } void reshapeFunc(int x, int y) { if (y == 0 || x==0) return; glLoadIdentity(); gluPerspective(45,(GLdouble)x/(GLdouble)y,0.5,200.0); glMatrixMode(GL_MODELVIEW); glViewport(0,0,x,y); //now going to displayFunc() function displayFunc(); } void idleFunc(void) { // idle event call back,here we increase the values and redisply . day = day + dayRate; year= year + yearRate; moonItsSelf = moonItsSelf + moonRotationItselfRate; moonAroundEarth = moonAroundEarth + moonAroundEarthRate; //now going to displayFunc() function displayFunc(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(800,800); glutCreateWindow("Sun,Earth,Moon = ROTATION "); Initialization(); glutDisplayFunc(displayFunc); glutReshapeFunc(reshapeFunc); glutIdleFunc(idleFunc); glutMainLoop(); return 0; }