Using morphable and freecam controllers in example app, blending matrices using vectors, improvements regarding updating projection matrices, removed FreeCam components from MorphableController, renamed variable to m_targetMorphStatePerspective, setting target morph state using setter
This commit is contained in:
@@ -39,7 +39,8 @@ namespace OpenVulkano
|
|||||||
{
|
{
|
||||||
Scene::Scene m_scene;
|
Scene::Scene m_scene;
|
||||||
Scene::MorphableCamera m_camera;
|
Scene::MorphableCamera m_camera;
|
||||||
Scene::MorphableCameraController m_cameraControl;
|
Scene::MorphableCameraController m_morphableCameraControl;
|
||||||
|
FreeCamCameraController m_cameraControl;
|
||||||
Scene::Material m_material;
|
Scene::Material m_material;
|
||||||
Scene::Shader m_shader;
|
Scene::Shader m_shader;
|
||||||
|
|
||||||
@@ -113,7 +114,11 @@ namespace OpenVulkano
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000) { m_cameraControl.Init(&m_camera); }
|
MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000)
|
||||||
|
{
|
||||||
|
m_morphableCameraControl.Init(&m_camera);
|
||||||
|
m_cameraControl.Init(&m_camera);
|
||||||
|
}
|
||||||
|
|
||||||
void Init() override
|
void Init() override
|
||||||
{
|
{
|
||||||
@@ -190,6 +195,7 @@ namespace OpenVulkano
|
|||||||
void Tick() override
|
void Tick() override
|
||||||
{
|
{
|
||||||
m_cameraControl.Tick();
|
m_cameraControl.Tick();
|
||||||
|
m_morphableCameraControl.Tick();
|
||||||
m_simpleAnimationController.Tick();
|
m_simpleAnimationController.Tick();
|
||||||
m_sequenceAnimationController.Tick();
|
m_sequenceAnimationController.Tick();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace OpenVulkano::Scene
|
|||||||
Math::Matrix4f result;
|
Math::Matrix4f result;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 4; ++j) { result[i][j] = glm::mix(mat1[i][j], mat2[i][j], t); }
|
result[i] = Math::Utils::mix(mat1[i], mat2[i], t);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -25,8 +25,17 @@ namespace OpenVulkano::Scene
|
|||||||
PerspectiveCamera::UpdateProjectionMatrix();
|
PerspectiveCamera::UpdateProjectionMatrix();
|
||||||
float aspectH = m_aspect;
|
float aspectH = m_aspect;
|
||||||
float aspectV = 1;
|
float aspectV = 1;
|
||||||
|
if (m_morphState == 0) { UpdateViewProjectionMatrix(); }
|
||||||
|
else if (m_morphState == 1)
|
||||||
|
{
|
||||||
|
m_projection = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
||||||
|
UpdateViewProjectionMatrix();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane);
|
||||||
m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState);
|
m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState);
|
||||||
UpdateViewProjectionMatrix();
|
UpdateViewProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,22 +17,16 @@ namespace OpenVulkano::Scene
|
|||||||
, m_animationDuration(1.0f)
|
, m_animationDuration(1.0f)
|
||||||
, m_currentTime(0.0f)
|
, m_currentTime(0.0f)
|
||||||
, m_isMorphing(false)
|
, m_isMorphing(false)
|
||||||
, m_targetMorphState(false)
|
, m_targetMorphStatePerspective(false)
|
||||||
{
|
{
|
||||||
auto input = OpenVulkano::Input::InputManager::GetInstance();
|
auto input = OpenVulkano::Input::InputManager::GetInstance();
|
||||||
m_actionMorph = input->GetAction("morph");
|
m_actionMorph = input->GetAction("morph");
|
||||||
m_actionForward = input->GetAction("forward");
|
|
||||||
m_actionSide = input->GetAction("side");
|
|
||||||
m_actionUp = input->GetAction("up");
|
|
||||||
m_actionLookUp = input->GetAction("look up");
|
|
||||||
m_actionLookSide = input->GetAction("look side");
|
|
||||||
m_actionBoost = input->GetAction("boost");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MorphableCameraController::Init(MorphableCamera* camera)
|
void MorphableCameraController::Init(MorphableCamera* camera)
|
||||||
{
|
{
|
||||||
CameraController::Init(camera);
|
CameraController::Init(camera);
|
||||||
SetDefaultKeybindings();
|
m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MorphableCameraController::Tick()
|
void MorphableCameraController::Tick()
|
||||||
@@ -44,7 +38,7 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
m_isMorphing = true;
|
m_isMorphing = true;
|
||||||
m_currentTime = 0.0f;
|
m_currentTime = 0.0f;
|
||||||
m_targetMorphState = !m_targetMorphState;
|
m_targetMorphStatePerspective = !m_targetMorphStatePerspective;
|
||||||
}
|
}
|
||||||
m_wasMorphingKeyDown = isMorphingDown;
|
m_wasMorphingKeyDown = isMorphingDown;
|
||||||
|
|
||||||
@@ -58,52 +52,8 @@ namespace OpenVulkano::Scene
|
|||||||
t = 1.0f;
|
t = 1.0f;
|
||||||
m_isMorphing = false;
|
m_isMorphing = false;
|
||||||
}
|
}
|
||||||
float newState = m_targetMorphState ? t : (1.0f - t);
|
float newState = m_targetMorphStatePerspective ? t : (1.0f - t);
|
||||||
static_cast<MorphableCamera*>(GetCamera())->SetMorphState(newState);
|
static_cast<MorphableCamera*>(GetCamera())->SetMorphState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Movement logic
|
|
||||||
const float MOVEMENT_SPEED = 3.0f;
|
|
||||||
const float BOOST_MULT = 2.0f;
|
|
||||||
|
|
||||||
Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp),
|
|
||||||
-input->GetAxis(m_actionForward));
|
|
||||||
if (Math::Utils::length2(vec) > 1.0f) { vec = Math::Utils::normalize(vec); }
|
|
||||||
|
|
||||||
float dt = CURRENT_FRAME.frameTime;
|
|
||||||
vec = vec * dt * MOVEMENT_SPEED;
|
|
||||||
if (input->GetButton(m_actionBoost)) { vec *= BOOST_MULT; }
|
|
||||||
|
|
||||||
m_yaw -= input->GetAxis(m_actionLookSide) * dt / 2.0f;
|
|
||||||
m_pitch -= input->GetAxis(m_actionLookUp) * dt / 2.0f;
|
|
||||||
m_pitch = std::min(1.4f, std::max(-1.4f, m_pitch));
|
|
||||||
|
|
||||||
const Math::QuaternionF rot(Math::Vector3f(m_pitch, m_yaw, 0));
|
|
||||||
m_position += rot * vec;
|
|
||||||
Math::Matrix4f camTransformation = Math::Utils::toMat4(rot);
|
|
||||||
camTransformation[3] = Math::Vector4f(m_position, 1);
|
|
||||||
GetCamera()->SetMatrix(camTransformation);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MorphableCameraController::SetDefaultKeybindings()
|
|
||||||
{
|
|
||||||
m_actionMorph->BindKey(Input::InputKey::Keyboard::KEY_P);
|
|
||||||
|
|
||||||
m_actionForward->BindKey(Input::InputKey::Controller::AXIS_LEFT_Y);
|
|
||||||
m_actionForward->BindAxisButtons(Input::InputKey::Keyboard::KEY_W, Input::InputKey::Keyboard::KEY_S);
|
|
||||||
m_actionForward->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_Y, -0.0025f);
|
|
||||||
m_actionSide->BindKey(Input::InputKey::Controller::AXIS_LEFT_X);
|
|
||||||
m_actionSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_D, Input::InputKey::Keyboard::KEY_A);
|
|
||||||
m_actionSide->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_X, 0.0025f);
|
|
||||||
m_actionLookUp->BindKey(Input::InputKey::Controller::AXIS_RIGHT_Y);
|
|
||||||
m_actionLookUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_DOWN, Input::InputKey::Keyboard::KEY_UP);
|
|
||||||
m_actionLookUp->BindKey(Input::InputKey::Touch::AXIS_PAN_Y, 0.10f);
|
|
||||||
m_actionLookSide->BindKey(Input::InputKey::Controller::AXIS_RIGHT_X);
|
|
||||||
m_actionLookSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_RIGHT, Input::InputKey::Keyboard::KEY_LEFT);
|
|
||||||
m_actionLookSide->BindKey(Input::InputKey::Touch::AXIS_PAN_X, 0.10f);
|
|
||||||
m_actionLookUp->BindKey(Input::InputKey::Mouse::AXIS_Y);
|
|
||||||
m_actionLookSide->BindKey(Input::InputKey::Mouse::AXIS_X);
|
|
||||||
m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL);
|
|
||||||
m_actionBoost->BindKey(Input::InputKey::Keyboard::KEY_LEFT_SHIFT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,17 +18,8 @@ namespace OpenVulkano::Scene
|
|||||||
double m_animationDuration;
|
double m_animationDuration;
|
||||||
double m_currentTime;
|
double m_currentTime;
|
||||||
bool m_isMorphing;
|
bool m_isMorphing;
|
||||||
bool m_targetMorphState; // true for perspective, false for orthographic
|
bool m_targetMorphStatePerspective; // true for perspective, false for orthographic
|
||||||
|
|
||||||
float m_yaw = 0, m_pitch = 0, m_boostFactor = 2;
|
|
||||||
Math::Vector3f_SIMD m_position = { 0, 0, 0 };
|
|
||||||
|
|
||||||
Input::InputAction* m_actionForward;
|
|
||||||
Input::InputAction* m_actionSide;
|
|
||||||
Input::InputAction* m_actionUp;
|
|
||||||
Input::InputAction* m_actionLookUp;
|
|
||||||
Input::InputAction* m_actionLookSide;
|
|
||||||
Input::InputAction* m_actionBoost;
|
|
||||||
Input::InputAction* m_actionMorph;
|
Input::InputAction* m_actionMorph;
|
||||||
bool m_wasMorphingKeyDown = false;
|
bool m_wasMorphingKeyDown = false;
|
||||||
|
|
||||||
@@ -37,10 +28,10 @@ namespace OpenVulkano::Scene
|
|||||||
|
|
||||||
void Init(MorphableCamera* camera);
|
void Init(MorphableCamera* camera);
|
||||||
void Tick() override;
|
void Tick() override;
|
||||||
void SetDefaultKeybindings();
|
|
||||||
|
|
||||||
void SetDuration(double duration) { m_animationDuration = duration; }
|
void SetDuration(double duration) { m_animationDuration = duration; }
|
||||||
double GetDuration() { return m_animationDuration; }
|
double GetDuration() { return m_animationDuration; }
|
||||||
|
void SetTargetState(bool toPerspective) { m_targetMorphStatePerspective = toPerspective; }
|
||||||
void Reset() { m_currentTime = 0; }
|
void Reset() { m_currentTime = 0; }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user