summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-08-10 08:06:30 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2011-08-11 15:22:35 +0200
commitb318e82356c185b54ef4cd404704422ea24fa277 (patch)
tree08ef9ba8115ebb97ffebbb035b75e3c3feb42a04
parent98fa00db12b4658f6bce61f0a2c03c69b963f8f2 (diff)
downloadminetest-b318e82356c185b54ef4cd404704422ea24fa277.tar.gz
minetest-b318e82356c185b54ef4cd404704422ea24fa277.tar.bz2
minetest-b318e82356c185b54ef4cd404704422ea24fa277.zip
Refactor player's eye position coding
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.
-rw-r--r--src/client.cpp4
-rw-r--r--src/client.h4
-rw-r--r--src/game.cpp8
-rw-r--r--src/player.h8
4 files changed, 16 insertions, 8 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 02f78e233..30bd10198 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -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();
}
diff --git a/src/client.h b/src/client.h
index 0150b687e..1c71b2c2c 100644
--- a/src/client.h
+++ b/src/client.h
@@ -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);
diff --git a/src/game.cpp b/src/game.cpp
index c4a9aba00..65f160f7b 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -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
diff --git a/src/player.h b/src/player.h
index 00a1d4408..45454e9e1 100644
--- a/src/player.h
+++ b/src/player.h
@@ -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;