Question
Please I want to modify the error with this code and run it, I want to run it after deleting the key function. Run in
#include
#ifdef __SUN__
#include
#else
#include
#endif
#include
#include
#include
/* GLUT callback Handlers */
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// Planet class that will hold all our planetary data
class Planet {
public :
std::string name ="";
double x=0;
double y=0;
double c1=0;
double c2=0;
double c3=0;
double f=0;
double a=0;
double s1=0;
Planet(std::string, double, double, double, double, double, double);
void glStuff(double t, double closeness);
void printPlanet ();
};
// Simple planet constructor
Planet::Planet(std::string name="",double c1=0,double c2=0, double c3=0, double f=0,double a=0, double s1=0){
this->name = name;
this->x=0;
this->y=0;
this->c1=0;
this->c2=0;
this->c3=0;
this->f=0;
this->a=0;
this->s1=0;
}
//Function will compute new planet position
void Planet::glstuff(double t, double closeness) {
glColor3d(c1,c2,c3);
glPushMatrix();
glTranslated(x,y,closeness);
glRotated(50.0*t,0,0,1);
glutSolidSphere(s1,20,20);
glPopMatrix();
}
static double closeness = -3.0;
Planet** planets;
double moon_x; // moon x position
double moon_y; // moon y position
static double t; // time
static void display (void) // void
{
t=glutGet(GLUT_ELAPSED_TIME)/ 1000.0;
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
(*planets [3]) .g1Stuff (t, closeness) ;
//moon orbit calculation
moon_x = -sin(t)*0.5+ planets[3]->x;
moon_y=cos(t)*0.5+planets[3]->y;
//Moon
glColor3d (0.7,0.7,0.7);
glPushMatrix ();
glTranslated(moon_x ,moon_y , closeness);
glRotated (60,1,0,0);
glRotated(50.0*t, ,0,0,1);
glutSolidSphere (0.1, 20, 20) ;
glPopMatrix();
glutSwapBuffers();
}
static void key (unsigned char key, int x, int y)
{
switch (key)
case 27:
case 'q':
exit (0);
break;
case "+":
if (closeness
closeness += 0.5;
}
break;
case '-':
closeness -=0.5;
break;
case'a':
glClearColor (0,0,0,0);
break;
case 'b':
glClearColor (1,1,1,0);
break;
}
glutPostRedisplay();
}
Static void idle(void)
{
glutPostRedisplay();
}
Const GLfloat light_ambient[] = {0.0f , 0.0f , 0.0f , 1.0f};
Const GLfloat light_diffuse[] = {1.0f , 1.0f , 1.0f , 1.0f};
Const GLfloat light_specular[] = {1.0f , 1.0f , 1.0f , 1.0f };
Const GLfloat light_position[] = {-20.0f , 10.0f , 0.0f , 0.0f};
Const GLfloat mat_ambient[] = {0.7f , 0.7f , 0.7f , 1.0f};
Const GLfloat mat_diffuse[] = {0.8f , 0.8f , 0.8f , 1.0f};
Const GLfloat mat_specular[] = {1.0f , 1.0f , 1.0f , 1.0f};
Const GLfloat high_shininess[] = {50.0f};
int main(int argc , char*argv[])
{
Planet = new Planet*[1];
Planet d( "earth", 0.0 , 0.0 , 0.7 , 0.2 , 4.0 , 0.2); planet[3]=&d;
glutInit(&argc , argv);
glutInitWindowSize(900,600);
glutInitWindowPosition(100,20);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreatWindow("Earth AND Moon");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(Key);
glutIdleFunc(idle);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHTE);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHTE, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHTE, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHTE, GL_SPECULAR , light_specular);
glLightfv(GL_LIGHTE, GL_POSITION,
glight_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR , mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
glutMainLoop();
return EXIT_SUCCESS;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started