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

Public Member Functions

 camera_class ()
 Default constructor for camera_class. Initializes the camera position and rotation to zero.
 
 camera_class (const camera_class &)
 
void set_position (float, float, float)
 Sets the position of the camera in 3D space.
 
void set_rotation (float, float, float)
 Sets the rotation of the camera in 3D space.
 
XMFLOAT3 get_position ()
 Gets the current position of the camera.
 
XMFLOAT3 get_rotation ()
 Gets the current rotation of the camera.
 
void render ()
 Updates the camera's view matrix based on its position and rotation. This method recalculates the view matrix to reflect the current camera state.
 
XMMATRIX get_view_matrix (XMMATRIX &view_matrix) const
 Retrieves the current view matrix of the camera.
 
void render_reflection (float)
 Renders the reflection of the scene from the camera's perspective.
 
void get_reflection_view_matrix (XMMATRIX &) const
 Retrieves the reflection view matrix of the camera.
 

Detailed Description

Definition at line 18 of file camera_class.h.

Constructor & Destructor Documentation

◆ camera_class() [1/2]

camera_class::camera_class ( )

Default constructor for camera_class. Initializes the camera position and rotation to zero.

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 ( )

Gets the current position of the camera.

Returns
A 3D vector representing the camera's 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

Retrieves the reflection view matrix of the camera.

Parameters
reflection_view_matrixThe matrix to store the reflection view matrix.

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 ( )

Gets the current rotation of the camera.

Returns
A 3D vector representing the camera's rotation in degrees.

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

Retrieves the current view matrix of the camera.

Returns
The view matrix representing the camera's orientation and position.

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 ( )

Updates the camera's view matrix based on its position and rotation. This method recalculates the view matrix to reflect the current camera state.

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)

Renders the reflection of the scene from the camera's perspective.

Parameters
reflection_plane_yThe y-coordinate of the reflection plane.

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 )

Sets the position of the camera in 3D space.

Parameters
position_xThe x-coordinate of the camera's position.
position_yThe y-coordinate of the camera's position.
position_zThe z-coordinate of the camera's position.

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 )

Sets the rotation of the camera in 3D space.

Parameters
rotation_xThe rotation around the x-axis in degrees.
rotation_yThe rotation around the y-axis in degrees.
rotation_zThe rotation around the z-axis in degrees.

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: