- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 210字
- 2021-06-30 14:45:51
Vector reflection
Vector reflection can mean one of two things: a mirror-like reflection or a bounce-like reflection. The following figure shows the different types of reflections:

Figure 2.8: A comparison of the mirror and bounce reflections
The bounce reflection is more useful and intuitive than the mirror reflection. To make a bounce projection work, project vector A onto vector B. This will yield a vector that points in the opposite direction to the reflection. Negate this projection and subtract it twice from vector A. The following figure demonstrates this:

Figure 2.9: Visualizing a bounce reflection
Implement the reflect function in vec3.cpp. Don't forget to add the function declaration to vec3.h:
vec3 reflect(const vec3 &a, const vec3 &b) {
float magBSq = len(b);
if (magBSq < VEC3_EPSILON) {
return vec3();
}
float scale = dot(a, b) / magBSq;
vec3 proj2 = b * (scale * 2);
return a - proj2;
}
Vector reflection is useful for physics and AI. We won't need to use reflection for animation, but it's good to have the function implemented in case it is needed.
- HornetQ Messaging Developer’s Guide
- JavaScript前端開發(fā)模塊化教程
- Android和PHP開發(fā)最佳實(shí)踐(第2版)
- CMDB分步構(gòu)建指南
- Unity Virtual Reality Projects
- Python編程與幾何圖形
- 軟件架構(gòu):Python語言實(shí)現(xiàn)
- Clojure Reactive Programming
- RabbitMQ Cookbook
- C#應(yīng)用程序設(shè)計(jì)教程
- 大數(shù)據(jù)分析與應(yīng)用實(shí)戰(zhàn):統(tǒng)計(jì)機(jī)器學(xué)習(xí)之?dāng)?shù)據(jù)導(dǎo)向編程
- Deep Learning with R Cookbook
- Hands-On Robotics Programming with C++
- Python 3快速入門與實(shí)戰(zhàn)
- C語言程序設(shè)計(jì)教程