Question: #include #include float x = 0 ; float y = 0 ; int ligt = 0 ; float red = 1 . 0 f ,

#include
#include
float x =0;
float y =0;
int ligt =0;
float red =1.0f, blue =0.0f, green =0.0f;
void processSpecialKeys(int key, int x, int y);
void processSpecialKeys(int key, int x, int y){
switch (key){
case GLUT_KEY_F1:
red =1.0;
green =1.0;
blue =0.0; break;
case GLUT_KEY_F2:
red =0.666;
green =.666;
blue =1.0; break;
case GLUT_KEY_F3:
red =0.0;
green =0.555;
blue =.555; break;
}
}
void Drow(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(0.0f,0.0f,150.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
GLfloat position[]={0,0,1,0};
glLightfv(GL_LIGHT1, GL_POSITION, position);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//spaceship
glColor3f(red, green, blue);
glColor3f(0,1,1);
glPushMatrix();
glTranslated(x, y,0);
glRotatef(50,0,0,1);
glScaled(1,.9,1);
glutSolidSphere(13,15,15);
glPopMatrix();
glPushMatrix();
// the moon
glColor3f(.888,.888,.888);
glTranslated(-50,-50,0);
glutSolidSphere(30,100,5);
glPopMatrix();
//black circule in the moon
glPushMatrix();
glColor3f(0,1,0);
glTranslated(-40,-40,0);
glutSolidSphere(10,20,5);
glPopMatrix();
glPushMatrix();
//the earth
glColor3f(0,0,.777);
glTranslated(-10,40,0);
glutSolidSphere(17,100,100);
glPopMatrix();
glPushMatrix();
glTranslated(x, y,0);
glLineWidth(5.0f);
glBegin(GL_LINES);
glColor3f(1,1,0);
glVertex3f(0,0,0); // Center of the circle
glVertex3f(12,12,9); // Point on the circle's circumference
glEnd();
glPopMatrix();
glPushMatrix();
glTranslated(x, y,0);
glLineWidth(5.0f);
glBegin(GL_LINES);
glColor3f(1,1,0);
glVertex3f(-4,-2,0); // Center of the circle
glVertex3f(-17,-11,-16); // Point on the circle's circumference
glEnd();
glPopMatrix();
glPushMatrix();
glTranslated(x, y,0);
glLineWidth(5.0f);
glBegin(GL_LINES);
glColor3f(1,1,0);
glVertex3f(-3,-6,-1); // Center of the circle
glVertex3f(-8,-19,-17); // Point on the circle's circumference
glEnd();
glPopMatrix();
glColor3f(1.0f,1.0f,1.0f);
glPointSize(4.5f); // Set the point size for stars
glBegin(GL_POINTS);
glColor3f(1,1,1);
for (int i =0; i <1000; ++i){
float rx =(float)(rand()%600-300); // Random x coordinate within viewport
float ry =(float)(rand()%600-300); // Random y coordinate within viewport
glVertex3f(rx, ry,-50.0f); // Draw stars randomly in the background
}
glEnd();
//circul around the space ship
glPushMatrix();
glColor3f(1,1,0);
glTranslated(x, y,0);
glRotatef(250,1,0,1);
glutSolidTorus(2.5,17,15,15);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_LIGHT0);
//moving the space ship
x +=0.03;
if (x >50){
x =-50;
}
y +=0.03;
if (y >50){
y =-50;
}
glutSwapBuffers();
glutSpecialFunc(processSpecialKeys);
}
int main(){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("project");
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1,80,-100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutDisplayFunc(Drow);
glClearColor(0,0,0,0);
glutIdleFunc(Drow);
glutMainLoop();
}
I want to modify the code above by 1- Adding gray spots on the moon to make it more realistic. 2- Adding a green color to the blue ball to resemble planet Earth.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!