zenilib: zenilib/jni/external/zenilib/zeni/Zeni/Vector3f.hxx Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vector3f.hxx
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef ZENI_VECTOR3F_HXX
19 #define ZENI_VECTOR3F_HXX
20
21 #include <Zeni/Vector3f.h>
22
23 // HXXed below
24 #include <Zeni/Coordinate.h>
25 #include <Zeni/Vector2f.h>
26
27 // Not HXXed
28 #include <cassert>
29 #include <cmath>
30
31 namespace Zeni {
32
33 Vector3f::Vector3f(const bool &degenerate_)
34 : i(0.0f), j(0.0f), k(0.0f), degenerate(degenerate_)
35 {
36 }
37
38 Vector3f::Vector3f(const float &i_, const float &j_, const float &k_, const bool &degenerate_)
39 : i(i_), j(j_), k(k_), degenerate(degenerate_)
40 {
41 }
42
43 Vector3f::Vector3f(const Vector3f &rhs, const bool &degenerate_)
44 : i(rhs.i), j(rhs.j), k(rhs.k), degenerate(rhs.degenerate || degenerate_)
45 {
46 }
47
48 Vector3f::Vector3f(const Point3f &rhs)
49 : i(rhs.x), j(rhs.y), k(rhs.z)
50 {
51 }
52
53 Vector3f::Vector3f(const Vector2f &rhs)
54 : i(rhs.x), j(rhs.y), k(0.0f)
55 {
56 }
57
58 Vector3f Vector3f::operator+(const Vector3f &rhs) const {
59 return Vector3f(i + rhs.i,
60 j + rhs.j,
61 k + rhs.k,
62 degenerate || rhs.degenerate);
63 }
64
65 Vector3f Vector3f::operator-(const Vector3f &rhs) const {
66 return Vector3f(i - rhs.i,
67 j - rhs.j,
68 k - rhs.k,
69 degenerate || rhs.degenerate);
70 }
71
72 Vector3f & Vector3f::operator+=(const Vector3f &rhs) {
73 i += rhs.i;
74 j += rhs.j;
75 k += rhs.k;
76 degenerate |= rhs.degenerate;
77 return *this;
78 }
79
80 Vector3f & Vector3f::operator-=(const Vector3f &rhs) {
81 i -= rhs.i;
82 j -= rhs.j;
83 k -= rhs.k;
84 degenerate |= rhs.degenerate;
85 return *this;
86 }
87
88 float Vector3f::operator*(const Vector3f &rhs) const {
89 return
90 i * rhs.i +
91 j * rhs.j +
92 k * rhs.k;
93 }
94
95 Vector3f Vector3f::operator%(const Vector3f &rhs) const {
96 return Vector3f(j * rhs.k - rhs.j *k,
97 rhs.i *k - i * rhs.k,
98 i * rhs.j - rhs.i *j,
99 degenerate || rhs.degenerate);
100 }
101
102 Vector3f & Vector3f::operator%=(const Vector3f &rhs) {
103 degenerate |= rhs.degenerate;
104 return *this = *this % rhs;
105 }
106
107 Vector3f Vector3f::operator*(const float &rhs) const {
108 return Vector3f(i * rhs, j * rhs, k * rhs, degenerate);
109 }
110
111 Vector3f Vector3f::operator/(const float &rhs) const {
112 return Vector3f(i / rhs, j / rhs, k / rhs, degenerate);
113 }
114
115 Vector3f & Vector3f::operator*=(const float &rhs) {
116 i *= rhs;
117 j *= rhs;
118 k *= rhs;
119 return *this;
120 }
121
122 Vector3f & Vector3f::operator/=(const float &rhs) {
123 i /= rhs;
124 j /= rhs;
125 k /= rhs;
126 return *this;
127 }
128
129 Vector3f Vector3f::operator-() const {
130 return *this * -1;
131 }
132
133 // Vector Scalar Multiplication Part II of II
134 Vector3f operator*(const float &lhs, const Vector3f &rhs) {
135 return rhs * lhs;
136 }
137
138 float Vector3f::magnitude2() const {
139 return i * i + j * j + k * k;
140 }
141
142 float Vector3f::magnitude() const {
143 return float(sqrt(magnitude2()));
144 }
145
146 Vector3f Vector3f::get_i() const {
147 return Vector3f(i, 0.0f, 0.0f);
148 }
149
150 Vector3f Vector3f::get_j() const {
151 return Vector3f(0.0f, j, 0.0f);
152 }
153
154 Vector3f Vector3f::get_k() const {
155 return Vector3f(0.0f, 0.0f, k);
156 }
157
158 Vector3f Vector3f::get_ij() const {
159 return Vector3f(i, j, 0.0f);
160 }
161
162 Vector3f Vector3f::get_ik() const {
163 return Vector3f(i, 0.0f, k);
164 }
165
166 Vector3f Vector3f::get_jk() const {
167 return Vector3f(0.0f, j, k);
168 }
169
170 Vector3f Vector3f::multiply_by(const Vector3f &rhs) const {
171 return Vector3f(i*rhs.i, j*rhs.j, k*rhs.k, degenerate || rhs.degenerate);
172 }
173
174 Vector3f Vector3f::divide_by(const Vector3f &rhs) const {
175 return Vector3f(i/rhs.i, j/rhs.j, k/rhs.k, degenerate || rhs.degenerate);
176 }
177
178 float Vector3f::angle_between(const Vector3f &rhs) const {
179 const float a = magnitude();
180 const float b = rhs.magnitude();
181 const float c = (rhs - *this).magnitude();
182
183 return float(acos((a * a + b * b - c * c) / (2 * a * b)));
184 }
185
186 const float & Vector3f::operator[](const int &index) const {
187 assert(-1 < index && index < 3);
188 const float * const ptr = &i;
189 return ptr[index];
190 }
191
192 float & Vector3f::operator[](const int &index) {
193 assert(-1 < index && index < 3);
194 float * const ptr = &i;
195 return ptr[index];
196 }
197
198 }
199
200 #include <Zeni/Coordinate.hxx>
201 #include <Zeni/Vector2f.hxx>
202
203 #endif
Zeni::Vector3f::magnitude2
float magnitude2() const
Get the &#39;magnitude squared&#39; of the vector.
Definition: Vector3f.hxx:138
Zeni::Vector3f::get_ik
Vector3f get_ik() const
Get just the i and k parts.
Definition: Vector3f.hxx:162
Zeni::Vector3f::operator/
Vector3f operator/(const float &rhs) const
Get the scalar... something.
Definition: Vector3f.hxx:111
f
GLclampf f
Definition: glew.h:3390
Zeni::Vector3f::operator%=
Vector3f & operator%=(const Vector3f &rhs)
Set equal to the cross-product.
Definition: Vector3f.hxx:102
k
int32_t k
Definition: e_log.c:102
Zeni::Vector3f::operator/=
Vector3f & operator/=(const float &rhs)
Set equal to the scalar something.
Definition: Vector3f.hxx:122
x
EGLSurface EGLint x
Definition: eglext.h:293
j
int32_t j
Definition: e_log.c:102
Coordinate.hxx
Zeni::Vector3f::get_i
Vector3f get_i() const
Get just the i-part.
Definition: Vector3f.hxx:146
Zeni::Vector3f::divide_by
Vector3f divide_by(const Vector3f &rhs) const
Divide corresponding members.
Definition: Vector3f.hxx:174
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
Zeni::Vector3f::multiply_by
Vector3f multiply_by(const Vector3f &rhs) const
Multiply corresponding members.
Definition: Vector3f.hxx:170
assert
#define assert(x)
Definition: SDL_malloc.c:1234
Zeni::Vector3f::get_ij
Vector3f get_ij() const
Get just the i and j parts.
Definition: Vector3f.hxx:158
Zeni::Vector3f::magnitude
float magnitude() const
Get the magnitude of the vector.
Definition: Vector3f.hxx:142
Zeni::Vector3f::get_j
Vector3f get_j() const
Get just the j-part.
Definition: Vector3f.hxx:150
Zeni::Vector3f::get_jk
Vector3f get_jk() const
Get just the j and k parts.
Definition: Vector3f.hxx:166
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Coordinate.h
Vector3f.h
Zeni::Vector3f::operator*
float operator*(const Vector3f &rhs) const
Get the dot-product.
Definition: Vector3f.hxx:88
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::Vector3f::degenerate
bool degenerate
Definition: Vector3f.h:123
Zeni::Vector3f::operator*=
Vector3f & operator*=(const float &rhs)
Set equal to the scalar multiple.
Definition: Vector3f.hxx:115
c
const GLfloat * c
Definition: glew.h:14913
Zeni::Vector3f::get_k
Vector3f get_k() const
Get just the k-part.
Definition: Vector3f.hxx:154
index
GLuint index
Definition: glew.h:1800
Zeni::operator*
Quaternion operator*(const float &lhs, const Quaternion &rhs)
Definition: Quaternion.h:110
Zeni::Vector3f::operator[]
const float & operator[](const int &index) const
Get &#39;index&#39;.
Definition: Vector3f.hxx:186
Zeni::Vector3f::angle_between
float angle_between(const Vector3f &rhs) const
Find the angle between the Vector3fs.
Definition: Vector3f.hxx:178
Zeni::Vector3f::k
float k
Definition: Vector3f.h:119
Zeni::Vector3f::Vector3f
Vector3f(const bool &degenerate_=false)
The best way to create a Vector3f.
Definition: Vector3f.hxx:33
Zeni::Vector3f::operator-
Vector3f operator-() const
Get the negation.
Definition: Vector3f.hxx:129
Zeni::Vector3f::operator-=
Vector3f & operator-=(const Vector3f &rhs)
Set equal to the difference.
Definition: Vector3f.hxx:80
y
EGLSurface EGLint EGLint y
Definition: eglext.h:293
Zeni::Vector3f::j
float j
Definition: Vector3f.h:115
Zeni::Vector3f::operator+=
Vector3f & operator+=(const Vector3f &rhs)
Set equal to the sum.
Definition: Vector3f.hxx:72
Zeni::Vector3f::operator%
Vector3f operator%(const Vector3f &rhs) const
Get the cross-product.
Definition: Vector3f.hxx:95
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
z
GLint GLint GLint GLint z
Definition: gl2ext.h:1214
Vector2f.h
i
int i
Definition: pngrutil.c:1377
Vector2f.hxx
Zeni::Vector3f::i
float i
Definition: Vector3f.h:111
Zeni::Vector3f::operator+
Vector3f operator+(const Vector3f &rhs) const
Get the sum.
Definition: Vector3f.hxx:58
Zeni::Vector2f
A 2-Space Vector Class.
Definition: Vector2f.h:41