summaryrefslogtreecommitdiffstats
path: root/debian/fireflies/fireflies-2.08/libgfx/tests/t-vec.cxx
blob: 434c97d311b9602049dffd04809ceca6b2141a55 (plain)
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
/************************************************************************

  Test various vector math facilities provided by libgfx.

  by Michael Garland, 2000.
  
  $Id: t-vec.cxx 426 2004-09-27 04:34:55Z garland $

 ************************************************************************/

#include <gfx/gfx.h>

#include <gfx/vec2.h>
#include <gfx/vec3.h>
#include <gfx/vec4.h>
#include <gfx/intvec.h>

using namespace std;

void test_intvec()
{
    cout << "Testing IntVec types" << endl;

    class Normal : public IntVec<short, SHRT_MAX, 3>
    {
    public:
	Normal(const Vec3& v) { (*this) = v; }

	Vec3 unpack() const { return Vec3((*this)[0],(*this)[1],(*this)[2]); }
	void pack(const Vec3& v)
	    { set(0, v[0]); set(1, v[1]); set(2, v[2]); }

	Normal& operator=(const Vec3& v) { pack(v); return *this; }
    };

    Normal n = Vec3(1.0, 0.4, -1.0);
    cout << "  n = " << n.unpack() << endl;

    n.set(0, -1.0);  n.set(1, 0.4);  n.set(2, 1);
    cout << "  n = " << n[0] << " " << n[1] << " " << n[2] << endl;


    typedef IntVec3<unsigned char, UCHAR_MAX> byteColor;
    byteColor rgb(0.8, 0.2, 0.2);
    cout << "  rgb = " << rgb.unpack() << endl;
}

template<class Vec>
void test_vector()
{
    Vec u = 0;
    Vec v = 0;

    u[0] = 1;
    v[1] = 1;

    Vec x = u * 2.0;
    Vec y = v / 2.0;

    cout << "  x = " << x << endl;
    cout << "  y = " << y << endl;
}

int main()
{
    cout << "+ Testing class Vec2" << endl;
    test_vector<Vec2>();

    cout << "+ Testing class Vec3" << endl;
    test_vector<Vec3>();

    cout << "+ Testing class Vec4" << endl;
    test_vector<Vec4>();

    test_intvec();

    return 0;
}