- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 169字
- 2021-06-30 14:45:50
Scaling vectors
When a vector is scaled, it only changes in magnitude, not direction. As with addition and subtraction, scaling is a component-wise operation. Unlike addition and subtraction, a vector is scaled by a scalar, not another vector.
Visually, a scaled vector points in the same direction as the original vector, but it has a different length. The following figure shows two vectors: (2, 1) and (2, 4). Both vectors share the same direction, but the magnitude of the second vector is longer:

Figure 2.4: Vector scaling
To implement vector scaling, multiply every component of the vector by the given scalar value.
Implement the scale function by overloading the * operator in vec3.cpp. Don't forget to add the function declaration to vec3.h:
vec3 operator*(const vec3 &v, float f) {
return vec3(v.x * f, v.y * f, v.z * f);
}
Negating a vector can be done by scaling the vector by -1. When negating a vector, the vector maintains its magnitude but changes its direction.
- 玩轉Scratch少兒趣味編程
- .NET 4.0面向對象編程漫談:基礎篇
- INSTANT Weka How-to
- Learning Linux Binary Analysis
- Mastering Python High Performance
- Learning Firefox OS Application Development
- Learning Neo4j 3.x(Second Edition)
- Hands-On Functional Programming with TypeScript
- 焊接機器人系統操作、編程與維護
- Android系統原理及開發要點詳解
- Java程序員面試筆試寶典(第2版)
- Domain-Driven Design in PHP
- Java圖像處理:基于OpenCV與JVM
- 平面設計經典案例教程:CorelDRAW X6
- The Statistics and Calculus with Python Workshop