Skip to content

Commit ea39e65

Browse files
committed
address comments
1 parent d834c39 commit ea39e65

File tree

3 files changed

+140
-35
lines changed

3 files changed

+140
-35
lines changed

en/Building_a_Simple_Engine/Camera_Transformations/02_math_foundations.adoc

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
::pp: {plus}{plus}
1+
:pp: {plus}{plus}
22

33
= Camera & Transformations: Mathematical Foundations
44
:doctype: book
55
:sectnums:
66
:sectnumlevels: 4
7-
:toc: left
87
:icons: font
98
:source-highlighter: highlightjs
109
:source-language: c++
@@ -97,34 +96,6 @@ glm::vec3 crossProduct = glm::cross(a, b); // (-3.0, 6.0, -3.0)
9796
glm::vec3 normalized = glm::normalize(a); // (0.267, 0.535, 0.802)
9897
----
9998

100-
==== The Right-Hand Rule
101-
102-
The right-hand rule is a convention used in 3D graphics and mathematics to determine the orientation of coordinate systems and the direction of cross products.
103-
104-
* *For Cross Products*: When calculating A × B:
105-
1. Point your right hand's index finger in the direction of vector A
106-
2. Point your middle finger in the direction of vector B (perpendicular to A)
107-
3. Your thumb now points in the direction of the resulting cross product
108-
109-
* *For Coordinate Systems*: In a right-handed coordinate system:
110-
1. Point your right hand's index finger along the positive X-axis
111-
2. Point your middle finger along the positive Y-axis
112-
3. Your thumb points along the positive Z-axis
113-
114-
[source,cpp]
115-
----
116-
// The cross product direction follows the right-hand rule
117-
glm::vec3 xAxis(1.0f, 0.0f, 0.0f); // Point right (positive X)
118-
glm::vec3 yAxis(0.0f, 1.0f, 0.0f); // Point up (positive Y)
119-
120-
// Cross product gives the Z axis in a right-handed system
121-
glm::vec3 zAxis = glm::cross(xAxis, yAxis); // Points forward (positive Z)
122-
// zAxis will be (0.0f, 0.0f, 1.0f)
123-
124-
// If we reverse the order, we get the opposite direction
125-
glm::vec3 negativeZ = glm::cross(yAxis, xAxis); // Points backward (negative Z)
126-
// negativeZ will be (0.0f, 0.0f, -1.0f)
127-
----
12899

129100
=== Matrices and Transformations
130101

@@ -177,9 +148,31 @@ glm::mat4 modelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
177148

178149
==== Matrix Order Matters
179150

180-
The order of matrix multiplication is crucial:
181-
* In `A * B`, the transformation B is applied first, then A
182-
* For our camera: `projectionMatrix * viewMatrix * modelMatrix * vertex`
151+
The order of matrix multiplication is crucial because transformations are applied from right to left. Getting the order wrong can completely change your object's final position and orientation.
152+
153+
Consider this practical example: if you want to rotate a cube around its own center and then move it to a new position, you must apply the transformations in the correct order:
154+
155+
[source,cpp]
156+
----
157+
// CORRECT: Scale first, then rotate, then translate
158+
// This rotates the cube around its own center, then moves it
159+
glm::mat4 modelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
160+
161+
// WRONG: Translate first, then rotate
162+
// This would move the cube away from origin, then rotate it around the world origin
163+
// The cube would orbit around the world center instead of rotating in place!
164+
glm::mat4 wrongMatrix = rotationMatrix * translationMatrix * scaleMatrix;
165+
----
166+
167+
For our camera pipeline: `projectionMatrix * viewMatrix * modelMatrix * vertex`
168+
Each transformation prepares the data for the next stage, and changing this order would break the rendering pipeline.
169+
170+
==== Visual Example: Why Matrix Order Matters
171+
172+
The following diagram illustrates the difference between correct and incorrect matrix multiplication order when transforming a cube:
173+
174+
.Matrix Transformation Order Comparison
175+
image::../../../images/matrix-order-comparison.svg[Matrix Order Comparison showing correct T×R×S vs incorrect R×T×S transformation sequences]
183176

184177
==== Row-Major vs Column-Major Representation
185178

en/Building_a_Simple_Engine/GUI/03_input_handling.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ void processInput(float deltaTime) {
156156
}
157157
----
158158

159-
=== Platform-Specific Input Implementation
159+
=== Implementing Platform Adapters for Input
160160

161-
Our platform-agnostic input system needs specific implementations for each windowing library to capture input events. Here's an example implementation using GLFW, a popular windowing library:
161+
While our input system design is platform-agnostic, we still need platform-specific adapters to bridge between our unified interface and each windowing library's native input events. Here's an example implementation using GLFW, a popular windowing library:
162162

163163
==== Example: GLFW Implementation
164164

images/matrix-order-comparison.svg

Lines changed: 112 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)