moved files around

This commit is contained in:
ejcoumans
2006-05-25 19:18:29 +00:00
commit e061ec1ebf
1024 changed files with 349445 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMArray.h
The file contains the vector class, which improves on the standard C++ vector class.
*/
/**
A dynamically-sized array.
Built on top of the standard C++ vector class, this class improves on the interface
by adding the following functionality:
- constructor that takes in a constant-sized array.
- comparison which a constant-sized array.
@ingroup FMath
*/
template <class T>
class FCOLLADA_EXPORT vector : public std::vector<T>
{
public:
/** Default constructor. */
vector() : std::vector<T>() {}
/** Constructor: Builds a dynamically-sized array of the wanted size.
@param size The wanted size of the array. */
vector(size_t size) : std::vector<T>(size) {}
/** Constructor: Builds a dynamically-sized array of the wanted size.
@param size The wanted size of the array
@param defaultValue The default value to use for all the entries of the array. */
vector(size_t size, const T& defaultValue) : std::vector<T>(size, defaultValue) {}
/** Copy constructor.
@param copy The dynamically-sized array to copy the values from. */
vector(const std::vector& copy) : std::vector<T>(copy) {}
/** Constructor: Builds a dynamically-sized array from a constant-sized array.
@param values A constant-sized array of floating-point values.
@param count The size of the constant-sized array. */
vector(const T* values, size_t count) : std::vector<T>()
{
resize(count);
memcpy(&at(0), values, count * sizeof(T));
}
};
/** Returns whether a dynamically-sized array is equivalent to a constant-sized array.
@param dl A dynamically-sized array.
@param cl A constant-sized array.
@param count The size of the constant-sized array.
@return Whether the two arrays are equivalent. */
template <typename T>
inline bool IsEquivalent(const vector<T>& dl, const T* cl, size_t count)
{
if (dl.size() != count) return false;
bool equivalent = true;
for (size_t i = 0; i < count && equivalent; ++i) equivalent = IsEquivalent(dl.at(i), cl[i]);
return equivalent;
}

View File

@@ -0,0 +1,74 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
#include "FMColor.h"
FMColor::FMColor(const float* components, uint32 componentCount)
{
switch (componentCount)
{
case 1:
r = (uint8) (components[0] * 255.0f);
g = 0; b = 0; a = 255;
break;
case 2:
r = (uint8) (components[0] * 255.0f);
g = (uint8) (components[1] * 255.0f);
b = 0; a = 255;
break;
case 3:
r = (uint8) (components[0] * 255.0f);
g = (uint8) (components[1] * 255.0f);
b = (uint8) (components[2] * 255.0f);
a = 255;
break;
case 4:
r = (uint8) (components[0] * 255.0f);
g = (uint8) (components[1] * 255.0f);
b = (uint8) (components[2] * 255.0f);
a = (uint8) (components[3] * 255.0f);
break;
default:
r = 0; g = 0; b = 0; a = 255;
break;
}
}
void FMColor::ToFloats(float* components, uint32 componentCount)
{
switch (componentCount)
{
case 1:
components[0] = float(r) / 255.0f;
break;
case 2:
components[0] = float(r) / 255.0f;
components[1] = float(g) / 255.0f;
break;
case 3:
components[0] = float(r) / 255.0f;
components[1] = float(g) / 255.0f;
components[2] = float(b) / 255.0f;
break;
case 4:
components[0] = float(r) / 255.0f;
components[1] = float(g) / 255.0f;
components[2] = float(b) / 255.0f;
break;
default:
for (uint32 i = 0; i < componentCount; ++i) components[i] = 0.0f;
break;
}
}

View File

@@ -0,0 +1,113 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMColor.h
The file containing the class and global functions for RBGA colors.
*/
#ifndef _FM_COLOR_H_
#define _FM_COLOR_H_
/**
A RBGA color.
Not used within FCollada.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMColor
{
public:
uint8 r; /**< The red component. */
uint8 g; /**< The green component. */
uint8 b; /**< The blue component. */
uint8 a; /**< The alpha component. */
/**
* Creates an empty FMColor.
*
* The default values are non deterministic.
*/
FMColor() {}
/**
* Creates the FMColor with the coordinates values.
*
* The first three coordinates are taken from the FMVector3, where the
* first one is the x value, the second is that y, and the third is the z.
* The forth value is the \c float specified.
*
*
* @param _r The red value.
* @param _g The green value.
* @param _b The blue value.
* @param _a The alpha value.
*/
FMColor(uint8 _r, uint8 _g, uint8 _b, uint8 _a) { r = _r; g = _g; b = _b; a = _a; }
/**
* Creates the FMColor from a color encoded into a uint32.
*
* The most significant byte makes up the red value. The second most
* significant makes up the green value, the third the blue, and the forth
* the alpha.
*
* @param hex The uint to decode the color values from.
*/
FMColor(uint32 hex) { r = uint8((hex & 0xFF000000) >> 24); g = uint8((hex & 0xFF0000) >> 16); b = uint8((hex & 0xFF00) >> 8); a = uint8(hex & 0xFF); }
/**
* Creates the FMColor from a list of \c floats.
*
* It creates the FMColor with the values specified in the \c floats, which
* range from 0.0f to 1.0f.
*
* \a componentCount is used to determined how many values to take from the
* \c float array. If there are insufficient values, then it will give the
* remaining values default values. The default values are 0 for the colors
* and 255 for the alpha. It fills in the values in this order: red, green,
* blue, alpha.
*
* @param components The \c float array to get values from.
* @param componentCount The amount of \c float to take from the array.
*/
FMColor(const float* components, uint32 componentCount);
/**
* Get this FMColor as an array of \c floats.
*
* It fills the first \a componentCount elements (max 4) of \c components
* with the red, green, blue, alpha values of this FMColor in that order.
*
* @param components The \c float array to fill.
* @param componentCount The amount of \c float to fill into the array.
*/
void ToFloats(float* components, uint32 componentCount);
/**
* Get the average of the three color values of this FMColor.
*
* @return The averages of the three colors values of this FMColor.
*/
inline uint8 ComponentAverage() { return uint8((uint32(r) + uint32(g) + uint32(b)) / 3); }
/**
* Get this FMColor as an array of uint8s.
*
* @return The \c uint8 array.
*/
operator uint8*() { return &b; }
};
/**
* Multiplication of a scalar with the FMColor.
*
* @param s The scalar to multiply by.
* @param c The FMColor to multiply with.
* @return the FMColor representing the resulting color.
*/
inline FMColor operator*(float s, const FMColor& c) { return FMColor(uint8(c.r * s), uint8(c.g * s), uint8(c.b * s), uint8(c.a * s)); }
#endif // _FM_COLOR_H_

View File

@@ -0,0 +1,46 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMFloat.h
The file containing functions and constants for floating point values.
*/
#ifdef WIN32
#include <float.h>
#endif
/** The default tolerance for double-sized floating-point comparison functions. */
#define DBL_TOLERANCE 0.0001
/** The default tolerance for single-sized floating-point comparison functions. */
#define FLT_TOLERANCE 0.0001f
/** A dynamically-sized array of double-sized floating-point values. */
typedef vector<double> DoubleList;
/** A dynamically-sized array of floating-point values. */
typedef vector<float> FloatList;
/** Returns whether two floating-point values are equivalent within a given tolerance.
@param f1 A first floating-point value.
@param f2 A second floating-point value. */
inline bool IsEquivalent(float f1, float f2) { return f1 - f2 < FLT_TOLERANCE && f2 - f1 < FLT_TOLERANCE; }
/** Returns whether two floating-point values are equivalent within a given tolerance.
@param f1 A first floating-point value.
@param f2 A second floating-point value.
@param tolerance The tolerance in which to accept the two floating-point values as equivalent. */
inline bool IsEquivalent(float f1, float f2, float tolerance) { return f1 - f2 < tolerance && f2 - f1 < tolerance; }
/** Returns whether two double-sized floating-point values are equivalent.
@param f1 A first double-sized floating-point value.
@param f2 A second double-sized floating-point value. */
inline bool IsEquivalent(double f1, double f2) { return f1 - f2 < DBL_TOLERANCE && f2 - f1 < DBL_TOLERANCE; }
/** Returns whether two double-sized floating-point values are equivalent within a given tolerance.
@param f1 A first double-sized floating-point value.
@param f2 A second double-sized floating-point value.
@param tolerance The tolerance in which to accept the two double-sized floating-point values as equivalent. */
inline bool IsEquivalent(double f1, double f2, double tolerance) { return f1 - f2 < tolerance && f2 - f1 < tolerance; }

View File

@@ -0,0 +1,37 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMInteger.h
The file containing functions and constants for integer values.
*/
/** A dynamically-sized array of 32-bit signed integer values. */
typedef vector<int32> Int32List;
/** A dynamically-sized array of 32-bit unsigned integer values. */
typedef vector<uint32> UInt32List;
/** A dynamically-sized array of 16-bit unsigned integer values. */
typedef vector<uint16> UInt16List;
/** A dynamically-sized array of 8-bit unsigned integer values. */
typedef vector<uint8> UInt8List;
/** A dynamically-sized array of 8-bit signed integer values. */
typedef vector<int8> Int8List;
/** A dynamically-sized array of boolean values. */
typedef vector<bool> BooleanList;
/** Returns whether two signed or unsigned integers are equivalent.
For integers, this function simply wraps around the operator==.
@param i1 A first integer.
@param i2 A second integer.
@return Whether the two integers are equivalent. */
inline bool IsEquivalent(int8 i1, int8 i2) { return i1 == i2; }
inline bool IsEquivalent(uint8 i1, uint8 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(int16 i1, int16 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(uint16 i1, uint16 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(int32 i1, int32 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(uint32 i1, uint32 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(int64 i1, int64 i2) { return i1 == i2; } /**< See above. */
inline bool IsEquivalent(uint64 i1, uint64 i2) { return i1 == i2; } /**< See above. */

View File

@@ -0,0 +1,9 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
#include "FMath/FMInterpolation.h"
// TODO: Move the float-float interpolations here, instead of within the animation system: va_list, anyone?

View File

@@ -0,0 +1,33 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMInterpolation.h
The file containing the enum for interpolation.
*/
#ifndef _FM_INTERPOLATION_H_
#define _FM_INTERPOLATION_H_
/**
A namespace for interpolations.
@ingroup FMath
*/
namespace FMInterpolation
{
/** The different types of interpolation. */
enum Interpolation
{
NONE = 0, /**< No interpolation. Also called step interpolation. */
LINEAR, /**< Linear interpolation. */
BEZIER, /**< Bezier interpolation. */
UNKNOWN, /**< Unknown interpolation. */
DEFAULT = NONE, /**< Default interpolation (None). */
};
};
#endif // _FM_INTERPOLATION_H_

View File

@@ -0,0 +1,118 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
static float __identity[] = { 1, 0, 0, 0, 1, 0 ,0, 0, 1 };
FMMatrix33 FMMatrix33::identity(__identity);
FMMatrix33::FMMatrix33(float* _m)
{
m[0][0] = _m[0]; m[1][0] = _m[1]; m[2][0] = _m[2];
m[0][1] = _m[3]; m[1][1] = _m[4]; m[2][1] = _m[5];
m[0][2] = _m[6]; m[1][2] = _m[7]; m[2][2] = _m[8];
}
FMMatrix33& FMMatrix33::operator=(const FMMatrix33& copy)
{
m[0][0] = copy.m[0][0]; m[0][1] = copy.m[0][1]; m[0][2] = copy.m[0][2];
m[1][0] = copy.m[1][0]; m[1][1] = copy.m[1][1]; m[1][2] = copy.m[1][2];
m[2][0] = copy.m[2][0]; m[2][1] = copy.m[2][1]; m[2][2] = copy.m[2][2];
return *this;
}
// Returns the transpose of this matrix
FMMatrix33 FMMatrix33::Transposed() const
{
FMMatrix33 mx;
mx.m[0][0] = m[0][0]; mx.m[1][0] = m[0][1]; mx.m[2][0] = m[0][2];
mx.m[0][1] = m[1][0]; mx.m[1][1] = m[1][1]; mx.m[2][1] = m[1][2];
mx.m[0][2] = m[2][0]; mx.m[1][2] = m[2][1]; mx.m[2][2] = m[2][2];
return mx;
}
FMMatrix33 FMMatrix33::RotationMatrix(float angle)
{
FMMatrix33 m(identity);
float c = cosf(angle), s = sinf(angle);
m[0][0] = c; m[1][1] = c;
m[0][1] = -s; m[1][0] = s;
return m;
}
FMMatrix33 FMMatrix33::TranslationMatrix(float tx, float ty)
{
FMMatrix33 m(identity);
m[2][0] = tx; m[2][1] = ty;
return m;
}
FMMatrix33 FMMatrix33::ScaleMatrix(float sx, float sy)
{
FMMatrix33 m(identity);
m[0][0] = sx; m[1][1] = sy;
return m;
}
// Code taken and adapted from nVidia's nv_algebra: det2x2, invert, multiply
// -----
// Calculate the determinent of a 2x2 matrix
static inline float det2x2(float a1, float a2, float b1, float b2)
{
return a1 * b2 - b1 * a2;
}
// Returns the inverse of this matrix
FMMatrix33 FMMatrix33::Inverted() const
{
FMMatrix33 b;
b.m[0][0] = det2x2(m[1][1], m[1][2], m[2][1], m[2][2]);
b.m[0][1] = -det2x2(m[0][1], m[0][2], m[2][1], m[2][2]);
b.m[0][2] = det2x2(m[0][1], m[0][2], m[1][1], m[1][2]);
b.m[1][0] = -det2x2(m[1][0], m[1][2], m[2][0], m[2][2]);
b.m[1][1] = det2x2(m[0][0], m[0][2], m[2][0], m[2][2]);
b.m[1][2] = -det2x2(m[0][0], m[0][2], m[1][0], m[1][2]);
b.m[2][0] = det2x2(m[1][0], m[1][1], m[2][0], m[2][1]);
b.m[2][1] = -det2x2(m[0][0], m[0][1], m[2][0], m[2][1]);
b.m[2][2] = det2x2(m[0][0], m[0][1], m[1][0], m[1][1]);
float det = (m[0][0] * b.m[0][0]) + (m[1][0] * b.m[0][1]) + (m[2][0] * b.m[0][2]);
// We should consider throwing an exception if det < eps.
if (IsEquivalent(det, 0.0f)) det = 0.01f;
float oodet = 1.0f / det;
b.m[0][0] *= oodet;
b.m[0][1] *= oodet;
b.m[0][2] *= oodet;
b.m[1][0] *= oodet;
b.m[1][1] *= oodet;
b.m[1][2] *= oodet;
b.m[2][0] *= oodet;
b.m[2][1] *= oodet;
b.m[2][2] *= oodet;
return b;
}
FMMatrix33 operator*(const FMMatrix33& m1, const FMMatrix33& m2)
{
FMMatrix33 mx;
mx.m[0][0] = m1.m[0][0] * m2.m[0][0] + m1.m[1][0] * m2.m[0][1] + m1.m[2][0] * m2.m[0][2];
mx.m[0][1] = m1.m[0][1] * m2.m[0][0] + m1.m[1][1] * m2.m[0][1] + m1.m[2][1] * m2.m[0][2];
mx.m[0][2] = m1.m[0][2] * m2.m[0][0] + m1.m[1][2] * m2.m[0][1] + m1.m[2][2] * m2.m[0][2];
mx.m[1][0] = m1.m[0][0] * m2.m[1][0] + m1.m[1][0] * m2.m[1][1] + m1.m[2][0] * m2.m[1][2];
mx.m[1][1] = m1.m[0][1] * m2.m[1][0] + m1.m[1][1] * m2.m[1][1] + m1.m[2][1] * m2.m[1][2];
mx.m[1][2] = m1.m[0][2] * m2.m[1][0] + m1.m[1][2] * m2.m[1][1] + m1.m[2][2] * m2.m[1][2];
mx.m[2][0] = m1.m[0][0] * m2.m[2][0] + m1.m[1][0] * m2.m[2][1] + m1.m[2][0] * m2.m[2][2];
mx.m[2][1] = m1.m[0][1] * m2.m[2][0] + m1.m[1][1] * m2.m[2][1] + m1.m[2][1] * m2.m[2][2];
mx.m[2][2] = m1.m[0][2] * m2.m[2][0] + m1.m[1][2] * m2.m[2][1] + m1.m[2][2] * m2.m[2][2];
return mx;
}

View File

@@ -0,0 +1,159 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMMatrix33.h
The file containing the class and global functions for 3x3 matrices.
*/
#ifndef _FM_MATRIX33_H_
#define _FM_MATRIX33_H_
/**
A 3x3 matrix: use to represent 2D transformations.
Not used within FCollada.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMMatrix33
{
public:
float m[3][3]; /**< The matrix elements stored in a 2D array. */
/**
* Creates a FMMatrix33 from the \c float array.
*
* The float array stores the elements in the following order: m[0][0],
* m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2].
*
* @param _m The \c float array to create the matrix from.
*/
FMMatrix33(float* _m);
/**
* Creates an empty FMMatrix33.
*
* The default values are non deterministic.
*/
#ifndef _DEBUG
FMMatrix33() {}
#else
FMMatrix33() { memset(m, 55, 3 * 3 * sizeof(float)); }
#endif
/**
* Get this FMMatrix33 as an array of \c floats.
*
* The array contains the elements in the following order: m[0][0],
* m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2].
*
* @return The \c float array.
*/
operator float*() { return &m[0][0]; }
/**
* Get this FMMatrix as an array of \c floats.
*
* The array contains the elements in the following order: m[0][0],
* m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2].
*
* @return The \c float array.
*/
operator const float*() const { return &m[0][0]; }
/**
* Get a specified row of FMMatrix33 as an array of \c floats.
*
* @param a The row index, starting at 0, of the row to get.
* @return The \c float array of the elements in the specified row.
*/
float* operator[](int a) { return m[a]; }
/**
* Assign this FMMatrix33's elements to be the same as that of the given
* FMMatrix33.
*
* @param copy The FMMatrix to copy elements from.
* @return This FMMatrix.
*/
FMMatrix33& operator=(const FMMatrix33& copy);
/**
* Gets the transposed of this FMMatrix33.
*
* @return The transposed of this FMMatrix.
*/
FMMatrix33 Transposed() const;
/**
* Gets the inversion of this FMMatrix33.
*
* @return The inversion of this FMMatrix.
*/
FMMatrix33 Inverted() const;
public:
static FMMatrix33 identity; /**< The identity FMMatrix33. */
/**
* Gets the FMMatrix33 representation of a 2D counter-clockwise rotation
* about the z-axis.
*
* @param angle The angle of rotation in radians.
* @return The rotation FMMatrix.
*/
static FMMatrix33 RotationMatrix(float angle);
/**
* Gets the FMMatrix33 representation of a 2D translation.
*
* @param tx The translation in the x direction.
* @param ty The translation in the y direction.
* @return The translation FMMatrix.
*/
static FMMatrix33 TranslationMatrix(float tx, float ty);
/**
* Gets the FMMatrix33 representation of a 2D scale.
*
* @param sx The scale factor in the x direction.
* @param sy The scale factor in the y direction.
* @return The scale FMMatrix.
*/
static FMMatrix33 ScaleMatrix(float sx, float sy);
/**
* Gets the FMMatrix33 representation of a 2D translation.
*
* The translation in the x direction is the \a u componenet of the given
* FMVector2 and the translation in the y direction is the \a v component.
*
* @param translation The FMVector2 to get the translation components from.
* @return The translation FMMatrix33.
*/
static inline FMMatrix33 TranslationMatrix(FMVector2 translation) { return TranslationMatrix(translation.u, translation.v); }
/**
* Gets the FMMatrix33 representation of a 2D scale.
*
* The scale in the x direction is the \a u componenet of the given
* FMVector and the scale in the y direction is the \a v component.
*
* @param scale The FMVector2 to get the scale components from.
* @return The scale FMMatrix33.
*/
static inline FMMatrix33 ScaleMatrix(FMVector2 scale) { return ScaleMatrix(scale.u, scale.v); }
};
/**
* Matrix multiplication with two FMMatrix33.
*
* @param m1 The first matrix.
* @param m2 The second matrix.
* @return The FMMatrix44 representation of the resulting matrix.
*/
FMMatrix33 FCOLLADA_EXPORT operator*(const FMMatrix33& m1, const FMMatrix33& m2);
#endif // _FM_MATRIX33_H_

View File

@@ -0,0 +1,251 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
#include "FMath/FMMatrix44.h"
static float __identity[] = { 1, 0, 0, 0, 0, 1, 0 ,0 ,0, 0, 1, 0, 0, 0, 0, 1 };
FMMatrix44 FMMatrix44::Identity(__identity);
FMMatrix44::FMMatrix44(const float* _m)
{
m[0][0] = _m[0]; m[1][0] = _m[1]; m[2][0] = _m[2]; m[3][0] = _m[3];
m[0][1] = _m[4]; m[1][1] = _m[5]; m[2][1] = _m[6]; m[3][1] = _m[7];
m[0][2] = _m[8]; m[1][2] = _m[9]; m[2][2] = _m[10]; m[3][2] = _m[11];
m[0][3] = _m[12]; m[1][3] = _m[13]; m[2][3] = _m[14]; m[3][3] = _m[15];
}
FMMatrix44& FMMatrix44::operator=(const FMMatrix44& copy)
{
m[0][0] = copy.m[0][0]; m[0][1] = copy.m[0][1]; m[0][2] = copy.m[0][2]; m[0][3] = copy.m[0][3];
m[1][0] = copy.m[1][0]; m[1][1] = copy.m[1][1]; m[1][2] = copy.m[1][2]; m[1][3] = copy.m[1][3];
m[2][0] = copy.m[2][0]; m[2][1] = copy.m[2][1]; m[2][2] = copy.m[2][2]; m[2][3] = copy.m[2][3];
m[3][0] = copy.m[3][0]; m[3][1] = copy.m[3][1]; m[3][2] = copy.m[3][2]; m[3][3] = copy.m[3][3];
return *this;
}
// Returns the transpose of this matrix
FMMatrix44 FMMatrix44::Transposed() const
{
FMMatrix44 mx;
mx.m[0][0] = m[0][0]; mx.m[1][0] = m[0][1]; mx.m[2][0] = m[0][2]; mx.m[3][0] = m[0][3];
mx.m[0][1] = m[1][0]; mx.m[1][1] = m[1][1]; mx.m[2][1] = m[1][2]; mx.m[3][1] = m[1][3];
mx.m[0][2] = m[2][0]; mx.m[1][2] = m[2][1]; mx.m[2][2] = m[2][2]; mx.m[3][2] = m[2][3];
mx.m[0][3] = m[3][0]; mx.m[1][3] = m[3][1]; mx.m[2][3] = m[3][2]; mx.m[3][3] = m[3][3];
return mx;
}
FMVector3 FMMatrix44::TransformCoordinate(const FMVector3& coordinate) const
{
FMVector3 out;
out.x = m[0][0] * coordinate.x + m[1][0] * coordinate.y + m[2][0] * coordinate.z + m[3][0];
out.y = m[0][1] * coordinate.x + m[1][1] * coordinate.y + m[2][1] * coordinate.z + m[3][1];
out.z = m[0][2] * coordinate.x + m[1][2] * coordinate.y + m[2][2] * coordinate.z + m[3][2];
return out;
}
FMVector3 FMMatrix44::TransformVector(const FMVector3& v) const
{
FMVector3 out;
out.x = m[0][0] * v.x + m[1][0] * v.y + m[2][0] * v.z;
out.y = m[0][1] * v.x + m[1][1] * v.y + m[2][1] * v.z;
out.z = m[0][2] * v.x + m[1][2] * v.y + m[2][2] * v.z;
return out;
}
FMVector3 FMMatrix44::GetTranslation() const
{
return FMVector3(m[3][0], m[3][1], m[3][2]);
}
static float det3x3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3);
void FMMatrix44::Decompose(FMVector3& scale, FMVector3& rotation, FMVector3& translation, float& inverted) const
{
// Assume Scale/Rotation/Translation, in this order.
scale.x = sqrtf(m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0]);
scale.y = sqrtf(m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1]);
scale.z = sqrtf(m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2]);
inverted = FMath::Sign(det3x3(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]));
// Calculate the rotation in Y first, using m[0][2], checking for out-of-bounds values
float c;
if (m[0][2] / scale.x >= 1.0f - FLT_TOLERANCE)
{
rotation.y = ((float) FMath::Pi) / -2.0f;
c = 0.0f;
}
else if (m[0][2] / scale.x <= -1.0f + FLT_TOLERANCE)
{
rotation.y = ((float) FMath::Pi) / 2.0f;
c = 0.0f;
}
else
{
rotation.y = asinf(-m[0][2] / scale.x);
c = cosf(rotation.y);
}
// Using the cosine of the Y rotation will give us the rotation in X and Z.
// Check for the infamous Gimbal Lock.
if (fabsf(c) > 0.01f)
{
float rx = m[2][2] / scale.z / c;
float ry = m[1][2] / scale.z / c;
rotation.x = atan2f(ry, rx);
rx = m[0][0] / scale.x / c;
ry = m[0][1] / scale.y / c;
rotation.z = atan2f(ry, rx);
}
else
{
rotation.z = 0;
float rx = m[1][1] / scale.y;
float ry = -m[1][0] / scale.y;
rotation.x = atan2f(ry, rx);
}
translation = GetTranslation();
}
// Code taken and adapted from nVidia's nv_algebra: det2x2, det3x3, invert, multiply
// -----
// Calculate the determinant of a 2x2 matrix
static float det2x2(float a1, float a2, float b1, float b2)
{
return a1 * b2 - b1 * a2;
}
// Calculate the determinent of a 3x3 matrix
static float det3x3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3)
{
return a1 * det2x2(b2, b3, c2, c3) - b1 * det2x2(a2, a3, c2, c3) + c1 * det2x2(a2, a3, b2, b3);
}
// Returns the inverse of this matrix
FMMatrix44 FMMatrix44::Inverted() const
{
FMMatrix44 b;
b.m[0][0] = det3x3(m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]);
b.m[0][1] = -det3x3(m[0][1], m[0][2], m[0][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]);
b.m[0][2] = det3x3(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[3][1], m[3][2], m[3][3]);
b.m[0][3] = -det3x3(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3]);
b.m[1][0] = -det3x3(m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]);
b.m[1][1] = det3x3(m[0][0], m[0][2], m[0][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]);
b.m[1][2] = -det3x3(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[3][0], m[3][2], m[3][3]);
b.m[1][3] = det3x3(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3]);
b.m[2][0] = det3x3(m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]);
b.m[2][1] = -det3x3(m[0][0], m[0][1], m[0][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]);
b.m[2][2] = det3x3(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
b.m[2][3] = -det3x3(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3]);
b.m[3][0] = -det3x3(m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]);
b.m[3][1] = det3x3(m[0][0], m[0][1], m[0][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]);
b.m[3][2] = -det3x3(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[3][0], m[3][1], m[3][2]);
b.m[3][3] = det3x3(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]);
float det = (m[0][0] * b.m[0][0]) + (m[1][0] * b.m[0][1]) + (m[2][0] * b.m[0][2]) + (m[3][0] * b.m[0][3]);
if (IsEquivalent(det, 0.0f)) det = 0.01f;
float oodet = 1.0f / det;
b.m[0][0] *= oodet;
b.m[0][1] *= oodet;
b.m[0][2] *= oodet;
b.m[0][3] *= oodet;
b.m[1][0] *= oodet;
b.m[1][1] *= oodet;
b.m[1][2] *= oodet;
b.m[1][3] *= oodet;
b.m[2][0] *= oodet;
b.m[2][1] *= oodet;
b.m[2][2] *= oodet;
b.m[2][3] *= oodet;
b.m[3][0] *= oodet;
b.m[3][1] *= oodet;
b.m[3][2] *= oodet;
b.m[3][3] *= oodet;
return b;
}
FMMatrix44 operator*(const FMMatrix44& m1, const FMMatrix44& m2)
{
FMMatrix44 mx;
mx.m[0][0] = m1.m[0][0] * m2.m[0][0] + m1.m[1][0] * m2.m[0][1] + m1.m[2][0] * m2.m[0][2] + m1.m[3][0] * m2.m[0][3];
mx.m[0][1] = m1.m[0][1] * m2.m[0][0] + m1.m[1][1] * m2.m[0][1] + m1.m[2][1] * m2.m[0][2] + m1.m[3][1] * m2.m[0][3];
mx.m[0][2] = m1.m[0][2] * m2.m[0][0] + m1.m[1][2] * m2.m[0][1] + m1.m[2][2] * m2.m[0][2] + m1.m[3][2] * m2.m[0][3];
mx.m[0][3] = m1.m[0][3] * m2.m[0][0] + m1.m[1][3] * m2.m[0][1] + m1.m[2][3] * m2.m[0][2] + m1.m[3][3] * m2.m[0][3];
mx.m[1][0] = m1.m[0][0] * m2.m[1][0] + m1.m[1][0] * m2.m[1][1] + m1.m[2][0] * m2.m[1][2] + m1.m[3][0] * m2.m[1][3];
mx.m[1][1] = m1.m[0][1] * m2.m[1][0] + m1.m[1][1] * m2.m[1][1] + m1.m[2][1] * m2.m[1][2] + m1.m[3][1] * m2.m[1][3];
mx.m[1][2] = m1.m[0][2] * m2.m[1][0] + m1.m[1][2] * m2.m[1][1] + m1.m[2][2] * m2.m[1][2] + m1.m[3][2] * m2.m[1][3];
mx.m[1][3] = m1.m[0][3] * m2.m[1][0] + m1.m[1][3] * m2.m[1][1] + m1.m[2][3] * m2.m[1][2] + m1.m[3][3] * m2.m[1][3];
mx.m[2][0] = m1.m[0][0] * m2.m[2][0] + m1.m[1][0] * m2.m[2][1] + m1.m[2][0] * m2.m[2][2] + m1.m[3][0] * m2.m[2][3];
mx.m[2][1] = m1.m[0][1] * m2.m[2][0] + m1.m[1][1] * m2.m[2][1] + m1.m[2][1] * m2.m[2][2] + m1.m[3][1] * m2.m[2][3];
mx.m[2][2] = m1.m[0][2] * m2.m[2][0] + m1.m[1][2] * m2.m[2][1] + m1.m[2][2] * m2.m[2][2] + m1.m[3][2] * m2.m[2][3];
mx.m[2][3] = m1.m[0][3] * m2.m[2][0] + m1.m[1][3] * m2.m[2][1] + m1.m[2][3] * m2.m[2][2] + m1.m[3][3] * m2.m[2][3];
mx.m[3][0] = m1.m[0][0] * m2.m[3][0] + m1.m[1][0] * m2.m[3][1] + m1.m[2][0] * m2.m[3][2] + m1.m[3][0] * m2.m[3][3];
mx.m[3][1] = m1.m[0][1] * m2.m[3][0] + m1.m[1][1] * m2.m[3][1] + m1.m[2][1] * m2.m[3][2] + m1.m[3][1] * m2.m[3][3];
mx.m[3][2] = m1.m[0][2] * m2.m[3][0] + m1.m[1][2] * m2.m[3][1] + m1.m[2][2] * m2.m[3][2] + m1.m[3][2] * m2.m[3][3];
mx.m[3][3] = m1.m[0][3] * m2.m[3][0] + m1.m[1][3] * m2.m[3][1] + m1.m[2][3] * m2.m[3][2] + m1.m[3][3] * m2.m[3][3];
return mx;
}
FMMatrix44 FMMatrix44::TranslationMatrix(const FMVector3& translation)
{
FMMatrix44 matrix;
matrix[0][0] = 1.0f; matrix[0][1] = 0.0f; matrix[0][2] = 0.0f; matrix[0][3] = 0.0f;
matrix[1][0] = 0.0f; matrix[1][1] = 1.0f; matrix[1][2] = 0.0f; matrix[1][3] = 0.0f;
matrix[2][0] = 0.0f; matrix[2][1] = 0.0f; matrix[2][2] = 1.0f; matrix[2][3] = 0.0f;
matrix[3][0] = translation.x; matrix[3][1] = translation.y; matrix[3][2] = translation.z; matrix[3][3] = 1.0f;
return matrix;
}
FMMatrix44 FMMatrix44::AxisRotationMatrix(const FMVector3& axis, float angle)
{
// Formulae comes from http://www.mines.edu/~gmurray/ArbitraryAxisRotation/ArbitraryAxisRotation.html
FMMatrix44 matrix;
FMVector3 a = (IsEquivalent(axis.LengthSquared(), 1.0f)) ? axis : axis.Normalize();
float xSq = a.x * a.x;
float ySq = a.y * a.y;
float zSq = a.z * a.z;
float cT = cosf(angle);
float sT = sinf(angle);
matrix[0][0] = xSq + (ySq + zSq) * cT;
matrix[0][1] = a.x * a.y * (1.0f - cT) + a.z * sT;
matrix[0][2] = a.x * a.z * (1.0f - cT) - a.y * sT;
matrix[0][3] = 0;
matrix[1][0] = a.x * a.y * (1.0f - cT) - a.z * sT;
matrix[1][1] = ySq + (xSq + zSq) * cT;
matrix[1][2] = a.y * a.z * (1.0f - cT) + a.x * sT;
matrix[1][3] = 0;
matrix[2][0] = a.x * a.z * (1.0f - cT) + a.y * sT;
matrix[2][1] = a.y * a.z * (1.0f - cT) - a.x * sT;
matrix[2][2] = zSq + (xSq + ySq) * cT;
matrix[2][3] = 0;
matrix[3][2] = matrix[3][1] = matrix[3][0] = 0;
matrix[3][3] = 1;
return matrix;
}
bool IsEquivalent(const FMMatrix44& m1, const FMMatrix44& m2)
{
return IsEquivalent(m1.m[0][0], m2.m[0][0]) && IsEquivalent(m1.m[1][0], m2.m[1][0])
&& IsEquivalent(m1.m[2][0], m2.m[2][0]) && IsEquivalent(m1.m[3][0], m2.m[3][0])
&& IsEquivalent(m1.m[0][1], m2.m[0][1]) && IsEquivalent(m1.m[1][1], m2.m[1][1])
&& IsEquivalent(m1.m[2][1], m2.m[2][1]) && IsEquivalent(m1.m[3][1], m2.m[3][1])
&& IsEquivalent(m1.m[0][2], m2.m[0][2]) && IsEquivalent(m1.m[1][2], m2.m[1][2])
&& IsEquivalent(m1.m[2][2], m2.m[2][2]) && IsEquivalent(m1.m[3][2], m2.m[3][2])
&& IsEquivalent(m1.m[0][3], m2.m[0][3]) && IsEquivalent(m1.m[1][3], m2.m[1][3])
&& IsEquivalent(m1.m[2][3], m2.m[2][3]) && IsEquivalent(m1.m[3][3], m2.m[3][3]);
}

View File

@@ -0,0 +1,195 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMMatrix44.h
The file containing the class and global functions for 4x4 matrices.
*/
#ifndef _FM_MATRIX44_H_
#define _FM_MATRIX44_H_
/**
A 4x4 matrix: use to represent 3D transformations.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMMatrix44
{
public:
float m[4][4]; /**< The matrix elements stored in a 2D array. */
/**
* Creates a FMMatrix44 from the \c float array.
*
* The float array stores the elements in the following order: m[0][0],
* m[1][0], m[2][0], m[3][0], m[0][1], m[1][1], m[2][1], m[3][1], m[0][2],
* m[1][2], m[2][2], m[3][2], m[0][3], m[1][3], m[2][3], m[3][3].
*
* @param _m The \c float array to create the matrix from.
*/
FMMatrix44(const float* _m);
/**
* Creates an empty FMMatrix44.
*
* The default values are non deterministic.
*/
#ifndef _DEBUG
FMMatrix44() {}
#else
FMMatrix44() { memset(m, 55, 16 * sizeof(float)); }
#endif
/**
* Get this FMMatrix44 as an array of \c floats.
*
* The array contains the elements in the following order: m[0][0],
* m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0],
* m[2][1], m[2][2], m[0][3], m[3][0], m[3][1], m[3][2], m[3][3].
*
* @return The \c float array.
*/
operator float*() { return &m[0][0]; }
/**
* Get this FMMatrix44 as an array of \c floats.
*
* The array contains the elements in the following order: m[0][0],
* m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0],
* m[2][1], m[2][2], m[0][3], m[3][0], m[3][1], m[3][2], m[3][3].
*
* @return The \c float array.
*/
operator const float*() const { return &m[0][0]; }
/**
* Get a specified row of FMMatrix44 as an array of \c floats.
*
* @param a The row index, starting at 0, of the row to get.
* @return The \c float array of the elements in the specified row.
*/
float* operator[](int a) { return m[a]; }
/**
* Get a specified row of FMMatrix44 as an array of \c floats.
*
* @param a The row index, starting at 0, of the row to get.
* @return The \c float array of the elements in the specified row.
*/
const float* operator[](int a) const { return m[a]; }
/**
* Assign this FMMatrix44's elements to be the same as that of the given
* FMMatrix44.
*
* @param copy The FMMatrix to copy elements from.
* @return This FMMatrix.
*/
FMMatrix44& operator=(const FMMatrix44& copy);
/**
* Gets the transposed of this FMMatrix44.
*
* @return The transposed of this FMMatrix.
*/
FMMatrix44 Transposed() const;
/**
* Gets the inversion of this FMMatrix33.
*
* @return The inversion of this FMMatrix.
*/
FMMatrix44 Inverted() const;
/**
* Decompose this FMMatrix44 into it's scale, rotation, and translation
* components; it also tells whether it is inverted.
*
* @param Scale The FMVector to place the scale components to.
* @param Rotation The FMVector to place the rotation components to.
* @param Translation The FMVector to place the translation components to.
* @param inverted The value corresponding to if it was inverted (-1.0f or
* 1.0f)
*/
void Decompose(FMVector3& Scale, FMVector3& Rotation, FMVector3& Translation, float& inverted) const;
/**
* Transforms the given point by this FMMatrix44.
*
* @param coordinate The point to transform.
* @return The FMVector3 representation of the transformed point.
*/
FMVector3 TransformCoordinate(const FMVector3& coordinate) const;
/**
* Transforms the given vector by this FMMatrix44.
*
* @param v The vector to transform.
* @return The FMVector3 representation of the transformed vector.
*/
FMVector3 TransformVector(const FMVector3& v) const;
/**
* Gets the translation component of this FMMatrix44.
*
* @return The FMVector3 representation of the translation.
*/
FMVector3 GetTranslation() const;
public:
static FMMatrix44 Identity; /**< The identity FMMatrix44. */
/**
* Gets the FMMatrix44 representation of a 3D translation.
*
* The translation in the x, y and z directions correspond to the \a x,
* \a y, and \a z components of the FMVector3.
*
* @param translation The FMVector3 to get the translation components from.
* @return The translation FMMatrix44.
*/
static FMMatrix44 TranslationMatrix(const FMVector3& translation);
/**
* Gets the FMMatrix44 representation of a 3D rotation about a given axis
* by an angle.
*
* @param axis The axis of rotation.
* @param angle The angle of rotation in radians.
* @return The rotation FMMatrix44.
*/
static FMMatrix44 AxisRotationMatrix(const FMVector3& axis, float angle);
};
/**
* Matrix multiplication with two FMMatrix44.
*
* @param m1 The first matrix.
* @param m2 The second matrix.
* @return The FMMatrix44 representation of the resulting matrix.
*/
FMMatrix44 FCOLLADA_EXPORT operator*(const FMMatrix44& m1, const FMMatrix44& m2);
/**
Matrix equality comparison function.
@param m1 The first matrix.
@param m2 The second matrix.
@return Whether the given matrices are equal.
*/
bool IsEquivalent(const FMMatrix44& m1, const FMMatrix44& m2);
/**
Matrix equality operator override.
@param m1 The first matrix.
@param m2 The second matrix.
@return Whether the given matrices are equal.
*/
inline bool operator==(const FMMatrix44& m1, const FMMatrix44& m2) { return IsEquivalent(m1, m2); }
/** A dynamically-sized array of 4x4 matrices. */
typedef vector<FMMatrix44> FMMatrix44List;
#endif // _FM_MATRIX44_H_

