- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 190字
- 2021-06-30 14:45:50
Vector addition
Adding two vectors together yields a third vector, which has the combined displacement of both input vectors. Vector addition is a component-wise operation; to perform it, you need to add like components.
To visualize the addition of two vectors, draw the base of the second vector at the tip of the first vector. Next, draw an arrow from the base of the first vector to the tip of the second vector. This arrow represents the vector that is the result of the addition:

Figure 2.2: Vector addition
To implement vector addition in code, add like components of the input vectors. Create a new file, vec3.cpp. This is where you will define functions related to the vec3 struct. Don't forget to include vec3.h. Overload the + operator to perform vector addition. Don't forget to add the function signature to vec3.h:
vec3 operator+(const vec3 &l, const vec3 &r) {
return vec3(l.x + r.x, l.y + r.y, l.z + r.z);
}
When thinking about vector addition, remember that a vector represents a displacement. When adding two vectors, the result is the combined displacement of both input vectors.
- Visual Basic .NET程序設計(第3版)
- Learning Cython Programming
- Python入門很簡單
- Visual Basic程序設計(第3版):學習指導與練習
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- Unity 3D/2D移動開發實戰教程
- Python數據可視化之美:專業圖表繪制指南(全彩)
- Go語言入門經典
- Web前端開發最佳實踐
- Visual Basic程序設計基礎
- 少兒編程輕松學(全2冊)
- SQL Server 2014 Development Essentials
- 計算機程序的構造和解釋(JavaScript版)
- R統計應用開發實戰
- Modular Programming with PHP 7