1. Camera ( Free Mode / Unity Style )
- TODO : 카메라에 영향 받지 않는 gizmo 출력 ( UI )
더보기
#pragma once
//class Cube;
class Camera : public Transform
{
private:
float camSpeed;
float rotSpeed;
float wheelSpeed;
//
Vector3 mousePosTemp;
//
//Cube* gizmo;
///////////////////////////////////
public:
Camera();
~Camera();
//
void Update();
void Render();
///////////////////////////////////
private:
void CamMove();
void CamRotation();
//
void SetView();
};
/////////////////////////////////////////////////////////////////////////////////////
#include "Framework.h"
#include "Objects/Basic/Cube.h"
Camera::Camera()
:Transform("MainCamera"),
camSpeed(5.0f), rotSpeed(1.0f), wheelSpeed(128.0f)
{
position = { 5.0f, 7.0f, -7.0f };
rotation = { PI / 4.0f, 0, 0 };
//
//gizmo = new Cube;
}
Camera::~Camera()
{
//delete gizmo;
}
void Camera::Update()
{
//gizmo->Update();
//
CamMove();
CamRotation();
//
UpdateWorld();
//
SetView();
}
void Camera::Render()
{
//gizmo->Render();
}
void Camera::CamMove()
{
/* Keyboard Controlled Move */
if (KEY_PRESS(VK_RBUTTON))
{
if (KEY_PRESS('A'))
position -= Right() * camSpeed * DELTA;
else if (KEY_PRESS('D'))
position += Right() * camSpeed * DELTA;
if (KEY_PRESS('W'))
position += Forward() * camSpeed * DELTA;
else if (KEY_PRESS('S'))
position -= Forward() * camSpeed * DELTA;
}
/* Mouse Controlled Move */
if (KEY_DOWN(VK_MBUTTON))
mousePosTemp = MOUSE->GetMousePos();
else if (KEY_PRESS(VK_MBUTTON))
{
Vector3 delta = MOUSE->GetMousePos() - mousePosTemp;
position.x -= delta.x * camSpeed * DELTA;
position.z -= delta.y * camSpeed * DELTA;
mousePosTemp = MOUSE->GetMousePos();
}
/* Mouse Wheel Controlled Move */
if (MOUSE_WHEEL != 0) // Wheel Down (Zoom Out)
position += Forward() * MOUSE_WHEEL * wheelSpeed * DELTA;
else
return;
}
void Camera::CamRotation()
{
/* Keyboard Controlled Rotation */
if (KEY_PRESS(VK_UP))
rotation.x += rotSpeed * DELTA;
else if (KEY_PRESS(VK_DOWN))
rotation.x -= rotSpeed * DELTA;
if (KEY_PRESS(VK_LEFT))
rotation.y -= rotSpeed * DELTA;
else if (KEY_PRESS(VK_RIGHT))
rotation.y += rotSpeed * DELTA;
/* Mouse Controlled Rotation */
if (KEY_DOWN(VK_RBUTTON))
mousePosTemp = MOUSE->GetMousePos();
else if (KEY_PRESS(VK_RBUTTON))
{
Vector3 delta = MOUSE->GetMousePos() - mousePosTemp;
rotation.x -= delta.y * DELTA;
rotation.y += delta.x * DELTA;
mousePosTemp = MOUSE->GetMousePos();
}
}
void Camera::SetView()
{
XMVECTOR eye = XMVectorSet(position.x, position.y, position.z, 0);
Vector3 vFocus = position + Forward();
XMVECTOR focus = XMVectorSet(vFocus.x, vFocus.y, vFocus.z, 0);
XMVECTOR up = XMVectorSet(Up().x, Up().y, Up().z, 0);
Environment::Get()->SetView(eye, focus, up);
}