View File

@@ -0,0 +1,38 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
#include "FMath/FMath.h"
#include "FMath/FMVector3.h"
#include "FMath/FMQuaternion.h"
// [Glaforte 03-08-2006] VERY EXPERIMENTAL CODE: DON'T USE.
FMQuaternion::FMQuaternion(const FMVector3& axis, float angle)
{
float s = sinf(angle / 2.0f);
x = axis.x * s;
y = axis.y * s;
z = axis.z * s;
w = cosf(angle / 2.0f);
}
FMQuaternion FMQuaternion::operator*(const FMQuaternion& q) const
{
FMQuaternion r;
r.w = w * q.w - x * q.x - y * q.y - z * q.z;
r.x = w * q.x + x * q.w + y * q.z - z * q.y;
r.y = w * q.y + y * q.w + z * q.x - x * q.z;
r.z = w * q.z + z * q.w + x * q.y - y * q.x;
return r;
}
FMQuaternion FMQuaternion::EulerRotationQuaternion(float x, float y, float z)
{
FMQuaternion qx(FMVector3::XAxis, x);
FMQuaternion qy(FMVector3::YAxis, y);
FMQuaternion qz(FMVector3::ZAxis, z);
return qx * qy * qz;
}

View File

@@ -0,0 +1,105 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMQuaternion.h
The file containing the class for quaternions.
*/
#ifndef _FM_QUATERNION_H_
#define _FM_QUATERNION_H_
/**
A quaternion.
Not used within FCollada
[Glaforte 03-08-2006] VERY EXPERIMENTAL CODE: DON'T USE.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMQuaternion
{
public:
float x; /**< The i component. */
float y; /**< The j component. */
float z; /**< The k component. */
float w; /**< The scalar component. */
#ifndef _DEBUG
/**
* Creates an empty FMQuaternion.
*
* The default values are non deterministic.
*/
FMQuaternion() {}
#else
FMQuaternion() { x = 123456789.0f; y = 123456789.0f; z = 123456789.0f; w = 123456789.0f; }
#endif
/**
* Creates the FMQuaternion with the given component values.
*
* @param _x The i component.
* @param _y The j component.
* @param _z The k component.
* @param _w The scalar component.
*/
FMQuaternion(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
/**
* Creates the FMQuaternion from a given axis and angle of rotation.
*
* @param axis The axis of rotation.
* @param angle The angle of rotation in radians.
*/
FMQuaternion(const FMVector3& axis, float angle);
/**
* Get this FMQuaternion as an array of \c floats.
*
* @return The \c float array.
*/
inline operator float*() { return &x; }
/**
* Get this FMQuaternion as an array of \c floats.
*
* @return The \c float array.
*/
inline operator const float*() const { return &x; }
/**
* Assign this FMQuaternion to the given \c float array.
*
* Assigns each coordinate of this FMQuaternion to the elements in the
* \c float array. The first element to the i component, the second to the
* j, the third to the k, and the forth to the scalar. It returns this
* FMQuaternion.
*
* @param v The \c float array to assign with.
* @return This FMQuaternion.
*/
inline FMQuaternion& operator =(const float* v) { x = *v; y = *(v + 1); z = *(v + 2); w = *(v + 3); return *this; }
/**
* Applys quaternion multiplication of the given FMQuaternion with this
* FMQuaternion and returns the value.
*
* @param q The FMQuaternion multiply with.
* @return The resulting FMQuaternion.
*/
FMQuaternion operator*(const FMQuaternion& q) const;
/**
* Get the FMQuaternion representation of the Euler rotation angles.
*
* @param _x The rotation about the x-axis (roll), in radians.
* @param _y The rotation about the y-axis (pitch), in radians.
* @param _z The rotation about the z-axis (yaw), in radians.
*/
static FMQuaternion EulerRotationQuaternion(float _x, float _y, float _z);
};
#endif // _FM_QUATERNION_H_

