added introductions of Basic3D

This commit is contained in:
pezy
2014-09-10 09:11:18 +08:00
parent 4789e90a85
commit 741d7d97fe
2 changed files with 18 additions and 16 deletions

View File

@@ -2,3 +2,5 @@ Basic3D
======= =======
3D Graphics Library (Basic Classes) for learning 3D Graphics Library (Basic Classes) for learning
在实际应用中, 构建 3D 场景都会基于比较成熟的图形库, 如[OpenSceneGraph](http://www.openscenegraph.org/)和[Orge](http://www.ogre3d.org/), 或是为了追求效率直接使用 OpenGL 或是 Direct3D. 但无论用哪一种方案, 都毋需担心最底层的数学计算问题. 因为这些库已经或多或少的封装了一些必备数学运算操作. 尤其是关于线性代数方面的运算操作. 但在没有夯实这些数学基础的情况下, 总会在构建场景时遇到一些疑惑, 最典型的就是搞不清楚诸如旋转到底是什么, 怎么转的, 往哪边转之类的问题. 去看底层的源码, 又过分庞杂, 很难快速找到自己感兴趣的点. 这种情况下, 只好去翻书查询基本的数学原理. 但多数的书都偏重于数学公式的推演,

View File

@@ -2,7 +2,7 @@
///@Brief Check the exercise of 5.13 ///@Brief Check the exercise of 5.13
///@Author PEZY ///@Author PEZY
///@Date Sept. 2014 ///@Date Sept. 2014
///@See class B3D::Vec3 ///@See class B3D::Vec3, "3D Math Primer for Graphics and Game Development"
/// ///
#include <iostream> #include <iostream>
@@ -29,53 +29,53 @@ int main()
Vec3 vd(4, -7, 0); Vec3 vd(4, -7, 0);
vd = 3*vd; vd = 3*vd;
cout << "[" << vd.x << "," << vd.y << "," << vd.z << "]" << endl; cout << "[" << vd.x << "," << vd.y << "," << vd.z << "]" << endl;
Vec3 ve(4, 5, 0); Vec3 ve(4, 5, 0);
ve /= 2; ve /= 2;
cout << "[" << ve.x << "," << ve.y << "," << ve.z << "]" << endl; cout << "[" << ve.x << "," << ve.y << "," << ve.z << "]" << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
///> Exercise 5.13.2 ///> Exercise 5.13.2
{ {
Vec3 va(-12, 5, 0); Vec3 va(-12, 5, 0);
Vec3 vb(8, -3, 0.5); Vec3 vb(8, -3, 0.5);
va.normalize(); va.normalize();
vb.normalize(); vb.normalize();
cout << "[" << va.x << "," << va.y << "," << va.z << "]" << endl; cout << "[" << va.x << "," << va.y << "," << va.z << "]" << endl;
cout << "[" << vb.x << "," << vb.y << "," << vb.z << "]" << endl; cout << "[" << vb.x << "," << vb.y << "," << vb.z << "]" << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
///> Exercise 5.13.3 ///> Exercise 5.13.3
{ {
Vec3 va1(3, 10, 7); Vec3 va1(3, 10, 7);
Vec3 va2(8, -7, 4); Vec3 va2(8, -7, 4);
Vec3 va = va1 - va2; Vec3 va = va1 - va2;
cout << "[" << va.x << "," << va.y << "," << va.z << "]" << endl; cout << "[" << va.x << "," << va.y << "," << va.z << "]" << endl;
Vec3 vb1(1, 2, 3); Vec3 vb1(1, 2, 3);
Vec3 vb2(2, 10, -6); Vec3 vb2(2, 10, -6);
Vec3 vb = 3*vb1 - 4*vb2; Vec3 vb = 3*vb1 - 4*vb2;
cout << "[" << vb.x << "," << vb.y << "," << vb.z << "]" << endl; cout << "[" << vb.x << "," << vb.y << "," << vb.z << "]" << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
///> Exercise 5.13.4 ///> Exercise 5.13.4
{ {
Vec3 va1(3, 10, 7); Vec3 va1(3, 10, 7);
Vec3 va2(8, -7, 4); Vec3 va2(8, -7, 4);
cout << B3D::distance(va1, va2) << endl; cout << B3D::distance(va1, va2) << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
///> Exercise 5.13.5 ///> Exercise 5.13.5
{ {
Vec3 vb(-2, 0, 4); Vec3 vb(-2, 0, 4);
cout << 3*vb*(Vec3(8, -2, 1.5) + Vec3(0, 9, 7)) << endl; cout << 3*vb*(Vec3(8, -2, 1.5) + Vec3(0, 9, 7)) << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
///> Exercise 5.13.8 ///> Exercise 5.13.8
{ {
Vec3 v = B3D::crossProduct(Vec3(3, 10, 7), Vec3(8, -7, 4)); Vec3 v = B3D::crossProduct(Vec3(3, 10, 7), Vec3(8, -7, 4));
cout << "[" << v.x << "," << v.y << "," << v.z << "]" << endl; cout << "[" << v.x << "," << v.y << "," << v.z << "]" << endl;
} }
cout << "----------" << endl; cout << "----------" << endl;
return 0; return 0;
} }