src/libUnuk/Geometry.h
Go to the documentation of this file.

    00001 #ifndef _GEOMETRY_H_
    00002 #define _GEOMETRY_H_
    00003 #include <cmath>
    00004
    00005 struct TexCoord {
    00006   float s, t;
    00007   TexCoord(void):
    00008     s(0.0f),
    00009     t(0.0f) {}
    00010
    00011   TexCoord(float s, float t):
    00012     s(s),
    00013     t(t) {}
    00014 };
    00015
    00016 struct Colour {
    00017   float r, g, b, a;
    00018   Colour(float R, float G, float B, float A):
    00019     r(R),
    00020     g(G),
    00021     b(B),
    00022     a(A) {}
    00023
    00024   Colour(void):
    00025     r(0.0f),
    00026     g(0.0f),
    00027     b(0.0f),
    00028     a(0.0f) {}
    00029 };
    00030
    00031 struct Vector2 {
    00032   float x, y;
    00033   Vector2(float X, float Y):
    00034     x(X),
    00035     y(Y) {}
    00036
    00037   Vector2(void):
    00038     x(0.0f),
    00039     y(0.0f) {}
    00040
    00041   Vector2(const Vector2& v):
    00042     x(v.x),
    00043     y(v.y) {}
    00044
    00045   Vector2 operator*(const float s) const {
    00046     return Vector2(x*s, y*s);
    00047   }
    00048
    00049   Vector2& operator=(const Vector2& v) {
    00050     if(this == &v) {
    00051       return *this;
    00052     }
    00053     x = v.x;
    00054     y = v.y;
    00055
    00056     return *this;
    00057   }
    00058
    00059   Vector2& operator+=(const Vector2& v) {
    00060     this->x += v.x;
    00061     this->y += v.y;
    00062
    00063     return *this;
    00064   }
    00065
    00066   const Vector2 operator-(const Vector2& v) const {
    00067     Vector2 result;
    00068     result.x = x - v.x;
    00069     result.y = y - v.y;
    00070
    00071     return result;
    00072   }
    00073
    00074   float length(void) const {
    00075     return sqrtf(x*x+y*y);
    00076   }
    00077
    00078   void normalize(void) {
    00079     float l = 1.0f / length();
    00080     x *= l;
    00081     y *= l;
    00082   }
    00083 };
    00084
    00085 typedef Vector2 Vertex;
    00086
    00087 inline float degreesToRadians(const float degrees) {
    00088   const float PIOver180 = 3.14159f / 180.0f;
    00089   return degrees * PIOver180;
    00090 }
    00091
    00092 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines