SuperTuxKart
Public Member Functions | Private Member Functions | List of all members
Vec3 Class Reference

A wrapper around bullets btVector3 to include conventient conversion functions (e.g. More...

#include <vec3.hpp>

Inheritance diagram for Vec3:
Inheritance graph
[legend]

Public Member Functions

 Vec3 (const core::vector3df &v)
 Convert an irrlicht vector3df into the internal (bullet) format. More...
 
 Vec3 (const btVector3 &a)
 Initialises a vector from a btVector3 (or a Vec3). More...
 
 Vec3 ()
 Empty constructor. More...
 
 Vec3 (float x, float y, float z)
 Creates a 3d vector from three scalars. More...
 
 Vec3 (float x, float y, float z, float w)
 Creates a 3d vector from three scalars. More...
 
 Vec3 (float x)
 Initialises a 3d vector from one scalar value, which is used to initialise all components. More...
 
 Vec3 (float heading, const Vec3 &normal)
 Sets the heading, and computes pitch and roll dependent on the normal it is displayed on. More...
 
void setHPR (const btQuaternion &q)
 Sets the heading, pitch, roll of this vector that is used to store a rotation from a quaternion. More...
 
const float & operator[] (int n) const
 Returns a reference to the n-th element (x=0, y=1, z=2, w=3). More...
 
float & operator[] (int n)
 Returns a reference to the n-th element (x=0, y=1, z=2, w=3). More...
 
const float getHeading () const
 Returns the heading of a vector that is used to store a rotation. More...
 
const float getPitch () const
 Returns the pitch of a vector that is used to store a rotation. More...
 
const float getRoll () const
 Returns the roll of a vector that is used to store a rotation. More...
 
const float getW () const
 Returns the W component (bullet vectors contain 4 elements, the last element is usually unused). More...
 
const void setHeading (float f)
 Sets the heading of a vector that is used to store a rotation. More...
 
const void setPitch (float f)
 Sets the pitch of a vector that is used to store a rotation. More...
 
const void setRoll (float f)
 Sets the roll of a vector that is used to store a rotation. More...
 
const core::vector3df & toIrrVector () const
 Converts a vec3 into an irrlicht vector (which is a simple type cast). More...
 
const core::vector3df toIrrHPR () const
 Converts a bullet HPR value into an irrlicht HPR value. More...
 
const core::vector2df toIrrVector2d () const
 Returns the X and Z component as an irrlicht 2d vector. More...
 
void degreeToRad ()
 Converts degree values stored in this vec3 to radians. More...
 
Vec3operator= (const btVector3 &a)
 Sets this = a. More...
 
Vec3operator= (const btQuaternion &q)
 Sets the rotation given by the quaternion as HPR vector. More...
 
bool operator== (const Vec3 &other) const
 Operator== of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circumstances). More...
 
bool operator!= (const Vec3 &other) const
 Operator!= of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circumstances). More...
 
Vec3 operator- (const Vec3 &v1) const
 Computes this = this - v1. More...
 
Vec3 operator- (const btVector3 v1) const
 Computes this = this - v1. More...
 
float length2_2d () const
 Helper functions to treat this vec3 as a 2d vector. More...
 
float length_2d () const
 Returns the length of this vector in the plane, i.e. More...
 
void max (const Vec3 &a)
 Sets this = max(this, a) componentwise. More...
 
void min (const Vec3 &a)
 Sets this = min(this, a) componentwise. More...
 
float sideOfLine2D (const Vec3 &start, const Vec3 &end) const
 Determines which side of a line this point is. More...
 
float sideofPlane (const Vec3 &x1, const Vec3 &x2, const Vec3 &x3) const
 

Private Member Functions

void setPitchRoll (const Vec3 &normal)
 Sets the pitch and the roll of this vector to follow the normal given. More...
 

Detailed Description

A wrapper around bullets btVector3 to include conventient conversion functions (e.g.

between btVector3 and the graphics specific 3d vector).

Constructor & Destructor Documentation

◆ Vec3() [1/7]

Vec3::Vec3 ( const core::vector3df &  v)
inline

Convert an irrlicht vector3df into the internal (bullet) format.

Irrlicht's and STK's axis are different (STK: Z up, irrlicht: Y up). We might want to change this as well, makes it easier to work with bullet and irrlicht together, without having to swap indices (bullet can handle any axis ordering). Note that toIrrVector swaps the axis as well (so a vector3df can be stored in and restored from a vec3).

◆ Vec3() [2/7]

Vec3::Vec3 ( const btVector3 &  a)
inline

Initialises a vector from a btVector3 (or a Vec3).

◆ Vec3() [3/7]

Vec3::Vec3 ( )
inline

Empty constructor.

◆ Vec3() [4/7]

Vec3::Vec3 ( float  x,
float  y,
float  z 
)
inline

Creates a 3d vector from three scalars.

◆ Vec3() [5/7]

Vec3::Vec3 ( float  x,
float  y,
float  z,
float  w 
)
inline

Creates a 3d vector from three scalars.

◆ Vec3() [6/7]

Vec3::Vec3 ( float  x)
inline

Initialises a 3d vector from one scalar value, which is used to initialise all components.

◆ Vec3() [7/7]

Vec3::Vec3 ( float  heading,
const Vec3 normal 
)
inline

Sets the heading, and computes pitch and roll dependent on the normal it is displayed on.

Parameters
headingThe heading to set.
normalThe normal from which pitch and roll should be computed.

Member Function Documentation

◆ degreeToRad()

void Vec3::degreeToRad ( )
inline

Converts degree values stored in this vec3 to radians.

◆ getHeading()

const float Vec3::getHeading ( ) const
inline

Returns the heading of a vector that is used to store a rotation.

◆ getPitch()

const float Vec3::getPitch ( ) const
inline

Returns the pitch of a vector that is used to store a rotation.

◆ getRoll()

const float Vec3::getRoll ( ) const
inline

Returns the roll of a vector that is used to store a rotation.

◆ getW()

const float Vec3::getW ( ) const
inline

Returns the W component (bullet vectors contain 4 elements, the last element is usually unused).

◆ length2_2d()

float Vec3::length2_2d ( ) const
inline

Helper functions to treat this vec3 as a 2d vector.

This returns the square of the length of the first 2 dimensions.

◆ length_2d()

float Vec3::length_2d ( ) const
inline

Returns the length of this vector in the plane, i.e.

the vector is used as a 2d vector. Returns the length of the vector using only the x/z coordinates.

◆ max()

void Vec3::max ( const Vec3 a)
inline

Sets this = max(this, a) componentwise.

Parameters
Vectorto compare with.

◆ min()

void Vec3::min ( const Vec3 a)
inline

Sets this = min(this, a) componentwise.

Parameters
aVector to compare with.

◆ operator!=()

bool Vec3::operator!= ( const Vec3 other) const
inline

Operator!= of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circumstances).

◆ operator-() [1/2]

Vec3 Vec3::operator- ( const Vec3 v1) const
inline

Computes this = this - v1.

◆ operator-() [2/2]

Vec3 Vec3::operator- ( const btVector3  v1) const
inline

Computes this = this - v1.

On VS this special version is needed, since otherwise Vec3-btVector3 is ont unique (could be cast to btVector3-btVector3, or convert btVector3 to Vec3()).

◆ operator=() [1/2]

Vec3& Vec3::operator= ( const btVector3 &  a)
inline

Sets this = a.

◆ operator=() [2/2]

Vec3& Vec3::operator= ( const btQuaternion &  q)
inline

Sets the rotation given by the quaternion as HPR vector.

◆ operator==()

bool Vec3::operator== ( const Vec3 other) const
inline

Operator== of btQuadWord also compares m_floats[3], which is not useful (and wrong in certain circumstances).

◆ operator[]() [1/2]

const float& Vec3::operator[] ( int  n) const
inline

Returns a reference to the n-th element (x=0, y=1, z=2, w=3).

◆ operator[]() [2/2]

float& Vec3::operator[] ( int  n)
inline

Returns a reference to the n-th element (x=0, y=1, z=2, w=3).

◆ setHeading()

const void Vec3::setHeading ( float  f)
inline

Sets the heading of a vector that is used to store a rotation.

◆ setHPR()

void Vec3::setHPR ( const btQuaternion &  q)

Sets the heading, pitch, roll of this vector that is used to store a rotation from a quaternion.

◆ setPitch()

const void Vec3::setPitch ( float  f)
inline

Sets the pitch of a vector that is used to store a rotation.

◆ setPitchRoll()

void Vec3::setPitchRoll ( const Vec3 normal)
private

Sets the pitch and the roll of this vector to follow the normal given.

The heading is taken from this vector.

Parameters
normalThe normal vector to which pitch and roll should be aligned.

◆ setRoll()

const void Vec3::setRoll ( float  f)
inline

Sets the roll of a vector that is used to store a rotation.

◆ sideOfLine2D()

float Vec3::sideOfLine2D ( const Vec3 start,
const Vec3 end 
) const
inline

Determines which side of a line this point is.

This is using a 2d projection (into the X-Z plane).

Parameters
startThe start point of the line.
endThe end point of the line.
Returns
>0 Point is to the left side; <0 if it's on the right.

◆ toIrrHPR()

const core::vector3df Vec3::toIrrHPR ( ) const
inline

Converts a bullet HPR value into an irrlicht HPR value.

◆ toIrrVector()

const core::vector3df& Vec3::toIrrVector ( ) const
inline

Converts a vec3 into an irrlicht vector (which is a simple type cast).

◆ toIrrVector2d()

const core::vector2df Vec3::toIrrVector2d ( ) const
inline

Returns the X and Z component as an irrlicht 2d vector.


The documentation for this class was generated from the following files: