|
|
|
@ -7,6 +7,7 @@
|
|
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
#include "../mwworld/ptr.hpp"
|
|
|
|
@ -16,6 +17,8 @@
|
|
|
|
|
#include "../mwmechanics/movement.hpp"
|
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../mwphysics/physicssystem.hpp"
|
|
|
|
|
|
|
|
|
|
#include "npcanimation.hpp"
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
@ -195,6 +198,7 @@ namespace MWRender
|
|
|
|
|
rotateCamera(0.f, osg::DegreesToRadians(3.f * duration), true);
|
|
|
|
|
|
|
|
|
|
updateFocalPointOffset(duration);
|
|
|
|
|
updatePosition();
|
|
|
|
|
|
|
|
|
|
float speed = mTrackingPtr.getClass().getSpeed(mTrackingPtr);
|
|
|
|
|
speed /= (1.f + speed / 500.f);
|
|
|
|
@ -205,6 +209,42 @@ namespace MWRender
|
|
|
|
|
updateStandingPreviewMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::updatePosition()
|
|
|
|
|
{
|
|
|
|
|
mFocalPointAdjustment = osg::Vec3d();
|
|
|
|
|
if (isFirstPerson())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const float cameraObstacleLimit = 5.0f;
|
|
|
|
|
const float focalObstacleLimit = 10.f;
|
|
|
|
|
|
|
|
|
|
const MWPhysics::PhysicsSystem* physics = MWBase::Environment::get().getWorld()->getPhysics();
|
|
|
|
|
|
|
|
|
|
// Adjust focal point to prevent clipping.
|
|
|
|
|
osg::Vec3d focal = getFocalPoint();
|
|
|
|
|
osg::Vec3d focalOffset = getFocalPointOffset();
|
|
|
|
|
float offsetLen = focalOffset.length();
|
|
|
|
|
if (offsetLen > 0)
|
|
|
|
|
{
|
|
|
|
|
MWPhysics::PhysicsSystem::RayResult result = physics->castSphere(focal - focalOffset, focal, focalObstacleLimit);
|
|
|
|
|
if (result.mHit)
|
|
|
|
|
{
|
|
|
|
|
double adjustmentCoef = -(result.mHitPos + result.mHitNormal * focalObstacleLimit - focal).length() / offsetLen;
|
|
|
|
|
mFocalPointAdjustment = focalOffset * std::max(-1.0, adjustmentCoef);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate camera distance.
|
|
|
|
|
mCameraDistance = mBaseCameraDistance + getCameraDistanceCorrection();
|
|
|
|
|
if (mDynamicCameraDistanceEnabled)
|
|
|
|
|
mCameraDistance = std::min(mCameraDistance, mMaxNextCameraDistance);
|
|
|
|
|
osg::Vec3d cameraPos;
|
|
|
|
|
getPosition(focal, cameraPos);
|
|
|
|
|
MWPhysics::PhysicsSystem::RayResult result = physics->castSphere(focal, cameraPos, cameraObstacleLimit);
|
|
|
|
|
if (result.mHit)
|
|
|
|
|
mCameraDistance = (result.mHitPos + result.mHitNormal * cameraObstacleLimit - focal).length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::updateStandingPreviewMode()
|
|
|
|
|
{
|
|
|
|
|
if (!mStandingPreviewAllowed)
|
|
|
|
@ -389,7 +429,6 @@ namespace MWRender
|
|
|
|
|
mIsNearest = dist <= mNearest;
|
|
|
|
|
mBaseCameraDistance = osg::clampBetween(dist, mNearest, mFurthest);
|
|
|
|
|
Settings::Manager::setFloat("third person camera distance", "Camera", mBaseCameraDistance);
|
|
|
|
|
setCameraDistance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::setCameraDistance(float dist, bool adjust)
|
|
|
|
@ -414,16 +453,6 @@ namespace MWRender
|
|
|
|
|
return pitchCorrection + speedCorrection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::setCameraDistance()
|
|
|
|
|
{
|
|
|
|
|
mFocalPointAdjustment = osg::Vec3d();
|
|
|
|
|
if (isFirstPerson())
|
|
|
|
|
return;
|
|
|
|
|
mCameraDistance = mBaseCameraDistance + getCameraDistanceCorrection();
|
|
|
|
|
if (mDynamicCameraDistanceEnabled)
|
|
|
|
|
mCameraDistance = std::min(mCameraDistance, mMaxNextCameraDistance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::setAnimation(NpcAnimation *anim)
|
|
|
|
|
{
|
|
|
|
|
mAnimation = anim;
|
|
|
|
|