595 |
jab |
1 |
/* ----------------------------------------------------------------------- *
|
|
|
2 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors and DTU Informatics
|
|
|
4 |
* For license and list of authors, see ../../doc/intro.pdf
|
|
|
5 |
* ----------------------------------------------------------------------- */
|
|
|
6 |
|
|
|
7 |
/** @file Vec4f.h
|
|
|
8 |
* @brief 4D float vector class.
|
|
|
9 |
*/
|
|
|
10 |
|
2 |
bj |
11 |
#ifndef __CGLA_VEC4F_H__
|
|
|
12 |
#define __CGLA_VEC4F_H__
|
|
|
13 |
|
|
|
14 |
#include "Vec3f.h"
|
|
|
15 |
#include "ArithVec4Float.h"
|
|
|
16 |
|
|
|
17 |
namespace CGLA {
|
|
|
18 |
|
89 |
jab |
19 |
/** \brief A four dimensional floating point vector.
|
|
|
20 |
|
2 |
bj |
21 |
This class is also used (via typedef) for
|
|
|
22 |
homogeneous vectors.
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
class Vec4f: public ArithVec4Float<float,Vec4f>
|
|
|
26 |
{
|
|
|
27 |
public:
|
|
|
28 |
|
|
|
29 |
/// Construct a (0,0,0,0) homogenous Vector
|
501 |
jrf |
30 |
Vec4f(): ArithVec4Float<float,Vec4f>(0.0f,0.0f,0.0f,0.0f) {}
|
2 |
bj |
31 |
|
|
|
32 |
/// Construct a (0,0,0,0) homogenous Vector
|
|
|
33 |
explicit Vec4f(float _a): ArithVec4Float<float,Vec4f>(_a,_a,_a,_a) {}
|
|
|
34 |
|
|
|
35 |
/// Construct a 4D vector
|
|
|
36 |
Vec4f(float _a, float _b, float _c, float _d):
|
|
|
37 |
ArithVec4Float<float,Vec4f>(_a,_b,_c,_d) {}
|
|
|
38 |
|
|
|
39 |
/// Construct a homogenous vector (a,b,c,1)
|
|
|
40 |
Vec4f(float _a, float _b, float _c):
|
501 |
jrf |
41 |
ArithVec4Float<float,Vec4f>(_a,_b,_c,1.0f) {}
|
2 |
bj |
42 |
|
|
|
43 |
/// Construct a homogenous vector from a non-homogenous.
|
|
|
44 |
explicit Vec4f(const Vec3f& v):
|
501 |
jrf |
45 |
ArithVec4Float<float,Vec4f>(v[0],v[1],v[2],1.0f) {}
|
2 |
bj |
46 |
|
|
|
47 |
/// Construct a homogenous vector from a non-homogenous.
|
|
|
48 |
explicit Vec4f(const Vec3f& v,float _d):
|
|
|
49 |
ArithVec4Float<float,Vec4f>(v[0],v[1],v[2],_d) {}
|
|
|
50 |
|
|
|
51 |
operator Vec3f() const
|
|
|
52 |
{
|
|
|
53 |
float k = 1.0f/(*this)[3];
|
|
|
54 |
return Vec3f((*this)[0]*k,(*this)[1]*k,(*this)[2]*k);
|
|
|
55 |
}
|
|
|
56 |
};
|
|
|
57 |
}
|
|
|
58 |
#endif
|
|
|
59 |
|