From a8f4ffac7031ef195aa5985b22affeca36e49b0e Mon Sep 17 00:00:00 2001 From: Dk Date: Thu, 3 Apr 2014 15:37:44 +0530 Subject: [PATCH 1/8] Camera Moves Smoothly --- src/graphics/camera.cpp | 48 ++++++++++++++++++++++++++--------------- src/graphics/camera.hpp | 3 +-- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 6dd9b2192..16cf45ebf 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -287,8 +287,7 @@ void Camera::reset() void Camera::setInitialTransform() { if (m_kart == NULL) return; - - Vec3 start_offset(0, 25, -50); + Vec3 start_offset(0, 2, -5); Vec3 xx = m_kart->getTrans()(start_offset); m_camera->setPosition( xx.toIrrVector()); // Reset the target from the previous target (in case of a restart @@ -312,17 +311,36 @@ 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; - if(m_mode!=CM_FALLING) - m_camera->setPosition(current_position); - m_camera->setTarget(current_target); + 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(); + + float steer=m_kart->getSteerPercent(); + 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.12 ? ratio : -0.12; + + Vec3 camera_offset(-5*(1+ratio)*sin(skid_angle/2), 2*(1+ratio/2),-5*(1+ratio)*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 + + current_position += ((wanted_position - current_position)*dt*(m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1*m_kart->getSpeed()/3) ); + + m_camera->setPosition(current_position); + m_camera->setTarget(current_target);//set new target assert(!isnan(m_camera->getPosition().X)); assert(!isnan(m_camera->getPosition().Y)); @@ -480,13 +498,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 +549,7 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle, if (smoothing) { - smoothMoveCamera(dt, wanted_position, wanted_target); + smoothMoveCamera(dt); } else { diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 6b7e01fcf..e9555ea7f 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -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); From 18335676e49f2b8f393d8a514216fa99d8eaddbc Mon Sep 17 00:00:00 2001 From: Dk Date: Thu, 3 Apr 2014 16:35:11 +0530 Subject: [PATCH 2/8] Smooth Move Camera --- src/graphics/camera.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 16cf45ebf..597955ec2 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -316,28 +316,28 @@ void Camera::smoothMoveCamera(float dt) core::vector3df current_position = m_camera->getPosition(); // Smoothly interpolate towards the position and target - const KartProperties *kp=m_kart->getKartProperties(); + 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(); + float current_speed = m_kart->getSpeed(); - float steer=m_kart->getSteerPercent(); - const Skidding *ks=m_kart->getSkidding(); - float skid_factor=ks->getVisualSkidRotation(); + float steer = m_kart->getSteerPercent(); + 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; + float ratio = (current_speed - max_speed_without_zipper) / max_increase_with_zipper; ratio = ratio > -0.12 ? ratio : -0.12; - - Vec3 camera_offset(-5*(1+ratio)*sin(skid_angle/2), 2*(1+ratio/2),-5*(1+ratio)*cos(skid_angle/2));// defines how far camera should be from player kart. + float camera_distance = -5 * (1 + ratio);// distance of camera from kart in x and z plane + Vec3 camera_offset(camera_distance * sin(skid_angle / 2), 2 * (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 current_target = m_kart->getXYZ().toIrrVector();// next target core::vector3df wanted_position = m_kart_camera_position_with_offset.toIrrVector();// new required position of camera - current_position += ((wanted_position - current_position)*dt*(m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1*m_kart->getSpeed()/3) ); + current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() / 3) ); m_camera->setPosition(current_position); m_camera->setTarget(current_target);//set new target @@ -500,7 +500,7 @@ void Camera::update(float dt) // above the kart). // Note: this code is replicated from smoothMoveCamera so that // the camera keeps on pointing to the same spot. - core::vector3df current_target = (m_kart->getXYZ().toIrrVector()+core::vector3df(0, above_kart, 0)); + core::vector3df current_target = (m_kart->getXYZ().toIrrVector()+core::vector3df(0, above_kart, 0)); m_camera->setTarget(current_target); } else From ff2f3c089682aa2d8fcc645af6b33dc06722b9b9 Mon Sep 17 00:00:00 2001 From: Dk Date: Sat, 5 Apr 2014 00:24:07 +0530 Subject: [PATCH 3/8] Camera while moving back is fixed --- src/graphics/camera.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 597955ec2..dab24b176 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -287,7 +287,7 @@ void Camera::reset() void Camera::setInitialTransform() { if (m_kart == NULL) return; - Vec3 start_offset(0, 2, -5); + Vec3 start_offset(0, 1.6, -3.5); Vec3 xx = m_kart->getTrans()(start_offset); m_camera->setPosition( xx.toIrrVector()); // Reset the target from the previous target (in case of a restart @@ -328,8 +328,8 @@ void Camera::smoothMoveCamera(float dt) float skid_angle = asin(skid_factor); float ratio = (current_speed - max_speed_without_zipper) / max_increase_with_zipper; ratio = ratio > -0.12 ? ratio : -0.12; - float camera_distance = -5 * (1 + ratio);// distance of camera from kart in x and z plane - Vec3 camera_offset(camera_distance * sin(skid_angle / 2), 2 * (1 + ratio / 2),camera_distance * cos(skid_angle / 2));// defines how far camera should be from player kart. + float camera_distance = -3.5 * (1 + ratio);// distance of camera from kart in x and z plane + Vec3 camera_offset(camera_distance * sin(skid_angle / 2), 1.6 * (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); @@ -337,9 +337,10 @@ void Camera::smoothMoveCamera(float dt) 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 - current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() / 3) ); - - m_camera->setPosition(current_position); + current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 2 ) ); + + if(m_mode!=CM_FALLING) + m_camera->setPosition(current_position); m_camera->setTarget(current_target);//set new target assert(!isnan(m_camera->getPosition().X)); From 746e23c0f148142f0c108fdc56befb1ba8c80d66 Mon Sep 17 00:00:00 2001 From: Dk Date: Sat, 5 Apr 2014 06:39:42 +0530 Subject: [PATCH 4/8] Camera even moved more closer --- src/graphics/camera.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index dab24b176..fbdd1d4f6 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -287,7 +287,7 @@ void Camera::reset() void Camera::setInitialTransform() { if (m_kart == NULL) return; - Vec3 start_offset(0, 1.6, -3.5); + Vec3 start_offset(0, 1.6, -3); Vec3 xx = m_kart->getTrans()(start_offset); m_camera->setPosition( xx.toIrrVector()); // Reset the target from the previous target (in case of a restart @@ -328,7 +328,7 @@ void Camera::smoothMoveCamera(float dt) float skid_angle = asin(skid_factor); float ratio = (current_speed - max_speed_without_zipper) / max_increase_with_zipper; ratio = ratio > -0.12 ? ratio : -0.12; - float camera_distance = -3.5 * (1 + ratio);// distance of camera from kart in x and z plane + 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.6 * (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); @@ -337,7 +337,7 @@ void Camera::smoothMoveCamera(float dt) 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 - current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 2 ) ); + current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 1.5 ) ); if(m_mode!=CM_FALLING) m_camera->setPosition(current_position); From 0345f26a7bab3623c88301caaeff4f6c5de1fedc Mon Sep 17 00:00:00 2001 From: Dk Date: Wed, 9 Apr 2014 21:06:07 +0530 Subject: [PATCH 5/8] Camera After Rescue comes to normal quickly --- src/graphics/camera.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index fbdd1d4f6..e961872a0 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -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.6, -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) { @@ -288,8 +283,8 @@ void Camera::setInitialTransform() { if (m_kart == NULL) return; Vec3 start_offset(0, 1.6, -3); - Vec3 xx = m_kart->getTrans()(start_offset); - m_camera->setPosition( xx.toIrrVector()); + 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 @@ -321,7 +316,6 @@ void Camera::smoothMoveCamera(float dt) float max_speed_without_zipper = kp->getMaxSpeed(); float current_speed = m_kart->getSpeed(); - float steer = m_kart->getSteerPercent(); const Skidding *ks = m_kart->getSkidding(); float skid_factor = ks->getVisualSkidRotation(); @@ -337,8 +331,14 @@ void Camera::smoothMoveCamera(float dt) 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 - current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 1.5 ) ); - + 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 * m_kart->getSpeed() * 1.5 + 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);//set new target From d25ea996659f1ba00721ef43d7d9b3e26a0a7279 Mon Sep 17 00:00:00 2001 From: Dk Date: Wed, 9 Apr 2014 22:24:32 +0530 Subject: [PATCH 6/8] Revert "Camera After Rescue comes to normal quickly" This reverts commit 0345f26a7bab3623c88301caaeff4f6c5de1fedc. git commit -m "revert" --- src/graphics/camera.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index e961872a0..fbdd1d4f6 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -234,12 +234,17 @@ 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) || (m_mode==CM_FALLING && mode==CM_NORMAL)) + if(m_mode==CM_REVERSE && mode==CM_NORMAL) { - Vec3 start_offset(0, 1.6, -3); - Vec3 current_position = m_kart->getTrans()(start_offset); - m_camera->setPosition( current_position.toIrrVector()); - m_camera->setTarget(m_camera->getPosition()); + 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)); + } if(mode==CM_FINAL) { @@ -283,8 +288,8 @@ void Camera::setInitialTransform() { if (m_kart == NULL) return; Vec3 start_offset(0, 1.6, -3); - Vec3 current_position = m_kart->getTrans()(start_offset); - m_camera->setPosition( current_position.toIrrVector()); + Vec3 xx = m_kart->getTrans()(start_offset); + m_camera->setPosition( xx.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 @@ -316,6 +321,7 @@ void Camera::smoothMoveCamera(float dt) float max_speed_without_zipper = kp->getMaxSpeed(); float current_speed = m_kart->getSpeed(); + float steer = m_kart->getSteerPercent(); const Skidding *ks = m_kart->getSkidding(); float skid_factor = ks->getVisualSkidRotation(); @@ -331,14 +337,8 @@ void Camera::smoothMoveCamera(float dt) 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 * m_kart->getSpeed() * 1.5 + 2.0f)); - } - else - { - current_position += (wanted_position - current_position) * dt * 5; - } + current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 1.5 ) ); + if(m_mode!=CM_FALLING) m_camera->setPosition(current_position); m_camera->setTarget(current_target);//set new target From 50ca35ca96df7bb417b28d82e95ff4ee2f0fc4b3 Mon Sep 17 00:00:00 2001 From: Dk Date: Wed, 9 Apr 2014 22:30:05 +0530 Subject: [PATCH 7/8] Rescue Camera is working properly --- src/graphics/camera.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index fbdd1d4f6..e961872a0 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -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.6, -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) { @@ -288,8 +283,8 @@ void Camera::setInitialTransform() { if (m_kart == NULL) return; Vec3 start_offset(0, 1.6, -3); - Vec3 xx = m_kart->getTrans()(start_offset); - m_camera->setPosition( xx.toIrrVector()); + 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 @@ -321,7 +316,6 @@ void Camera::smoothMoveCamera(float dt) float max_speed_without_zipper = kp->getMaxSpeed(); float current_speed = m_kart->getSpeed(); - float steer = m_kart->getSteerPercent(); const Skidding *ks = m_kart->getSkidding(); float skid_factor = ks->getVisualSkidRotation(); @@ -337,8 +331,14 @@ void Camera::smoothMoveCamera(float dt) 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 - current_position += ((wanted_position - current_position) * dt * (m_kart->getSpeed()>0 ? m_kart->getSpeed()/3 : -1 * m_kart->getSpeed() * 1.5 ) ); - + 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 * m_kart->getSpeed() * 1.5 + 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);//set new target From e0d22a28d60d1993852dc888c0527a161fe378db Mon Sep 17 00:00:00 2001 From: Dk Date: Thu, 10 Apr 2014 07:06:13 +0530 Subject: [PATCH 8/8] Camera Moves Back Smoothly --- src/graphics/camera.cpp | 69 +++++++++++++++++++++++++---------------- src/graphics/camera.hpp | 3 +- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/graphics/camera.cpp b/src/graphics/camera.cpp index 6dd9b2192..e961872a0 100644 --- a/src/graphics/camera.cpp +++ b/src/graphics/camera.cpp @@ -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.6, -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.6, -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,42 @@ 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.12 ? ratio : -0.12; + 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.6 * (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 * m_kart->getSpeed() * 1.5 + 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 +499,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 +550,7 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle, if (smoothing) { - smoothMoveCamera(dt, wanted_position, wanted_target); + smoothMoveCamera(dt); } else { diff --git a/src/graphics/camera.hpp b/src/graphics/camera.hpp index 6b7e01fcf..e9555ea7f 100644 --- a/src/graphics/camera.hpp +++ b/src/graphics/camera.hpp @@ -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);