I cant make my triangels spin dammit!

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 ; 
}
 
This lets you rotate XY passively with one mouse button pressed. Z with the middle, and translate XY with the other.

Press 'R' to reset the co-ords! :)

Code:
#include <windows.h> 
#include <math.h>
#include <GL/glut.h>

#define PI 3.1415926535898
#define MAXX 500
#define MAXY 500

float Xpos = 0.5;
float Ypos = 0.8;
float rotX = 0.0;
float rotY = 0.0;
float rotZ = 0.0;

int  rightMouseBTNPressed = 0;
int  centerMouseBTNPressed = 0;
int  leftMouseBTNPressed = 0;

float lastx   = 0;
float lasty   = 0;

void init(void) 
{ 
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ; 
	glShadeModel(GL_SMOOTH);
}

void reshape(int w, int h)
{
	//control the 2d viewport
	//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, 10.0);
	glMatrixMode(GL_MODELVIEW);
}

void display(void) 
{

	glClear(GL_COLOR_BUFFER_BIT); //clear colour buffer to black
	const float colour1[] = {1.0, 0.0, 0.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);
		glColor3f(1.0f,.0f,0.0f);
		glVertex3f(-0.6f,-0.6,0.0f);
		glColor3f(0.0f,1.0f,0.0f);
		glVertex3f(0.0,0.6,0.0f);
		glColor3f(0.5f,1.0f,0.5f);
		glVertex3f(0.0,-0.6,0.0f);
	glEnd();

	////////////////////////////////// 

	////////////triangle (move)////////////////////
	glShadeModel(GL_SMOOTH);
	glTranslatef(Xpos,Ypos,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);
	glEnd();

	/////////////////////////////////// 
	glEnd();
	glutSwapBuffers(); //update screen 

}

void keyboard(unsigned char key, int x, int y) 
{
	
	switch(key)
	{

//	translate keys
	case'a':case'A':
			Xpos = Xpos - 0.05f;
			glutPostRedisplay();
			break;

	 case'd':case'D':
			Xpos = Xpos + 0.05f;
			glutPostRedisplay();
			break;

	 case'w':case'W':
			Ypos = Ypos + 0.05f;
			glutPostRedisplay();
			break;

	case's':case'S':
			Ypos = Ypos - 0.05f;
			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'v':case'V':
			rotY = rotY + 10.0f;
			glutPostRedisplay();
			break;
	case'b':case'B':
			rotZ = rotZ - 10.0f;
			glutPostRedisplay();
			break;

	case'n':case'N':
			rotZ = rotZ + 10.0f;
			glutPostRedisplay();
			break;

	case'r':case'R':
			Xpos = 0;
			Ypos = 0;
			rotX = 0;
			rotY = 0;
			rotZ = 0;
			glutPostRedisplay();
		default:
			break;
	}
}

// clips window co-ords to floats -1 to +1
void XYtoGLXY(int x, int y)
{
	lastx = (( x - (MAXX / 2)) / (float)MAXX );
	lasty = (( (MAXY / 2) - y) / (float)MAXY );
}

void mouse(int button, int state, int x, int y)
{
	/*  Mouse buttons. 
	#define GLUT_LEFT_BUTTON		0
	#define GLUT_MIDDLE_BUTTON		1
	#define GLUT_RIGHT_BUTTON		2

	// Mouse button  state.
	#define GLUT_DOWN			0
	#define GLUT_UP				1
	*/

	switch(button)
	{
		case GLUT_LEFT_BUTTON: 
			leftMouseBTNPressed = state;
			break;
		
		case GLUT_MIDDLE_BUTTON: 
			centerMouseBTNPressed = state;
			glutPostRedisplay();
			break;
			
		case GLUT_RIGHT_BUTTON: 
			rightMouseBTNPressed = state;
			break;

		default:
			break;
	}
		
}


void passive(int x, int y)
{
	XYtoGLXY(x,y);
	if (leftMouseBTNPressed){
		Xpos = lastx;
		Ypos = lasty;
	}
	if (rightMouseBTNPressed){
		rotX = lastx * 200.0;
		rotY = lasty * 200.0;
	}
	if (centerMouseBTNPressed){
		rotZ = lastx *200;
	}


	glutPostRedisplay();
}

int main(int argc, char** argv) 
{ 
	glutInit (&argc, argv) ; 
	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ; 
	glutInitWindowSize(MAXX, MAXY) ; 
	glutInitWindowPosition (100, 100) ; 
	glutCreateWindow ("Spinny!") ; 

	init() ; //initialise opengl settings
	glutDisplayFunc (display);  //set up call back for display
	glutReshapeFunc (reshape);  //set up call back for reshape
	glutKeyboardFunc(keyboard);	//set up call back for user input
	glutMouseFunc(mouse);
	glutMotionFunc(passive);
	glutMainLoop () ; 

return 0 ; 
}
 
What was wrong with my version ? i thought the coding was sound so could say where ive gone wrong?
 
The function you are using isn't passive, and takes 4 parameters.

button pressed, the change of state (up or down), then x and y co-ords.

Just change the callback fn to glutMotionFunc(passive);
 
Do i need to rename the void process passive mouse to motionfunc or something because from looking at the code the glmotionfunc has no relation to the glprocessPassiveMouse
 
Oracle said:
Do i need to rename the void process passive mouse to motionfunc or something because from looking at the code the glmotionfunc has no relation to the glprocessPassiveMouse

nope just put that name in where I have (passive).

glutMotionFunc is the passive mouse function that feeds upto the minute mouse data only when a button is pressed in the window.

The (passive) is the name of the function that the callback function will call when mouse changes occur.

So your mouse handler function void processPassiveMouse(int x, int y)

is either renamed to "void passive(int x, int y)"

or you can place: "glutMotionFunc(processPassiveMouse);" in the main()

Get it?!
 
kewl:)

ok ive tried bith methods: the method yu designed urself and my one and both dont do much ill show you what i mean:

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)//Mouse controls[/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]glutMotionFunc(processPassiveMouse);[/b]
	glutDisplayFunc (display); //set up call back for display
	glutReshapeFunc (reshape); //set up call back for reshape
	glutMainLoop (); 


	return 0 ; 
}
 
your passive mouse function obviously doesn't do anything becuase of two major points!

1. height and width variables are not initialised. When running a release version of the program (not debug) these vars will be whatever is in that area of memory, not 0. Which is just as bad.

2. you manupulate to variables called angX and angY. You don't actually use these variables anywhere.

Rename angX to posX and stuff will happen!
 
Ok ive changed the angx/y to pos etc

but

im confused about the height thing you talk of do you mean this :

posX = 0.0

?
 
Oracle said:
Ok ive changed the angx/y to pos etc

but

im confused about the height thing you talk of do you mean this :

posX = 0.0

?

no the variables that store the window size so you can scale the co-ordinates to openGL.

"width" and "height" used in your mouse callback function. Intialise them to 500 at the top of the file, as this is the size of the window.

Look at my function glutInitWindowSize in main(). Notice how I have defined the window size. Do a search for MAXX and MAXY and you will see I use these values elsewhere.
Specifically here:

Code:
// clips window co-ords to floats -1 to +1
void XYtoGLXY(int x, int y)
{
	mouseX = (( x - (MAXX / 2)) / (float)MAXX );
	mouseY = (( (MAXY / 2) - y) / (float)MAXY );
}

When you click in the window of the app you get a x,y co-ord of say (365,219). That's useless when the range from left to right is -1 to +1, and the Y axis is about +3 to -3 (I clip to +/- 1 however) for the triangle verticies.

For the rotation I just multipled the converted value by 200 to get some decent movement as the value is too small for the rotate function's angle parameter. If you change that to 360.0 then you get 1 full rotation by dragging the mouse from one side to the other. I just didn't bother working out what the proper values were.

