add camera parameter forward-smoothing (bool to set smoothing) and implement forward-up-angle in smoothing case
This commit is contained in:
parent
bb3e54fd88
commit
8449bf2714
@ -180,11 +180,13 @@
|
||||
Distance between kart and camera.
|
||||
forward-up-angle: Angle between camera and plane of kart (pitch)
|
||||
when the camera is pointing forward
|
||||
forward-smoothing: if true, use smoothing (forward-up-angle become relative to speed) when pointing forward
|
||||
backward-up-angle: Angle between camera and plane of kart (pitch)
|
||||
when the camera is pointing backwards. This is usually
|
||||
larger than the forward-up-angle, since the kart itself
|
||||
otherwise obstricts too much of the view. -->
|
||||
<camera distance="1.0" forward-up-angle="15"
|
||||
<camera distance="1.0"
|
||||
forward-up-angle="0" forward-smoothing="true"
|
||||
backward-up-angle="5" />
|
||||
|
||||
<!-- Jump animation
|
||||
|
@ -77,7 +77,7 @@ CameraNormal::CameraNormal(Camera::CameraType type, int camera_index,
|
||||
* \param dt Delta time,
|
||||
* \param if false, the camera instantly moves to the endpoint, or else it smoothly moves
|
||||
*/
|
||||
void CameraNormal::moveCamera(float dt, bool smooth)
|
||||
void CameraNormal::moveCamera(float dt, bool smooth, float cam_angle, float distance)
|
||||
{
|
||||
if(!m_kart) return;
|
||||
|
||||
@ -108,11 +108,16 @@ void CameraNormal::moveCamera(float dt, bool smooth)
|
||||
|
||||
// distance of camera from kart in x and z plane
|
||||
float camera_distance = -1.25f - 2.5f * ratio;
|
||||
if (camera_distance > -2.0f) camera_distance = -2.0f; // don't get too close to the kart
|
||||
float min_distance = (distance * 2.0f);
|
||||
if (distance > 0) camera_distance += distance + 1; // note that distance < 0
|
||||
if (camera_distance > min_distance) camera_distance = min_distance; // don't get too close to the kart
|
||||
|
||||
float tan_up = 0;
|
||||
if (cam_angle > 0) tan_up = tanf(cam_angle) * distance;
|
||||
|
||||
// Defines how far camera should be from player kart.
|
||||
Vec3 wanted_camera_offset(camera_distance * sinf(skid_angle / 2),
|
||||
(0.85f + ratio / 2.5f),
|
||||
(0.85f + ratio / 2.5f) - tan_up,
|
||||
camera_distance * cosf(skid_angle / 2));
|
||||
|
||||
float delta = 1;
|
||||
@ -172,7 +177,7 @@ void CameraNormal::moveCamera(float dt, bool smooth)
|
||||
//-----------------------------------------------------------------------------
|
||||
void CameraNormal::snapToPosition()
|
||||
{
|
||||
moveCamera(1.0f, false);
|
||||
moveCamera(1.0f, false, 0, 0);
|
||||
} // snapToPosition
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -203,7 +208,7 @@ void CameraNormal::getCameraSettings(float *above_kart, float *cam_angle,
|
||||
// quadratically to dampen small variations (but keep sign)
|
||||
float dampened_steer = fabsf(steering) * steering;
|
||||
*sideway = -m_rotation_range*dampened_steer*0.5f;
|
||||
*smoothing = true;
|
||||
*smoothing = kp->getCameraForwardSmoothing();
|
||||
*cam_roll_angle = 0.0f;
|
||||
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
@ -369,7 +374,7 @@ void CameraNormal::positionCamera(float dt, float above_kart, float cam_angle,
|
||||
|
||||
if (smoothing)
|
||||
{
|
||||
moveCamera(dt, true);
|
||||
moveCamera(dt, true, cam_angle, distance);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ private:
|
||||
|
||||
Vec3 m_camera_offset;
|
||||
|
||||
void moveCamera(float dt, bool smooth);
|
||||
void moveCamera(float dt, bool smooth, float cam_angle, float distance);
|
||||
void handleEndCamera(float dt);
|
||||
void getCameraSettings(float *above_kart, float *cam_angle,
|
||||
float *side_way, float *distance,
|
||||
|
@ -111,6 +111,8 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
|
||||
return TYPE_FLOAT;
|
||||
case CAMERA_FORWARD_UP_ANGLE:
|
||||
return TYPE_FLOAT;
|
||||
case CAMERA_FORWARD_SMOOTHING:
|
||||
return TYPE_BOOL;
|
||||
case CAMERA_BACKWARD_UP_ANGLE:
|
||||
return TYPE_FLOAT;
|
||||
case JUMP_ANIMATION_TIME:
|
||||
@ -863,6 +865,18 @@ float AbstractCharacteristic::getCameraForwardUpAngle() const
|
||||
return result;
|
||||
} // getCameraForwardUpAngle
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool AbstractCharacteristic::getCameraForwardSmoothing() const
|
||||
{
|
||||
bool result;
|
||||
bool is_set = false;
|
||||
process(CAMERA_FORWARD_SMOOTHING, &result, &is_set);
|
||||
if (!is_set)
|
||||
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
|
||||
getName(CAMERA_FORWARD_SMOOTHING).c_str());
|
||||
return result;
|
||||
} // getCameraForwardSmoothing (advanced option)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
float AbstractCharacteristic::getCameraBackwardUpAngle() const
|
||||
{
|
||||
|
@ -114,6 +114,7 @@ public:
|
||||
// Camera
|
||||
CAMERA_DISTANCE,
|
||||
CAMERA_FORWARD_UP_ANGLE,
|
||||
CAMERA_FORWARD_SMOOTHING,
|
||||
CAMERA_BACKWARD_UP_ANGLE,
|
||||
|
||||
// Jump
|
||||
@ -298,6 +299,7 @@ public:
|
||||
|
||||
float getCameraDistance() const;
|
||||
float getCameraForwardUpAngle() const;
|
||||
bool getCameraForwardSmoothing() const;
|
||||
float getCameraBackwardUpAngle() const;
|
||||
|
||||
float getJumpAnimationTime() const;
|
||||
|
@ -785,6 +785,11 @@ float KartProperties::getCameraForwardUpAngle() const
|
||||
return m_cached_characteristic->getCameraForwardUpAngle();
|
||||
} // getCameraForwardUpAngle
|
||||
|
||||
bool KartProperties::getCameraForwardSmoothing() const
|
||||
{
|
||||
return m_cached_characteristic->getCameraForwardSmoothing();
|
||||
} // getCameraForwardSmoothing
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
float KartProperties::getCameraBackwardUpAngle() const
|
||||
{
|
||||
|
@ -405,6 +405,7 @@ public:
|
||||
|
||||
float getCameraDistance() const;
|
||||
float getCameraForwardUpAngle() const;
|
||||
bool getCameraForwardSmoothing() const;
|
||||
float getCameraBackwardUpAngle() const;
|
||||
|
||||
float getJumpAnimationTime() const;
|
||||
|
@ -403,6 +403,8 @@ void XmlCharacteristic::load(const XMLNode *node)
|
||||
&m_values[CAMERA_DISTANCE]);
|
||||
sub_node->get("forward-up-angle",
|
||||
&m_values[CAMERA_FORWARD_UP_ANGLE]);
|
||||
sub_node->get("forward-smoothing",
|
||||
&m_values[CAMERA_FORWARD_SMOOTHING]);
|
||||
sub_node->get("backward-up-angle",
|
||||
&m_values[CAMERA_BACKWARD_UP_ANGLE]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user