Graphics Reference
In-Depth Information
float Length( );
void Print( char * = “”, FILE * = stderr );
Vec3 Unit( );
Vec3& Unitize( );
Several operators are overloaded so you can use these vectors in expres-
sions, such as
Vec3 a( 1., 2., 3. );
Vec3 b( 4., 5., 6. );
Vec3 e = a + b;
Another class, Point3 , is sub-classed from Vec3 . A Point3 variable can
use all the same methods a Vec3 class variable can, but by using the Point3
name you are making it clear that the three-element array is meant to be a
point (with positions) instead of a vector (with directions):
Point3 Q( 1., 2., 0. );
Point3 R( 5., 3., 0. );
Vec3 S = R - Q;
Some of these methods return a reference to the result so that they can be
chained together, like this:
float i = c.Dot( a.Cross(b) );
Vec3 normal = ( R - Q ).Cross( S - Q );
Here are some examples of using the Vec3 class.
#include “vec3.h”
Vec3 b( 1., 2., 3. );
Vec3 c( 5., 6., 7. );
Vec3 d( c );
Vec3 a = c;
a.Unitize( );
a.Print( “a =” );
b.Print( “b =” );
c.Print( “c =” );
d.Print( “d =” );
a = Vec3( 2., -5., 8. );
a.Print( “a =” );
Search WWH ::




Custom Search