add a camera mode to spectate soccer in large isometric view (switchable with accel/brake keys) (#4245)

Co-authored-by: luffah <luffah@runbox.com>
This commit is contained in:
Luffah 2020-03-13 06:08:40 +01:00 committed by GitHub
parent 490bb88cb0
commit cf6225e3ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 3 deletions

View File

@ -190,6 +190,7 @@ void Camera::setupCamera()
*/ */
void Camera::setMode(Mode mode) void Camera::setMode(Mode mode)
{ {
if (mode == m_mode) return;
// If we switch from reverse view, move the camera immediately to the // If we switch from reverse view, move the camera immediately to the
// correct position. // correct position.
if( (m_mode==CM_REVERSE && mode==CM_NORMAL) || if( (m_mode==CM_REVERSE && mode==CM_NORMAL) ||
@ -204,6 +205,7 @@ void Camera::setMode(Mode mode)
m_camera->setTarget(target_position.toIrrVector()); m_camera->setTarget(target_position.toIrrVector());
} }
m_previous_mode = m_mode;
m_mode = mode; m_mode = mode;
} // setMode } // setMode
@ -215,6 +217,14 @@ Camera::Mode Camera::getMode()
return m_mode; return m_mode;
} // getMode } // getMode
// ----------------------------------------------------------------------------
/** Returns the last kwown mode of the camera.
*/
Camera::Mode Camera::getPreviousMode()
{
return m_previous_mode;
} // getMode
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/** Reset is called when a new race starts. Make sure that the camera /** Reset is called when a new race starts. Make sure that the camera
is aligned neutral, and not like in the previous race is aligned neutral, and not like in the previous race

View File

@ -64,6 +64,7 @@ public:
CM_CLOSEUP, //!< Closer to kart CM_CLOSEUP, //!< Closer to kart
CM_REVERSE, //!< Looking backwards CM_REVERSE, //!< Looking backwards
CM_LEADER_MODE, //!< for deleted player karts in follow the leader CM_LEADER_MODE, //!< for deleted player karts in follow the leader
CM_SPECTATOR_SOCCER, //!< for spectator (in soccer mode)
CM_SIMPLE_REPLAY, CM_SIMPLE_REPLAY,
CM_FALLING CM_FALLING
}; // Mode }; // Mode
@ -77,6 +78,7 @@ private:
/** Camera's mode. */ /** Camera's mode. */
Mode m_mode; Mode m_mode;
Mode m_previous_mode;
/** The type of the camera. */ /** The type of the camera. */
CameraType m_type; CameraType m_type;
@ -173,6 +175,7 @@ public:
void setMode(Mode mode); /** Set the camera to the given mode */ void setMode(Mode mode); /** Set the camera to the given mode */
Mode getMode(); Mode getMode();
Mode getPreviousMode();
void setKart(AbstractKart *new_kart); void setKart(AbstractKart *new_kart);
virtual void setInitialTransform(); virtual void setInitialTransform();
virtual void activate(bool alsoActivateInIrrlicht=true); virtual void activate(bool alsoActivateInIrrlicht=true);

View File

@ -25,6 +25,7 @@
#include "input/device_manager.hpp" #include "input/device_manager.hpp"
#include "input/input_manager.hpp" #include "input/input_manager.hpp"
#include "input/multitouch_device.hpp" #include "input/multitouch_device.hpp"
#include "modes/soccer_world.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/explosion_animation.hpp" #include "karts/explosion_animation.hpp"
#include "karts/kart.hpp" #include "karts/kart.hpp"
@ -262,6 +263,16 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
*cam_roll_angle = 0.0f; *cam_roll_angle = 0.0f;
break; break;
} }
case CM_SPECTATOR_SOCCER:
{
*above_kart = 0.0f;
*cam_angle = 40*DEGREE_TO_RAD;
*sideway = 0;
*distance = -6.75f*m_distance;
*smoothing = true;
*cam_roll_angle = 0.0f;
break;
}
case CM_SIMPLE_REPLAY: case CM_SIMPLE_REPLAY:
// TODO: Implement // TODO: Implement
break; break;
@ -327,6 +338,21 @@ void CameraNormal::positionCamera(float dt, float above_kart, float cam_angle,
Vec3 wanted_target = m_kart->getSmoothedTrans()(Vec3(0, above_kart, 0)); Vec3 wanted_target = m_kart->getSmoothedTrans()(Vec3(0, above_kart, 0));
float tan_up = tanf(cam_angle); float tan_up = tanf(cam_angle);
if (getMode() == CM_SPECTATOR_SOCCER)
{
SoccerWorld *soccer_world = dynamic_cast<SoccerWorld*> (World::getWorld());
if (soccer_world)
{
Vec3 ball_pos = soccer_world->getBallPosition();
Vec3 to_target=(ball_pos-wanted_target);
wanted_position = wanted_target + Vec3(0, fabsf(distance)*tan_up+above_kart, 0) + (to_target.normalize() * distance);
m_camera->setPosition(wanted_position.toIrrVector());
m_camera->setTarget(wanted_target.toIrrVector());
return;
}
}
Vec3 relative_position(side_way, Vec3 relative_position(side_way,
fabsf(distance)*tan_up+above_kart, fabsf(distance)*tan_up+above_kart,
distance); distance);

View File

@ -1441,11 +1441,19 @@ void ClientLobby::changeSpectateTarget(PlayerAction action, int value,
if (action == PA_LOOK_BACK) if (action == PA_LOOK_BACK)
{ {
if (cam->getMode() == Camera::CM_REVERSE) if (cam->getMode() == Camera::CM_REVERSE)
cam->setMode(Camera::CM_NORMAL); cam->setMode(cam->getPreviousMode());
else else
cam->setMode(Camera::CM_REVERSE); cam->setMode(Camera::CM_REVERSE);
return; return;
} }
if (action == PA_ACCEL)
{
if (cam->getMode() == Camera::CM_SPECTATOR_SOCCER)
cam->setMode(cam->getPreviousMode());
else
cam->setMode(Camera::CM_SPECTATOR_SOCCER);
return;
}
World::KartList karts = World::getWorld()->getKarts(); World::KartList karts = World::getWorld()->getKarts();
bool sort_kart_for_position = bool sort_kart_for_position =
@ -1513,11 +1521,12 @@ void ClientLobby::addSpectateHelperMessage() const
core::stringw left = dc->getBindingAsString(PA_STEER_LEFT); core::stringw left = dc->getBindingAsString(PA_STEER_LEFT);
core::stringw right = dc->getBindingAsString(PA_STEER_RIGHT); core::stringw right = dc->getBindingAsString(PA_STEER_RIGHT);
core::stringw back = dc->getBindingAsString(PA_LOOK_BACK); core::stringw back = dc->getBindingAsString(PA_LOOK_BACK);
core::stringw accel = dc->getBindingAsString(PA_ACCEL);
// I18N: Message shown in game to tell the player it's possible to change // I18N: Message shown in game to tell the player it's possible to change
// the camera target in spectate mode of network // the camera target in spectate mode of network
core::stringw msg = _("Press <%s> or <%s> to change the targeted player " core::stringw msg = _("Press <%s> or <%s> to change the targeted player, "
"or <%s> for the camera position.", left, right, back); "<%s> or <%s> for the camera position.", left, right, back, accel);
MessageQueue::add(MessageQueue::MT_GENERIC, msg); MessageQueue::add(MessageQueue::MT_GENERIC, msg);
} // addSpectateHelperMessage } // addSpectateHelperMessage