OpenGL - Rotate

Soldato
Joined
22 Oct 2005
Posts
2,882
Location
Moving...
I've drawn an aeroplane in openGL and all I want to do is make it rotate around the x axis. However I want to rotate it around itself rather than around 0,0,0. The centre of the aeroplane is (50000,50000,-10000)(x,y,z).

I've tried all kinds of combinations of numbers but I cant get it to to rotate correctly. I'm using glRotatef(angle, X, Y, Z). I thought it would simply be either glRotatef(angle, 1, 0, 0) or glRotatef(angle, 50000, 0, 0) neither of these work, the closest I've come is using glRotatef(angle, 50000, 50000, -10000), this rotates around itself but not around the x-axis it seems to go round all 3!! :confused:

Sorry this is a really stupid question, but what am I doing wrong?

Thanks.
 
Thanks Phil, that code does work but that rotates it around 0,0,0 because that is the centre of each of the shapes. The problem I have is that mine isn't at 0,0,0, it's at 50000,50000,-10000 but I think it's still rotating it around 0,0,0 rather than 50000,50000,-10000 which is messing things up
 
Sure. Here it is:

Code:
float xCord =50000.0; 
float yCord =50500.0;
float zCord =-10000.0; 
float xRotP =90.0;
float yRotP =90.0;
float xTest = 0.0;


void display (void){


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glPushMatrix();

	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);

	glColorPointer(3, GL_FLOAT, 0, colors);
	glVertexPointer(3, GL_FLOAT, 0, vertices);

	glDrawElements(GL_TRIANGLES, indexSize, GL_UNSIGNED_INT, index);


	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	getNames();	
	drawNames();
	
	drawPlane();

	glPopMatrix();
	glutSwapBuffers();
}



void drawPlane(){

	glRotatef(xTest, 1.0, 0.0, 0.0);   //******PROBLEM!!!!*******

	//Draw Plane
	glColor4f(1.0,1.0,1.0,0.5);
	quadratic=gluNewQuadric();
	
	//Main part
	glPushMatrix();	 
	glTranslatef(xCord,yCord,zCord);
	glRotatef(yRotP,0.0,1.0,0.0); //Parallel with ground
	glRotatef(xRotP,1.0,0.0,0.0); //Direction
	gluCylinder(quadratic,700.0,700.0,5000.0,30,30);	
	glPopMatrix();
	
	//Back of plane
	glPushMatrix(); 
	glTranslatef(xCord,yCord+3000.0,zCord);
	glRotatef(yRotP,0.0,1.0,0.0); 
	glRotatef(xRotP,1.0,0.0,0.0); 
	gluCylinder(quadratic,50.0,700.0,3000.0,30,30);
	glPopMatrix();
	
	//Front of plane
	glPushMatrix(); 
	glTranslatef(xCord,yCord-5000.0,zCord);
	glRotatef(yRotP,0.0,1.0,0.0);
	glRotatef(xRotP,1.0,0.0,0.0); 
	gluSphere(quadratic,700.0,30,30);
	glPopMatrix();

	

	glColor4f(1.0,1.0,1.0,0.75);
	
	//Right Wing
	glPushMatrix();
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(xCord+700.0, yCord-3500.0, zCord); 
	glTexCoord2f(0.0, 1.0); glVertex3f(xCord+700.0, yCord-1500, zCord); 
	glTexCoord2f(1.0, 1.0); glVertex3f(xCord+7000.0, yCord, zCord); 
	glTexCoord2f(1.0, 0.0); glVertex3f(xCord+7000.0, yCord-2000, zCord); 
	glEnd();
	glPopMatrix();

	
	//Left Wing
	glPushMatrix();	
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); glVertex3f(xCord-7000.0, yCord-2000.0, zCord); 
	glTexCoord2f(0.0, 1.0); glVertex3f(xCord-7000.0, yCord, zCord); 
	glTexCoord2f(1.0, 1.0); glVertex3f(xCord-700.0, yCord-1500.0, zCord); 
	glTexCoord2f(1.0, 0.0); glVertex3f(xCord-700.0, yCord-3500.0, zCord); 
	glEnd();
	glPopMatrix();
}

I think that's all you need, let me know if it isn't.

Basically the program is a map, and on the map I want to include an plane which can be moved around the map. All the stuff in the display function displays the map (this all works) and the function drawPlane() draws the plane after the terrain has been drawn.

In the drawPlane() I set up the parts of the plane, it consists of a main 'hull', front nose, tail, and two wings. These are all defined individually in the drawPlane() function, they each have their own glTranslate and glRotate to get them into the correct position initially. The idea is then use the rotate function right at the top of the function to rotate the entire plane as if it were just a single object. The angle of rotation is controlled by the xTest variable, this is changed via the keyboard.

I think I just need to change the parameters inside this problematic rotate function, but I dont know what to!!

Thanks again
 
Back
Top Bottom