Hi there,
I have this cube which i rotate around a centre, I'm attempting to make it register when i move a sphere beyond it's x,y,z position.
However the cubes x,y,z position seems to be it's origin of rotation and not it's actual current position.

I believe this is because i translate & rotate to give the impression of rotation. But am unsure if i can change this without reworking the code.
Here is my code or the rotating cube.

void bat (void) {
	glPushMatrix();
	glColor3f(1.0,1.0,1.0);

	//glTranslatef(0.0,0.0,0.0);
	if (Rotateleft == TRUE) //left arrow pressed rotate left.
	{
	glRotated((GLdouble)spin, batX,batY,batZ+=1.0);
	glTranslatef(batX+10,0.0,0.0);
		spin+=1;
	if (spin>360.0)
		spin=spin-360.0;

	}

	if (Rotateleft == FALSE && Rotateright == FALSE) //left and right arrow not pressed, do nothing.
	{
	glRotated((GLdouble)spin, batX,batY,batZ);
	glTranslatef(batX+10,0.0,0.0);
	}

	if (Rotateright == TRUE) //right arrow pressed, rotate right
	{
	glRotated((GLdouble)spin, batX,batY,batZ+=1.0);
	glTranslatef(batX+10,0.0,0.0);
		spin-=1;
	if (spin<1)
		spin=spin+360;
	}

	glBegin(GL_QUADS); //begin the four sided shape
	glVertex3f (...) //Creation of cube here
	glEnd();
	glPopMatrix();
}

Heres the code for a simple test i'm trying to do with the sphere.

void collision(void)
{
  if (ballX < batX)
  {
	glDisable(GL_LIGHTING);
  }
	else
  {
	glEnable(GL_LIGHTING);
  }
}

Help on this matter would be appreciated.
Thanks!

Recommended Answers

All 4 Replies

>>I'm attempting to make it register when i move a sphere beyond it's x,y,z position.

I am confused by this statement. Can you clarify a what you mean?
Also can you clarify what exactly your problem is. Sorry I couldn't
understand what you were trying to say.

My apolgese about that then:

Well basically, i have a sphere and a cube. I'm trying to setup collision.

To test, when the sphere's X position is >= the cube's X position it turns the 2nd light on (so i can see something working).

My problem is:
http://img.photobucket.com/albums/v617/thehivetyrant/diagram.jpg

The red X is where the cube's X position is (and Y).
The yellow arrows shows how the cube rotates around the circle.
The white X is where i want the cubes X position to be. (which changes as it rotates.)

Because at the minute the test works when the sphere moves past the red X.

I hope thats more clear. :)

>> The white X is where i want the cubes X position to be. (which changes as it rotates.

Right now where is the rectangle's x position relative to?

It's relative to the Red X. (no matter where it's rotated too.

If the sphere is on one side of the red X the test registers true, the other side false.
(which just turns the light on)

I think it's somethng to do with the fact i rotate to the edge of the circle and then translate it out.
It's X,Y,Z positon is where it would be if i never translated it. the centre.

glRotated((GLdouble)spin, batX,batY,batZ);	
glTranslatef(batX+10,0.0,0.0);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.