Merge branch 'master' of https://github.com/supertuxkart/stk-code
This commit is contained in:
commit
d873d2d4fd
@ -234,17 +234,12 @@ void Camera::setMode(Mode mode)
|
||||
{
|
||||
// If we switch from reverse view, move the camera immediately to the
|
||||
// correct position.
|
||||
if(m_mode==CM_REVERSE && mode==CM_NORMAL)
|
||||
if((m_mode==CM_REVERSE && mode==CM_NORMAL) || (m_mode==CM_FALLING && mode==CM_NORMAL))
|
||||
{
|
||||
Vec3 wanted_position, wanted_target;
|
||||
computeNormalCameraPosition(&wanted_position, &wanted_target);
|
||||
m_camera->setPosition(wanted_position.toIrrVector());
|
||||
m_camera->setTarget(wanted_target.toIrrVector());
|
||||
|
||||
assert(!isnan(m_camera->getPosition().X));
|
||||
assert(!isnan(m_camera->getPosition().Y));
|
||||
assert(!isnan(m_camera->getPosition().Z));
|
||||
|
||||
Vec3 start_offset(0, 1.6f, -3);
|
||||
Vec3 current_position = m_kart->getTrans()(start_offset);
|
||||
m_camera->setPosition( current_position.toIrrVector());
|
||||
m_camera->setTarget(m_camera->getPosition());
|
||||
}
|
||||
if(mode==CM_FINAL)
|
||||
{
|
||||
@ -287,10 +282,9 @@ void Camera::reset()
|
||||
void Camera::setInitialTransform()
|
||||
{
|
||||
if (m_kart == NULL) return;
|
||||
|
||||
Vec3 start_offset(0, 25, -50);
|
||||
Vec3 xx = m_kart->getTrans()(start_offset);
|
||||
m_camera->setPosition( xx.toIrrVector());
|
||||
Vec3 start_offset(0, 1.6f, -3);
|
||||
Vec3 current_position = m_kart->getTrans()(start_offset);
|
||||
m_camera->setPosition( current_position.toIrrVector());
|
||||
// Reset the target from the previous target (in case of a restart
|
||||
// of a race) - otherwise the camera will initially point in the wrong
|
||||
// direction till smoothMoveCamera has corrected this. Setting target
|
||||
@ -312,17 +306,46 @@ void Camera::setInitialTransform()
|
||||
* \param wanted_position The position the camera wanted to reach.
|
||||
* \param wanted_target The point the camera wants to point to.
|
||||
*/
|
||||
void Camera::smoothMoveCamera(float dt, const Vec3 &wanted_position,
|
||||
const Vec3 &wanted_target)
|
||||
void Camera::smoothMoveCamera(float dt)
|
||||
{
|
||||
|
||||
core::vector3df current_position = m_camera->getPosition();
|
||||
// Smoothly interpolate towards the position and target
|
||||
core::vector3df current_position = m_camera->getPosition();
|
||||
core::vector3df current_target = m_camera->getTarget();
|
||||
current_target += ((wanted_target.toIrrVector() - current_target ) * m_target_speed ) * dt;
|
||||
current_position += ((wanted_position.toIrrVector() - current_position) * m_position_speed) * dt;
|
||||
const KartProperties *kp = m_kart->getKartProperties();
|
||||
float max_increase_with_zipper = kp->getZipperMaxSpeedIncrease();
|
||||
float max_speed_without_zipper = kp->getMaxSpeed();
|
||||
float current_speed = m_kart->getSpeed();
|
||||
|
||||
const Skidding *ks = m_kart->getSkidding();
|
||||
float skid_factor = ks->getVisualSkidRotation();
|
||||
|
||||
float skid_angle = asin(skid_factor);
|
||||
float ratio = (current_speed - max_speed_without_zipper) / max_increase_with_zipper;
|
||||
ratio = ratio > -0.12f ? ratio : -0.12f;
|
||||
float camera_distance = -3 * (1 + ratio);// distance of camera from kart in x and z plane
|
||||
Vec3 camera_offset(camera_distance * sin(skid_angle / 2),
|
||||
1.6f * (1 + ratio / 2),
|
||||
camera_distance * cos(skid_angle / 2));// defines how far camera should be from player kart.
|
||||
Vec3 m_kart_camera_position_with_offset = m_kart->getTrans()(camera_offset);
|
||||
|
||||
|
||||
|
||||
core::vector3df current_target = m_kart->getXYZ().toIrrVector();// next target
|
||||
core::vector3df wanted_position = m_kart_camera_position_with_offset.toIrrVector();// new required position of camera
|
||||
|
||||
if ((m_kart->getSpeed() > 5 ) || (m_kart->getSpeed() < 0 ))
|
||||
{
|
||||
current_position += ((wanted_position - current_position) * dt
|
||||
* (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 + 1.0f
|
||||
: -1.5f * m_kart->getSpeed() + 2.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
current_position += (wanted_position - current_position) * dt * 5;
|
||||
}
|
||||
if(m_mode!=CM_FALLING)
|
||||
m_camera->setPosition(current_position);
|
||||
m_camera->setTarget(current_target);
|
||||
m_camera->setTarget(current_target);//set new target
|
||||
|
||||
assert(!isnan(m_camera->getPosition().X));
|
||||
assert(!isnan(m_camera->getPosition().Y));
|
||||
@ -480,13 +503,9 @@ void Camera::update(float dt)
|
||||
|
||||
// Aim at the usual same position of the kart (i.e. slightly
|
||||
// above the kart).
|
||||
core::vector3df wanted_target(m_kart->getXYZ().toIrrVector()
|
||||
+core::vector3df(0, above_kart, 0) );
|
||||
core::vector3df current_target = m_camera->getTarget();
|
||||
// Note: this code is replicated from smoothMoveCamera so that
|
||||
// the camera keeps on pointing to the same spot.
|
||||
current_target += ((wanted_target-current_target)*m_target_speed)*dt;
|
||||
|
||||
core::vector3df current_target = (m_kart->getXYZ().toIrrVector()+core::vector3df(0, above_kart, 0));
|
||||
m_camera->setTarget(current_target);
|
||||
}
|
||||
else
|
||||
@ -535,7 +554,7 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle,
|
||||
|
||||
if (smoothing)
|
||||
{
|
||||
smoothMoveCamera(dt, wanted_position, wanted_target);
|
||||
smoothMoveCamera(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -188,8 +188,7 @@ private:
|
||||
unsigned int m_next_end_camera;
|
||||
|
||||
void setupCamera();
|
||||
void smoothMoveCamera(float dt, const Vec3 &wanted_position,
|
||||
const Vec3 &wanted_target);
|
||||
void smoothMoveCamera(float dt);
|
||||
void computeNormalCameraPosition(Vec3 *wanted_position,
|
||||
Vec3 *wanted_target);
|
||||
void handleEndCamera(float dt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user