Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include GLfloat angle = 0 . 0 f; GLfloat scale = 1 . 0 f; GLfloat xTrans = 0 . 0 f; GLfloat yTrans =

#include
GLfloat angle =0.0f;
GLfloat scale =1.0f;
GLfloat xTrans =0.0f;
GLfloat yTrans =0.0f;
void init(){
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.0,1.0,100.0);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-5.0f);
glTranslatef(xTrans, yTrans, 0.0f);
glRotatef(angle,1.0f,1.0f,1.0f);
glScalef(scale, scale, scale);
glBegin(GL_QUADS);
glColor3f(1.0,1.0,0.0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,1.0);
glVertex3f(1.0,1.0,1.0);
glVertex3f(-1.0,1.0,1.0);
glColor3f(0.0,1.0,1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,1.0,-1.0);
glVertex3f(1.0,1.0,-1.0);
glVertex3f(1.0,-1.0,-1.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(-1.0,1.0,-1.0);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(1.0,1.0,1.0);
glVertex3f(1.0,1.0,-1.0);
glColor3f(1.0,0.0,0.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(1.0,-1.0,-1.0);
glVertex3f(1.0,-1.0,1.0);
glVertex3f(-1.0,-1.0,1.0);
glColor3f(1.0,0.0,1.0);
glVertex3f(1.0,-1.0,-1.0);
glVertex3f(1.0,1.0,-1.0);
glVertex3f(1.0,1.0,1.0);
glVertex3f(1.0,-1.0,1.0);
glColor3f(1.0,1.0,1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(-1.0,1.0,-1.0);
glEnd();
glutSwapBuffers();
}
void update(int value){
angle +=2.0f;
if (angle >360){
angle -=360;
}
glutPostRedisplay();
glutTimerFunc(16, update, 0);
}
void specialKeys(int key, int x, int y){
switch (key){
case GLUT_KEY_UP:
yTrans +=0.1f;
break;
case GLUT_KEY_DOWN:
yTrans -=0.1f;
break;
case GLUT_KEY_LEFT:
xTrans -=0.1f;
break;
case GLUT_KEY_RIGHT:
xTrans +=0.1f;
break;
}
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y){
switch (key){
case 'w':
case 'W':
yTrans +=0.1f;
break;
case 's':
case 'S':
yTrans -=0.1f;
break;
case 'a':
case 'A':
xTrans -=0.1f;
break;
case 'd':
case 'D':
xTrans +=0.1f;
break;
case '+':
scale +=0.1f;
break;
case '-':
scale -=0.1f;
if (scale <0.1f) scale =0.1f;
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500,500);
glutCreateWindow("201911204_497_LAB9");
glutDisplayFunc(display);
glutSpecialFunc(specialKeys);
glutKeyboardFunc(keyboard);
init();
glutTimerFunc(16, update, 0);
glutMainLoop();
return 0;
}
Using your code from, implement a mouse click function. When the left mouse button is clicked, another shape with the same one you created is added to the clicked location and does the same animations as the original. For every click, create another shape.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions