Oracle
New member
Ive highlighted in bold what i was talking about i.e passive mouse command the code is done but it isnt able to declare it properly
Code:
#include <windows.h>
#include <math.h>
#include <GL/glut.h>
#include <conio.h>
#include <stdio.h>
#define PI 3.1415926535898
char key;
//float Xpos = 0.5;
//float Ypos = 0.5;
float Zpos = 0.5;
float Xpos = 0.5;
float Ypos = 0.8;
float rotX = 0.0;
float rotY = 0.0;
float rotZ = 0.0;
float angX;
float angY;
float width;
float height;
float rotAngle;
void keyboard(char key);
void init(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ;
glShadeModel(GL_SMOOTH);
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei) w, (GLsizei) h);//control the 3d clipping volume
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.5, 0.5, -1.0, 1.0, 0.5, 50.0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); //clear colour buffer to black
const float colour1[] = {1.0, 0.0, 1.0}; //red
glLoadIdentity();
glTranslatef(0.0, 0.0, -1.0);
glColor3fv(colour1);
glutWireCube(1.0);
if(Xpos <= 0.005&&Xpos >= -0.005&&Ypos <= 0.005&&Ypos >= -0.005)//moving code
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
///////////////triangle (non)////////////////////
glShadeModel(GL_SMOOTH);
glRotatef(rotX,1,0,0);
glRotatef(rotY,0,1,0);
glRotatef(rotZ,0,0,1);
glBegin(GL_POLYGON);
//glRotatef(Xpos*10,1.0f,0.0f,0.0f);//rotate the triangle on the X axis
glTranslatef(Xpos,Ypos,0.0f);//translate the polygon on the x &y axis
glBegin(GL_POLYGON);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-0.6f,-0.6f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.6f,0.0f);
glColor3f(0.5f,1.0f,0.5f);
glVertex3f(0.0f,-0.6f,0.0f);
glLoadIdentity();
glEnd();
///////////////////////////////////////////////
////////////triangle (move)////////////////////
glShadeModel(GL_SMOOTH);
//glRotatef(Ypos*10,0.0f,1.0f,0.0f);//rotate the triangle on the X axis
glTranslatef(Ypos,Xpos, 0.0f);//translate the polygon on the x &y axis
glBegin(GL_POLYGON);
glColor3f(0.5f,0.0f,0.5f);
glVertex3f(0.0f,-0.6f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(0.0f,0.6f,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.6f,-0.6f,0.0f);
glLoadIdentity();
glEnd();
///////////////////////////////////
glEnd();
glutSwapBuffers(); //update screen
}
[B]void processPassiveMouse(int x, int y)[/B]
{
if (x < 0)
angX = 0.0;
else if (x > width)
angX = 360.0;
else
angX = 360.0 *((float) x)/width;
if (y < 0)
angY = 0.0;
else if (angY > width)
angY = 360.0;
else
angY = 360.0 *((float) y)/height;
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
//Direction keys
case's':
Xpos = Xpos - 0.05f;
glutPostRedisplay();
break;
case'w':
Xpos = Xpos + 0.05f;
glutPostRedisplay();
break;
case'a':
Ypos = Ypos - 0.05f;
glutPostRedisplay();
break;
case'd':
Ypos = Ypos + 0.05f;
glutPostRedisplay();
break;
case'e':
Ypos = Xpos + Ypos/ Zpos;
glutPostRedisplay();
break;
//rotation keys
case'z':case'Z':
rotX = rotX - 10.0f;
glutPostRedisplay();
break;
case'x':case'X':
rotX = rotX + 10.0f;
glutPostRedisplay();
break;
case'c':case'C':
rotY = rotY - 10.0f;
glutPostRedisplay();
break;
case'h':case'H':
rotY = rotY + 10.0f;
glutPostRedisplay();
break;
case'j':case'B':
rotZ = rotZ - 10.0f;
glutPostRedisplay();
break;
case'n':case'N':
rotZ = rotZ + 10.0f;
glutPostRedisplay();
break;
case'r':
Zpos = Zpos * 20.0f;
glutPostRedisplay();
break;
case 'q':
Xpos = 0.0f;
Ypos = 0.0f;
rotX = 0.0f;
rotY = 0.0f;
rotZ = 0.0f;
glutPostRedisplay();
break;
case 27: /* Escape Key */
exit(0);
break;
case 'l':
Xpos = Xpos + 25.0f;
Ypos = Ypos - 25.0f;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Spinny!");
init(); //initialise opengl settings
glutKeyboardFunc (keyboard);
// [B]glutMouseFunc (passive);[/B]
glutDisplayFunc (display); //set up call back for display
glutReshapeFunc (reshape); //set up call back for reshape
glutMainLoop ();
return 0 ;
}