zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vector3f.h
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 
34 #ifndef ZENI_VECTOR3F_H
35 #define ZENI_VECTOR3F_H
36 
37 #include <Zeni/Serialization.h>
38 
39 namespace Zeni {
40 
41  struct Point3f;
42  struct Vector2f;
43  struct Vector3f;
44 
45  namespace Global {
46  ZENI_DLL extern const float pi;
47  ZENI_DLL extern const float pi_over_two;
48  ZENI_DLL extern const float three_pi_over_two;
49  ZENI_DLL extern const float over_three;
50  ZENI_DLL extern const float sqrt_two;
51  ZENI_DLL extern const float sqrt_three;
52 
53  ZENI_DLL extern const Vector3f vector_i;
54  ZENI_DLL extern const Vector3f vector_j;
55  ZENI_DLL extern const Vector3f vector_k;
56  }
57 
58  struct ZENI_DLL Vector3f {
60  inline explicit Vector3f(const bool &degenerate_ = false);
61  inline Vector3f(const float &i_, const float &j_, const float &k_, const bool &degenerate_ = false);
62  inline Vector3f(const Vector3f &rhs, const bool &degenerate_ = false);
63  inline Vector3f(const Point3f &rhs);
64  inline explicit Vector3f(const Vector2f &rhs);
65 
66  // Vector addition/subtraction
67  inline Vector3f operator+(const Vector3f &rhs) const;
68  inline Vector3f operator-(const Vector3f &rhs) const;
69  inline Vector3f & operator+=(const Vector3f &rhs);
70  inline Vector3f & operator-=(const Vector3f &rhs);
71 
72  // Vector Dot-Product and Cross-Product
73  inline float operator*(const Vector3f &rhs) const;
74  inline Vector3f operator%(const Vector3f &rhs) const;
75  inline Vector3f & operator%=(const Vector3f &rhs);
76 
77  // Vector Scalar Multiplication I of II
78  inline Vector3f operator*(const float &rhs) const;
79  inline Vector3f operator/(const float &rhs) const;
80  inline Vector3f & operator*=(const float &rhs);
81  inline Vector3f & operator/=(const float &rhs);
82  inline Vector3f operator-() const;
83 
84  // Other Standard Functions
85  Vector3f & normalize();
86  Vector3f normalized() const;
87  inline float magnitude2() const;
88  inline float magnitude() const;
89 
90  // Other helpful functions
91  inline Vector3f get_i() const;
92  inline Vector3f get_j() const;
93  inline Vector3f get_k() const;
94  inline Vector3f get_ij() const;
95  inline Vector3f get_ik() const;
96  inline Vector3f get_jk() const;
97  inline Vector3f multiply_by(const Vector3f &rhs) const;
98  inline Vector3f divide_by(const Vector3f &rhs) const;
99  inline float angle_between(const Vector3f &rhs) const;
100 
101  // Indexing
102  inline const float & operator[](const int &index) const;
103  inline float & operator[](const int &index);
104 
105  // Spherical Accessors and Modifiers
106  float theta() const;
107  float phi() const;
108  void set_spherical(const float &theta, const float &phi, const float &magnitude = 1);
109 
110  union {
111  float i;
112  float x;
113  };
114  union {
115  float j;
116  float y;
117  };
118  union {
119  float k;
120  float z;
121  };
122 
124  };
125 
126  // Vector Scalar Multiplication Part II of II
127  inline Vector3f operator*(const float &lhs, const Vector3f &rhs);
128 
129  ZENI_DLL std::ostream & serialize(std::ostream &os, const Vector3f &value);
130  ZENI_DLL std::istream & unserialize(std::istream &is, Vector3f &value);
131 }
132 
133 #endif
GLint GLenum GLboolean normalized
Definition: glew.h:1891
const float sqrt_three
sqrt(3.0f)
Definition: Vector3f.cpp:32
TiXmlString operator+(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.cpp:86
Quaternion operator/(const float &lhs, const Quaternion &rhs)
Definition: Quaternion.h:114
std::istream & unserialize(std::istream &is, Color &value)
Definition: Color.cpp:72
std::ostream & serialize(std::ostream &os, const Color &value)
Definition: Color.cpp:68
A 3D Point represented with floats.
Definition: Coordinate.h:133
const Vector3f vector_k(0, 0, 1)
k == Vector3f(0, 0, 1)
Definition: Vector3f.h:55
const float sqrt_two
sqrt(2.0f)
Definition: Vector3f.cpp:31
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
bool degenerate
Definition: Vector3f.h:123
const float pi
pi == 3.1415926...
Definition: Vector3f.cpp:27
GLuint index
Definition: glew.h:1800
Quaternion operator*(const float &lhs, const Quaternion &rhs)
Definition: Quaternion.h:110
const float pi_over_two
pi/23
Definition: Vector3f.cpp:28
EGLSurface EGLint void ** value
Definition: eglext.h:301
const Vector3f vector_i(1, 0, 0)
i == Vector3f(1, 0, 0)
Definition: Vector3f.h:53
const float three_pi_over_two
3*pi/2
Definition: Vector3f.cpp:29
const Vector3f vector_j(0, 1, 0)
j == Vector3f(0, 1, 0)
Definition: Vector3f.h:54
const float over_three
1/3
Definition: Vector3f.cpp:30
A 2-Space Vector Class.
Definition: Vector2f.h:41