20#ifndef HEADER_VEC3_HPP
21#define HEADER_VEC3_HPP
27#include "LinearMath/btVector3.h"
28#include "LinearMath/btMatrix3x3.h"
30#include "utils/constants.hpp"
34class Vec3 :
public btVector3
48 inline Vec3(
const core::vector3df &v) : btVector3(v.X, v.Y, v.Z) {}
51 inline Vec3(
const btVector3& a) : btVector3(a) {}
54 inline Vec3() : btVector3(0, 0, 0) {}
57 inline Vec3(
float x,
float y,
float z) : btVector3(x,y,z) {}
60 inline Vec3(
float x,
float y,
float z,
float w) : btVector3(x,y,z)
65 inline Vec3(
float x) : btVector3(x,x,x) {}
81 void setHPR(
const btQuaternion& q);
84 inline const float&
operator[](
int n)
const {
return m_floats[n]; }
90 inline const float getHeading()
const {
return m_floats[1]; }
93 inline const float getPitch()
const {
return m_floats[0]; }
96 inline const float getRoll()
const {
return m_floats[2]; }
100 inline const float getW()
const {
return m_floats[3]; }
106 inline const void setPitch(
float f) { m_floats[0] = f; }
109 inline const void setRoll(
float f) { m_floats[2] = f; }
115 return (
const core::vector3df&)*
this;
121 return core::vector3df(RAD_TO_DEGREE*(getX()),
122 RAD_TO_DEGREE*(getY()),
123 RAD_TO_DEGREE*(getZ()) );
129 return core::vector2df(m_floats[0], m_floats[2]);
135 m_floats[0]*=DEGREE_TO_RAD;
136 m_floats[1]*=DEGREE_TO_RAD;
137 m_floats[2]*=DEGREE_TO_RAD;
151 return ((m_floats[2]==other.m_floats[2]) &&
152 (m_floats[1]==other.m_floats[1]) &&
153 (m_floats[0]==other.m_floats[0]) );
161 return ((m_floats[2]!=other.m_floats[2]) ||
162 (m_floats[1]!=other.m_floats[1]) ||
163 (m_floats[0]!=other.m_floats[0]) );
176 return *(btVector3*)
this - v1;
182 + m_floats[2]*m_floats[2]; }
188 float length_2d()
const {
return sqrtf( m_floats[0]*m_floats[0]
189 + m_floats[2]*m_floats[2]);}
193 void max(
const Vec3& a) {
if(a.getX()>m_floats[0]) m_floats[0]=a.getX();
194 if(a.getY()>m_floats[1]) m_floats[1]=a.getY();
195 if(a.getZ()>m_floats[2]) m_floats[2]=a.getZ();}
199 void min(
const Vec3& a) {
if(a.getX()<m_floats[0]) m_floats[0]=a.getX();
200 if(a.getY()<m_floats[1]) m_floats[1]=a.getY();
201 if(a.getZ()<m_floats[2]) m_floats[2]=a.getZ();}
211 return (end.getX()-start.getX())*(m_floats[2]-start.getZ()) -
212 (end.getZ()-start.getZ())*(m_floats[0]-start.getX());
216 float sideofPlane(
const Vec3& x1,
const Vec3& x2,
const Vec3& x3)
const
218 return ((x2 - x1).cross(x3 - x1)).dot(*
this - x1);
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
Vec3 operator-(const Vec3 &v1) const
Computes this = this - v1.
Definition: vec3.hpp:168
void setHPR(const btQuaternion &q)
Sets the heading, pitch, roll of this vector that is used to store a rotation from a quaternion.
Definition: vec3.cpp:21
const float getRoll() const
Returns the roll of a vector that is used to store a rotation.
Definition: vec3.hpp:96
float sideOfLine2D(const Vec3 &start, const Vec3 &end) const
Determines which side of a line this point is.
Definition: vec3.hpp:209
void max(const Vec3 &a)
Sets this = max(this, a) componentwise.
Definition: vec3.hpp:193
const void setHeading(float f)
Sets the heading of a vector that is used to store a rotation.
Definition: vec3.hpp:103
const float getW() const
Returns the W component (bullet vectors contain 4 elements, the last element is usually unused).
Definition: vec3.hpp:100
bool operator==(const Vec3 &other) const
Operator== of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circums...
Definition: vec3.hpp:149
const void setRoll(float f)
Sets the roll of a vector that is used to store a rotation.
Definition: vec3.hpp:109
void setPitchRoll(const Vec3 &normal)
Sets the pitch and the roll of this vector to follow the normal given.
Definition: vec3.cpp:42
bool operator!=(const Vec3 &other) const
Operator!= of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circums...
Definition: vec3.hpp:159
Vec3(float x, float y, float z)
Creates a 3d vector from three scalars.
Definition: vec3.hpp:57
const core::vector3df toIrrHPR() const
Converts a bullet HPR value into an irrlicht HPR value.
Definition: vec3.hpp:119
const float getPitch() const
Returns the pitch of a vector that is used to store a rotation.
Definition: vec3.hpp:93
float length_2d() const
Returns the length of this vector in the plane, i.e.
Definition: vec3.hpp:188
Vec3(const btVector3 &a)
Initialises a vector from a btVector3 (or a Vec3).
Definition: vec3.hpp:51
Vec3()
Empty constructor.
Definition: vec3.hpp:54
const core::vector2df toIrrVector2d() const
Returns the X and Z component as an irrlicht 2d vector.
Definition: vec3.hpp:127
void min(const Vec3 &a)
Sets this = min(this, a) componentwise.
Definition: vec3.hpp:199
float length2_2d() const
Helper functions to treat this vec3 as a 2d vector.
Definition: vec3.hpp:181
Vec3(float x)
Initialises a 3d vector from one scalar value, which is used to initialise all components.
Definition: vec3.hpp:65
Vec3 & operator=(const btVector3 &a)
Sets this = a.
Definition: vec3.hpp:141
const core::vector3df & toIrrVector() const
Converts a vec3 into an irrlicht vector (which is a simple type cast).
Definition: vec3.hpp:113
Vec3 operator-(const btVector3 v1) const
Computes this = this - v1.
Definition: vec3.hpp:174
Vec3 & operator=(const btQuaternion &q)
Sets the rotation given by the quaternion as HPR vector.
Definition: vec3.hpp:144
Vec3(float heading, const Vec3 &normal)
Sets the heading, and computes pitch and roll dependent on the normal it is displayed on.
Definition: vec3.hpp:72
Vec3(float x, float y, float z, float w)
Creates a 3d vector from three scalars.
Definition: vec3.hpp:60
void degreeToRad()
Converts degree values stored in this vec3 to radians.
Definition: vec3.hpp:133
const void setPitch(float f)
Sets the pitch of a vector that is used to store a rotation.
Definition: vec3.hpp:106
const float getHeading() const
Returns the heading of a vector that is used to store a rotation.
Definition: vec3.hpp:90
float & operator[](int n)
Returns a reference to the n-th element (x=0, y=1, z=2, w=3).
Definition: vec3.hpp:87
const float & operator[](int n) const
Returns a reference to the n-th element (x=0, y=1, z=2, w=3).
Definition: vec3.hpp:84
Vec3(const core::vector3df &v)
Convert an irrlicht vector3df into the internal (bullet) format.
Definition: vec3.hpp:48