graphene
changeset 2:fb032d88839f
moved gmath under src
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 25 Jul 2015 05:08:22 +0300 |
parents | f85a59195206 |
children | d71b4e899e08 |
files | Makefile gmath/vec.h src/gmath/vec.h src/graphene3d.h test/src/main.cc |
diffstat | 5 files changed, 159 insertions(+), 149 deletions(-) [+] |
line diff
1.1 --- a/Makefile Fri Jul 24 01:28:00 2015 +0300 1.2 +++ b/Makefile Sat Jul 25 05:08:22 2015 +0300 1.3 @@ -1,7 +1,7 @@ 1.4 ccsrc = $(wildcard src/*.cc) \ 1.5 - $(wildcard gmath/*.cc) 1.6 + $(wildcard src/gmath/*.cc) 1.7 csrc = $(wildcard src/*.c) \ 1.8 - $(wildcard gmath/*.c) 1.9 + $(wildcard src/gmath/*.c) 1.10 obj = $(ccsrc:.cc=.o) $(csrc:.c=.o) 1.11 dep = $(obj:.o=.d) 1.12
2.1 --- a/gmath/vec.h Fri Jul 24 01:28:00 2015 +0300 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,146 +0,0 @@ 2.4 -#ifndef GMATH_VEC_H_ 2.5 -#define GMATH_VEC_H_ 2.6 - 2.7 -#include <math.h> 2.8 - 2.9 -namespace gmath { 2.10 - 2.11 -class Vec3 { 2.12 -public: 2.13 - float x, y, z; 2.14 - 2.15 - Vec3() : x(0), y(0), z(0) {} 2.16 - Vec3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {} 2.17 - 2.18 - void normalize() 2.19 - { 2.20 - float len = length(*this); 2.21 - if(len != 0.0f) { 2.22 - x /= len; 2.23 - y /= len; 2.24 - z /= len; 2.25 - } 2.26 - } 2.27 -}; 2.28 - 2.29 -inline Vec3 operator +(const Vec3 &a, const Vec3 &b) 2.30 -{ 2.31 - return Vec3(a.x + b.x, a.y + b.y, a.z + b.z); 2.32 -} 2.33 - 2.34 -inline Vec3 operator -(const Vec3 &a, const Vec3 &b) 2.35 -{ 2.36 - return Vec3(a.x - b.x, a.y - b.y, a.z - b.z); 2.37 -} 2.38 - 2.39 -inline Vec3 operator *(const Vec3 &a, const Vec3 &b) 2.40 -{ 2.41 - return Vec3(a.x * b.x, a.y * b.y, a.z * b.z); 2.42 -} 2.43 - 2.44 -inline Vec3 operator /(const Vec3 &a, const Vec3 &b) 2.45 -{ 2.46 - return Vec3(a.x / b.x, a.y / b.y, a.z / b.z); 2.47 -} 2.48 - 2.49 -inline Vec3 operator *(const Vec3 &v, float s) 2.50 -{ 2.51 - return Vec3(v.x * s, v.y * s, v.z * s); 2.52 -} 2.53 - 2.54 -inline Vec3 operator *(float s, const Vec3 &v) 2.55 -{ 2.56 - return Vec3(s * v.x, s * v.y, s * v.z); 2.57 -} 2.58 - 2.59 -inline Vec3 operator /(const Vec3 &v, float s) 2.60 -{ 2.61 - return Vec3(v.x / s, v.y / s, v.z / s); 2.62 -} 2.63 - 2.64 -inline Vec3 operator /(float s, const Vec3 &v) 2.65 -{ 2.66 - return Vec3(s / v.x, s / v.y, s / v.z); 2.67 -} 2.68 - 2.69 -inline Vec3 &operator +=(Vec3 &a, const Vec3 &b) 2.70 -{ 2.71 - a.x += b.x; 2.72 - a.y += b.y; 2.73 - a.z += b.z; 2.74 - return *this; 2.75 -} 2.76 - 2.77 -inline Vec3 &operator -=(Vec3 &a, const Vec3 &b) 2.78 -{ 2.79 - a.x -= b.x; 2.80 - a.y -= b.y; 2.81 - a.z -= b.z; 2.82 - return *this; 2.83 -} 2.84 - 2.85 -inline Vec3 &operator *=(Vec3 &a, const Vec3 &b) 2.86 -{ 2.87 - a.x *= b.x; 2.88 - a.y *= b.y; 2.89 - a.z *= b.z; 2.90 - return *this; 2.91 -} 2.92 - 2.93 -inline Vec3 &operator /=(Vec3 &a, const Vec3 &b) 2.94 -{ 2.95 - a.x /= b.x; 2.96 - a.y /= b.y; 2.97 - a.z /= b.z; 2.98 - return *this; 2.99 -} 2.100 - 2.101 -inline Vec3 &operator *=(Vec3 &v, float s) 2.102 -{ 2.103 - v.x *= s; 2.104 - v.y *= s; 2.105 - v.z *= s; 2.106 - return *this; 2.107 -} 2.108 - 2.109 -inline Vec3 &operator /=(Vec3 &v, float s) 2.110 -{ 2.111 - v.x /= s; 2.112 - v.y /= s; 2.113 - v.z /= s; 2.114 - return *this; 2.115 -} 2.116 - 2.117 -inline float dot(const Vec3 &a, const Vec3 &b) 2.118 -{ 2.119 - return a.x * b.x + a.y * b.y + a.z * b.z; 2.120 -} 2.121 - 2.122 -inline Vec3 cross(const Vec3 &a, const Vec3 &b) 2.123 -{ 2.124 - return Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); 2.125 -} 2.126 - 2.127 -inline float length(const Vec3 &v) 2.128 -{ 2.129 - return (float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z); 2.130 -} 2.131 - 2.132 -inline float length_sq(const Vec3 &v) 2.133 -{ 2.134 - return v.x * v.x + v.y * v.y + v.z * v.z; 2.135 -} 2.136 - 2.137 -inline Vec3 normalize(const Vec3 &v) 2.138 -{ 2.139 - float len = length(v); 2.140 - if(len == 0.0f) { 2.141 - return v; 2.142 - } 2.143 - 2.144 - return Vec3(v.x / len, v.y / len, v.z / len); 2.145 -} 2.146 - 2.147 -} 2.148 - 2.149 -#endif /* GMATH_VEC_H_ */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/gmath/vec.h Sat Jul 25 05:08:22 2015 +0300 3.3 @@ -0,0 +1,149 @@ 3.4 +#ifndef GMATH_VEC_H_ 3.5 +#define GMATH_VEC_H_ 3.6 + 3.7 +#include <math.h> 3.8 + 3.9 +namespace gph { 3.10 + 3.11 +class Vector3 { 3.12 +public: 3.13 + float x, y, z; 3.14 + 3.15 + Vector3() : x(0), y(0), z(0) {} 3.16 + Vector3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {} 3.17 + 3.18 + inline void normalize(); 3.19 +}; 3.20 + 3.21 +inline Vector3 operator +(const Vector3 &a, const Vector3 &b) 3.22 +{ 3.23 + return Vector3(a.x + b.x, a.y + b.y, a.z + b.z); 3.24 +} 3.25 + 3.26 +inline Vector3 operator -(const Vector3 &a, const Vector3 &b) 3.27 +{ 3.28 + return Vector3(a.x - b.x, a.y - b.y, a.z - b.z); 3.29 +} 3.30 + 3.31 +inline Vector3 operator *(const Vector3 &a, const Vector3 &b) 3.32 +{ 3.33 + return Vector3(a.x * b.x, a.y * b.y, a.z * b.z); 3.34 +} 3.35 + 3.36 +inline Vector3 operator /(const Vector3 &a, const Vector3 &b) 3.37 +{ 3.38 + return Vector3(a.x / b.x, a.y / b.y, a.z / b.z); 3.39 +} 3.40 + 3.41 +inline Vector3 operator *(const Vector3 &v, float s) 3.42 +{ 3.43 + return Vector3(v.x * s, v.y * s, v.z * s); 3.44 +} 3.45 + 3.46 +inline Vector3 operator *(float s, const Vector3 &v) 3.47 +{ 3.48 + return Vector3(s * v.x, s * v.y, s * v.z); 3.49 +} 3.50 + 3.51 +inline Vector3 operator /(const Vector3 &v, float s) 3.52 +{ 3.53 + return Vector3(v.x / s, v.y / s, v.z / s); 3.54 +} 3.55 + 3.56 +inline Vector3 operator /(float s, const Vector3 &v) 3.57 +{ 3.58 + return Vector3(s / v.x, s / v.y, s / v.z); 3.59 +} 3.60 + 3.61 +inline Vector3 &operator +=(Vector3 &a, const Vector3 &b) 3.62 +{ 3.63 + a.x += b.x; 3.64 + a.y += b.y; 3.65 + a.z += b.z; 3.66 + return a; 3.67 +} 3.68 + 3.69 +inline Vector3 &operator -=(Vector3 &a, const Vector3 &b) 3.70 +{ 3.71 + a.x -= b.x; 3.72 + a.y -= b.y; 3.73 + a.z -= b.z; 3.74 + return a; 3.75 +} 3.76 + 3.77 +inline Vector3 &operator *=(Vector3 &a, const Vector3 &b) 3.78 +{ 3.79 + a.x *= b.x; 3.80 + a.y *= b.y; 3.81 + a.z *= b.z; 3.82 + return a; 3.83 +} 3.84 + 3.85 +inline Vector3 &operator /=(Vector3 &a, const Vector3 &b) 3.86 +{ 3.87 + a.x /= b.x; 3.88 + a.y /= b.y; 3.89 + a.z /= b.z; 3.90 + return a; 3.91 +} 3.92 + 3.93 +inline Vector3 &operator *=(Vector3 &v, float s) 3.94 +{ 3.95 + v.x *= s; 3.96 + v.y *= s; 3.97 + v.z *= s; 3.98 + return v; 3.99 +} 3.100 + 3.101 +inline Vector3 &operator /=(Vector3 &v, float s) 3.102 +{ 3.103 + v.x /= s; 3.104 + v.y /= s; 3.105 + v.z /= s; 3.106 + return v; 3.107 +} 3.108 + 3.109 +inline float dot(const Vector3 &a, const Vector3 &b) 3.110 +{ 3.111 + return a.x * b.x + a.y * b.y + a.z * b.z; 3.112 +} 3.113 + 3.114 +inline Vector3 cross(const Vector3 &a, const Vector3 &b) 3.115 +{ 3.116 + 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); 3.117 +} 3.118 + 3.119 +inline float length(const Vector3 &v) 3.120 +{ 3.121 + return (float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z); 3.122 +} 3.123 + 3.124 +inline float length_sq(const Vector3 &v) 3.125 +{ 3.126 + return v.x * v.x + v.y * v.y + v.z * v.z; 3.127 +} 3.128 + 3.129 +inline Vector3 normalize(const Vector3 &v) 3.130 +{ 3.131 + float len = length(v); 3.132 + if(len == 0.0f) { 3.133 + return v; 3.134 + } 3.135 + 3.136 + return Vector3(v.x / len, v.y / len, v.z / len); 3.137 +} 3.138 + 3.139 +inline void Vector3::normalize() 3.140 +{ 3.141 + float len = length(*this); 3.142 + if(len != 0.0f) { 3.143 + x /= len; 3.144 + y /= len; 3.145 + z /= len; 3.146 + } 3.147 +} 3.148 + 3.149 + 3.150 +} 3.151 + 3.152 +#endif /* GMATH_VEC_H_ */