- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 163字
- 2021-06-30 14:45:50
Vector subtraction
As with adding vectors, subtracting vectors is also a component-wise operation. You can think of subtracting vectors as adding the negative of the second vector to the first vector. When visualized as an arrow, subtraction points from the tip of the second vector to the tip of the first one.
To visually subtract vectors, place both vectors so they share the same origin. Draw a vector from the tip of the second arrow to the tip of the first one. The resulting arrow is the subtraction result vector:

Figure 2.3: Vector subtraction
To implement vector subtraction, subtract like components. Implement the subtraction function by overloading the - operator in vec3.cpp. Don't forget to add the function declaration 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);
}
The steps and logic are very similar to vector addition. It might help to think of vector subtraction as adding a negative vector.
- Oracle從入門到精通(第3版)
- OpenCV實例精解
- Visual FoxPro程序設計教程
- 軟件工程
- 小學生C++創意編程(視頻教學版)
- Learning Three.js:The JavaScript 3D Library for WebGL
- Android Wear Projects
- CoffeeScript Application Development Cookbook
- Django 3.0應用開發詳解
- UML2面向對象分析與設計(第2版)
- Hands-On Robotics Programming with C++
- 百萬在線:大型游戲服務端開發
- Learning Swift
- 深入理解MySQL主從原理
- SQL Server 2012數據庫管理與開發(慕課版)