# HG changeset patch # User John Tsiombikas # Date 1437790102 -10800 # Node ID fb032d88839f6586e112f525910cbbc244c066d8 # Parent f85a5919520684d747692b7d508d1e1909de4e45 moved gmath under src diff -r f85a59195206 -r fb032d88839f Makefile --- a/Makefile Fri Jul 24 01:28:00 2015 +0300 +++ b/Makefile Sat Jul 25 05:08:22 2015 +0300 @@ -1,7 +1,7 @@ ccsrc = $(wildcard src/*.cc) \ - $(wildcard gmath/*.cc) + $(wildcard src/gmath/*.cc) csrc = $(wildcard src/*.c) \ - $(wildcard gmath/*.c) + $(wildcard src/gmath/*.c) obj = $(ccsrc:.cc=.o) $(csrc:.c=.o) dep = $(obj:.o=.d) diff -r f85a59195206 -r fb032d88839f gmath/vec.h --- a/gmath/vec.h Fri Jul 24 01:28:00 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -#ifndef GMATH_VEC_H_ -#define GMATH_VEC_H_ - -#include - -namespace gmath { - -class Vec3 { -public: - float x, y, z; - - Vec3() : x(0), y(0), z(0) {} - Vec3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {} - - void normalize() - { - float len = length(*this); - if(len != 0.0f) { - x /= len; - y /= len; - z /= len; - } - } -}; - -inline Vec3 operator +(const Vec3 &a, const Vec3 &b) -{ - return Vec3(a.x + b.x, a.y + b.y, a.z + b.z); -} - -inline Vec3 operator -(const Vec3 &a, const Vec3 &b) -{ - return Vec3(a.x - b.x, a.y - b.y, a.z - b.z); -} - -inline Vec3 operator *(const Vec3 &a, const Vec3 &b) -{ - return Vec3(a.x * b.x, a.y * b.y, a.z * b.z); -} - -inline Vec3 operator /(const Vec3 &a, const Vec3 &b) -{ - return Vec3(a.x / b.x, a.y / b.y, a.z / b.z); -} - -inline Vec3 operator *(const Vec3 &v, float s) -{ - return Vec3(v.x * s, v.y * s, v.z * s); -} - -inline Vec3 operator *(float s, const Vec3 &v) -{ - return Vec3(s * v.x, s * v.y, s * v.z); -} - -inline Vec3 operator /(const Vec3 &v, float s) -{ - return Vec3(v.x / s, v.y / s, v.z / s); -} - -inline Vec3 operator /(float s, const Vec3 &v) -{ - return Vec3(s / v.x, s / v.y, s / v.z); -} - -inline Vec3 &operator +=(Vec3 &a, const Vec3 &b) -{ - a.x += b.x; - a.y += b.y; - a.z += b.z; - return *this; -} - -inline Vec3 &operator -=(Vec3 &a, const Vec3 &b) -{ - a.x -= b.x; - a.y -= b.y; - a.z -= b.z; - return *this; -} - -inline Vec3 &operator *=(Vec3 &a, const Vec3 &b) -{ - a.x *= b.x; - a.y *= b.y; - a.z *= b.z; - return *this; -} - -inline Vec3 &operator /=(Vec3 &a, const Vec3 &b) -{ - a.x /= b.x; - a.y /= b.y; - a.z /= b.z; - return *this; -} - -inline Vec3 &operator *=(Vec3 &v, float s) -{ - v.x *= s; - v.y *= s; - v.z *= s; - return *this; -} - -inline Vec3 &operator /=(Vec3 &v, float s) -{ - v.x /= s; - v.y /= s; - v.z /= s; - return *this; -} - -inline float dot(const Vec3 &a, const Vec3 &b) -{ - return a.x * b.x + a.y * b.y + a.z * b.z; -} - -inline Vec3 cross(const Vec3 &a, const Vec3 &b) -{ - 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); -} - -inline float length(const Vec3 &v) -{ - return (float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z); -} - -inline float length_sq(const Vec3 &v) -{ - return v.x * v.x + v.y * v.y + v.z * v.z; -} - -inline Vec3 normalize(const Vec3 &v) -{ - float len = length(v); - if(len == 0.0f) { - return v; - } - - return Vec3(v.x / len, v.y / len, v.z / len); -} - -} - -#endif /* GMATH_VEC_H_ */ diff -r f85a59195206 -r fb032d88839f src/gmath/vec.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gmath/vec.h Sat Jul 25 05:08:22 2015 +0300 @@ -0,0 +1,149 @@ +#ifndef GMATH_VEC_H_ +#define GMATH_VEC_H_ + +#include + +namespace gph { + +class Vector3 { +public: + float x, y, z; + + Vector3() : x(0), y(0), z(0) {} + Vector3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {} + + inline void normalize(); +}; + +inline Vector3 operator +(const Vector3 &a, const Vector3 &b) +{ + return Vector3(a.x + b.x, a.y + b.y, a.z + b.z); +} + +inline Vector3 operator -(const Vector3 &a, const Vector3 &b) +{ + return Vector3(a.x - b.x, a.y - b.y, a.z - b.z); +} + +inline Vector3 operator *(const Vector3 &a, const Vector3 &b) +{ + return Vector3(a.x * b.x, a.y * b.y, a.z * b.z); +} + +inline Vector3 operator /(const Vector3 &a, const Vector3 &b) +{ + return Vector3(a.x / b.x, a.y / b.y, a.z / b.z); +} + +inline Vector3 operator *(const Vector3 &v, float s) +{ + return Vector3(v.x * s, v.y * s, v.z * s); +} + +inline Vector3 operator *(float s, const Vector3 &v) +{ + return Vector3(s * v.x, s * v.y, s * v.z); +} + +inline Vector3 operator /(const Vector3 &v, float s) +{ + return Vector3(v.x / s, v.y / s, v.z / s); +} + +inline Vector3 operator /(float s, const Vector3 &v) +{ + return Vector3(s / v.x, s / v.y, s / v.z); +} + +inline Vector3 &operator +=(Vector3 &a, const Vector3 &b) +{ + a.x += b.x; + a.y += b.y; + a.z += b.z; + return a; +} + +inline Vector3 &operator -=(Vector3 &a, const Vector3 &b) +{ + a.x -= b.x; + a.y -= b.y; + a.z -= b.z; + return a; +} + +inline Vector3 &operator *=(Vector3 &a, const Vector3 &b) +{ + a.x *= b.x; + a.y *= b.y; + a.z *= b.z; + return a; +} + +inline Vector3 &operator /=(Vector3 &a, const Vector3 &b) +{ + a.x /= b.x; + a.y /= b.y; + a.z /= b.z; + return a; +} + +inline Vector3 &operator *=(Vector3 &v, float s) +{ + v.x *= s; + v.y *= s; + v.z *= s; + return v; +} + +inline Vector3 &operator /=(Vector3 &v, float s) +{ + v.x /= s; + v.y /= s; + v.z /= s; + return v; +} + +inline float dot(const Vector3 &a, const Vector3 &b) +{ + return a.x * b.x + a.y * b.y + a.z * b.z; +} + +inline Vector3 cross(const Vector3 &a, const Vector3 &b) +{ + 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); +} + +inline float length(const Vector3 &v) +{ + return (float)sqrt(v.x * v.x + v.y * v.y + v.z * v.z); +} + +inline float length_sq(const Vector3 &v) +{ + return v.x * v.x + v.y * v.y + v.z * v.z; +} + +inline Vector3 normalize(const Vector3 &v) +{ + float len = length(v); + if(len == 0.0f) { + return v; + } + + return Vector3(v.x / len, v.y / len, v.z / len); +} + +inline void Vector3::normalize() +{ + float len = length(*this); + if(len != 0.0f) { + x /= len; + y /= len; + z /= len; + } +} + + +} + +#endif /* GMATH_VEC_H_ */ diff -r f85a59195206 -r fb032d88839f src/graphene3d.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/graphene3d.h Sat Jul 25 05:08:22 2015 +0300 @@ -0,0 +1,7 @@ +#ifndef GRAPHENE3D_H_ +#define GRAPHENE3D_H_ + +#include "opengl.h" +#include "gmath/vec.h" + +#endif // GRAPHENE3D_H_ diff -r f85a59195206 -r fb032d88839f test/src/main.cc --- a/test/src/main.cc Fri Jul 24 01:28:00 2015 +0300 +++ b/test/src/main.cc Sat Jul 25 05:08:22 2015 +0300 @@ -1,6 +1,6 @@ #include #include -#include "opengl.h" +#include "graphene3d.h" #include void display();