- 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.
- vSphere High Performance Cookbook
- Mastering Entity Framework
- Java編程指南:基礎(chǔ)知識(shí)、類庫(kù)應(yīng)用及案例設(shè)計(jì)
- 匯編語(yǔ)言程序設(shè)計(jì)(第2版)
- Python程序設(shè)計(jì)案例教程
- C語(yǔ)言實(shí)驗(yàn)指導(dǎo)及習(xí)題解析
- KnockoutJS Starter
- 從0到1:Python數(shù)據(jù)分析
- ASP.NET Core 2 Fundamentals
- SQL基礎(chǔ)教程(第2版)
- 零基礎(chǔ)趣學(xué)C語(yǔ)言
- Mastering ArcGIS Enterprise Administration
- Python語(yǔ)言科研繪圖與學(xué)術(shù)圖表繪制從入門到精通
- scikit-learn Cookbook(Second Edition)
- 邊玩邊學(xué)Scratch3.0少兒趣味編程