1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include <iostream>
namespace kazu
{
//forward declarations
namespace base
{
template<typename T, unsigned int L>
struct vecN;
template<typename T, unsigned int L>
struct vecD;
}
namespace math
{
template<
typename T,
unsigned int L,
typename V = kazu::base::vecD<T, L>
>
struct vecmath;
}
//typedefs
template<typename T>
struct blast
{
typedef base::vecD<T, 2> vec2;
typedef base::vecD<T, 3> vec3;
typedef base::vecD<T, 4> vec4;
};
}
namespace kazu
{
namespace base
{
template<typename T>
struct vecD<T, 2> : kazu::math::vecmath<T, 2>
{
union
{
T _v[2];
struct { T x, y;};
struct { T s, t;};
struct { T i, a;};
};
vecD(const T v[2]): x(v[0]), y(v[1]) {}
vecD(T x_ = (T)0, T y_ = (T)0): x(x_), y(y_) {}
vecD(const vecD& ref): x(ref.x), y(ref.y) {}
};
template<typename T>
struct vecD<T, 3> : kazu::math::vecmath<T, 3>
{
union
{
T _v[3];
struct { T x, y, z;};
struct { T s, t, p;};
struct { T r, g, b;};
};
vecD(const T v[3]): x(v[0]), y(v[1]), z(v[2]) {}
vecD(T x_ = (T)0, T y_ = (T)0, T z_ = (T)0): x(x_), y(y_), z(z_) {}
vecD(const vecD& ref): x(ref.x), y(ref.y), z(ref.z) {}
};
template<typename T>
struct vecD<T, 4> : kazu::math::vecmath<T, 4>
{
union
{
T _v[4];
struct { T x, y, z, w;};
struct { T s, t, p, q;};
struct { T r, g, b, a;};
};
vecD(const T v[4]): x(v[0]), y(v[1]), z(v[2]), w(v[3]) {}
vecD(T x_ = (T)0, T y_ = (T)0, T z_ = (T)0, T w_ = (T)0): x(x_), y(y_), z(z_), w(w_) {}
vecD(const vecD& ref): x(ref.x), y(ref.y), z(ref.z), w(ref.w) {}
};
template<typename T, unsigned int L>
struct vecN :
vecD<T, L>,
kazu::math::vecmath<T, L>
{
};
}
namespace math
{
template<
typename T,
unsigned int L,
typename V
>
struct vecmath
{
typedef T scalar_type;
typedef V vector_type;
enum { vector_length = L };
static V cross(const V& rhv, const V& lhv);
static T dot(const V& rhv, const V& lhv);
static V lerp(const V& rhv, const V& lhv, float t);
};
}
}
using namespace kazu;
template<typename T>
kazu::math::vecmath<T, 2>::vector_type
kazu::math::vecmath<T, 2>::cross( //erreur ici
kazu::math::vecmath<T, 2>::vector_type& rhv,
kazu::math::vecmath<T, 2>::vector_type& lhv)
{
//impl
return kazu::math::vecmath<T, 2>::vector_type(rhv.x* lhv.y, rhv.y * lhv.x);
}
template<typename T>
kazu::math::vecmath<T, 2>::scalar_type
kazu::math::vecmath<T, 2>::dot( //erreur ici
kazu::math::vecmath<T, 2>::vector_type& rhv,
kazu::math::vecmath<T, 2>::vector_type& lhv)
{
//impl
return kazu::math::vecmath<T, 2>::value_type(0);
}
int main (int argc, char * const argv[])
{
//using kazu::blast<float>;
kazu::blast<float>::vec2 a2;
kazu::blast<float>::vec2 b2;
kazu::blast<float>::vec2 c2(kazu::blast<float>::vec2::cross(a2, b2));
float dot2 = kazu::blast<float>::vec2::dot(a2, c2);
kazu::blast<float>::vec3 a3;
kazu::blast<float>::vec3 b3;
kazu::blast<float>::vec3 c3(kazu::blast<float>::vec3::cross(a3, b3));
float dot3 = kazu::blast<float>::vec3::dot(a3, c3);
// insert code here...
std::cout << "Hello, World!\n" << dot2 << dot3;
return 0;
} |
Partager