All you need to do is fix angX, rotX is probably more suitable in retrospect, and initialise width and height as 500.

IE your code fixed:

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 width = 500;
float height = 500;
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 
}

void processPassiveMouse(int x, int y)//Mouse controls

{		
	if (x < 0)
		
			rotX = 0.0;

		else if (x > width)

			rotX = 360.0;

		else

			rotX =  360.0 *((float) x)/width;

		if (y < 0)

			rotY = 0.0;

		else if (rotY > width)

			rotY = 360.0;

		else

			rotY =  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;A
	
	}

}


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);
	glutMotionFunc(processPassiveMouse);
	glutDisplayFunc (display); //set up call back for display
	glutReshapeFunc (reshape); //set up call back for reshape
	glutMainLoop (); 


	return 0 ; 
}
 
hmmmm ok ive changed my code around and something does happen but the camara doesnt actually move the polygons just flash slightly,

On the upside i have flashing polygons :D
 
Well ive revamped the code so that the triangles can move on there own which is nice and ive added a square as well
 
new code for y'all

new code for y'all

Code:
#include <windows.h>   
#include <gl.h>   
#include <stdio.h>							
#include <glut.h> 
#include "vertexdatatypes.h"  
//#include "vertex stuff.h"
float	rtri;							

				
double	angY, angX;

vertex3 cameraPos;	


void InitGL (GLvoid)     
{
	
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glShadeModel(GL_SMOOTH);							
	cameraPos.x = 0.0;
	cameraPos.y = 0.0;
	cameraPos.z = 3.0;
				
	glClearDepth(1.0f);									// Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

	float LightAmbient[]=		{ 0.5f, 0.5f, 0.5f, 1.0f };
	float LightDiffuse[]=		{ 1.0f, 1.0f, 1.0f, 1.0f };
	float LightPosition[]=	{ 0.0f, 0.0f, 2.0f, 1.0f };

	glDepthFunc(GL_LEQUAL);								
	glEnable ( GL_COLOR_MATERIAL );
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);		// Setup The Ambient Light
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);		// Setup The Diffuse Light
	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);	// Position The Light
	
	glEnable(GL_LIGHT1);								// Enable Light One

}


void draw_aster(float)

{
  	glBegin(GL_TRIANGLES);

	glColor3f(1.0f,0.0f,0.0f);
	glVertex3f(0.0f,3.0f,0.0f);
	glVertex3f(1.0f,0.0f,0.0f);
	glVertex3f(0.0f,0.0f,1.0f);

	glColor3f(0.0f,0.0f,1.0f);
	glVertex3f(0.0f,3.0f,0.0f);
	glVertex3f(0.0f,0.0f,-2.0f);
	glVertex3f(-2.0f,0.0f,0.0f);

	glColor3f(0.0f,1.0f,0.0f);
	glVertex3f(0.0f,0.0f,-2.0f);
	glVertex3f(1.0f,0.0f,0.0f);
	glVertex3f(0.0f,-1.0f,0.0f);

	glColor3f(0.0f,0.0f,1.0f);
	glVertex3f(-2.0f,0.0f,0.0f);
	glVertex3f(0.0f,-1.0f,0.0f);
	glVertex3f(0.0f,0.0f,1.0f);

	glColor3f(1.0f,0.5f,0.0f);
	glVertex3f(0.0f,0.0f,1.0f);
	glVertex3f(-2.0f,0.0f,0.0f);
	glVertex3f(0.0f,3.0f,0.0f);

	glColor3f(1.0f,1.0f,1.0f);
	glVertex3f(1.0f,0.0f,0.0f);
	glVertex3f(0.0f,0.0f,-2.0f);
	glVertex3f(0.0f,3.0f,0.0f);

	glColor3f(1.0f,1.0f,0.0f);
	glVertex3f(1.0f,0.0f,0.0f);
	glVertex3f(0.0f,0.0f,1.0f);
	glVertex3f(0.0f,-1.0f,.0f);

	glColor3f(0.5f,0.0f,0.5f);
	glVertex3f(0.0f,0.0f,-2.0f);
	glVertex3f(-2.0f,0.0f,0.0f);
	glVertex3f(0.0f,-1.0f,0.0f);

	
	
glEnd();

}

void display ( void )  

{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
  glLoadIdentity();
  gluLookAt(cameraPos.x, cameraPos.y, cameraPos.z, 0.0,0.0,0.0,0.0,1.0,0.0);
	//rotate model
	glRotatef(angY,0.0,1.0,0.0);
	glRotatef(angX,1.0,0.0,0.0);
  glPopMatrix();
   rtri+=0.3f;

  glLoadIdentity();									// Reset 
     
		
		glTranslatef(-1.5f,0.0f,-6.0f);				
		glRotatef(rtri,1.0f,0.0f,0.0f);				// Rotate The Triangle On The X axis
		

		draw_aster(1.0f); 


  glLoadIdentity();									// Reset 
     
		
		glTranslatef(1.0f,0.0f,-9.0f);						
		glRotatef(rtri,0.0f,0.0f,1.0f);				// Rotate The Triangle On The Z axis
		

		draw_aster(1.0f); 

	glLoadIdentity();	

	
		

		glTranslatef(4.0f,0.0f,-7.0f);						
		glRotatef(rtri,0.0f,1.0f,1.0f);				// Rotate The Triangle On The Y/Z axis
		
		draw_aster(1.0f);

  glPopMatrix();
  rtri+=0.3f;



  glutSwapBuffers ( );// Clear buffers
  glPushMatrix();
}


void keyboard(unsigned char key, int x, int y) 

{
	switch(key)
	{

   case 27:   //Escape Key  
			exit(0);
			break;

   case 'r':     
		    glutFullScreen (); //  Full Screen 
		    break;

   case 't':
      glutReshapeWindow (500, 500); //  Window Mode
      break;
   
   case GLUT_KEY_LEFT:
		angY -= 2.0;
		break;
	case GLUT_KEY_UP:
		angX += 2.0;
		break;
	case GLUT_KEY_DOWN:
		angX -= 2.0;
		break;
	case GLUT_KEY_PAGE_UP:
		cameraPos.z -= 0.02f;
		break;
	case GLUT_KEY_PAGE_DOWN:
		cameraPos.z += 0.02f;
		break;
	default:
		break;

	}
}

void reshape (int w, int h )   
{
  glViewport(0,0,w, h);
  glMatrixMode(GL_PROJECTION);  // Select The Projection Matrix
  glLoadIdentity();                // Reset The Projection Matrix
  if (h==0)  // 
     gluPerspective (80,(float) w,1.0,5000.0);
  else
     gluPerspective (80, (float) w / (float) h, 1.0, 5000.0);
  glMatrixMode(GL_MODELVIEW);  
  glLoadIdentity ();    
}

void main (int argc,char** argv)   // Create Main Function For Bringing It All Together
{

  glutInit(&argc,argv); 
  

  glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); // Display Mode
  glutInitWindowSize (500, 500); 
  glutCreateWindow ("Asteriod" ); 
  InitGL(); 
  glutFullScreen      ( );          // Put Into Full Screen
  glutDisplayFunc(display);  
  glutReshapeFunc(reshape);
  glutIdleFunc(display);
  glutKeyboardFunc(keyboard);//activate keyboard
 
  glutMainLoop        ( );          
}

hey guys sorry for the lack of updates lots of work bin hellish

what this code does is:

Calls the function aster 3 times and each asteroid spins on a different axis. ok there not what you would call common asteroids but hey its progress:)

sadly the asteroids are hard coded which my lecturer doesnt like :P so ive gotta shove all this crap into a display listand light it all!

but its coming together kinda :)
 
Back
Top