Refactor player's eye position coding
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Wed, 10 Aug 2011 06:06:30 +0000 (08:06 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 11 Aug 2011 13:22:35 +0000 (15:22 +0200)
Collect the player's eye position coding in a Player method, and
use it in client to pass the eye position information to the game.

src/client.cpp
src/client.h
src/game.cpp
src/player.h

index 02f78e233293236c193b08ab5ef7d1dfa1206016..30bd101984fa7e6e3c62a8a434d1c075f90b01fc 100644 (file)
@@ -1935,11 +1935,13 @@ NodeMetadata* Client::getNodeMetadata(v3s16 p)
        return m_env.getMap().getNodeMetadata(p);
 }
 
-v3f Client::getPlayerPosition()
+v3f Client::getPlayerPosition(v3f *eye_position)
 {
        //JMutexAutoLock envlock(m_env_mutex); //bulk comment-out
        LocalPlayer *player = m_env.getLocalPlayer();
        assert(player != NULL);
+       if (eye_position)
+               *eye_position = player->getEyePosition();
        return player->getPosition();
 }
 
index 0150b687e9414dac1f19fa22ce8520ac852031b4..1c71b2c2c3e4b7635a52aa813715b32f53c65288 100644 (file)
@@ -206,7 +206,9 @@ public:
        // Wrapper to Map
        NodeMetadata* getNodeMetadata(v3s16 p);
 
-       v3f getPlayerPosition();
+       // Get the player position, and optionally put the
+       // eye position in *eye_position
+       v3f getPlayerPosition(v3f *eye_position=NULL);
 
        void setPlayerControl(PlayerControl &control);
        
index c4a9aba00050fb306b63db026b72ae1e02a446d3..65f160f7bdd0e906952f3ba99b3bbc536ffccf68 100644 (file)
@@ -1521,7 +1521,8 @@ void the_game(
                }
                
                // Get player position
-               v3f player_position = client.getPlayerPosition();
+               v3f camera_position;
+               v3f player_position = client.getPlayerPosition(&camera_position);
 
                //TimeTaker //timer2("//timer2");
 
@@ -1581,11 +1582,6 @@ void the_game(
                v3f camera_direction = v3f(0,0,1);
                camera_direction.rotateYZBy(camera_pitch);
                camera_direction.rotateXZBy(camera_yaw);
-               
-               // This is at the height of the eyes of the current figure
-               //v3f camera_position = player_position + v3f(0, BS+BS/2, 0);
-               // This is more like in minecraft
-               v3f camera_position = player_position + v3f(0, BS+BS*0.625, 0);
 
                camera->setPosition(camera_position);
                // *100.0 helps in large map coordinates
index 00a1d440832995fd23467bd807815c92f8996f85..45454e9e1e6c728c0da5e1bcf3b47e947fdcecf3 100644 (file)
@@ -67,6 +67,14 @@ public:
                return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
        }
 
+       v3f getEyePosition()
+       {
+               // This is at the height of the eyes of the current figure
+               // return m_position + v3f(0, BS+BS/2, 0);
+               // This is more like in minecraft
+               return m_position + v3f(0,BS+(5*BS)/8,0);
+       }
+
        virtual void setPosition(const v3f &position)
        {
                m_position = position;