Results 1 to 3 of 3

Thread: Moving around in 3d space with input

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2000
    Austin, TX, usa

    Moving around in 3d space with input

    I am trying to get user input from the client and move around in 3D space. I thought it would be an easy task buy doing something like this

    case 'f' :
    veiwerPos.z += 1;
    } break;
    case 'r':
    veiwerPos.z -=1;
    } break;
    case 'g':
    veiwerPos.x += 1;
    } break;
    case 'h' :
    veiwerPos.x -= 1;
    } break;

    vgvec2 pos(event->mouseDeltaX, event>mouseDeltaY);
    angleX += pos.x;
    angleY += pos.y;
    if(angleY > 45.0f)
    angleY = 45.0f;
    if(angleY < -45.0f)
    angleY = -45.0f;
    axis = pos.Normalize();
    glRotatef(angleX, 0, axis, 0);
    glRotatef(angleY, axis, 0, 0);
    glTranslatef(veiwerPos.x, veiwerPos.y, veiwerPos.z )

    I am not saying this works but it is not how I want it to work. If any one that knows what I am doing wrong or can help me out please e-mail me or respond to this post
    David Gholami
    You must learn how to crawl before you can walk

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2000

    Re: Moving around in 3d space with input

    you have to think of a sphere.
    so, i will give you the math, you will write the code:

    x = sin(angle_one_in_radians)

    z = cos(angle_one_in_radians)

    y = cos(angle_one_in_redians)

    where angle_one is the angle starting looking down the z-axis and rotating around the y-axis, and angle_two is rotating around the x-axis.

    this i called the equation for a sphere, pretty standard stuff, this gets the unit change, you can multiply x and z by any scalar to increase the step amount.

    finally it will look like this

    for walking forward:

    player_pos_x += player_pos_x + (x*scalar)
    player_pos_z += player_pos_z + (z*scalar)

    walking backward just subtracts tehm.

    and for turning:

    cam_pos_x += cam_pos_x + (x*scalar)
    cam_pos_x += cam_pos_x + (z*scalar)
    cam_pos_y += cam_pos_y + (y*scalar)

  3. #3
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000

    Re: Moving around in 3d space with input

    I'm not sure what the axis = pos.Normalize()means. Normally I would expect something like
    glRotatef(angleX, 1.0f, 0.0f, 0.0f);
    glRotatef(angleY, 0.0f, 1.0f, 0.0f);
    for the x- and y-axis (or maybe in the other order, first yaw then pitch?)

    Don't forget to start with the same matrix all the time, so add glLoadIdentity() before or glPushMatrix(); glPopMatrix() around the transformations. Otherwise the rotations and transformations will concatenate at each loop (far out...).

Similar Threads

  1. Replies: 6
    Last Post: 01-07-2013, 04:38 AM
  2. moving around in 3d space
    By ltrain_riders in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 12-05-2002, 06:35 PM
  3. Moving in 3d-space
    By FoxDie in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-23-2002, 04:23 PM
  4. Moving without user input
    By TolTol in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-12-2002, 12:51 PM
  5. moving my Flyer in 3d space
    By teflon_dragon in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-29-2002, 07:50 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