Khaotic Engine Reborn
Loading...
Searching...
No Matches
camera_class Class Reference

Public Member Functions

 camera_class (const camera_class &)
 
void set_position (float, float, float)
 
void set_rotation (float, float, float)
 
XMFLOAT3 get_position ()
 
XMFLOAT3 get_rotation ()
 
void render ()
 
XMMATRIX get_view_matrix (XMMATRIX &view_matrix) const
 
void render_reflection (float)
 
void get_reflection_view_matrix (XMMATRIX &) const
 

Detailed Description

Definition at line 18 of file camera_class.h.

Constructor & Destructor Documentation

◆ camera_class() [1/2]

camera_class::camera_class ( )

Definition at line 6 of file camera_class.cpp.

7{
8 position_x_ = 0.0f;
9 position_y_ = 0.0f;
10 position_z_ = 0.0f;
11
12 rotation_x_ = 0.0f;
13 rotation_y_ = 0.0f;
14 rotation_z_ = 0.0f;
15}

◆ camera_class() [2/2]

camera_class::camera_class ( const camera_class & other)

Definition at line 18 of file camera_class.cpp.

19{
20}

◆ ~camera_class()

camera_class::~camera_class ( )

Definition at line 23 of file camera_class.cpp.

24{
25}

Member Function Documentation

◆ get_position()

XMFLOAT3 camera_class::get_position ( )

Definition at line 44 of file camera_class.cpp.

45{
46 return XMFLOAT3(position_x_, position_y_, position_z_);
47}

◆ get_reflection_view_matrix()

void camera_class::get_reflection_view_matrix ( XMMATRIX & reflectionViewMatrix) const

Definition at line 167 of file camera_class.cpp.

168{
169 reflectionViewMatrix = reflection_view_matrix_;
170 return;
171}

◆ get_rotation()

XMFLOAT3 camera_class::get_rotation ( )

Definition at line 50 of file camera_class.cpp.

51{
52 return XMFLOAT3(rotation_x_, rotation_y_, rotation_z_);
53}

◆ get_view_matrix()

XMMATRIX camera_class::get_view_matrix ( XMMATRIX & view_matrix) const

Definition at line 108 of file camera_class.cpp.

109{
110 view_matrix = view_matrix_;
111 return view_matrix;
112}

◆ render()

void camera_class::render ( )

Definition at line 55 of file camera_class.cpp.

56{
57 XMFLOAT3 up, position, lookAt;
58 XMVECTOR upVector, positionVector, lookAtVector;
59 float yaw, pitch, roll;
60 XMMATRIX rotationMatrix;
61
62
63 // Setup the vector that points upwards.
64 up.x = 0.0f;
65 up.y = 1.0f;
66 up.z = 0.0f;
67
68 // Load it into a XMVECTOR structure.
69 upVector = XMLoadFloat3(&up);
70
71 // Setup the position of the camera in the world.
72 position.x = position_x_;
73 position.y = position_y_;
74 position.z = position_z_;
75
76 // Load it into a XMVECTOR structure.
77 positionVector = XMLoadFloat3(&position);
78
79 // Setup where the camera is looking by default.
80 lookAt.x = 0.0f;
81 lookAt.y = 0.0f;
82 lookAt.z = 1.0f;
83
84 // Load it into a XMVECTOR structure.
85 lookAtVector = XMLoadFloat3(&lookAt);
86
87 // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
88 pitch = rotation_x_ * 0.0174532925f;
89 yaw = rotation_y_ * 0.0174532925f;
90 roll = rotation_z_ * 0.0174532925f;
91
92 // Create the rotation matrix from the yaw, pitch, and roll values.
93 rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
94
95 // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
96 lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
97 upVector = XMVector3TransformCoord(upVector, rotationMatrix);
98
99 // Translate the rotated camera position to the location of the viewer.
100 lookAtVector = XMVectorAdd(positionVector, lookAtVector);
101
102 // Finally create the view matrix from the three updated vectors.
103 view_matrix_ = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
104
105 return;
106}

◆ render_reflection()

void camera_class::render_reflection ( float height)

Definition at line 114 of file camera_class.cpp.

115{
116 XMFLOAT3 up, position, lookAt;
117 XMVECTOR upVector, positionVector, lookAtVector;
118 float yaw, pitch, roll;
119 XMMATRIX rotationMatrix;
120
121
122 // Setup the vector that points upwards.
123 up.x = 0.0f;
124 up.y = 1.0f;
125 up.z = 0.0f;
126
127 // Load it into a XMVECTOR structure.
128 upVector = XMLoadFloat3(&up);
129
130 // Setup the position of the camera in the world.
131 position.x = position_x_;
132 position.y = -position_y_ + (height * 2.0f);
133 position.z = position_z_;
134
135 // Load it into a XMVECTOR structure.
136 positionVector = XMLoadFloat3(&position);
137
138 // Setup where the camera is looking by default.
139 lookAt.x = 0.0f;
140 lookAt.y = 0.0f;
141 lookAt.z = 1.0f;
142
143 // Load it into a XMVECTOR structure.
144 lookAtVector = XMLoadFloat3(&lookAt);
145
146 // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
147 pitch = (-1.0f * rotation_x_) * 0.0174532925f; // Invert for reflection
148 yaw = rotation_y_ * 0.0174532925f;
149 roll = rotation_z_ * 0.0174532925f;
150
151 // Create the rotation matrix from the yaw, pitch, and roll values.
152 rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll);
153
154 // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
155 lookAtVector = XMVector3TransformCoord(lookAtVector, rotationMatrix);
156 upVector = XMVector3TransformCoord(upVector, rotationMatrix);
157
158 // Translate the rotated camera position to the location of the viewer.
159 lookAtVector = XMVectorAdd(positionVector, lookAtVector);
160
161 // Finally create the view matrix from the three updated vectors.
162 reflection_view_matrix_ = XMMatrixLookAtLH(positionVector, lookAtVector, upVector);
163
164 return;
165}

◆ set_position()

void camera_class::set_position ( float x,
float y,
float z )

Definition at line 27 of file camera_class.cpp.

28{
29 position_x_ = x;
30 position_y_ = y;
31 position_z_ = z;
32 return;
33}

◆ set_rotation()

void camera_class::set_rotation ( float x,
float y,
float z )

Definition at line 36 of file camera_class.cpp.

37{
38 rotation_x_ = x;
39 rotation_y_ = y;
40 rotation_z_ = z;
41 return;
42}

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