Added some editor camera controls
This commit is contained in:
parent
33b173ab9e
commit
efe8ba4f11
|
@ -37,24 +37,24 @@ namespace SHADE
|
|||
}
|
||||
void SHCameraComponent::SetPositionX(float x) noexcept
|
||||
{
|
||||
position[0] = x;
|
||||
position.x = x;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionY(float y) noexcept
|
||||
{
|
||||
position[1] = y;
|
||||
position.y = y;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionZ(float z) noexcept
|
||||
{
|
||||
position[2] = z;
|
||||
position.z = z;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(float x,float y, float z) noexcept
|
||||
{
|
||||
position[0] = x;
|
||||
position[1] = y;
|
||||
position[2] = z;
|
||||
position.x = x;
|
||||
position.y = y;
|
||||
position.z = z;
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(SHVec3& pos) noexcept
|
||||
|
|
|
@ -12,10 +12,49 @@ namespace SHADE
|
|||
{
|
||||
SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem());
|
||||
|
||||
SHVec3 target{ 0.0f,0.0f,1.0f };
|
||||
SHVec3 up = { 0.0f,1.0f,0.0f };
|
||||
|
||||
|
||||
SHCameraComponent& camera = system->editorCamera;
|
||||
SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
|
||||
SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
|
||||
//SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
|
||||
|
||||
target = SHVec3::Normalise(target);
|
||||
|
||||
SHVec3::RotateZ(up, camera.roll);
|
||||
up = SHVec3::Normalise(up);
|
||||
|
||||
|
||||
SHVec3 view = target - camera.position; view = SHVec3::Normalise(view);
|
||||
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
|
||||
const SHVec3 UP = SHVec3::Cross(right, view);
|
||||
|
||||
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::A))
|
||||
{
|
||||
system->editorCamera.SetPositionX(system->editorCamera.position[0] - dt * system->editorCamera.movementSpeed);
|
||||
|
||||
system->editorCamera.position -= right * dt * camera.movementSpeed;
|
||||
}
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::D))
|
||||
{
|
||||
system->editorCamera.position += right * dt * camera.movementSpeed;
|
||||
}
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::W))
|
||||
{
|
||||
system->editorCamera.position += view * dt * camera.movementSpeed;
|
||||
}
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::S))
|
||||
{
|
||||
system->editorCamera.position -= view * dt * camera.movementSpeed;
|
||||
}
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::Q))
|
||||
{
|
||||
system->editorCamera.position += UP * dt * camera.movementSpeed;
|
||||
}
|
||||
if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::E))
|
||||
{
|
||||
system->editorCamera.position -= UP * dt * camera.movementSpeed;
|
||||
}
|
||||
system->UpdateCameraComponent(system->editorCamera);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue