Thread: WSAD Problem Pls Help

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    68

    WSAD Problem Pls Help

    Hi guys first lets start with some code

    Code:
    GLfloat position_x = -camera_x;
    	GLfloat position_z = -camera_z;
    	GLfloat world_rotate = 360.0f - y_rotate;
    			
    	glRotatef(x_z_rotate, 1.0f, 0.0f, 0.0f);
    	glRotatef(world_rotate, 0.0f, 1.0f, 0.0f);
    	// if I use y_rotate instead of world_rotate A and D works
            //  W and S will work in a wierd way
    	
    
    	glTranslatef(position_x, -height, position_z);
            
    
           // draw all my stuff here

    Code:
    if (keys['W'])
    					{
    						camera_x -= (float)sin(direction * piover180) * 0.05f;
    						camera_z -= (float)cos(direction * piover180) * 0.05f;
    					}
    					if (keys['S'])
    					{
    						camera_x += (float)sin(direction * piover180) * 0.05f;
    						camera_z += (float)cos(direction * piover180) * 0.05f;
    					}
    					if (keys['A'])
    					{
    						camera_x += (float)cos(direction * piover180) * 0.05f;
    						camera_z += (float)sin(direction * piover180) * 0.05f;
    					}
    					if (keys['D'])
    					{
    						camera_x -= (float)cos(direction * piover180) * 0.05f;
    						camera_z -= (float)sin(direction * piover180) * 0.05f;
    					}
    Thats the code I am using to govern the WSAD and I got the W and S to work but A and D works in a wierd way

    if I use y_rotate instead of world_rotate in code 1 A and D works but W and S works in a wierd way.

    is there any way to fix this?

    I've tried alot of stuff and coudlnt' get it working.
    -Ti22-

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You need to rotate around an arbitrary axis. You are experiencing gimbal lock where one axis rotation is mapped onto another axis.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  2. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 01:40 AM