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 4 of 4

Thread: 3D Game - When any arrow key is pressed the screen goes smaller then dissapears

Threaded View

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

    Exclamation 3D Game - When any arrow key is pressed the screen goes smaller then dissapears

    I have made a 3d game when any arrow buttons are pressed the ball is meant to travel that way it was working until i put the aim targets on the wall after that it decided to stop working, instead the screen goes small first time a arrow button is pressed then after second press screen goes all black why is this

    Click image for larger version. 

Name:	Screen Shot 2012-12-23 at 6.12.52 PM.jpg 
Views:	87 
Size:	20.4 KB 
ID:	929Click image for larger version. 

Name:	Screen Shot 2012-12-23 at 6.13.04 PM.jpg 
Views:	89 
Size:	10.1 KB 
ID:	930Click image for larger version. 

Name:	Screen Shot 2012-12-23 at 6.13.14 PM.jpg 
Views:	80 
Size:	5.7 KB 
ID:	931


    Heres some code that could help

    GLfloat ballSpin = 0.0f;

    GLfloat ballXpos = 40.0f;
    GLfloat ballYpos = -30.0;
    GLfloat ballZpos = 180.0;

    GLfloat ballZspeed = 8.0f;
    GLfloat ballXspeed = 2.0f;

    GLfloat tempXpos = 40.0f;
    GLfloat tempYpos = -30.0;
    GLfloat tempZpos = 180.0;


    void specialKeys(int key, int x, int y)
    {
    if(key == GLUT_KEY_UP){
    ballZpos = ballZpos - ballZspeed;
    ballSpin -= 90.0f;
    glutPostRedisplay();
    }

    if(key == GLUT_KEY_DOWN){
    ballZpos = ballZpos + ballZspeed;
    ballSpin += 90.0f;
    glutPostRedisplay();
    }


    if(key == GLUT_KEY_LEFT){
    ballXpos = ballXpos - ballXspeed;
    ballSpin += 45.0f;
    glutPostRedisplay();
    }

    if(key == GLUT_KEY_RIGHT){
    ballXpos = ballXpos + ballXspeed;
    ballSpin -= 45.0f;
    glutPostRedisplay();
    }
    }


    void RenderScene(void)
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    sky(skylight);
    frontWall(bricks);
    leftWall(bricks);
    rightWall(bricks);
    floor(grass);

    eightPoints();
    sixPoints();
    fivePoints();

    glPushMatrix();
    glTranslatef(ballXpos, ballYpos, ballZpos);
    glRotatef(ballSpin, 1.0, 1.0, 1.0);
    ball(football);
    glPopMatrix();
    glFlush();

    glutSwapBuffers();

    }





    Also can anybody tell me how I would code this for the when i press the z key it should shoot the ball toward the z axis, and if i use any of the arrows it will aim towards that angle.
    Last edited by donmitz; 12-23-2012 at 11:25 AM. Reason: keys, shoot, angles, trouble, view

Posting Permissions

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