|
@@ -1,5 +1,5 @@
|
|
|
-#ifndef _VEC3_H_
|
|
|
|
|
-#define _VEC3_H_
|
|
|
|
|
|
|
+#ifndef VEC3_H
|
|
|
|
|
+#define VEC3_H
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
#include "Common.h"
|
|
|
#include "MathForwardDecls.h"
|
|
#include "MathForwardDecls.h"
|
|
@@ -12,12 +12,19 @@ namespace M {
|
|
|
class Vec3
|
|
class Vec3
|
|
|
{
|
|
{
|
|
|
public:
|
|
public:
|
|
|
- // data members
|
|
|
|
|
|
|
+ /// @name Data members
|
|
|
|
|
+ /// @{
|
|
|
float x, y, z;
|
|
float x, y, z;
|
|
|
- // accessors
|
|
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Accessors
|
|
|
|
|
+ /// @{
|
|
|
float& operator [](uint i);
|
|
float& operator [](uint i);
|
|
|
float operator [](uint i) const;
|
|
float operator [](uint i) const;
|
|
|
- // constructors & distructors
|
|
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Constructors & distructors
|
|
|
|
|
+ /// @{
|
|
|
explicit Vec3();
|
|
explicit Vec3();
|
|
|
explicit Vec3(float f);
|
|
explicit Vec3(float f);
|
|
|
explicit Vec3(float x, float y, float z);
|
|
explicit Vec3(float x, float y, float z);
|
|
@@ -25,70 +32,83 @@ class Vec3
|
|
|
Vec3(const Vec3& b);
|
|
Vec3(const Vec3& b);
|
|
|
explicit Vec3(const Vec4& v4);
|
|
explicit Vec3(const Vec4& v4);
|
|
|
explicit Vec3(const Quat& q);
|
|
explicit Vec3(const Quat& q);
|
|
|
- // ops with same type
|
|
|
|
|
- Vec3 operator + (const Vec3& b) const;
|
|
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Operators with same type
|
|
|
|
|
+ /// @{
|
|
|
|
|
+ Vec3 operator +(const Vec3& b) const;
|
|
|
Vec3& operator +=(const Vec3& b);
|
|
Vec3& operator +=(const Vec3& b);
|
|
|
- Vec3 operator - (const Vec3& b) const;
|
|
|
|
|
|
|
+ Vec3 operator -(const Vec3& b) const;
|
|
|
Vec3& operator -=(const Vec3& b);
|
|
Vec3& operator -=(const Vec3& b);
|
|
|
- Vec3 operator * (const Vec3& b) const;
|
|
|
|
|
|
|
+ Vec3 operator *(const Vec3& b) const;
|
|
|
Vec3& operator *=(const Vec3& b);
|
|
Vec3& operator *=(const Vec3& b);
|
|
|
- Vec3 operator / (const Vec3& b) const;
|
|
|
|
|
|
|
+ Vec3 operator /(const Vec3& b) const;
|
|
|
Vec3& operator /=(const Vec3& b);
|
|
Vec3& operator /=(const Vec3& b);
|
|
|
- Vec3 operator - () const; // return the negative
|
|
|
|
|
- // ops with float
|
|
|
|
|
- Vec3 operator + (float f) const;
|
|
|
|
|
|
|
+ Vec3 operator -() const;
|
|
|
|
|
+ bool operator ==(const Vec3& b) const;
|
|
|
|
|
+ bool operator !=(const Vec3& b) const;
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Operators with float
|
|
|
|
|
+ /// @{
|
|
|
|
|
+ Vec3 operator +(float f) const;
|
|
|
Vec3& operator +=(float f);
|
|
Vec3& operator +=(float f);
|
|
|
- Vec3 operator - (float f) const;
|
|
|
|
|
|
|
+ Vec3 operator -(float f) const;
|
|
|
Vec3& operator -=(float f);
|
|
Vec3& operator -=(float f);
|
|
|
- Vec3 operator * (float f) const;
|
|
|
|
|
|
|
+ Vec3 operator *(float f) const;
|
|
|
Vec3& operator *=(float f);
|
|
Vec3& operator *=(float f);
|
|
|
- Vec3 operator / (float f) const;
|
|
|
|
|
|
|
+ Vec3 operator /(float f) const;
|
|
|
Vec3& operator /=(float f);
|
|
Vec3& operator /=(float f);
|
|
|
- // ops with other types
|
|
|
|
|
- Vec3 operator * (const Mat3& m3) const;
|
|
|
|
|
- // comparision
|
|
|
|
|
- bool operator ==(const Vec3& b) const;
|
|
|
|
|
- bool operator !=(const Vec3& b) const;
|
|
|
|
|
- // other
|
|
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Operators with other types
|
|
|
|
|
+ /// @{
|
|
|
|
|
+ Vec3 operator * (const Mat3& m3) const;
|
|
|
|
|
+ /// @}
|
|
|
|
|
+
|
|
|
|
|
+ /// @name Other
|
|
|
|
|
+ /// @{
|
|
|
float dot(const Vec3& b) const;
|
|
float dot(const Vec3& b) const;
|
|
|
- Vec3 cross(const Vec3& b) const;
|
|
|
|
|
|
|
+ Vec3 cross(const Vec3& b) const;
|
|
|
float getLength() const;
|
|
float getLength() const;
|
|
|
float getLengthSquared() const;
|
|
float getLengthSquared() const;
|
|
|
float getDistanceSquared(const Vec3& b) const;
|
|
float getDistanceSquared(const Vec3& b) const;
|
|
|
void normalize();
|
|
void normalize();
|
|
|
- Vec3 getNormalized() const;
|
|
|
|
|
- Vec3 getProjection(const Vec3& toThis) const;
|
|
|
|
|
- Vec3 getRotated(const Quat& q) const; ///< Returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
|
|
|
|
|
|
|
+ Vec3 getNormalized() const;
|
|
|
|
|
+ Vec3 getProjection(const Vec3& toThis) const;
|
|
|
|
|
+ /// Returns q * this * q.Conjucated() aka returns a rotated this. 18 muls, 12 adds
|
|
|
|
|
+ Vec3 getRotated(const Quat& q) const;
|
|
|
void rotate(const Quat& q);
|
|
void rotate(const Quat& q);
|
|
|
- Vec3 lerp(const Vec3& v1, float t) const; ///< return lerp(this, v1, t)
|
|
|
|
|
|
|
+ Vec3 lerp(const Vec3& v1, float t) const; ///< Return lerp(this, v1, t)
|
|
|
|
|
+ /// @}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @name Transformations
|
|
|
|
|
- * The faster way is by far the mat4 * vec3 or the getTransformed(Vec3, Mat3)
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ /// @name Transformations
|
|
|
|
|
+ /// The faster way is by far the mat4 * vec3 or the getTransformed(Vec3, Mat3)
|
|
|
/**@{*/
|
|
/**@{*/
|
|
|
- Vec3 getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const;
|
|
|
|
|
- void transform(const Vec3& translate, const Mat3& rotate, float scale);
|
|
|
|
|
- Vec3 getTransformed(const Vec3& translate, const Mat3& rotate) const;
|
|
|
|
|
- void transform(const Vec3& translate, const Mat3& rotate);
|
|
|
|
|
- Vec3 getTransformed(const Vec3& translate, const Quat& rotate, float scale) const;
|
|
|
|
|
- void transform(const Vec3& translate, const Quat& rotate, float scale);
|
|
|
|
|
- Vec3 getTransformed(const Vec3& translate, const Quat& rotate) const;
|
|
|
|
|
- void transform(const Vec3& translate, const Quat& rotate);
|
|
|
|
|
- Vec3 getTransformed(const Mat4& transform) const; ///< 9 muls, 9 adds
|
|
|
|
|
- void transform(const Mat4& transform);
|
|
|
|
|
- Vec3 getTransformed(const Transform& transform) const;
|
|
|
|
|
- void transform(const Transform& transform);
|
|
|
|
|
|
|
+ Vec3 getTransformed(const Vec3& translate, const Mat3& rotate, float scale) const;
|
|
|
|
|
+ void transform(const Vec3& translate, const Mat3& rotate, float scale);
|
|
|
|
|
+ Vec3 getTransformed(const Vec3& translate, const Mat3& rotate) const;
|
|
|
|
|
+ void transform(const Vec3& translate, const Mat3& rotate);
|
|
|
|
|
+ Vec3 getTransformed(const Vec3& translate, const Quat& rotate, float scale) const;
|
|
|
|
|
+ void transform(const Vec3& translate, const Quat& rotate, float scale);
|
|
|
|
|
+ Vec3 getTransformed(const Vec3& translate, const Quat& rotate) const;
|
|
|
|
|
+ void transform(const Vec3& translate, const Quat& rotate);
|
|
|
|
|
+ Vec3 getTransformed(const Mat4& transform) const; ///< 9 muls, 9 adds
|
|
|
|
|
+ void transform(const Mat4& transform);
|
|
|
|
|
+ Vec3 getTransformed(const Transform& transform) const;
|
|
|
|
|
+ void transform(const Transform& transform);
|
|
|
/**@}*/
|
|
/**@}*/
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
-// other operators
|
|
|
|
|
|
|
+/// @name Other operators
|
|
|
|
|
+/// @{
|
|
|
extern Vec3 operator +(float f, const Vec3& v);
|
|
extern Vec3 operator +(float f, const Vec3& v);
|
|
|
extern Vec3 operator -(float f, const Vec3& v);
|
|
extern Vec3 operator -(float f, const Vec3& v);
|
|
|
extern Vec3 operator *(float f, const Vec3& v);
|
|
extern Vec3 operator *(float f, const Vec3& v);
|
|
|
extern Vec3 operator /(float f, const Vec3& v);
|
|
extern Vec3 operator /(float f, const Vec3& v);
|
|
|
extern ostream& operator<<(ostream& s, const Vec3& v);
|
|
extern ostream& operator<<(ostream& s, const Vec3& v);
|
|
|
|
|
+/// @}
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace
|
|
} // end namespace
|