TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::CoordinateFrame Class Reference

A rigid body RT (rotation-translation) transformation. More...

#include <CoordinateFrame.h>

Public Member Functions

 CoordinateFrame (const Any &any)
 
Any toAny () const
 
bool operator== (const CoordinateFrame &other) const
 
bool operator!= (const CoordinateFrame &other) const
 
bool fuzzyEq (const CoordinateFrame &other) const
 
bool fuzzyIsIdentity () const
 
bool isIdentity () const
 
 CoordinateFrame ()
 
 CoordinateFrame (const Point3 &_translation)
 
 CoordinateFrame (const Matrix3 &rotation, const Point3 &translation)
 
 CoordinateFrame (const Matrix3 &rotation)
 
 CoordinateFrame (const class UprightFrame &f)
 
std::string toXYZYPRDegreesString () const
 
 CoordinateFrame (class BinaryInput &b)
 
void deserialize (class BinaryInput &b)
 
void serialize (class BinaryOutput &b) const
 
 CoordinateFrame (const CoordinateFrame &other)
 
CoordinateFrame inverse () const
 
 ~CoordinateFrame ()
 
class Matrix4 toMatrix4 () const
 
void getXYZYPRRadians (float &x, float &y, float &z, float &yaw, float &pitch, float &roll) const
 
void getXYZYPRDegrees (float &x, float &y, float &z, float &yaw, float &pitch, float &roll) const
 
std::string toXML () const
 
float getHeading () const
 
CoordinateFrame toObjectSpace (const CoordinateFrame &c) const
 
Vector4 toObjectSpace (const Vector4 &v) const
 
Vector4 toWorldSpace (const Vector4 &v) const
 
Point3 pointToWorldSpace (const Point3 &v) const
 
Point3 pointToObjectSpace (const Point3 &v) const
 
Vector3 vectorToWorldSpace (const Vector3 &v) const
 
Vector3 normalToWorldSpace (const Vector3 &v) const
 
class Ray toObjectSpace (const Ray &r) const
 
Ray toWorldSpace (const Ray &r) const
 
Frustum toWorldSpace (const Frustum &f) const
 
Vector3 vectorToObjectSpace (const Vector3 &v) const
 
Vector3 normalToObjectSpace (const Vector3 &v) const
 
void pointToWorldSpace (const Array< Point3 > &v, Array< Point3 > &vout) const
 
void normalToWorldSpace (const Array< Vector3 > &v, Array< Vector3 > &vout) const
 
void vectorToWorldSpace (const Array< Vector3 > &v, Array< Vector3 > &vout) const
 
void pointToObjectSpace (const Array< Point3 > &v, Array< Point3 > &vout) const
 
void normalToObjectSpace (const Array< Vector3 > &v, Array< Vector3 > &vout) const
 
void vectorToObjectSpace (const Array< Vector3 > &v, Array< Vector3 > &vout) const
 
void toWorldSpace (const class AABox &b, class AABox &result) const
 
class Box toWorldSpace (const class AABox &b) const
 
class Box toWorldSpace (const class Box &b) const
 
class Cylinder toWorldSpace (const class Cylinder &b) const
 
class Capsule toWorldSpace (const class Capsule &b) const
 
class Plane toWorldSpace (const class Plane &p) const
 
class Sphere toWorldSpace (const class Sphere &b) const
 
class Triangle toWorldSpace (const class Triangle &t) const
 
class Box toObjectSpace (const AABox &b) const
 
class Box toObjectSpace (const Box &b) const
 
class Plane toObjectSpace (const Plane &p) const
 
class Sphere toObjectSpace (const Sphere &b) const
 
Triangle toObjectSpace (const Triangle &t) const
 
CoordinateFrame operator* (const CoordinateFrame &other) const
 
CoordinateFrame operator+ (const Vector3 &v) const
 
CoordinateFrame operator- (const Vector3 &v) const
 
void moveTowards (const CoordinateFrame &goal, float maxTranslation, float maxRotation)
 
void lookAt (const Point3 &target)
 
void lookAt (const Point3 &target, Vector3 up)
 
Vector3 lookVector () const
 
class Ray lookRay () const
 
Vector3 upVector () const
 
Vector3 rightVector () const
 
Vector3 leftVector () const
 
CoordinateFrame lerp (const CoordinateFrame &other, float alpha) const
 

Static Public Member Functions

static CoordinateFrame fromXYZYPRRadians (float x, float y, float z, float yaw=0.0f, float pitch=0.0f, float roll=0.0f)
 
static CoordinateFrame fromXYZYPRDegrees (float x, float y, float z, float yaw=0.0f, float pitch=0.0f, float roll=0.0f)
 

Public Attributes

Matrix3 rotation
 
Point3 translation
 

Detailed Description

A rigid body RT (rotation-translation) transformation.

CoordinateFrame abstracts a 4x4 matrix that maps object space to world space:

v_world = C * v_object

CoordinateFrame::rotation is the upper 3x3 submatrix, CoordinateFrame::translation is the right 3x1 column. The 4th row is always [0 0 0 1], so it isn't stored. So you don't have to remember which way the multiplication and transformation work, it provides explicit toWorldSpace and toObjectSpace methods. Also, points, vectors (directions), and surface normals transform differently, so they have separate methods.

Some helper functions transform whole primitives like boxes in and out of object space.

Convert to Matrix4 using CoordinateFrame::toMatrix4. You can construct a CoordinateFrame from a Matrix4 using Matrix4::approxCoordinateFrame, however, because a Matrix4 is more general than a CoordinateFrame, some information may be lost.

See also
G3D::UprightFrame, G3D::PhysicsFrame, G3D::Matrix4, G3D::Quat

Constructor & Destructor Documentation

G3D::CoordinateFrame::CoordinateFrame ( const Any any)
Parameters
anyMust be in one of the following forms:
  • CFrame((matrix3 expr), (Point3 expr))
  • CFrame::fromXYZYPRDegrees(#, #, #, #, #, #)
  • CFrame { rotation = (Matrix3 expr), translation = (Point3 expr) }
  • Point3( ... )
  • Matrix3( ... )
45  {
46  *this = CFrame();
47 
48  const std::string& n = toUpper(any.name());
49 
50  if (beginsWith(n, "VECTOR3") || beginsWith(n, "POINT3")) {
52  } else if (beginsWith(n, "MATRIX3")) {
53  rotation = Matrix3(any);
54  } else if (beginsWith(n, "MATRIX4")) {
55  *this = Matrix4(any).approxCoordinateFrame();
56  } else if ((n == "CFRAME") || (n == "COORDINATEFRAME")) {
57  any.verifyType(Any::TABLE, Any::ARRAY);
58  if (any.type() == Any::ARRAY) {
59  any.verifySize(2);
60  rotation = any[0];
61  translation = any[1];
62  } else {
63  AnyTableReader r(any);
64  r.getIfPresent("translation", translation);
65  r.getIfPresent("rotation", rotation);
66  r.verifyDone();
67  }
68  } else if (beginsWith(n, "PHYSICSFRAME") || beginsWith(n, "PFRAME")) {
69  *this = PhysicsFrame(any);
70 // } else if (beginsWith(n, "UPRIGHTFRAME") || beginsWith(n, "UFRAME")) {
71 // *this = UprightFrame(any);
72  } else {
73  any.verifyName("CFrame::fromXYZYPRDegrees", "CoordinateFrame::fromXYZYPRDegrees");
74  any.verifyType(Any::ARRAY);
75  any.verifySize(3, 6);
76 
77  int s = any.size();
78 
79  *this = fromXYZYPRDegrees(any[0], any[1], any[2],
80  (s > 3) ? (float)any[3].number() : 0.0f,
81  (s > 4) ? (float)any[4].number() : 0.0f,
82  (s > 5) ? (float)any[5].number() : 0.0f);
83  }
84 }
bool beginsWith(const std::string &test, const std::string &pattern)
Returns true if the test string begins with the pattern string.
Definition: stringutils.cpp:81
Definition: Any.h:187
static CoordinateFrame fromXYZYPRDegrees(float x, float y, float z, float yaw=0.0f, float pitch=0.0f, float roll=0.0f)
Definition: CoordinateFrame.cpp:142
class CoordinateFrame CFrame
Definition: Box2D.h:22
bool any(float x)
Definition: g3dmath.h:424
Matrix3 rotation
Definition: CoordinateFrame.h:63
Definition: Any.h:187
std::string toUpper(const std::string &x)
Definition: stringutils.cpp:216
Vector3 Point3
Definition: Vector3.h:820
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

G3D::CoordinateFrame::CoordinateFrame ( )

Initializes to the identity coordinate frame.

110  :
112 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
static const Vector3 & zero()
Definition: Vector3.cpp:119
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the caller graph for this function:

G3D::CoordinateFrame::CoordinateFrame ( const Point3 _translation)
inline
99  :
100  rotation(Matrix3::identity()), translation(_translation) {
101  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Point3 translation
Definition: CoordinateFrame.h:66
G3D::CoordinateFrame::CoordinateFrame ( const Matrix3 rotation,
const Point3 translation 
)
inline
103  :
105  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Point3 translation
Definition: CoordinateFrame.h:66
G3D::CoordinateFrame::CoordinateFrame ( const Matrix3 rotation)
inline
107  :
109  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
static const Vector3 & zero()
Definition: Vector3.cpp:119
Point3 translation
Definition: CoordinateFrame.h:66
G3D::CoordinateFrame::CoordinateFrame ( const class UprightFrame f)
105  {
106  *this = f.toCoordinateFrame();
107 }

+ Here is the call graph for this function:

G3D::CoordinateFrame::CoordinateFrame ( class BinaryInput b)
340  : rotation(Matrix3::zero()) {
341  deserialize(b);
342 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
void deserialize(class BinaryInput &b)
Definition: CoordinateFrame.cpp:345
static const Matrix3 & zero()
Definition: Matrix3.cpp:65

+ Here is the call graph for this function:

G3D::CoordinateFrame::CoordinateFrame ( const CoordinateFrame other)
inline
130  :
131  rotation(other.rotation), translation(other.translation) {}
Matrix3 rotation
Definition: CoordinateFrame.h:63
Point3 translation
Definition: CoordinateFrame.h:66
G3D::CoordinateFrame::~CoordinateFrame ( )
inline
143 {}

Member Function Documentation

void G3D::CoordinateFrame::deserialize ( class BinaryInput b)
345  {
348 }
void deserialize(class BinaryInput &b)
Definition: Matrix3.cpp:182
Matrix3 rotation
Definition: CoordinateFrame.h:63
void deserialize(class BinaryInput &b)
Definition: Vector3.cpp:190
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CoordinateFrame G3D::CoordinateFrame::fromXYZYPRDegrees ( float  x,
float  y,
float  z,
float  yaw = 0.0f,
float  pitch = 0.0f,
float  roll = 0.0f 
)
static

Construct a coordinate frame from translation = (x,y,z) and rotations (in that order) about Y, object space X, object space Z. Note that because object-space axes are used, these are not equivalent to Euler angles; they are known as Tait-Bryan rotations and are more convenient for intuitive positioning.

143  {
144  return fromXYZYPRRadians(x, y, z, toRadians(yaw), toRadians(pitch), toRadians(roll));
145 }
double toRadians(double deg)
Definition: g3dmath.h:798
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
static CoordinateFrame fromXYZYPRRadians(float x, float y, float z, float yaw=0.0f, float pitch=0.0f, float roll=0.0f)
Definition: CoordinateFrame.cpp:114
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CoordinateFrame G3D::CoordinateFrame::fromXYZYPRRadians ( float  x,
float  y,
float  z,
float  yaw = 0.0f,
float  pitch = 0.0f,
float  roll = 0.0f 
)
static
115  {
116  const Matrix3& rotation = Matrix3::fromEulerAnglesYXZ(yaw, pitch, roll);
117  const Vector3 translation(x, y, z);
118 
119  return CoordinateFrame(rotation, translation);
120 }
static Matrix3 fromEulerAnglesYXZ(float fYAngle, float fPAngle, float fRAngle)
Definition: Matrix3.cpp:1598
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::CoordinateFrame::fuzzyEq ( const CoordinateFrame other) const
153  {
154 
155  for (int c = 0; c < 3; ++c) {
156  for (int r = 0; r < 3; ++r) {
157  if (! G3D::fuzzyEq(other.rotation[r][c], rotation[r][c])) {
158  return false;
159  }
160  }
161  if (! G3D::fuzzyEq(translation[c], other.translation[c])) {
162  return false;
163  }
164  }
165 
166  return true;
167 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

bool G3D::CoordinateFrame::fuzzyIsIdentity ( ) const
170  {
171  const Matrix3& I = Matrix3::identity();
172 
173  for (int c = 0; c < 3; ++c) {
174  for (int r = 0; r < 3; ++r) {
175  if (fuzzyNe(I[r][c], rotation[r][c])) {
176  return false;
177  }
178  }
179  if (fuzzyNe(translation[c], 0)) {
180  return false;
181  }
182  }
183 
184  return true;
185 }
#define I(x, y, z)
Matrix3 rotation
Definition: CoordinateFrame.h:63
bool fuzzyNe(double a, double b)
Definition: g3dmath.h:861
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

float G3D::CoordinateFrame::getHeading ( ) const
inline

Returns the heading of the lookVector as an angle in radians relative to the world -z axis. That is, a counter-clockwise heading where north (-z) is 0 and west (-x) is PI/2.

Note that the heading ignores the Y axis, so an inverted object has an inverted heading.

166  {
167  Vector3 look = rotation.column(2);
168  float angle = -(float) atan2(-look.x, look.z);
169  return angle;
170  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 column(int c) const
Definition: Matrix3.cpp:203

+ Here is the call graph for this function:

void G3D::CoordinateFrame::getXYZYPRDegrees ( float &  x,
float &  y,
float &  z,
float &  yaw,
float &  pitch,
float &  roll 
) const
134  {
135  getXYZYPRRadians(x, y, z, yaw, pitch, roll);
136  yaw = toDegrees(yaw);
137  pitch = toDegrees(pitch);
138  roll = toDegrees(roll);
139 }
void getXYZYPRRadians(float &x, float &y, float &z, float &yaw, float &pitch, float &roll) const
Definition: CoordinateFrame.cpp:123
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
double toDegrees(double rad)
Definition: g3dmath.h:802
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::getXYZYPRRadians ( float &  x,
float &  y,
float &  z,
float &  yaw,
float &  pitch,
float &  roll 
) const
124  {
125  x = translation.x;
126  y = translation.y;
127  z = translation.z;
128 
129  rotation.toEulerAnglesYXZ(yaw, pitch, roll);
130 }
float x
Definition: Vector3.h:62
Matrix3 rotation
Definition: CoordinateFrame.h:63
float y
Definition: Vector3.h:62
G3D::int16 z
Definition: Vector3int16.h:46
bool toEulerAnglesYXZ(float &rfYAngle, float &rfPAngle, float &rfRAngle) const
Definition: Matrix3.cpp:1441
G3D::int16 y
Definition: Vector2int16.h:38
float z
Definition: Vector3.h:62
G3D::int16 x
Definition: Vector2int16.h:37
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CoordinateFrame G3D::CoordinateFrame::inverse ( ) const
inline

Computes the inverse of this coordinate frame.

136  {
137  CoordinateFrame out;
138  out.rotation = rotation.transpose();
139  out.translation = -out.rotation * translation;
140  return out;
141  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
static void transpose(const Matrix3 &A, Matrix3 &out)
Definition: Matrix3.h:233
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::CoordinateFrame::isIdentity ( ) const
188  {
189  return
190  (translation == Vector3::zero()) &&
192 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
static const Vector3 & zero()
Definition: Vector3.cpp:119
static const Matrix3 & identity()
Definition: Matrix3.cpp:70
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::leftVector ( ) const
inline

If a viewer looks along the look vector, this is the viewer's "left". Useful for strafing motions and building alternative coordinate frames.

336  {
337  return -rotation.column(0);
338  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 column(int c) const
Definition: Matrix3.cpp:203

+ Here is the call graph for this function:

CoordinateFrame G3D::CoordinateFrame::lerp ( const CoordinateFrame other,
float  alpha 
) const

Linearly interpolates between two coordinate frames, using Quat::slerp for the rotations.

See also
moveTowards
421  {
422 
423  if (alpha == 1.0f) {
424  return other;
425  } else if (alpha == 0.0f) {
426  return *this;
427  } else {
428  const Quat q1(this->rotation);
429  const Quat q2(other.rotation);
430 
431  return CoordinateFrame(
432  q1.slerp(q2, alpha).toRotationMatrix(),
433  translation * (1 - alpha) + other.translation * alpha);
434  }
435 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

void G3D::CoordinateFrame::lookAt ( const Point3 target)
377  {
378  lookAt(target, Vector3::unitY());
379 }
static const Vector3 & unitY()
Definition: Vector3.cpp:122
void lookAt(const Point3 &target)
Definition: CoordinateFrame.cpp:377

+ Here is the call graph for this function:

void G3D::CoordinateFrame::lookAt ( const Point3 target,
Vector3  up 
)
384  {
385 
386  up = up.direction();
387 
388  Vector3 look = (target - translation).direction();
389  if (fabs(look.dot(up)) > .99f) {
390  up = Vector3::unitX();
391  if (fabs(look.dot(up)) > .99f) {
392  up = Vector3::unitY();
393  }
394  }
395 
396  up -= look * look.dot(up);
397  up = up.direction();
398 
399  Vector3 z = -look;
400  Vector3 x = -z.cross(up);
401  x = x.direction();
402 
403  Vector3 y = z.cross(x);
404 
405  rotation.setColumn(0, x);
406  rotation.setColumn(1, y);
407  rotation.setColumn(2, z);
408 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
static const Vector3 & unitX()
Definition: Vector3.cpp:121
void setColumn(int iCol, const Vector3 &vector)
Definition: Matrix3.cpp:216
static const Vector3 & unitY()
Definition: Vector3.cpp:122
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

Ray G3D::CoordinateFrame::lookRay ( ) const

Returns the ray starting at the camera origin travelling in direction CoordinateFrame::lookVector.

148  {
150 }
static Ray fromOriginAndDirection(const Point3 &point, const Vector3 &direction)
Definition: Ray.h:87
Vector3 lookVector() const
Definition: CoordinateFrame.h:316
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::lookVector ( ) const
inline

The direction this camera is looking (its negative z axis)

316  {
317  return -rotation.column(2);
318  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 column(int c) const
Definition: Matrix3.cpp:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::moveTowards ( const CoordinateFrame goal,
float  maxTranslation,
float  maxRotation 
)

Transform this coordinate frame towards goal, but not past it, goverened by maximum rotation and translations. This is a useful alternative to lerp, especially if the goal is expected to change every transformation step so that constant start and end positions will not be available.

Parameters
goalStep from this towards goal
maxTranslationMeters
maxRotationRadians
See also
lerp
411  {
412  translation.moveTowards(goal.translation, maxTranslation);
413  Quat q(rotation);
414  q.moveTowards(Quat(goal.rotation), maxRotation);
415  rotation = Matrix3(q);
416 }
void moveTowards(const Vector3 &goal, float maxTranslation)
Definition: Vector3.cpp:42
Matrix3 rotation
Definition: CoordinateFrame.h:63
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::normalToObjectSpace ( const Vector3 v) const
inline
237  {
238  // Multiply on the left (same as rotation.transpose() * v)
239  return v * rotation;
240  }
Matrix3 rotation
Definition: CoordinateFrame.h:63

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::normalToObjectSpace ( const Array< Vector3 > &  v,
Array< Vector3 > &  vout 
) const
474  {
475  vout.resize(v.size());
476 
477  for (int i = v.size() - 1; i >= 0; --i) {
478  vout[i] = normalToObjectSpace(v[i]);
479  }
480 }
Vector3 normalToObjectSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:237

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::normalToWorldSpace ( const Vector3 v) const
inline
219  {
220  return rotation * v;
221  }
Matrix3 rotation
Definition: CoordinateFrame.h:63

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::normalToWorldSpace ( const Array< Vector3 > &  v,
Array< Vector3 > &  vout 
) const
447  {
448  vout.resize(v.size());
449 
450  for (int i = 0; i < v.size(); ++i) {
451  vout[i] = normalToWorldSpace(v[i]);
452  }
453 }
Vector3 normalToWorldSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:219

+ Here is the call graph for this function:

bool G3D::CoordinateFrame::operator!= ( const CoordinateFrame other) const
inline
84  {
85  return !(*this == other);
86  }
CoordinateFrame G3D::CoordinateFrame::operator* ( const CoordinateFrame other) const
inline

Compose: create the transformation that is other followed by this.

281  {
282  return CoordinateFrame(rotation * other.rotation,
283  pointToWorldSpace(other.translation));
284  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
Point3 pointToWorldSpace(const Point3 &v) const
Definition: CoordinateFrame.h:191

+ Here is the call graph for this function:

CoordinateFrame G3D::CoordinateFrame::operator+ ( const Vector3 v) const
inline
286  {
287  return CoordinateFrame(rotation, translation + v);
288  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

CoordinateFrame G3D::CoordinateFrame::operator- ( const Vector3 v) const
inline
290  {
291  return CoordinateFrame(rotation, translation - v);
292  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
CoordinateFrame()
Definition: CoordinateFrame.cpp:110
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

bool G3D::CoordinateFrame::operator== ( const CoordinateFrame other) const
inline
80  {
81  return (translation == other.translation) && (rotation == other.rotation);
82  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Point3 translation
Definition: CoordinateFrame.h:66
Point3 G3D::CoordinateFrame::pointToObjectSpace ( const Point3 v) const
inline

Transforms the point into object space. Assumes that the rotation matrix is orthonormal.

201  {
202  float p[3];
203  p[0] = v[0] - translation[0];
204  p[1] = v[1] - translation[1];
205  p[2] = v[2] - translation[2];
206  debugAssert(G3D::fuzzyEq(fabsf(rotation.determinant()), 1.0f));
207  return Point3(rotation[0][0] * p[0] + rotation[1][0] * p[1] + rotation[2][0] * p[2],
208  rotation[0][1] * p[0] + rotation[1][1] * p[1] + rotation[2][1] * p[2],
209  rotation[0][2] * p[0] + rotation[1][2] * p[1] + rotation[2][2] * p[2]);
210  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
#define debugAssert(exp)
Definition: debugAssert.h:160
Vector3 Point3
Definition: Vector3.h:820
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857
float determinant() const
Definition: Matrix3.cpp:453
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::pointToObjectSpace ( const Array< Point3 > &  v,
Array< Point3 > &  vout 
) const
465  {
466  vout.resize(v.size());
467 
468  for (int i = v.size() - 1; i >= 0; --i) {
469  vout[i] = pointToObjectSpace(v[i]);
470  }
471 }
Point3 pointToObjectSpace(const Point3 &v) const
Definition: CoordinateFrame.h:201

+ Here is the call graph for this function:

Point3 G3D::CoordinateFrame::pointToWorldSpace ( const Point3 v) const
inline

Transforms the point into world space.

191  {
192  return Point3
193  (rotation[0][0] * v[0] + rotation[0][1] * v[1] + rotation[0][2] * v[2] + translation[0],
194  rotation[1][0] * v[0] + rotation[1][1] * v[1] + rotation[1][2] * v[2] + translation[1],
195  rotation[2][0] * v[0] + rotation[2][1] * v[1] + rotation[2][2] * v[2] + translation[2]);
196  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 Point3
Definition: Vector3.h:820
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::pointToWorldSpace ( const Array< Point3 > &  v,
Array< Point3 > &  vout 
) const
438  {
439  vout.resize(v.size());
440 
441  for (int i = 0; i < v.size(); ++i) {
442  vout[i] = pointToWorldSpace(v[i]);
443  }
444 }
Point3 pointToWorldSpace(const Point3 &v) const
Definition: CoordinateFrame.h:191

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::rightVector ( ) const
inline
328  {
329  return rotation.column(0);
330  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 column(int c) const
Definition: Matrix3.cpp:203

+ Here is the call graph for this function:

void G3D::CoordinateFrame::serialize ( class BinaryOutput b) const
351  {
352  rotation.serialize(b);
354 }
Matrix3 rotation
Definition: CoordinateFrame.h:63
void serialize(class BinaryOutput &b) const
Definition: Vector3.cpp:219
void serialize(class BinaryOutput &b) const
Definition: Matrix3.cpp:192
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

Any G3D::CoordinateFrame::toAny ( ) const

Converts the CFrame to an Any.

87  {
88  float x, y, z, yaw, pitch, roll;
89  getXYZYPRDegrees(x, y, z, yaw, pitch, roll);
90  Any a(Any::ARRAY, "CFrame::fromXYZYPRDegrees");
91  a.append(x, y, z);
92  if ( ! G3D::fuzzyEq(yaw, 0.0f) || ! G3D::fuzzyEq(pitch, 0.0f) || ! G3D::fuzzyEq(roll, 0.0f)) {
93  a.append(yaw);
94  if (! G3D::fuzzyEq(pitch, 0.0f) || ! G3D::fuzzyEq(roll, 0.0f)) {
95  a.append(pitch);
96  if (! G3D::fuzzyEq(roll, 0.0f)) {
97  a.append(roll);
98  }
99  }
100  }
101  return a;
102 }
Definition: Any.h:187
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
G3D::int16 x
Definition: Vector2int16.h:37
void getXYZYPRDegrees(float &x, float &y, float &z, float &yaw, float &pitch, float &roll) const
Definition: CoordinateFrame.cpp:133
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Matrix4 G3D::CoordinateFrame::toMatrix4 ( ) const

See also Matrix4::approxCoordinateFrame

195  {
196  return Matrix4(*this);
197 }
CoordinateFrame G3D::CoordinateFrame::toObjectSpace ( const CoordinateFrame c) const
inline

Takes the coordinate frame into object space. this->inverse() * c

176  {
177  return this->inverse() * c;
178  }
CoordinateFrame inverse() const
Definition: CoordinateFrame.h:136

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector4 G3D::CoordinateFrame::toObjectSpace ( const Vector4 v) const
inline
180  {
181  return this->inverse().toWorldSpace(v);
182  }
CoordinateFrame inverse() const
Definition: CoordinateFrame.h:136
Vector4 toWorldSpace(const Vector4 &v) const
Definition: CoordinateFrame.h:184

+ Here is the call graph for this function:

Ray G3D::CoordinateFrame::toObjectSpace ( const Ray r) const
372  {
373  return Ray::fromOriginAndDirection(pointToObjectSpace(r.origin()), vectorToObjectSpace(r.direction()));
374 }
static Ray fromOriginAndDirection(const Point3 &point, const Vector3 &direction)
Definition: Ray.h:87
Vector3 vectorToObjectSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:232
Point3 pointToObjectSpace(const Point3 &v) const
Definition: CoordinateFrame.h:201

+ Here is the call graph for this function:

Box G3D::CoordinateFrame::toObjectSpace ( const AABox b) const
335  {
336  return toObjectSpace(Box(b));
337 }
CoordinateFrame toObjectSpace(const CoordinateFrame &c) const
Definition: CoordinateFrame.h:176

+ Here is the call graph for this function:

Plane G3D::CoordinateFrame::toObjectSpace ( const Plane p) const
210  {
211  // TODO
212  Vector3 N, P;
213  double d;
214  p.getEquation(N, d);
215  P = N * (float)d;
216  P = pointToObjectSpace(P);
217  N = normalToObjectSpace(N);
218  debugAssertM(isFinite(d), "Not implemented for infinite planes");
219  return Plane(N, P);
220 }
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
Vector3 normalToObjectSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:237
uint8 const P[]
Definition: AuthenticationPackets.cpp:225
bool isFinite(double x)
Definition: g3dmath.h:525
Point3 pointToObjectSpace(const Point3 &v) const
Definition: CoordinateFrame.h:201

+ Here is the call graph for this function:

Box G3D::CoordinateFrame::toObjectSpace ( const Box b) const
330  {
331  return inverse().toWorldSpace(b);
332 }
CoordinateFrame inverse() const
Definition: CoordinateFrame.h:136
Vector4 toWorldSpace(const Vector4 &v) const
Definition: CoordinateFrame.h:184

+ Here is the call graph for this function:

Sphere G3D::CoordinateFrame::toObjectSpace ( const Sphere b) const
362  {
363  return Sphere(pointToObjectSpace(b.center), b.radius);
364 }
Point3 pointToObjectSpace(const Point3 &v) const
Definition: CoordinateFrame.h:201

+ Here is the call graph for this function:

Triangle G3D::CoordinateFrame::toObjectSpace ( const Triangle t) const
263  {
264  return Triangle(pointToObjectSpace(t.vertex(0)),
265  pointToObjectSpace(t.vertex(1)),
266  pointToObjectSpace(t.vertex(2)));
267 }
Point3 pointToObjectSpace(const Point3 &v) const
Definition: CoordinateFrame.h:201

+ Here is the call graph for this function:

Vector4 G3D::CoordinateFrame::toWorldSpace ( const Vector4 v) const
inline
184  {
185  return Vector4(rotation * Vector3(v.x, v.y, v.z) + translation * v.w, v.w);
186  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the caller graph for this function:

Ray G3D::CoordinateFrame::toWorldSpace ( const Ray r) const
367  {
368  return Ray::fromOriginAndDirection(pointToWorldSpace(r.origin()), vectorToWorldSpace(r.direction()));
369 }
static Ray fromOriginAndDirection(const Point3 &point, const Vector3 &direction)
Definition: Ray.h:87
Vector3 vectorToWorldSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:215
Point3 pointToWorldSpace(const Point3 &v) const
Definition: CoordinateFrame.h:191

+ Here is the call graph for this function:

Frustum G3D::CoordinateFrame::toWorldSpace ( const Frustum f) const
223  {
224  Frustum g;
225  g.vertexPos.resize(f.vertexPos.size());
226  g.faceArray.resize(f.faceArray.size());
227 
228  for (int i = 0; i < f.vertexPos.size(); ++i) {
229  g.vertexPos[i] = toWorldSpace(f.vertexPos[i]);
230  }
231  for (int i = 0; i < f.faceArray.size(); ++i) {
232  g.faceArray[i].plane = toWorldSpace(f.faceArray[i].plane);
233  for (int j = 0; j < 4; ++j) {
234  g.faceArray[i].vertexIndex[j] = f.faceArray[i].vertexIndex[j];
235  }
236  }
237 
238  return g;
239 }
Vector4 toWorldSpace(const Vector4 &v) const
Definition: CoordinateFrame.h:184

+ Here is the call graph for this function:

class Box G3D::CoordinateFrame::toWorldSpace ( const class Box b) const
class Cylinder G3D::CoordinateFrame::toWorldSpace ( const class Cylinder b) const
class Box G3D::CoordinateFrame::toWorldSpace ( const class AABox b) const
void G3D::CoordinateFrame::toWorldSpace ( const class AABox b,
class AABox result 
) const
class Capsule G3D::CoordinateFrame::toWorldSpace ( const class Capsule b) const
class Triangle G3D::CoordinateFrame::toWorldSpace ( const class Triangle t) const
class Sphere G3D::CoordinateFrame::toWorldSpace ( const class Sphere b) const
class Plane G3D::CoordinateFrame::toWorldSpace ( const class Plane p) const
std::string G3D::CoordinateFrame::toXML ( ) const

Produces an XML serialization of this coordinate frame.

Deprecated:
200  {
201  return G3D::format(
202  "<COORDINATEFRAME>\n %lf,%lf,%lf,%lf,\n %lf,%lf,%lf,%lf,\n %lf,%lf,%lf,%lf,\n %lf,%lf,%lf,%lf\n</COORDINATEFRAME>\n",
203  rotation[0][0], rotation[0][1], rotation[0][2], translation.x,
204  rotation[1][0], rotation[1][1], rotation[1][2], translation.y,
205  rotation[2][0], rotation[2][1], rotation[2][2], translation.z,
206  0.0, 0.0, 0.0, 1.0);
207 }
float x
Definition: Vector3.h:62
Matrix3 rotation
Definition: CoordinateFrame.h:63
float y
Definition: Vector3.h:62
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
float z
Definition: Vector3.h:62
Point3 translation
Definition: CoordinateFrame.h:66

+ Here is the call graph for this function:

std::string G3D::CoordinateFrame::toXYZYPRDegreesString ( ) const
36  {
37  float x,y,z,yaw,pitch,roll;
38  getXYZYPRDegrees(x,y,z,yaw,pitch,roll);
39 
40  return format("CFrame::fromXYZYPRDegrees(% 5.1ff, % 5.1ff, % 5.1ff, % 5.1ff, % 5.1ff, % 5.1ff)",
41  x,y,z,yaw,pitch,roll);
42 }
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
G3D::int16 x
Definition: Vector2int16.h:37
void getXYZYPRDegrees(float &x, float &y, float &z, float &yaw, float &pitch, float &roll) const
Definition: CoordinateFrame.cpp:133

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::upVector ( ) const
inline

Up direction for this camera (its y axis).

324  {
325  return rotation.column(1);
326  }
Matrix3 rotation
Definition: CoordinateFrame.h:63
Vector3 column(int c) const
Definition: Matrix3.cpp:203

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::vectorToObjectSpace ( const Vector3 v) const
inline

Transforms the vector into object space (no translation).

232  {
233  // Multiply on the left (same as rotation.transpose() * v)
234  return v * rotation;
235  }
Matrix3 rotation
Definition: CoordinateFrame.h:63

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::vectorToObjectSpace ( const Array< Vector3 > &  v,
Array< Vector3 > &  vout 
) const
483  {
484  vout.resize(v.size());
485 
486  for (int i = v.size() - 1; i >= 0; --i) {
487  vout[i] = vectorToObjectSpace(v[i]);
488  }
489 }
Vector3 vectorToObjectSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:232

+ Here is the call graph for this function:

Vector3 G3D::CoordinateFrame::vectorToWorldSpace ( const Vector3 v) const
inline

Transforms the vector into world space (no translation).

215  {
216  return rotation * v;
217  }
Matrix3 rotation
Definition: CoordinateFrame.h:63

+ Here is the caller graph for this function:

void G3D::CoordinateFrame::vectorToWorldSpace ( const Array< Vector3 > &  v,
Array< Vector3 > &  vout 
) const
456  {
457  vout.resize(v.size());
458 
459  for (int i = v.size() - 1; i >= 0; --i) {
460  vout[i] = vectorToWorldSpace(v[i]);
461  }
462 }
Vector3 vectorToWorldSpace(const Vector3 &v) const
Definition: CoordinateFrame.h:215

+ Here is the call graph for this function:

Member Data Documentation

Matrix3 G3D::CoordinateFrame::rotation

Takes object space points to world space.

Point3 G3D::CoordinateFrame::translation

The origin of this coordinate frame in world space (or its parent's space, if nested).


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