View File

@@ -0,0 +1,132 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMVector2.h
The file containing the class and global functions for 2 dimensional
vectors.
*/
#ifndef _FM_VECTOR2_H_
#define _FM_VECTOR2_H_
/**
A 2 dimensional vector.
Not used within FCollada.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMVector2
{
public:
float u; /**< The first coordinate. */
float v; /**< The second coordinate. */
public:
/**
* Creates an empty FMVector2.
*/
#ifndef _DEBUG
FMVector2() {}
#else
FMVector2() { u = 123456789.0f; v = 123456789.0f; }
#endif
/**
* Creates the FMVector2 with the coordinates given.
*
* @param _u The first coordinate.
* @param _v The second coordinate.
*/
FMVector2(float _u, float _v) { u = _u; v = _v; }
/**
* Get this FMVector2 as an array of \c floats.
*
* @return The \c float array.
*/
inline operator float*() { return &u; }
/**
* Adds two FMVector2.
*
* Adds to this FMVector2's coordinates the individual components of the
* given FMVector2 and returns this FMVector2.
*
* @param a The FMVector2 to add with this one.
* @return This FMVector2.
*/
inline FMVector2& operator +=(const FMVector2& a) { u += a.u; v += a.v; return *this; }
/**
* Multiplies this FMVector2 by a scaler.
*
* Multiplies each of this FMVector2's coordinates with the scaler and
* returns this FMVector2.
*
* @param a The scalar to multiply with.
* @return This FMVector2.
*/
inline FMVector2& operator *=(float a) { u *= a; v *= a; return *this; }
/**
* Assign this FMVector2 to the given float array.
*
* Assigns each coordinate of this FMVector2 to the elements in the \c
* float array. The first element to the first coordinate and the second to
* the second. It returns this FMVector2.
*
* @param f The \c float array to assign with.
* @return This FMVector2.
*/
inline FMVector2& operator =(const float* f) { u = *f; v = *(f + 1); return *this; }
};
/**
* Vector addition with two FMVector2.
*
* @param a The first vector.
* @param b The second vector.
* @return The FMVector2 representation of the resulting vector.
*/
inline FMVector2 operator + (const FMVector2& a, const FMVector2& b) { return FMVector2(a.u + b.u, a.v + b.v); }
/**
* Vector subtraction with two FMVector2.
*
* @param a The first vector.
* @param b The second vector.
* @return The FMVector2 representation of the resulting vector.
*/
inline FMVector2 operator -(const FMVector2& a, const FMVector2& b) { return FMVector2(a.u - b.u, a.v - b.v); }
/**
* Dot product of two FMVector2.
*
* @param a The first vector.
* @param b The second vector.
* @return The result of the dot product.
*/
inline float operator *(const FMVector2& a, const FMVector2& b) { return a.u * b.u + a.v * b.v; }
/**
* Scalar multiplication with a FMVector2.
*
* @param a The vector.
* @param b The scalar.
* @return The FMVector2 representing the resulting the vector.
*/
inline FMVector2 operator *(const FMVector2& a, float b) { return FMVector2(a.u * b, a.v * b); }
/**
* Scalar multiplication with a FMVector2.
*
* @param a The scalar.
* @param b The vector.
* @return The FMVector2 representing the resulting the vector.
*/
inline FMVector2 operator *(float a, const FMVector2& b) { return FMVector2(a * b.u, a * b.v); }
#endif // _FM_VECTOR2_H_

View File

@@ -0,0 +1,25 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#include "StdAfx.h"
#include "FMath/FMVector2.h"
#include "FMath/FMVector3.h"
#include "FMath/FMVector4.h"
// Vector constants
const FMVector3 FMVector3::Zero(0.0f, 0.0f, 0.0f);
const FMVector3 FMVector3::XAxis(1.0f, 0.0f, 0.0f);
const FMVector3 FMVector3::YAxis(0.0f, 1.0f, 0.0f);
const FMVector3 FMVector3::ZAxis(0.0f, 0.0f, 1.0f);
const FMVector3 FMVector3::Origin = FMVector3::Zero;
const FMVector4 FMVector4::Zero(0.0f, 0.0f, 0.0f, 0.0f);
// Read in the vector from a source
FMVector3::FMVector3(const float* source, uint32 startIndex)
{
x = source[startIndex];
y = source[startIndex + 1];
z = source[startIndex + 2];
}

View File

@@ -0,0 +1,299 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMVector3.h The file containing the class and global functions for 3 dimensional vectors.
*/
#ifndef _FM_VECTOR3_H_
#define _FM_VECTOR3_H_
/**
A 3 dimensional vector.
Simple, non-optimized vector class: * is the dot-product, ^ is the
cross-product.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMVector3
{
public:
float x; /**< The first coordinate. */
float y; /**< The second coordinate. */
float z; /**< The third coordinate. */
public:
/**
* Creates an empty FMVector3.
*/
#ifndef _DEBUG
FMVector3() {}
#else
FMVector3() { x = 123456789.0f; y = 123456789.0f; z = 123456789.0f; }
#endif
/**
* Creates the FMVector3 with the coordinates given.
*
* @param _x The first coordinate.
* @param _y The second coordinate.
* @param _z The third coordinate.
*/
FMVector3(float _x, float _y, float _z) { x = _x; y = _y; z = _z; }
/**
* Creates the FMVector3 from a list of \c floats.
*
* It takes the first 3 \c floats starting from and including \a startIndex
* (0 indexing) in the array as the 3 coordinates. The first as the first
* coordinate, the second as the second, and the third as the third.
*
* @param source The \c float array.
* @param startIndex The index of the first element.
*/
FMVector3(const float* source, uint32 startIndex = 0);
/**
* Get the squared length.
*
* @return The squared length of this FMVector3.
*/
inline float LengthSquared() const { return x * x + y * y + z * z; }
/**
* Retrieves the length of the vector.
*
* @return The length of this FMVector3.
*/
inline float Length() const { return sqrtf(x * x + y * y + z * z); }
/**
* Normalize this FMVector3.
*/
inline void NormalizeIt() { float l = Length(); if (!IsEquivalent(l, 0.0f)) { x /= l; y /= l; z /= l; }}
/**
* Get a normalized FMVector3 with the same direction as this FMVector3.
*
* @return A FMVector3 with length 1 and same direction as this FMVector3.
*/
inline FMVector3 Normalize() const { float l = Length(); return FMVector3(x / l, y / l, z / l); }
/**
* Project this FMVector3 onto another FMVector3.
*
* @param unto The FMVector3 to project onto.
*/
inline void Project(const FMVector3& unto) { (*this) = Projected(unto); }
/**
* Get the projection of this FMVector3 onto another FMVector3.
*
* @param unto The FMVector3 to project onto.
* @return The projected FMVector3.
*/
inline FMVector3 Projected(const FMVector3& unto);
/**
* Get this FMVector3 as an array of \c floats.
*
* @return The \c float array.
*/
inline operator float*() { return &x; }
/**
* Get this FMVector3 as an array of \c floats.
*
* @return The \c float array.
*/
inline operator const float*() const { return &x; }
/**
* Assign this FMVector3 to the given float array.
*
* Assigns each coordinate of this FMVector3 to the elements in the \c
* float array. The first element to the first coordinate, the second to
* the second, and the third to the third. It returns this FMVector3.
*
* @param v The \c float array to assign with.
* @return This FMVector3.
*/
inline FMVector3& operator =(const float* v) { x = *v; y = *(v + 1); z = *(v + 2); return *this; }
/**
* Update each component of this FMVector to the minimum of two FMVector3s.
*
* Updates each of the three components to be the minimum of the current
* value and that of the corresponding value of the given FMVector3.
*
* @param min The FMVector to take values from.
*/
inline void ComponentMinimum(const FMVector3& min) { if (x < min.x) x = min.x; if (y < min.y) y = min.y; if (z < min.z) z = min.z; }
/**
* Update each component of this FMVector to the maximum of two FMVector3s.
*
* Updates each of the three components to be the maximum of the current
* value and that of the corresponding value of the given FMVector3.
*
* @param max The FMVector to take values from.
*/
inline void ComponentMaximum(const FMVector3& max) { if (x > max.x) x = max.x; if (y > max.y) y = max.y; if (z > max.z) z = max.z; }
/**
* Clamp each component of this FMVector by the corresponding components
* in the specified min and max FMVector3.
*
* Clamp refers to setting a value within a given range. If the value is
* lower than the minimum of the range, it is set to the minimum; same for
* the maximum.
*
* @param min The FMVector to take the minimum values from.
* @param max The FMVector to take the maximum values from.
*/
inline void ComponentClamp(const FMVector3& min, const FMVector3& max) { ComponentMinimum(min); ComponentMaximum(max); }
public:
static const FMVector3 XAxis; /**< The FMVector3 representing the x axis */
static const FMVector3 YAxis; /**< The FMVector3 representing the y axis */
static const FMVector3 ZAxis; /**< The FMVector3 representing the z axis */
static const FMVector3 Zero; /**< The FMVector3 representing zero */
static const FMVector3 Origin;/**< The FMVector3 representing the origin */
};
/**
* Vector addition with two FMVector3.
*
* @param a The first vector.
* @param b The second vector.
* @return The FMVector3 representation of the resulting vector.
*/
inline FMVector3 operator +(const FMVector3& a, const FMVector3& b) { return FMVector3(a.x + b.x, a.y + b.y, a.z + b.z); }
/**
* Vector subtraction with two FMVector3.
*
* @param a The first vector.
* @param b The second vector.
* @return The FMVector3 representation of the resulting vector.
*/
inline FMVector3 operator -(const FMVector3& a, const FMVector3& b) { return FMVector3(a.x - b.x, a.y - b.y, a.z - b.z); }
/**
* Positive operator of the given FMVector3.
*
* It applies the positive operator to each of the components of the FMVector3.
*
* @param a The vector to apply the positive operator to.
* @return The FMVector3 representation of the resulting vector.
*/
inline FMVector3 operator +(const FMVector3& a) { return FMVector3(+a.x, +a.y, +a.z); }
/**
* Negates the given FMVector3.
*
* It negates each of the components of the FMVector3.
*
* @param a The vector to negate.
* @return The FMVector3 representation of the resulting vector.
*/
inline FMVector3 operator -(const FMVector3& a) { return FMVector3(-a.x, -a.y, -a.z); }
/**
* Dot product of two FMVector3.
*
* @param a The first vector.
* @param b The second vector.
* @return The result of the dot product.
*/
inline float operator *(const FMVector3& a, const FMVector3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
/**
* Scalar multiplication with a FMVector3.
*
* @param a The vector.
* @param b The scalar.
* @return The FMVector3 representing the resulting vector.
*/
inline FMVector3 operator *(const FMVector3& a, float b) { return FMVector3(a.x * b, a.y * b, a.z * b); }
/**
* Scalar multiplication with a FMVector3.
*
* @param a The scalar.
* @param b The vector.
* @return The FMVector3 representing the resulting vector.
*/
inline FMVector3 operator *(float a, const FMVector3& b) { return FMVector3(a * b.x, a * b.y, a * b.z); }
/**
* Cross product of two FMVector3.
*
* @param a The first vector.
* @param b The second vector.
* @return The result of the dot product.
*/
inline FMVector3 operator ^(const FMVector3& a, const FMVector3& b) { return FMVector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); }
/**
* Assignment of the addition of two FMVector3.
*
* @param b The first vector, which will also be assigned to the result.
* @param a The second vector.
* @return The first vector, after it has been assigned new values.
*/
inline FMVector3& operator +=(FMVector3& b, const FMVector3& a) { b.x += a.x; b.y += a.y; b.z += a.z; return b; }
/**
* Assignment of the subtraction of two FMVector3.
*
* @param b The first vector, which will also be assigned to the result.
* @param a The second vector.
* @return The first vector, after it has been assigned new values.
*/
inline FMVector3& operator -=(FMVector3& b, const FMVector3& a) { b.x -= a.x; b.y -= a.y; b.z -= a.z; return b; }
/**
* Assignment of the scalar multiplication of a FMVector3.
*
* @param b The vector, which will also be assigned to the result.
* @param a The scalar.
* @return The vector, after it has been assigned new values.
*/
inline FMVector3& operator *=(FMVector3& b, float a) { b.x *= a; b.y *= a; b.z *= a; return b; }
/**
* Assignment of the scalar division of a FMVector3.
*
* @param b The vector, which will also be assigned to the result.
* @param a The scalar.
* @return The vector, after it has been assigned new values.
*/
inline FMVector3& operator /=(FMVector3& b, float a) { b.x /= a; b.y /= a; b.z /= a; return b; }
/**
Returns whether two 3D vectors or points are equivalent.
@param p A first vector.
@param q A second vector.
@return Whether the vectors are equivalent.
*/
inline bool IsEquivalent(const FMVector3& p, const FMVector3& q) { return IsEquivalent(p.x, q.x) && IsEquivalent(p.y, q.y) && IsEquivalent(p.z, q.z); }
/**
Check if two FMVector3 are equivalent (they have relatively the same component values).
@param a The first vector.
@param b The second vector.
@return Whether the vectors are equivalent.
*/
inline bool operator == (const FMVector3& a, const FMVector3& b) { return IsEquivalent(a, b); }
// Already documented above.
inline FMVector3 FMVector3::Projected(const FMVector3& unto) { return ((*this) * unto) / unto.LengthSquared() * unto; }
/** A dynamically-sized array of 3D vectors or points. */
typedef vector<FMVector3> FMVector3List;
#endif // _FM_VECTOR3_H_

View File

@@ -0,0 +1,79 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMVector4.h
This file contains the class for 4 dimensional vectors.
*/
#ifndef _FM_VECTOR4_H_
#define _FM_VECTOR4_H_
/**
A 4 dimensional vector.
Not used within FCollada.
@ingroup FMath
*/
class FCOLLADA_EXPORT FMVector4
{
public:
float x; /**< The first coordinate. */
float y; /**< The second coordinate. */
float z; /**< The third coordinate. */
float w; /**< The forth coordinate. */
/**
* Creates an empty FMVector4.
*/
#ifndef _DEBUG
FMVector4() {}
#else
FMVector4() { x = 123456789.0f; y = 123456789.0f; z = 123456789.0f; w = 123456789.0f; }
#endif
/**
* Creates the FMVector4 with the coordinates given.
*
* The first three coordinates are taken from the FMVector3, where the
* first one is the x value, the second is that y, and the third is the z.
* The forth value is the \c float specified.
*
*
* @param v The FMVector3 representing the first three coordinates.
* @param _w The final coordinate.
*/
FMVector4(FMVector3 v, float _w) { x = v.x; y = v.y; z = v.z; w = _w; }
/**
* Creates the FMVector4 with the coordinates given.
*
* @param _x The first coordinate.
* @param _y The second coordinate.
* @param _z The third coordinate.
* @param _w The forth coordinate.
*/
FMVector4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; }
public:
/**
* Get this FMVector4 as an array of \c floats.
*
* @return The \c float array.
*/
inline operator float*() { return &x; }
/**
* Get this FMVector4 as an array of \c floats.
*
* @return The \c float array.
*/
inline operator const float*() const { return &x; }
public:
static const FMVector4 Zero; /**< The FMVector4 representing zero */
};
#endif // _FM_VECTOR4_H_

