- 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.
- PWA入門與實踐
- 數據庫原理及應用(Access版)第3版
- Visual Basic 6.0程序設計計算機組裝與維修
- 無代碼編程:用云表搭建企業數字化管理平臺
- Django開發從入門到實踐
- 技術領導力:程序員如何才能帶團隊
- oreilly精品圖書:軟件開發者路線圖叢書(共8冊)
- Hands-On JavaScript High Performance
- Data Analysis with Stata
- Java EE 7 Development with NetBeans 8
- Reactive Programming With Java 9
- Getting Started with NativeScript
- Mastering Data Mining with Python:Find patterns hidden in your data
- UNIX Linux程序設計教程
- Spring MVC+MyBatis開發從入門到項目實踐(超值版)