summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/GLT/vector4.cpp
blob: 9f41ecc3bce330b2ec4a5bb0393259a39778352f (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
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
#include "glt_vector4.h"

/*! \file 
	\ingroup Math
*/

#include "glt_string.h"

#include <cassert>
#include <cmath>

#include <iostream>
#include <algorithm>
using namespace std;

Vector4::Vector4()
{
	_vector[0] = _vector[1] = _vector[2] = _vector[3] = 0.0;
}

Vector4::Vector4(const Vector4 &v)
{
	_vector[0] = v._vector[0];
	_vector[1] = v._vector[1];
	_vector[2] = v._vector[2];
	_vector[3] = v._vector[3];
}

Vector4::Vector4(const real x, const real y, const real z,const real w)
{
	_vector[0] = x;
	_vector[1] = y;
	_vector[2] = z;
	_vector[3] = w;
}

Vector4::Vector4(const float *v)
{
	_vector[0] = v[0];
	_vector[1] = v[1];
	_vector[2] = v[2];
	_vector[3] = v[3];
}

Vector4::Vector4(const double *v)
{
	_vector[0] = v[0];
	_vector[1] = v[1];
	_vector[2] = v[2];
	_vector[3] = v[3];
}

Vector4::Vector4(const string &str)
{
	#ifndef NDEBUG
	const int n = 
	#endif
		atoc(str,atof,"+-eE.0123456789",_vector+0,_vector+4);
		
	assert(n==4);
}

const real &
Vector4::operator[](const int i) const
{
	assert(i>=0 && i<4);
	return _vector[i];
}

real &
Vector4::operator[](const int i)
{
	assert(i>=0 && i<4);
	return _vector[i];
}

// Vector4::operator real*  (void)
// {
// 	return (real *) _vector;
// }

      real &Vector4::x()       { return _vector[0]; }
const real &Vector4::x() const { return _vector[0]; }
      real &Vector4::y()       { return _vector[1]; }
const real &Vector4::y() const { return _vector[1]; }
      real &Vector4::z()       { return _vector[2]; }
const real &Vector4::z() const { return _vector[2]; }
      real &Vector4::w()       { return _vector[3]; }
const real &Vector4::w() const { return _vector[3]; }


void
Vector4::glLight(GLenum light, GLenum pname) const
{
#ifdef GLT_FAST_FLOAT
    glLightfv(light, pname, _vector);
#else
    GLfloat params[4];
    params[0] = _vector[0];
    params[1] = _vector[1];
    params[2] = _vector[2];
    params[3] = _vector[3];
    glLightfv(light, pname, params);
#endif
}

////////////////////////// F R I E N D S

/*!
	\brief Output vector to stream
	\ingroup Math
*/

ostream &
operator<<(ostream &os, const Vector4 &x)
{
	os << x[0] << '\t';
	os << x[1] << '\t';
	os << x[2] << '\t';
	os << x[3];

	return os;
}

/*!
	\brief Input vector from stream
	\ingroup Math
*/

istream &
operator>>(istream &is, Vector4 &x)
{
	is >> x[0];
	is >> x[1];
	is >> x[2];
	is >> x[3];

	return is;
}