- 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.
- JavaScript從入門(mén)到精通(微視頻精編版)
- Spring 5.0 By Example
- Learn to Create WordPress Themes by Building 5 Projects
- C#完全自學(xué)教程
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及MySQL應(yīng)用教程
- Getting Started with PowerShell
- C#程序設(shè)計(jì)(慕課版)
- Java編程指南:基礎(chǔ)知識(shí)、類庫(kù)應(yīng)用及案例設(shè)計(jì)
- Visual C++串口通信技術(shù)詳解(第2版)
- Koa開(kāi)發(fā):入門(mén)、進(jìn)階與實(shí)戰(zhàn)
- Java Web應(yīng)用開(kāi)發(fā)技術(shù)與案例教程(第2版)
- Kotlin Standard Library Cookbook
- Python開(kāi)發(fā)基礎(chǔ)
- Scala Functional Programming Patterns
- Modernizing Legacy Applications in PHP