# source:trunk/src/matrix.h@235Tweet

Last change on this file since 235 was 235, checked in by sam, 11 years ago

Allow to access Int2, Float2 etc. members using [].

• Property svn:keywords set to Id
File size: 1.1 KB
Line
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The Matrix classes
13// ------------------
14//
15
16#if !defined __DH_MATRIX_H__
17#define __DH_MATRIX_H__
18
19template <typename T> struct Vector2
20{
21    Vector2() { x = y = 0; }
22    Vector2(T _x, T _y) { x = _x; y = _y; }
23    T& operator[](int n) { return *(&x + n); }
24
25    union { T x; T a; T i; };
26    union { T y; T b; T j; };
27};
28
29typedef Vector2<float> Float2;
30typedef Vector2<int> Int2;
31
32template <typename T> struct Vector3
33{
34    Vector3() { x = y = z = 0; }
35    Vector3(T _x, T _y, T _z) { x = _x; y = _y; z = _z; }
36    T& operator[](int n) { return *(&x + n); }
37
38    union { T x; T a; T i; };
39    union { T y; T b; T j; };
40    union { T z; T c; T k; };
41};
42
43typedef Vector3<float> Float3;
44typedef Vector3<int> Int3;
45
46#endif // __DH_MATRIX_H__
47
Note: See TracBrowser for help on using the repository browser.