- 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.
- Node.js+Webpack開發實戰
- Android應用程序開發與典型案例
- 測試驅動開發:入門、實戰與進階
- JavaScript語言精髓與編程實踐(第3版)
- Oracle JDeveloper 11gR2 Cookbook
- Apache Kafka Quick Start Guide
- Mastering Android Game Development
- 區塊鏈底層設計Java實戰
- Hands-On GUI Programming with C++ and Qt5
- Qlik Sense? Cookbook
- ASP.NET Web API Security Essentials
- 數據分析與挖掘算法:Python實戰
- 嵌入式Linux C語言程序設計基礎教程
- Learning Shiny
- HTML5 Canvas核心技術:圖形、動畫與游戲開發