|
|
|
@ -53,6 +53,7 @@ namespace MWRender
|
|
|
|
|
|
|
|
|
|
Camera::Camera (osg::Camera* camera)
|
|
|
|
|
: mHeightScale(1.f),
|
|
|
|
|
mCollisionType(MWPhysics::CollisionType::CollisionType_Default & ~MWPhysics::CollisionType::CollisionType_Actor),
|
|
|
|
|
mCamera(camera),
|
|
|
|
|
mAnimation(nullptr),
|
|
|
|
|
mFirstPersonView(true),
|
|
|
|
@ -127,6 +128,7 @@ namespace MWRender
|
|
|
|
|
pos = calculateFirstPersonPosition(recalculatedTrackedPosition);
|
|
|
|
|
}
|
|
|
|
|
cam->setViewMatrixAsLookAt(pos, pos + forward, up);
|
|
|
|
|
mViewMatrix = cam->getViewMatrix();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Camera::update(float duration, bool paused)
|
|
|
|
@ -174,7 +176,6 @@ namespace MWRender
|
|
|
|
|
constexpr float focalObstacleLimit = 10.f;
|
|
|
|
|
|
|
|
|
|
const auto* rayCasting = MWBase::Environment::get().getWorld()->getRayCasting();
|
|
|
|
|
constexpr int collisionType = (MWPhysics::CollisionType::CollisionType_Default & ~MWPhysics::CollisionType::CollisionType_Actor);
|
|
|
|
|
|
|
|
|
|
// Adjust focal point to prevent clipping.
|
|
|
|
|
osg::Vec3d focalOffset = getFocalPointOffset();
|
|
|
|
@ -184,7 +185,7 @@ namespace MWRender
|
|
|
|
|
float offsetLen = focalOffset.length();
|
|
|
|
|
if (offsetLen > 0)
|
|
|
|
|
{
|
|
|
|
|
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal - focalOffset, focal, focalObstacleLimit, collisionType);
|
|
|
|
|
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal - focalOffset, focal, focalObstacleLimit, mCollisionType);
|
|
|
|
|
if (result.mHit)
|
|
|
|
|
{
|
|
|
|
|
double adjustmentCoef = -(result.mHitPos + result.mHitNormal * focalObstacleLimit - focal).length() / offsetLen;
|
|
|
|
@ -196,7 +197,7 @@ namespace MWRender
|
|
|
|
|
mCameraDistance = mPreferredCameraDistance;
|
|
|
|
|
osg::Quat orient = osg::Quat(mPitch + mExtraPitch, osg::Vec3d(1,0,0)) * osg::Quat(mYaw + mExtraYaw, osg::Vec3d(0,0,1));
|
|
|
|
|
osg::Vec3d offset = orient * osg::Vec3d(0.f, -mCameraDistance, 0.f);
|
|
|
|
|
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal, focal + offset, cameraObstacleLimit, collisionType);
|
|
|
|
|
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal, focal + offset, cameraObstacleLimit, mCollisionType);
|
|
|
|
|
if (result.mHit)
|
|
|
|
|
{
|
|
|
|
|
mCameraDistance = (result.mHitPos + result.mHitNormal * cameraObstacleLimit - focal).length();
|
|
|
|
@ -211,7 +212,7 @@ namespace MWRender
|
|
|
|
|
if (mMode == newMode)
|
|
|
|
|
return;
|
|
|
|
|
Mode oldMode = mMode;
|
|
|
|
|
if (!force && (newMode == Mode::FirstPerson || oldMode == Mode::FirstPerson) && !mAnimation->upperBodyReady())
|
|
|
|
|
if (!force && (newMode == Mode::FirstPerson || oldMode == Mode::FirstPerson) && mAnimation && !mAnimation->upperBodyReady())
|
|
|
|
|
{
|
|
|
|
|
// Changing the view will stop all playing animations, so if we are playing
|
|
|
|
|
// anything important, queue the view change for later
|
|
|
|
|