diff --git a/src/camera.cpp b/src/camera.cpp index 419489617..e2ccce5ae 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -118,16 +118,18 @@ void Camera::setMode(Mode mode) if(m_mode==CM_CLOSEUP) m_distance = 2.5f; else - { - m_distance = m_kart->getKartProperties()->getCameraDistance(); + { + m_distance = m_kart->getKartProperties()->getCameraDistance(); - // In 2 and 3 player mode we have a different FOV and would not see our - // kart at the default distance. We use 1.5 times the distance to fix that. - const int num_players = race_manager->getNumPlayers(); - if (num_players == 2 || num_players == 3) - m_distance += m_distance / 2; - } + // In 2 and 3 player mode we have a different FOV and would not see our + // kart at the default distance. We use 1.5 times the distance to fix that. + const int num_players = race_manager->getNumPlayers(); + if (num_players == 2 || num_players == 3) + m_distance += m_distance / 2; + } } // setMode + +// ---------------------------------------------------------------------------- Camera::Mode Camera::getMode() { return m_mode; @@ -187,7 +189,7 @@ void Camera::update (float dt) // -------------------------------------------- // The reverse mode and the cam used in follow the leader mode (when a // kart has been eliminated) are facing backwards: - bool reverse = m_mode==CM_REVERSE || m_mode==CM_LEADER_MODE; + bool reverse = m_kart->getControls().m_look_back || m_mode==CM_LEADER_MODE; Vec3 cam_rel_pos(0.f, reverse ? m_distance : -m_distance, 1.5f); // Set the camera rotation diff --git a/src/camera.hpp b/src/camera.hpp index 9c75e7c47..c8b0ce134 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -35,7 +35,6 @@ public: CM_CLOSEUP, // Normal camera, closer to kart CM_DRIFTING, // FIXME: drifting behind when accelerating = not yet implemented CM_LEADER_MODE, // for deleted player karts in follow the leader - CM_REVERSE, // Camera is pointing backwards CM_FINAL, // Final camera to show the end of the race CM_SIMPLE_REPLAY }; diff --git a/src/items/bowling.cpp b/src/items/bowling.cpp index 151d06aad..df3b49661 100644 --- a/src/items/bowling.cpp +++ b/src/items/bowling.cpp @@ -31,9 +31,7 @@ Bowling::Bowling(Kart *kart) : Flyable(kart, POWERUP_BOWLING, 50.0f /* mass */) float y_offset = 0.5f*kart->getKartLength() + m_extend.getY()/2.0f; // if the kart is looking backwards, release from the back - PlayerKart* pk = dynamic_cast(kart); - const bool reverse_mode = (pk != NULL && pk->getCamera()->getMode() == Camera::CM_REVERSE); - if( reverse_mode ) + if( kart->getControls().m_look_back ) { y_offset = -y_offset; m_speed = -m_speed*2; diff --git a/src/items/plunger.cpp b/src/items/plunger.cpp index 9dd01756a..120e025ff 100644 --- a/src/items/plunger.cpp +++ b/src/items/plunger.cpp @@ -34,8 +34,7 @@ Plunger::Plunger(Kart *kart) : Flyable(kart, POWERUP_PLUNGER) float y_offset = 0.5f*kart->getKartLength()+0.5f*m_extend.getY(); // if the kart is looking backwards, release from the back - PlayerKart* pk = dynamic_cast(kart); - m_reverse_mode = (pk != NULL && pk->getCamera()->getMode() == Camera::CM_REVERSE); + m_reverse_mode = kart->getControls().m_look_back; // find closest kart in front of the current one const Kart *closest_kart=0; btVector3 direction; float kartDistSquared; diff --git a/src/karts/kart_control.hpp b/src/karts/kart_control.hpp index 0dd7ccbb3..8afc398db 100644 --- a/src/karts/kart_control.hpp +++ b/src/karts/kart_control.hpp @@ -32,24 +32,21 @@ public: bool m_drift; bool m_rescue; bool m_fire; + bool m_look_back; KartControl() : m_steer(0.0f), m_accel(0.0f), m_brake(false), m_nitro(false), m_drift(false), m_rescue(false), - m_fire(false) + m_fire(false), m_look_back(false) { } // ------------------------------------------------------------------------ /** Construct kart control from a Message (i.e. unserialise) */ KartControl(Message *m) { - m_steer = m->getFloat(); - m_accel = m->getFloat(); - char c = m->getChar(); - m_brake = (c & 1) != 0; - m_nitro = (c & 2) != 0; - m_drift = (c & 4) != 0; - m_rescue = (c & 8) != 0; - m_fire = (c & 16) != 0; + m_steer = m->getFloat(); + m_accel = m->getFloat(); + char c = m->getChar(); + setButtonsCompressed(c); } // KartControl(Message*) // ------------------------------------------------------------------------ /** Return the serialised size in bytes. */ @@ -73,11 +70,12 @@ public: /** Compresses all buttons into a single integer value. */ char getButtonsCompressed() const { - return m_brake ? 1 : 0 - + m_nitro ? 2 : 0 - + m_drift ? 4 : 0 - + m_rescue ? 8 : 0 - + m_fire ? 16 : 0; + return m_brake ? 1 : 0 + + m_nitro ? 2 : 0 + + m_drift ? 4 : 0 + + m_rescue ? 8 : 0 + + m_fire ? 16 : 0 + + m_look_back ? 32 : 0; } // getButtonsCompressed // ------------------------------------------------------------------------ /** Sets the buttons from a compressed representation. @@ -85,11 +83,12 @@ public: */ void setButtonsCompressed(char c) { - m_brake = (c & 1) != 0; - m_nitro = (c & 2) != 0; - m_drift = (c & 4) != 0; - m_rescue = (c & 8) != 0; - m_fire = (c & 16) != 0; + m_brake = (c & 1) != 0; + m_nitro = (c & 2) != 0; + m_drift = (c & 4) != 0; + m_rescue = (c & 8) != 0; + m_fire = (c & 16) != 0; + m_look_back = (c & 32) != 0; } // setButtonsCompressed }; diff --git a/src/karts/player_kart.cpp b/src/karts/player_kart.cpp index 6d0d89ccc..a5fdfef33 100644 --- a/src/karts/player_kart.cpp +++ b/src/karts/player_kart.cpp @@ -144,7 +144,7 @@ void PlayerKart::action(KartAction action, int value) m_controls.m_fire = (value!=0); break; case KA_LOOK_BACK: - m_camera->setMode(value!=0 ? Camera::CM_REVERSE : Camera::CM_NORMAL); + m_controls.m_look_back = (value!=0); break; case KA_DRIFT: m_controls.m_drift = (value!=0); diff --git a/src/robots/default_robot.cpp b/src/robots/default_robot.cpp index 596009a82..7e62eaa86 100755 --- a/src/robots/default_robot.cpp +++ b/src/robots/default_robot.cpp @@ -124,6 +124,8 @@ DefaultRobot::~DefaultRobot() //line, then move forward while turning. void DefaultRobot::update(float dt) { + // This is used to enable firing an item backwards. + m_controls.m_look_back = false; m_track_sector = m_world->m_kart_info[ getWorldKartId() ].m_track_sector; // The client does not do any AI computations. if(network_manager->getMode()==NetworkManager::NW_CLIENT)