clray

diff src/vector.inl @ 23:51f115e337c2

separated obj loading and vector class
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 13 Aug 2010 18:20:45 +0100
parents
children 6a30f27fa1e6
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/vector.inl	Fri Aug 13 18:20:45 2010 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +#include <math.h>
     1.5 +
     1.6 +inline float Vector3::length()
     1.7 +{
     1.8 +	return sqrt(x * x + y * y + z * z);
     1.9 +}
    1.10 +
    1.11 +inline float Vector3::lengthsq()
    1.12 +{
    1.13 +	return x * x + y * y + z * z;
    1.14 +}
    1.15 +
    1.16 +inline Vector3 operator +(const Vector3 &a, const Vector3 &b)
    1.17 +{
    1.18 +	return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
    1.19 +}
    1.20 +
    1.21 +inline Vector3 operator -(const Vector3 &a, const Vector3 &b)
    1.22 +{
    1.23 +	return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
    1.24 +}
    1.25 +
    1.26 +inline Vector3 operator *(const Vector3 &a, const Vector3 &b)
    1.27 +{
    1.28 +	return Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
    1.29 +}
    1.30 +
    1.31 +inline Vector3 operator /(const Vector3 &a, const Vector3 &b)
    1.32 +{
    1.33 +	return Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
    1.34 +}
    1.35 +
    1.36 +
    1.37 +inline Vector3 operator -(const Vector3 &vec)
    1.38 +{
    1.39 +	return Vector3(-vec.x, -vec.y, -vec.z);
    1.40 +}
    1.41 +
    1.42 +inline Vector3 operator *(const Vector3 &vec, float s)
    1.43 +{
    1.44 +	return Vector3(vec.x * s, vec.y * s, vec.z * s);
    1.45 +}
    1.46 +
    1.47 +
    1.48 +inline float dot(const Vector3 &a, const Vector3 &b)
    1.49 +{
    1.50 +	return a.x * b.x + a.y * b.y + a.z * b.z;
    1.51 +}
    1.52 +
    1.53 +inline Vector3 cross(const Vector3 &a, const Vector3 &b)
    1.54 +{
    1.55 +	return Vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
    1.56 +}