Skip to main content
GameDev.net gamedev.net
🔒 Locked

sphere rotation problem

Started by jmcheng Oct 13, 2006 at 5:05 AM 2 replies 800+ views
Original Post
jmcheng
jmcheng
Hi current, I have a array of sphere created using glSolidSphere and it is lined up in a line with no gaps between each of the sphere. So far so good, I can see the result I got. but as I try to rotate the sphere, the line of sphere moves but then gaps were started to show up between sphere. each of the gaps between the spheres start to increase as it reach at the end of the lines of spheres. before: OOOOOOOO (lines of sphere) after: O O O O O this is the code that I use to rotate the lines of sphere, I keep reading through but still cannot find anything wrong with it.can anyone give me some suggestion


	float tempX = 0;
	float tempY = 0;
	float updateX;
	float updateY;
	
	
	for(int i = 0; i < 10; i++){

		objects sphere = lowerLegArray;
		
		tempX = sphere.getLocationX();
		tempY = sphere.getLocationY();

		updateX = cos((float)0.1) * tempX - sin((float)0.1) * tempY;
		updateY = sin((float)0.1) * tempX + cos((float)0.1) * tempY;


		glPopMatrix();
		glTranslatef(updateX, updateY, 0);
		glTranslatef(tempX, tempY, 0);
		sphere.sphere();
		glPopMatrix();
		

		lowerLegArray.setLocation(updateX, updateY);
	}

thx for all the help
haegarr
haegarr
Shouldn't the first glPopMatrix() not be a glPushMatrix?

I'm not sure what the roles of updateX/Y and tempX/Y are. You first read getLocationX/Y into tempX/Y, so yielding in a position. Then you rotate that position, storing the result into updateX/Y. After that you translate by both tempX/Y _and_ updateX/Y, and finally store updateX/Y as new position. I.e. translating by both positions seems me curious.


BTW: Please wrap code with more than a few lines into [ source ] and [ /source ] tags (but leave out the inner spaces beneath the brackets).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.