Arbitrary starting camera position
This commit is contained in:
parent
679589554e
commit
fb891fa274
|
@ -16,7 +16,7 @@ DockId=0x00000001,0
|
||||||
|
|
||||||
[Window][Object Controls]
|
[Window][Object Controls]
|
||||||
Pos=1532,124
|
Pos=1532,124
|
||||||
Size=388,956
|
Size=388,937
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000004,0
|
DockId=0x00000004,0
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Collapsed=0
|
||||||
|
|
||||||
[Window][DockSpace Demo]
|
[Window][DockSpace Demo]
|
||||||
Pos=0,0
|
Pos=0,0
|
||||||
Size=1920,1080
|
Size=1920,1061
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Dear ImGui Demo]
|
[Window][Dear ImGui Demo]
|
||||||
|
@ -35,7 +35,7 @@ Size=1553,966
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=0,19 Size=1920,1061 Split=Y
|
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=0,19 Size=1920,1042 Split=Y
|
||||||
DockNode ID=0x00000001 Parent=0x3BC79352 SizeRef=1904,103 Selected=0x8CCBC963
|
DockNode ID=0x00000001 Parent=0x3BC79352 SizeRef=1904,103 Selected=0x8CCBC963
|
||||||
DockNode ID=0x00000002 Parent=0x3BC79352 SizeRef=1904,956 Split=X
|
DockNode ID=0x00000002 Parent=0x3BC79352 SizeRef=1904,956 Split=X
|
||||||
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=1530,956 CentralNode=1
|
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=1530,956 CentralNode=1
|
||||||
|
|
|
@ -5,10 +5,13 @@
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
glm::vec3 m_position = { 0.f, 0.f, 1.f };
|
glm::vec3 m_position = { -1.f, 1.f, 1.f };
|
||||||
glm::vec3 m_front = { 0.f, 0.f, 0.f };
|
glm::vec3 m_front = { 0.f, 0.f, 0.f };
|
||||||
glm::vec3 m_up = { 0.f, 1.f, 0.f };
|
glm::vec3 m_right = glm::normalize(glm::cross(m_position - m_front, glm::vec3(0.f, 1.f, 0.f)));
|
||||||
glm::vec3 m_right = { 1.f, 0.f, 0.f };
|
glm::vec3 m_up = glm::normalize(glm::cross(m_position - m_front, m_position - m_right));
|
||||||
|
|
||||||
|
float m_yaw = -44.977; // atan2(m_position.x, m_position.z) assuming m_position = {-1, 1, 1}
|
||||||
|
float m_pitch = 35.264; // asin(m_position.y) assuming m_position = {-1, 1, 1}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Since all variables are dependent on each other I've decided to
|
// Since all variables are dependent on each other I've decided to
|
||||||
|
@ -17,12 +20,19 @@ public:
|
||||||
// glm::vec3& front() { return m_front; }
|
// glm::vec3& front() { return m_front; }
|
||||||
// glm::vec3& up() { return m_up; }
|
// glm::vec3& up() { return m_up; }
|
||||||
// glm::vec3& right() { return m_right; }
|
// glm::vec3& right() { return m_right; }
|
||||||
|
//
|
||||||
const glm::vec3& position() const { return m_position; }
|
// float& yaw() { return m_yaw; }
|
||||||
const glm::vec3& front() const { return m_front; }
|
// float& pitch() { return m_pitch; }
|
||||||
const glm::vec3& up() const { return m_up; }
|
|
||||||
|
const glm::vec3& position() const { return m_position; }
|
||||||
|
const glm::vec3& front() const { return m_front; }
|
||||||
|
const glm::vec3& up() const { return m_up; }
|
||||||
const glm::vec3& right() const { return m_right; }
|
const glm::vec3& right() const { return m_right; }
|
||||||
|
|
||||||
|
const float& yaw() const { return m_yaw; }
|
||||||
|
const float pitch() const { return m_pitch; }
|
||||||
|
|
||||||
|
|
||||||
void pan(float dist_x, float dist_y);
|
void pan(float dist_x, float dist_y);
|
||||||
void orbit(float yaw, float pitch);
|
void orbit(float yaw, float pitch);
|
||||||
void zoom(float dist);
|
void zoom(float dist);
|
||||||
|
|
|
@ -48,8 +48,8 @@ namespace scene
|
||||||
|
|
||||||
float angle = glm::pi<float>() / 2.0f;
|
float angle = glm::pi<float>() / 2.0f;
|
||||||
|
|
||||||
float yaw = -90.f;
|
float yaw = camera.yaw(); // Initial yaw for position (-1, 1, 1)
|
||||||
float pitch = 0.f;
|
float pitch = camera.pitch(); // Initial pitch for position (-1, 1, 1)
|
||||||
|
|
||||||
std::vector<Primitive> primitiveData;
|
std::vector<Primitive> primitiveData;
|
||||||
std::vector<Light> lightData;
|
std::vector<Light> lightData;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
|
|
||||||
void Camera::pan(float dist_x, float dist_y) {
|
void Camera::pan(float dist_x, float dist_y)
|
||||||
|
{
|
||||||
m_front += m_right * dist_x;
|
m_front += m_right * dist_x;
|
||||||
m_position += m_right * dist_x;
|
m_position += m_right * dist_x;
|
||||||
|
|
||||||
|
@ -8,7 +9,11 @@ void Camera::pan(float dist_x, float dist_y) {
|
||||||
m_position += m_up * dist_y;
|
m_position += m_up * dist_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::orbit(float yaw, float pitch) {
|
void Camera::orbit(float yaw, float pitch)
|
||||||
|
{
|
||||||
|
m_yaw = yaw;
|
||||||
|
m_pitch = pitch;
|
||||||
|
|
||||||
glm::vec3 direction;
|
glm::vec3 direction;
|
||||||
|
|
||||||
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
|
||||||
|
@ -23,7 +28,8 @@ void Camera::orbit(float yaw, float pitch) {
|
||||||
m_up = glm::cross(m_right, glm::normalize(m_front - m_position));
|
m_up = glm::cross(m_right, glm::normalize(m_front - m_position));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::zoom(float dist) {
|
void Camera::zoom(float dist)
|
||||||
|
{
|
||||||
m_position += (m_position - m_front) * dist;
|
m_position += (m_position - m_front) * dist;
|
||||||
if (glm::length(m_position - m_front) > 100.f) {
|
if (glm::length(m_position - m_front) > 100.f) {
|
||||||
m_position = glm::normalize(m_position) * 100.f + m_front;
|
m_position = glm::normalize(m_position) * 100.f + m_front;
|
||||||
|
|
Loading…
Reference in New Issue