i6engine  1.0
i6eVector4.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 /*
26  * A class to "transport" 3D vector
27  *
28  * for the math stuff use the vector of the lib (bullet, ogre...)
29  *
30  * its better to send only 1 "type" to the game then many
31  */
32 
33 #ifndef __I6ENGINE_MATH_I6EVECTOR4_H__
34 #define __I6ENGINE_MATH_I6EVECTOR4_H__
35 
36 #include <cmath>
37 #include <map>
38 #include <string>
39 
41 
42 namespace Ogre {
43  class Vector4;
44 } /* namespace Ogre */
45 class btVector4;
46 
47 namespace i6e {
48 namespace math {
49 
57  static const double EPSILON;
58 
59  public:
63  i6eVector4() : _w(0.0), _x(0.0), _y(0.0), _z(0.0) {
64  }
65 
69  i6eVector4(const double w, const double x, const double y, const double z) : _w(w), _x(x), _y(y), _z(z) {
70  }
71 
77  explicit i6eVector4(const Ogre::Vector4 & ogre);
78 
84  explicit i6eVector4(const btVector4 & bullet);
85 
86  /*
87  * \brief Constructs a vector from an attributeMap
88  *
89  * \param[in] params the attributeMap containing informations for the vector
90  * \param[in] prefix prefix of the values
91  */
92  i6eVector4(const std::map<std::string, std::string> & params, const std::string & prefix);
93 
94  /*
95  * \brief Constructs a Vec4 from a string
96  */
97  explicit i6eVector4(const std::string & str);
98 
105  }
106 
110  double getW() const {
111  return _w;
112  }
113  double getX() const {
114  return _x;
115  }
116  double getY() const {
117  return _y;
118  }
119  double getZ() const {
120  return _z;
121  }
122 
126  void setW(const double w) {
127  _w = w;
128  }
129  void setX(const double x) {
130  _x = x;
131  }
132  void setY(const double y) {
133  _y = y;
134  }
135  void setZ(const double z) {
136  _z = z;
137  }
138 
142  i6eVector4 operator+(const i6eVector4 & other) const {
143  return i6eVector4(_w + other._w, _x + other._x, _y + other._y, _z + other._z);
144  }
145 
149  i6eVector4 operator-(const i6eVector4 & other) const {
150  return i6eVector4(_w - other._w, _x - other._x, _y - other._y, _z - other._z);
151  }
152 
156  i6eVector4 operator*(double d) const {
157  return i6eVector4(_w * d, _x * d, _y * d, _z * d);
158  }
159 
163  bool operator==(const i6eVector4 & b) const {
164  return std::abs(_x - b.getX()) < EPSILON && std::abs(_y - b.getY()) < EPSILON && std::abs(_z - b.getZ()) < EPSILON && std::abs(_w - b.getW()) < EPSILON;
165  }
166 
170  bool operator!=(const i6eVector4 & other) const {
171  return !(*this == other);
172  }
173 
179  Ogre::Vector4 toOgre() const;
180 
186  btVector4 toBullet() const;
187 
191  void insertInMap(const std::string & prefix, std::map<std::string, std::string> & map) const;
192 
196  std::string toString() const;
197 
201  template<class Archive>
202  void serialize(Archive & ar, const unsigned int) {
203  ar & _x;
204  ar & _y;
205  ar & _z;
206  ar & _w;
207  }
208 
209  private:
210  double _w, _x, _y, _z;
211  };
212 
216  ISIXE_MATH_API std::ostream & operator<<(std::ostream & stream, const i6eVector4 & v);
217 
218 } /* namespace math */
219 } /* namespace i6e */
220 
222 
223 #endif /* __I6ENGINE_MATH_I6EVECTOR4_H__ */
224 
Implements 4-dimensional vectors.
Definition: i6eVector4.h:56
double getY() const
Definition: i6eVector4.h:116
bool operator==(const i6eVector4 &b) const
Operator '==' for Vector4.
Definition: i6eVector4.h:163
double getW() const
getters for the values of the Vector
Definition: i6eVector4.h:110
#define ISIXE_MATH_API
i6eVector4 operator*(double d) const
operator
Definition: i6eVector4.h:156
void setW(const double w)
setters for the values of the Vector
Definition: i6eVector4.h:126
double getX() const
Definition: i6eVector4.h:113
i6e::math::i6eVector4 Vec4
Definition: i6eVector4.h:221
i6eVector4(const double w, const double x, const double y, const double z)
Creates a new vector with all values set to the given values.
Definition: i6eVector4.h:69
void setZ(const double z)
Definition: i6eVector4.h:135
void setX(const double x)
Definition: i6eVector4.h:129
double getZ() const
Definition: i6eVector4.h:119
i6eVector4()
Creates a new vector with all values set to 0.
Definition: i6eVector4.h:63
void serialize(Archive &ar, const unsigned int)
serializer for the vector
Definition: i6eVector4.h:202
ISIXE_MATH_API std::ostream & operator<<(std::ostream &stream, const i6eQuaternion &q)
stream operator for quaternion
void setY(const double y)
Definition: i6eVector4.h:132
i6eVector4 operator+(const i6eVector4 &other) const
operator
Definition: i6eVector4.h:142
bool operator!=(const i6eVector4 &other) const
Operator '!=' for Vector4 calls == and negatiates result.
Definition: i6eVector4.h:170
i6eVector4 operator-(const i6eVector4 &other) const
operator
Definition: i6eVector4.h:149