Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "GraphicsEngine/Component.h"
- #include "GraphicsEngine/Input.h"
- #include "GraphicsEngine/Object.h"
- #include "GraphicsEngine/Transform.h"
- #include "GraphicsEngine/Time.h"
- #include "GraphicsEngine/Vector3.h"
- #include "GraphicsEngine/GraphicsApi/OpenGL20/GL20.h"
- #include <iostream>
- class CameraController : public Component
- {
- Vector3 mousePos;
- Vector3 mousePosPrev;
- bool ignoreNext = false;
- public:
- CameraController()
- {
- mousePos = Vector3::Zero();
- mousePosPrev = Vector3::Zero();
- }
- virtual ~CameraController() {}
- virtual void Update()
- {
- Transform * pTransform = m_pObject->m_pTransform;
- // Camera Translation
- {
- Vector3 forward = pTransform->GetForward();
- Vector3 right = pTransform->GetRight();
- double dt = Time::GetDeltaTime();
- const double speed = 1.0;
- Vector3 direction;
- if (Input::GetKey(KEY_CODE_W))
- {
- direction += forward;
- }
- if (Input::GetKey(KEY_CODE_S))
- {
- direction -= forward;
- }
- if (Input::GetKey(KEY_CODE_D))
- {
- direction += right;
- }
- if (Input::GetKey(KEY_CODE_A))
- {
- direction -= right;
- }
- // TODO : Task08
- pTransform->Translate( speed * dt * direction );
- }
- // Camera Rotation
- {
- if (mousePosPrev.x == 0 && mousePosPrev.y == 0) {
- mousePosPrev = Input::GetMousePosition();
- return;
- }
- const double speed = 0.1;
- Vector3 direction;
- mousePos = Input::GetMousePosition();
- if (ignoreNext) {
- if (fabs(mousePos.x - mousePosPrev.x) > 0.0002f && fabs(mousePos.y - mousePosPrev.y) > 0.0002f) {
- return;
- }
- ignoreNext = false;
- }
- direction = mousePos - mousePosPrev;
- direction = direction * speed;
- pTransform->Rotate(direction.y, direction.x, 0);
- ignoreNext = true;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement