PDA

View Full Version : gluPerspective glTranslation problem



donmitz
12-20-2012, 04:56 PM
Hi I am making a program where I have a football which I have to hit against a wall with 3 hoops each of them have a points depending on which one i hit.

the problem im having is I seems to cannot get the ball to translate towards the z axis in order to reach the wall using glutKeyFunc.

The user controls the game with arrow keys.

left key - to aim the ball left
right key - to aim the ball right
up key - to aim the ball up
down key - to aim the ball down

z key to shoot the ball against the wall.

The aim of the game is to hit a hoop and score the points
shown inside the hoop.

Once all the hoops are hit the game ends.


Please can you help me as I am really confused what to do here, i have tried a method but it seems to not have worked.

Thanks

Dark Photon
12-20-2012, 07:59 PM
It's not really clear on what your problem is. Read up on MODELING and VIEWING transforms in the OpenGL Programming Guide (or elsewhere). What you're describing specifically is a MODELING transform.

donmitz
12-21-2012, 05:19 AM
Hi sorry if its not clear here it goes again


Hi I am making a game which I have a to kick a football against a wall which contains 3 hoops with different scores in them, depending on hoop the ball hits the score will differ. e.g. 3, 4, and 5 points.

My problem here is I cannot translate the ball towards the z axis in orde to hit the wall.

In order to translate the user uses glutKeyboardFunc

The game is controlled with the following keys: -

- left key - to aim the ball left
- right key - to aim the ball right
- up key - to aim the ball up
- down key - to aim the ball down

- z key to shoot the ball against the wall.

Hope this is more clear.

Thanks

Dark Photon
12-21-2012, 07:06 AM
Hi sorry if its not clear here it goes again ... My problem here is I cannot translate the ball towards the z axis in orde to hit the wall.

You didn't clarify anything. You just restated it, almost verbatim.

"I cannot" doesn't tell us anything about "why" you cannot. Do you have a computer with a GPU? Do you know how to program? Have you read anything about OpenGL? What have you tried? Let's see some code. Have you read up on how MODELING and VIEWING transforms work? Have you figured out which API calls you need to make to set those properly? Are you getting an error? What exactly are you getting? etc.....

donmitz
12-21-2012, 04:47 PM
OK forget what I said above I think I pretty much solved it now.

Now heres a problem im having with collision detection.

I want to be able to use collision detection in order to detect if the ball hits the wall (GL_QUADS) if it does I want it to return back to its original position. The ball travels towards the Z axis in order to get to the wall using glTranslate();

I have supplied the code for the ball, ball position and wall below:


GLfloat ballXpos = 0.0f;
GLfloat ballYpos = -30.0;
GLfloat ballZpos = -100.0;


void ball(void)
{
GLUquadricObj *quad;
quad = gluNewQuadric();
glColor3f(1, 1, 1);
gluQuadricNormals(quad, GLU_SMOOTH);
gluSphere(quad, 5, 50, 50);
}



void wall(void)
{
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(-100.0, -50.0, -350.0);
glVertex3f(-100.0, 50.0, -350.0);
glVertex3f(100.0, 50.0, -350.0);
glVertex3f(100.0, -50.0, -350.0);
glEnd();
}

I am using gluPerspective(45.0f, fAspect, 1.0, 500.0);


So in programming language 'if the ball hits the wall it should return back to its original position