View File

@@ -0,0 +1,128 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
/**
@file FMath.h
The file containing functions and constants for math.
@defgroup FMath Mathematics Classes.
*/
#ifndef _F_MATH_H_
#define _F_MATH_H_
#include <math.h>
#include <algorithm>
// Includes the improved vector class.
#include "FMath/FMArray.h"
// Includes the common integer and floating-point definitions and functions.
#include "FMath/FMFloat.h"
#include "FMath/FMInteger.h"
/**
A namespace for common math functions.
@ingroup FMath
*/
namespace FMath
{
const double Pi = 3.14159; /**< Mathematical value of pi to 5 decimals. */
/**
* Convert radians to degrees.
*
* @param val The value in radians.
* @return The value in degrees.
*/
inline double RadToDeg(double val) { return (val * 180.0/Pi); }
/**
* Convert radians to degrees.
*
* @param val The value in radians.
* @return The value in degrees.
*/
inline float RadToDeg(float val) { return (val * 180.0f/(float)Pi); }
/**
* Convert degrees to radians.
*
* @param val The value in degrees.
* @return The value in radians.
*/
inline double DegToRad(double val) { return (val * Pi/180.0); }
/**
* Convert degrees to radians.
*
* @param val The value in degrees.
* @return The value in radians.
*/
inline float DegToRad(float val) { return (val * (float)Pi/180.0f); }
/**
* Determines if given float is encoding for not a number (NAN).
*
* @param f The float to check.
* @return 0 if it is a number, something else if is NAN.
*/
#ifdef WIN32
inline int IsNotANumber(float f) { return _isnan(f); }
#else // Linux and Mac
inline int IsNotANumber(float f) { return !finite(f); }
#endif
/**
* Determine the sign of a number.
*
* @param val The number to check.
* @return 1.0 if positive, -1.0 if negative.
*/
inline double Sign(double val) { return (val >= 0.0) ? 1.0 : -1.0; }
/**
* Determine the sign of a number.
*
* @param val The number to check.
* @return 1.0f if positive, -1.0f if negative.
*/
inline float Sign(float val) { return (val >= 0.0f) ? 1.0f : -1.0f; }
/**
* Determine the sign of a number.
*
* @param val The number to check.
* @return 1 if positive, -1 if negative.
*/
inline int32 Sign(int32 val) { return (val >= 0) ? 1 : -1; }
/**
* Clamp the specified object within a range specified by two other objects
* of the same class.
*
* Clamp refers to setting a value within a given range. If the value is
* lower than the minimum of the range, it is set to the minimum; same for
* the maximum.
*
* @param val The object to clamp.
* @param mx The highest object of the range.
* @param mn The lowest object of the range.
* @return The clamped value.
*/
template <class T>
inline T Clamp(T val, T mn, T mx) { return std::max(std::min(val, mx), mn); }
};
// Include commonly used mathematical classes
#include "FMath/FMVector2.h"
#include "FMath/FMVector3.h"
#include "FMath/FMVector4.h"
#include "FMath/FMColor.h"
#include "FMath/FMMatrix33.h"
#include "FMath/FMMatrix44.h"
#endif // _F_MATH_H_

View File

@@ -0,0 +1,26 @@
#!/usr/bin/make
# FMath Makefile for PS3
include ../../MakeDefs
LIBNAME = libfmath
prefix=..
INCPATH=$(prefix)/include
LIBPATH=$(prefix)/lib
PPU_INCDIRS=-I$(INCPATH) -I..
PPU_OPTIMIZE_LV= -O3 -funroll-loops
PPU_LIB_TARGET=$(LIBNAME).a
PPU_SRCS = \
FMColor.cpp \
FMInterpolation.cpp \
FMMatrix33.cpp \
FMMatrix44.cpp \
FMQuaternion.cpp \
FMVector3.cpp \
StdAfx.cpp
include ../../MakeRules

View File

@@ -0,0 +1,3 @@
#include "StdAfx.h"
// [claforte] Changing temporarily to test trigger of automated build

View File

@@ -0,0 +1,12 @@
/*
Copyright (C) 2005-2006 Feeling Software Inc.
MIT License: http://www.opensource.org/licenses/mit-license.php
*/
#ifndef _STD_AFX_H_
#define _STD_AFX_H_
#define NO_LIBXML
#include "FUtils/FUtils.h"
#endif // _STD_AFX_H_