Norbert's Game Engine v200
Loading...
Searching...
No Matches
eViewport3D Class Reference

#include <Viewport3D.hpp>

Inheritance diagram for eViewport3D:
eBase

Public Member Functions

void Update (bgfx::ViewId viewId, real3 aspect, real3 zNear, real3 zFar)
 
void UpdateMV (bgfx::ViewId viewId, real3 aspect, real3 zNear, real3 zFar)
 
void UpdateOrtho (bgfx::ViewId viewId, eOrthoView ov, real3 zNear, real3 zFar)
 
void MouseRotate (real3 xpos, real3 ypos)
 
void SetTranslation (vec3 translation)
 
vec3 GetTranslation ()
 
void SetFront (vec3 front)
 
vec3 GetFront ()
 
void SetTarget (vec3 target)
 
vec3 GetTarget ()
 
void SetUp (vec3 up)
 
vec3 GetUp ()
 
void SetDirection (eDirection direction)
 
eDirection GetDirection ()
 
void SetZoom (real3 zoom)
 
real3 GetZoom ()
 
void SetMinMaxZoom (vec2 minMaxZoom)
 
vec2 GetMinMaxZoom ()
 
void SetMinMaxPitch (vec2 minMaxPitch)
 
vec2 GetMinMaxPitch ()
 
void SetMinMaxYaw (vec2 minMaxYaw)
 
vec2 GetMinMaxYaw ()
 
void SetSensitivity (real3 sensitivity)
 
real3 GetSensitivity ()
 
void SetView (mat4 view)
 
mat4 GetView ()
 
void SetFirstMouse (bool vl=true)
 
void SetOrbitMode (bool vl)
 
bool GetOrbitMode ()
 
void SetOrbitRadius (real3 radius)
 
real3 GetOrbitRadius ()
 
- Public Member Functions inherited from eBase
template<typename T >
T * Cast (eBase *obj)
 Cast class to base.
 

Detailed Description

Viewport class for 3D

Definition at line 24 of file Viewport3D.hpp.

Constructor & Destructor Documentation

◆ eViewport3D()

eViewport3D::eViewport3D ( )

Definition at line 8 of file Viewport3D.cpp.

9{
10 bFirstMouse = true;
11 bOrbitRot = false;
12 mTranslation = vec3(0.0f);
13 mDirection = { 0.0f, 0.0f, 0.0f };
14 mUp = vec3(0.0f, 1.0f, 0.0f);
15 mZoom = 70.0f;
16 mMinMaxZoom = vec2(10.0f, 180.0f);
17 mMinMaxPitch = vec2(-89.0f, 89.0f);
18 mMinMaxYaw = vec2(-360.0f, 360.0f);
19 mSensitivity = 1.0f;
20 mOrbitRadius = 400.0f;
21 MouseRotate(0.0f, 0.0f);
22}

Member Function Documentation

◆ GetDirection()

eDirection eViewport3D::GetDirection ( )

Definition at line 152 of file Viewport3D.cpp.

153{
154 return mDirection;
155}

◆ GetFront()

vec3 eViewport3D::GetFront ( )

Definition at line 122 of file Viewport3D.cpp.

123{
124 return mFront;
125}

◆ GetMinMaxPitch()

vec2 eViewport3D::GetMinMaxPitch ( )

Definition at line 182 of file Viewport3D.cpp.

183{
184 return mMinMaxPitch;
185}

◆ GetMinMaxYaw()

vec2 eViewport3D::GetMinMaxYaw ( )

Definition at line 192 of file Viewport3D.cpp.

193{
194 return mMinMaxYaw;
195}

◆ GetMinMaxZoom()

vec2 eViewport3D::GetMinMaxZoom ( )

Definition at line 172 of file Viewport3D.cpp.

173{
174 return mMinMaxZoom;
175}

◆ GetOrbitMode()

bool eViewport3D::GetOrbitMode ( )

Definition at line 227 of file Viewport3D.cpp.

228{
229 return bOrbitRot;
230}

◆ GetOrbitRadius()

real3 eViewport3D::GetOrbitRadius ( )

Definition at line 237 of file Viewport3D.cpp.

238{
239 return mOrbitRadius;
240}

◆ GetSensitivity()

real3 eViewport3D::GetSensitivity ( )

Definition at line 202 of file Viewport3D.cpp.

203{
204 return mSensitivity;
205}

◆ GetTarget()

vec3 eViewport3D::GetTarget ( )

Definition at line 132 of file Viewport3D.cpp.

133{
134 return mTarget;
135}

◆ GetTranslation()

vec3 eViewport3D::GetTranslation ( )

Definition at line 112 of file Viewport3D.cpp.

113{
114 return mTranslation;
115}

◆ GetUp()

vec3 eViewport3D::GetUp ( )

Definition at line 142 of file Viewport3D.cpp.

143{
144 return mUp;
145}

◆ GetView()

mat4 eViewport3D::GetView ( )

Definition at line 212 of file Viewport3D.cpp.

213{
214 return mView;
215}

◆ GetZoom()

real3 eViewport3D::GetZoom ( )

Definition at line 162 of file Viewport3D.cpp.

163{
164 return mZoom;
165}

◆ MouseRotate()

void eViewport3D::MouseRotate ( real3 xpos,
real3 ypos )

Definition at line 58 of file Viewport3D.cpp.

59{
60 if (bFirstMouse)
61 {
62 mLastX = xpos;
63 mLastY = ypos;
64 bFirstMouse = false;
65 }
66
67 float xoffset = xpos - mLastX;
68 float yoffset = mLastY - ypos; //Reversed: y ranges bottom to top
69 mLastX = xpos;
70 mLastY = ypos;
71
72 xoffset *= mSensitivity;
73 yoffset *= mSensitivity;
74
75 real3& yaw = mDirection.mYaw;
76 real3& pitch = mDirection.mPitch;
77
78 yaw -= xoffset;
79 pitch -= yoffset;
80 if (pitch >= mMinMaxPitch.y)
81 pitch = mMinMaxPitch.y;
82 if (pitch <= mMinMaxPitch.x)
83 pitch = mMinMaxPitch.x;
84
85 if (yaw >= mMinMaxYaw.y)
86 yaw = 0.0f;
87 if (yaw <= mMinMaxYaw.x)
88 yaw = 0.0f;
89
90 if (bOrbitRot)
91 {
92 mat4 invView = eMath::inverse(mView);
93 mFront = eMath::normalize(vec3(invView[2]));
94 }
95 else
96 {
97 vec3 direction;
98 direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); //Convert to radians first
99 direction.y = sin(glm::radians(pitch));
100 direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
101 mFront = glm::normalize(direction);
102 }
103 mat4 rollMat = glm::rotate(mat4(1.0f), glm::radians(mDirection.mRoll), mFront);
104 mUp = mat3(rollMat) * mUp;
105}

◆ SetDirection()

void eViewport3D::SetDirection ( eDirection direction)

Definition at line 147 of file Viewport3D.cpp.

148{
149 mDirection = direction;
150}

◆ SetFirstMouse()

void eViewport3D::SetFirstMouse ( bool vl = true)

Definition at line 217 of file Viewport3D.cpp.

218{
219 bFirstMouse = vl;
220}

◆ SetFront()

void eViewport3D::SetFront ( vec3 front)

Definition at line 117 of file Viewport3D.cpp.

118{
119 mFront = front;
120}

◆ SetMinMaxPitch()

void eViewport3D::SetMinMaxPitch ( vec2 minMaxPitch)

Definition at line 177 of file Viewport3D.cpp.

178{
179 mMinMaxPitch = minMaxPitch;
180}

◆ SetMinMaxYaw()

void eViewport3D::SetMinMaxYaw ( vec2 minMaxYaw)

Definition at line 187 of file Viewport3D.cpp.

188{
189 mMinMaxYaw = minMaxYaw;
190}

◆ SetMinMaxZoom()

void eViewport3D::SetMinMaxZoom ( vec2 minMaxZoom)

Definition at line 167 of file Viewport3D.cpp.

168{
169 mMinMaxZoom = minMaxZoom;
170}

◆ SetOrbitMode()

void eViewport3D::SetOrbitMode ( bool vl)

Definition at line 222 of file Viewport3D.cpp.

223{
224 bOrbitRot = vl;
225}

◆ SetOrbitRadius()

void eViewport3D::SetOrbitRadius ( real3 radius)

Definition at line 232 of file Viewport3D.cpp.

233{
234 mOrbitRadius = radius;
235}

◆ SetSensitivity()

void eViewport3D::SetSensitivity ( real3 sensitivity)

Definition at line 197 of file Viewport3D.cpp.

198{
199 mSensitivity = sensitivity;
200}

◆ SetTarget()

void eViewport3D::SetTarget ( vec3 target)

Definition at line 127 of file Viewport3D.cpp.

128{
129 mTarget = target;
130}

◆ SetTranslation()

void eViewport3D::SetTranslation ( vec3 translation)

Definition at line 107 of file Viewport3D.cpp.

108{
109 mTranslation = translation;
110}

◆ SetUp()

void eViewport3D::SetUp ( vec3 up)

Definition at line 137 of file Viewport3D.cpp.

138{
139 mUp = up;
140}

◆ SetView()

void eViewport3D::SetView ( mat4 view)

Definition at line 207 of file Viewport3D.cpp.

208{
209 mView = view;
210}

◆ SetZoom()

void eViewport3D::SetZoom ( real3 zoom)

Definition at line 157 of file Viewport3D.cpp.

158{
159 mZoom = zoom;
160}

◆ Update()

void eViewport3D::Update ( bgfx::ViewId viewId,
real3 aspect,
real3 zNear,
real3 zFar )

Definition at line 24 of file Viewport3D.cpp.

25{
26 if (bOrbitRot)
27 {
28 mView = eMath::translate(mat4(1.0f), vec3(0.0f, 0.0f, mOrbitRadius));
29 mView = eMath::rotate(mView, mDirection.mPitch * mSensitivity, vec3(1.0f, 0.0f, 0.0f));
30 mView = eMath::rotate(mView, mDirection.mYaw * mSensitivity, vec3(0.0f, 1.0f, 0.0f));
31 mView = eMath::translate(mView, -mTranslation);
32 }
33 else
34 {
35 mTarget = mTranslation + mFront;
36 mView = eMath::lookAtLH(mTranslation, mTarget, mUp);
37 }
38
39 float proj[16];
40 bx::mtxProj(proj, mZoom, aspect, zNear, zFar, bgfx::getCaps()->homogeneousDepth);
41 bgfx::setViewTransform(viewId, glm::value_ptr(mView), proj);
42}

◆ UpdateMV()

void eViewport3D::UpdateMV ( bgfx::ViewId viewId,
real3 aspect,
real3 zNear,
real3 zFar )

Definition at line 44 of file Viewport3D.cpp.

45{
46 float proj[16];
47 bx::mtxProj(proj, mZoom, aspect, zNear, zFar, bgfx::getCaps()->homogeneousDepth);
48 bgfx::setViewTransform(viewId, glm::value_ptr(mView), proj);
49}

◆ UpdateOrtho()

void eViewport3D::UpdateOrtho ( bgfx::ViewId viewId,
eOrthoView ov,
real3 zNear,
real3 zFar )

Definition at line 51 of file Viewport3D.cpp.

52{
53 mView = glm::lookAtLH(mTranslation, mTarget, mUp);
54 mat4 proj = glm::orthoLH(ov.mLeft, ov.mRight, ov.mBottom, ov.mTop, zNear, zFar);
55 bgfx::setViewTransform(viewId, glm::value_ptr(mView), glm::value_ptr(proj));
56}

The documentation for this class was generated from the following files: