Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: gluPerspective glTranslation problem

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12

    Post gluPerspective glTranslation problem

    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

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    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

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,220
    Quote Originally Posted by donmitz View Post
    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.....

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •