Commit 4f581e65 authored by AL's avatar AL

damn good camera control

parent 82a114c4
......@@ -58,12 +58,14 @@ void Camera::Reset() noexcept
yaw = 0.0f;
}
void Camera::SetFullTransform(CamTilt in_tilt, CamMove in_move)
void Camera::SetFullTransform(CamTrans in_trans)
{
Translate({ in_move.x, in_move.y, in_move.z });
roll = in_tilt.roll;
pitch = in_tilt.pitch;
yaw = in_tilt.yaw;
pos.x = in_trans.pos.x;
pos.y = in_trans.pos.y;
pos.z = in_trans.pos.z;
roll = in_trans.tilt.roll;
pitch = in_trans.tilt.pitch;
yaw = in_trans.tilt.yaw;
}
void Camera::Rotate( float dx,float dy ) noexcept
......
......@@ -3,15 +3,92 @@
struct CamTilt
{
float roll;
float pitch;
float yaw;
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
CamTilt& operator+=(const CamTilt& rhs)
{
roll += rhs.roll;
pitch += rhs.pitch;
yaw += rhs.yaw;
return *this;
}
friend CamTilt operator+(CamTilt lhs, const CamTilt& rhs)
{
lhs += rhs;
return lhs;
}
CamTilt operator*(float f)
{
CamTilt ct = *this;
ct.roll *= f;
ct.pitch *= f;
ct.yaw *= f;
return ct;
}
CamTilt& operator*=(float f)
{
roll *= f;
pitch *= f;
yaw *= f;
return *this;
}
};
struct CamMove
{
float x;
float y;
float z;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
CamMove& operator+=(const CamMove& rhs)
{
x += rhs.x;
y += rhs.y;
z += rhs.z;
return *this;
}
friend CamMove operator+(CamMove lhs, const CamMove& rhs)
{
lhs += rhs;
return lhs;
}
CamMove operator*(float f)
{
CamMove cm = *this;
cm.x *= f;
cm.y *= f;
cm.z *= f;
return cm;
}
CamMove& operator*=(float f)
{
x *= f;
y *= f;
z *= f;
return *this;
}
};
struct CamTrans
{
CamTilt tilt;
CamMove pos;
CamTrans& operator+=(const CamTrans& rhs)
{
tilt += rhs.tilt;
pos += rhs.pos;
return *this;
}
friend CamTrans operator+(CamTrans lhs, const CamTrans& rhs)
{
lhs += rhs;
return lhs;
}
CamTrans operator*(float f)
{
CamTrans ct = *this;
ct.tilt *= f;
ct.pos *= f;
return ct;
}
};
class Camera
{
......@@ -21,7 +98,7 @@ public:
DirectX::XMFLOAT3 GetPosition() const noexcept;
void SpawnControlWindow() noexcept;
void Reset() noexcept;
void SetFullTransform(CamTilt in_tilt, CamMove in_move);
void SetFullTransform(CamTrans in_trans);
void Rotate( float dx,float dy ) noexcept;
void Translate( DirectX::XMFLOAT3 translation ) noexcept;
private:
......
#include "CameraManager.h"
#include "Framework\ChiliMath.h"
CameraManager::CameraManager():
baseTrans({0.0f,PI/2.0f,0.0f,1.0f,1.0f,1.0f})
{
curTrans = baseTrans;
intermedTrans = baseTrans;
}
void CameraManager::PendScenario(Scenario s)
{
pendingScenarios.push_back(s);
}
void CameraManager::Update(float dt)
{
if (!pendingScenarios.empty())
{
switch (pendingScenarios.back())
{
case Scenario:: ThrowSand:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.1f,0.15f,0.0f }, { 0.0f,0.0f,0.0f }, 0.5f));
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.3f,-0.6f,0.0f }, { 0.0f,0.0f,0.0f }, 0.15f));
scenarious.emplace_back(cs);
break;
}
case Scenario::UnsettleDust:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.2f,0.0f,0.0f }, { 0.0f,-0.4f,0.0f }, 0.7f));
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.1f,-0.0f,0.0f }, { 0.0f,0.0f,0.0f }, 0.5f));
scenarious.emplace_back(cs);
break;
}
case Scenario::Strike:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ -0.2f,-2.9f,0.0f }, { 0.0f, 0.0f, 0.0f }, 0.06f));
scenarious.emplace_back(cs);
break;
}
case Scenario::Defend:
{
CamSequence cs;
cs.push(std::make_tuple<CamTilt, CamMove, float>({ 0.0f,0.2f,0.0f }, { -0.3f,0.0f,0.0f }, 0.7f));
scenarious.emplace_back(cs);
break;
}
}
pendingScenarios.pop_back();
}
scenarious.erase(std::remove_if(scenarious.begin(), scenarious.end(), [dt](CameraScenario& s) {return s.Update(dt); }), scenarious.end());
CamTrans targetTrans = baseTrans; //assembling target transform
for (auto& s : scenarious)targetTrans += s.GetCamData();
auto coeff = dt * speedCoeff;
intermedTrans = intermedTrans * (1.0f - coeff) + targetTrans * coeff;
curTrans = curTrans * (1.0f - coeff) + intermedTrans * coeff;
cam.SetFullTransform(curTrans);
}
DirectX::XMMATRIX CameraManager::GetMatrix() const noexcept
{
return cam.GetMatrix();
......@@ -30,9 +89,9 @@ bool CameraManager::CameraScenario::Update(float dt)
else return false;
}
std::pair<CamTilt, CamMove> CameraManager::CameraScenario::GetCamData()
CamTrans CameraManager::CameraScenario::GetCamData()
{
return std::make_pair(std::get<CamTilt>(stages.front()), std::get<CamMove>(stages.front()));
return { std::get<CamTilt>(stages.front()), std::get<CamMove>(stages.front()) };
}
std::vector<CameraManager::Scenario> CameraManager::pendingScenarios;
\ No newline at end of file
#pragma once
#include "Camera.h"
#include <queue>
#define CM CameraManager
class CameraManager
{
typedef std::queue<std::tuple<CamTilt, CamMove, float>> CamSequence;
......@@ -14,21 +15,22 @@ class CameraManager
CameraScenario& operator=(const CameraScenario&) = default;
bool Update(float dt); //returns 1 if all stages are passed
std::pair<CamTilt, CamMove>GetCamData();
CamTrans GetCamData();
private:
CameraManager::CamSequence stages;
float stageTime = 0.0f;
};
public:
CameraManager();
enum class Scenario
{
ThrowSand,
UnsettleDust,
Strike,
Defend
};
static void PendScenario(Scenario s);
void Update(float dt);
DirectX::XMMATRIX GetMatrix() const noexcept;
DirectX::XMFLOAT3 GetPosition() const noexcept;
......@@ -36,8 +38,11 @@ public:
private:
CamTilt baseCamTilt;
CamMove baseCamPos;
CamTrans baseTrans;
CamTrans intermedTrans;
CamTrans curTrans;
//CamTrans targetTrans;
float speedCoeff = 5.0f;
Camera cam;
std::vector<CameraScenario> scenarious;
static std::vector<Scenario> pendingScenarios;
......
......@@ -11,6 +11,7 @@
#include "EffectHandler.h"
#include "CameraManager.h"
#define DDDR damageDigitsDrawingRange
......@@ -118,15 +119,19 @@ int CombatManager::ProcessInput(Keyboard::Event in_event) //why does it return
if (in_event.GetCode() == 'T') //for testing
{
SceneLight::PendDistortion(SceneLight::LightDistortionType::DarkeningFlicker);
CM::PendScenario(CM::Scenario::ThrowSand);
}
if (in_event.GetCode() == 'Y') //for testing
{
SceneLight::PendDistortion(SceneLight::LightDistortionType::RednessBoost);
CM::PendScenario(CM::Scenario::UnsettleDust);
}
if (in_event.GetCode() == 'U') //for testing
{
SceneLight::PendDistortion(SceneLight::LightDistortionType::ColdEmbrace);
CM::PendScenario(CM::Scenario::Strike);
}
if (in_event.GetCode() == 'I') //for testing
{
CM::PendScenario(CM::Scenario::Defend);
}
......
......@@ -287,6 +287,7 @@ void LevelLayout::SubmitDrawables()
void LevelLayout::UpdateAndBindLight(float dt, DirectX::XMMATRIX cameraTransform)
{
sl.UpdateAndBind(dt, gfx, cameraTransform);
camMan.Update(dt);
}
DirectX::XMMATRIX LevelLayout::GetCameraMatrix() const noexcept
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment