Results 1 to 8 of 8

Thread: Problem on moving eye coordinate

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    6

    Problem on moving eye coordinate

    Hello,
    I've spend some time on GLUT and trying to do a camera-moving stuff by myself. I hope I would learn something by doing it from scratch. So I'm sorry the code following may seems clumsy...

    But here is my problem, when I try to move the cam forward. the cam DID move forward... But not in the direction of current eye coordinate, but along with the -Z arrow instead. However, I did rotate it before the tranlate it, and no other transformation between rotate & translate. If anyone got any clue about what's wrong, please point it out for me. If any background knowledge are needed, just a topic is fine. Thank you. =)

    moveframe1.C

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jun 2004
    Location
    mexico
    Posts
    125

    Re: Problem on moving eye coordinate

    translate before rotating

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2005
    Posts
    6

    Re: Problem on moving eye coordinate

    Sorry, seems not working, either.
    Thanks anyway.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    19

    Re: Problem on moving eye coordinate

    Hi!! Another way for doing a camera from the scratch is using gluLookAt, with the advantages that it's more clean your code, but you have to performs cossine and sine functions to do the rotation... I'm just making better the operations I have of camera and soon I post here, right?

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    19

    Re: Problem on moving eye coordinate

    Hi!! These are:

    mouse up {
    angleY += K;
    centerY = eyeY + sin(angleY);
    }

    mouse down {
    angleY -= K;
    centerY = eyeY + sin(angleY);
    }

    mouse left {
    angleX += K;
    centerX = eyeX + cos(angleX);
    centerZ = eyeZ - sin(angleX);
    }

    mouse right {
    angleX -= K;
    centerX = eyeX + cos(angleX);
    centerZ = eyeZ - sin(angleX);
    }

    hope it helps a little, if you need there are also the WSAD to implement a FPS Quake style camera, just contact by here or by email pedrodx@yahoo.com . Note that these I formulated so I'm not sure if these are optimized or work in all cases, but are fine.... See ya later!!!

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jun 2004
    Location
    mexico
    Posts
    125

    Re: Problem on moving eye coordinate

    could you post the WASD functions?

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    19

    Re: Problem on moving eye coordinate

    Hi! These are:

    switch (key) {
    case 87: //W
    case 119: //w
    glLoadIdentity();
    eyeX += cos(angleX) * K;
    eyeY += sin(angleY) * K;
    eyeZ += -sin(angleX) * K;
    centerX += cos(angleX) * K;
    centerY += sin(angleY) * K;
    centerZ += -sin(angleX) * K;
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    display4();
    return;
    case 83: //S
    case 115: //s
    glLoadIdentity();
    eyeX -= cos(angleX) * K;
    eyeY -= sin(angleY) * K;
    eyeZ -= -sin(angleX) * K;
    centerX -= cos(angleX) * K;
    centerY -= sin(angleY) * K;
    centerZ -= -sin(angleX) * K;
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    display4();
    return;
    case 65: //A
    case 97: //a
    glLoadIdentity();
    eyeX += cos(angleX + pi/2) * K;
    eyeZ += -sin(angleX + pi/2) * K;
    centerX += cos(angleX + pi/2) * K;
    centerZ += -sin(angleX + pi/2) * K;
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    display4();
    return;
    case 68: //D
    case 100: //d
    glLoadIdentity();
    eyeX += cos(angleX - pi/2) * K;
    eyeZ += -sin(angleX - pi/2) * K;
    centerX += cos(angleX - pi/2) * K;
    centerZ += -sin(angleX - pi/2) * K;
    gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, 0, 1, 0);
    display4();
    return;
    }

    and voilą!!! You have a Quake style FPS!!!
    Although a good way to do that is when you press a key, you set a boolean to true, and when you release set to false. This increases real-time rendering. Although, I learn yesterday that you should NOT call display func directly, but call glutPostRedisplay();

    Ahhhh! And remember doing the angle tests!! I didn't performed it in these operations. It means, in other words:

    if (angleY > 90.0f) {
    angleY = 90.0f;
    }
    if (angleY < -90.0f) {
    angleY = -90.0f;
    }

    That restricts the player to look up and stop.

    That's it! Hope it would be useful to the Opengl community, to me it was... Bye!!

  8. #8
    Senior Member Regular Contributor
    Join Date
    Jun 2004
    Location
    mexico
    Posts
    125

    Re: Problem on moving eye coordinate

    thanks!

Similar Threads

  1. Texture Coordinate Problem
    By mycral in forum OpenGL: GLSL
    Replies: 4
    Last Post: 10-15-2010, 07:15 PM
  2. texture coordinate look up problem
    By iris_raj in forum OpenGL: GLSL
    Replies: 3
    Last Post: 12-11-2006, 06:25 AM
  3. Fog Coordinate Problem... Please help
    By imported_nethtrick in forum OpenGL: Windows
    Replies: 1
    Last Post: 09-02-2004, 03:24 PM
  4. World coordinate problem
    By Lanstorp in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 08-20-2002, 11:14 PM
  5. Replies: 2
    Last Post: 11-27-2000, 07:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean