Initial revision

This commit is contained in:
Hans Lambermont
2002-10-12 11:37:38 +00:00
commit 12315f4d0e
1699 changed files with 444708 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef GEN_LIST_H
#define GEN_LIST_H
class GEN_Link {
public:
GEN_Link() : m_next(0), m_prev(0) {}
GEN_Link(GEN_Link *next, GEN_Link *prev) : m_next(next), m_prev(prev) {}
GEN_Link *getNext() const { return m_next; }
GEN_Link *getPrev() const { return m_prev; }
bool isHead() const { return m_prev == 0; }
bool isTail() const { return m_next == 0; }
void insertBefore(GEN_Link *link) {
m_next = link;
m_prev = link->m_prev;
m_next->m_prev = this;
m_prev->m_next = this;
}
void insertAfter(GEN_Link *link) {
m_next = link->m_next;
m_prev = link;
m_next->m_prev = this;
m_prev->m_next = this;
}
void remove() {
m_next->m_prev = m_prev;
m_prev->m_next = m_next;
}
private:
GEN_Link *m_next;
GEN_Link *m_prev;
};
class GEN_List {
public:
GEN_List() : m_head(&m_tail, 0), m_tail(0, &m_head) {}
GEN_Link *getHead() const { return m_head.getNext(); }
GEN_Link *getTail() const { return m_tail.getPrev(); }
void addHead(GEN_Link *link) { link->insertAfter(&m_head); }
void addTail(GEN_Link *link) { link->insertBefore(&m_tail); }
private:
GEN_Link m_head;
GEN_Link m_tail;
};
#endif

View File

@@ -0,0 +1,152 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef GEN_MAP_H
#define GEN_MAP_H
template <class Key, class Value>
class GEN_Map {
private:
struct Entry {
Entry (Entry *next, Key key, Value value) :
m_next(next),
m_key(key),
m_value(value) {}
Entry *m_next;
Key m_key;
Value m_value;
};
public:
GEN_Map(int num_buckets = 100) : m_num_buckets(num_buckets) {
m_buckets = new Entry *[num_buckets];
for (int i = 0; i < num_buckets; ++i) {
m_buckets[i] = 0;
}
}
int size() {
int count=0;
for (int i=0;i<m_num_buckets;i++)
{
Entry* bucket = m_buckets[i];
while(bucket)
{
bucket = bucket->m_next;
count++;
}
}
return count;
}
Value* at(int index) {
int count=0;
for (int i=0;i<m_num_buckets;i++)
{
Entry* bucket = m_buckets[i];
while(bucket)
{
if (count==index)
{
return &bucket->m_value;
}
bucket = bucket->m_next;
count++;
}
}
return 0;
}
void clear() {
for (int i = 0; i < m_num_buckets; ++i) {
Entry *entry_ptr = m_buckets[i];
while (entry_ptr != 0) {
Entry *tmp_ptr = entry_ptr->m_next;
delete entry_ptr;
entry_ptr = tmp_ptr;
}
m_buckets[i] = 0;
}
}
~GEN_Map() {
clear();
delete [] m_buckets;
}
void insert(const Key& key, const Value& value) {
Entry *entry_ptr = m_buckets[key.hash() % m_num_buckets];
while ((entry_ptr != 0) && !(key == entry_ptr->m_key)) {
entry_ptr = entry_ptr->m_next;
}
if (entry_ptr != 0) {
entry_ptr->m_value = value;
}
else {
Entry **bucket = &m_buckets[key.hash() % m_num_buckets];
*bucket = new Entry(*bucket, key, value);
}
}
void remove(const Key& key) {
Entry **entry_ptr = &m_buckets[key.hash() % m_num_buckets];
while ((*entry_ptr != 0) && !(key == (*entry_ptr)->m_key)) {
entry_ptr = &(*entry_ptr)->m_next;
}
if (*entry_ptr != 0) {
Entry *tmp_ptr = (*entry_ptr)->m_next;
delete *entry_ptr;
*entry_ptr = tmp_ptr;
}
}
Value *operator[](Key key) {
Entry *bucket = m_buckets[key.hash() % m_num_buckets];
while ((bucket != 0) && !(key == bucket->m_key)) {
bucket = bucket->m_next;
}
return bucket != 0 ? &bucket->m_value : 0;
}
private:
int m_num_buckets;
Entry **m_buckets;
};
#endif

View File

@@ -0,0 +1,147 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef INCLUDED_MT_CmMatrix4x4
#define INCLUDED_MT_CmMatrix4x4
/**
* A 4x4 matrix. This is an OpenGl style matrix (column major) meaning
* that the vector {m[0][0],m[0][1],m[0][2],m[0][3]} is the first column of
* the matrix , the same as what you get if you transform {1,0,0,0}.
* This makes it easy to transform stuff to OpenGl. Please note that the
* the other MoTo matrices are row major.
*
* This class should be deprecated in favour of the more consistent
* MT_Matrix4x4. Please do not start using this class.
*/
#include "MT_Scalar.h"
class MT_Point3;
class MT_Vector3;
class MT_CmMatrix4x4
{
public :
MT_CmMatrix4x4(
const float value[4][4]
);
MT_CmMatrix4x4(
);
MT_CmMatrix4x4(
const double value[16]
);
MT_CmMatrix4x4(
const MT_CmMatrix4x4 & other
);
MT_CmMatrix4x4(
const MT_Point3& orig,
const MT_Vector3& dir,
const MT_Vector3 up
);
void
Identity(
);
void
SetMatrix(
const MT_CmMatrix4x4 & other
);
double*
getPointer(
);
const
double*
getPointer(
) const;
void
setElem(
int pos,
double newvalue
);
MT_Vector3
GetRight(
) const;
MT_Vector3
GetUp(
) const;
MT_Vector3
GetDir(
) const;
MT_Point3
GetPos(
) const;
void
SetPos(
const MT_Vector3 & v
);
double&
operator (
) (int row,int col) { return m_V[col][row]; }
static
MT_CmMatrix4x4
Perspective(
MT_Scalar inLeft,
MT_Scalar inRight,
MT_Scalar inBottom,
MT_Scalar inTop,
MT_Scalar inNear,
MT_Scalar inFar
);
protected:
union
{
double m_V[4][4];
double m_Vflat[16];
};
};
#endif //MT_CmMatrix4x4

View File

@@ -0,0 +1,214 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_MATRIX3X3_H
#define MT_MATRIX3X3_H
#include <MT_assert.h>
#include "MT_Vector3.h"
#include "MT_Quaternion.h"
class MT_Matrix3x3 {
public:
MT_Matrix3x3() {}
MT_Matrix3x3(const float *m) { setValue(m); }
MT_Matrix3x3(const double *m) { setValue(m); }
MT_Matrix3x3(const MT_Quaternion& q) { setRotation(q); }
MT_Matrix3x3(const MT_Quaternion& q, const MT_Vector3& s) {
setRotation(q);
scale(s[0], s[1], s[2]);
}
MT_Matrix3x3(const MT_Vector3& euler) { setEuler(euler); }
MT_Matrix3x3(const MT_Vector3& euler, const MT_Vector3& s) {
setEuler(euler);
scale(s[0], s[1], s[2]);
}
MT_Matrix3x3(MT_Scalar xx, MT_Scalar xy, MT_Scalar xz,
MT_Scalar yx, MT_Scalar yy, MT_Scalar yz,
MT_Scalar zx, MT_Scalar zy, MT_Scalar zz) {
setValue(xx, xy, xz,
yx, yy, yz,
zx, zy, zz);
}
MT_Vector3& operator[](int i) { return m_el[i]; }
const MT_Vector3& operator[](int i) const { return m_el[i]; }
void setValue(const float *m) {
m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m++;
m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m++;
m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
}
void setValue(const double *m) {
m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m++;
m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m++;
m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
}
void setValue(MT_Scalar xx, MT_Scalar xy, MT_Scalar xz,
MT_Scalar yx, MT_Scalar yy, MT_Scalar yz,
MT_Scalar zx, MT_Scalar zy, MT_Scalar zz) {
m_el[0][0] = xx; m_el[0][1] = xy; m_el[0][2] = xz;
m_el[1][0] = yx; m_el[1][1] = yy; m_el[1][2] = yz;
m_el[2][0] = zx; m_el[2][1] = zy; m_el[2][2] = zz;
}
void setRotation(const MT_Quaternion& q) {
MT_Scalar d = q.length2();
MT_assert(!MT_fuzzyZero2(d));
MT_Scalar s = MT_Scalar(2.0) / d;
MT_Scalar xs = q[0] * s, ys = q[1] * s, zs = q[2] * s;
MT_Scalar wx = q[3] * xs, wy = q[3] * ys, wz = q[3] * zs;
MT_Scalar xx = q[0] * xs, xy = q[0] * ys, xz = q[0] * zs;
MT_Scalar yy = q[1] * ys, yz = q[1] * zs, zz = q[2] * zs;
setValue(MT_Scalar(1.0) - (yy + zz), xy - wz , xz + wy,
xy + wz , MT_Scalar(1.0) - (xx + zz), yz - wx,
xz - wy , yz + wx, MT_Scalar(1.0) - (xx + yy));
}
/**
* setEuler
* @param euler a const reference to a MT_Vector3 of euler angles
* These angles are used to produce a rotation matrix. The euler
* angles are applied in ZYX order. I.e a vector is first rotated
* about X then Y and then Z
**/
void setEuler(const MT_Vector3& euler) {
MT_Scalar ci = cos(euler[0]);
MT_Scalar cj = cos(euler[1]);
MT_Scalar ch = cos(euler[2]);
MT_Scalar si = sin(euler[0]);
MT_Scalar sj = sin(euler[1]);
MT_Scalar sh = sin(euler[2]);
MT_Scalar cc = ci * ch;
MT_Scalar cs = ci * sh;
MT_Scalar sc = si * ch;
MT_Scalar ss = si * sh;
setValue(cj * ch, sj * sc - cs, sj * cc + ss,
cj * sh, sj * ss + cc, sj * cs - sc,
-sj, cj * si, cj * ci);
}
void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z) {
m_el[0][0] *= x; m_el[0][1] *= y; m_el[0][2] *= z;
m_el[1][0] *= x; m_el[1][1] *= y; m_el[1][2] *= z;
m_el[2][0] *= x; m_el[2][1] *= y; m_el[2][2] *= z;
}
MT_Matrix3x3 scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z) const {
return MT_Matrix3x3(m_el[0][0] * x, m_el[0][1] * y, m_el[0][2] * z,
m_el[1][0] * x, m_el[1][1] * y, m_el[1][2] * z,
m_el[2][0] * x, m_el[2][1] * y, m_el[2][2] * z);
}
void setIdentity() {
setValue(MT_Scalar(1.0), MT_Scalar(0.0), MT_Scalar(0.0),
MT_Scalar(0.0), MT_Scalar(1.0), MT_Scalar(0.0),
MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(1.0));
}
void getValue(float *m) const {
*m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = 0.0;
*m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = 0.0;
*m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m = 0.0;
}
void getValue(double *m) const {
*m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = 0.0;
*m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = 0.0;
*m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m = 0.0;
}
MT_Quaternion getRotation() const;
MT_Matrix3x3& operator*=(const MT_Matrix3x3& m);
MT_Scalar tdot(int c, const MT_Vector3& v) const {
return m_el[0][c] * v[0] + m_el[1][c] * v[1] + m_el[2][c] * v[2];
}
MT_Scalar cofac(int r1, int c1, int r2, int c2) const {
return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1];
}
MT_Scalar determinant() const;
MT_Matrix3x3 adjoint() const;
MT_Matrix3x3 absolute() const;
MT_Matrix3x3 transposed() const;
void transpose();
MT_Matrix3x3 inverse() const;
void invert();
protected:
MT_Vector3 m_el[3];
};
MT_Vector3 operator*(const MT_Matrix3x3& m, const MT_Vector3& v);
MT_Vector3 operator*(const MT_Vector3& v, const MT_Matrix3x3& m);
MT_Matrix3x3 operator*(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2);
MT_Matrix3x3 MT_multTransposeLeft(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2);
MT_Matrix3x3 MT_multTransposeRight(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2);
inline MT_OStream& operator<<(MT_OStream& os, const MT_Matrix3x3& m) {
return os << m[0] << GEN_endl << m[1] << GEN_endl << m[2] << GEN_endl;
}
#ifdef GEN_INLINED
#include "MT_Matrix3x3.inl"
#endif
#endif

View File

@@ -0,0 +1,128 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Quaternion MT_Matrix3x3::getRotation() const {
static int next[3] = { 1, 2, 0 };
MT_Quaternion result;
MT_Scalar trace = m_el[0][0] + m_el[1][1] + m_el[2][2];
if (trace > 0.0)
{
MT_Scalar s = sqrt(trace + MT_Scalar(1.0));
result[3] = s * MT_Scalar(0.5);
s = MT_Scalar(0.5) / s;
result[0] = (m_el[2][1] - m_el[1][2]) * s;
result[1] = (m_el[0][2] - m_el[2][0]) * s;
result[2] = (m_el[1][0] - m_el[0][1]) * s;
}
else
{
int i = 0;
if (m_el[1][1] > m_el[0][0])
i = 1;
if (m_el[2][2] > m_el[i][i])
i = 2;
int j = next[i];
int k = next[j];
MT_Scalar s = sqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + MT_Scalar(1.0));
result[i] = s * MT_Scalar(0.5);
s = MT_Scalar(0.5) / s;
result[3] = (m_el[k][j] - m_el[j][k]) * s;
result[j] = (m_el[j][i] + m_el[i][j]) * s;
result[k] = (m_el[k][i] + m_el[i][k]) * s;
}
return result;
}
GEN_INLINE MT_Matrix3x3& MT_Matrix3x3::operator*=(const MT_Matrix3x3& m) {
setValue(m.tdot(0, m_el[0]), m.tdot(1, m_el[0]), m.tdot(2, m_el[0]),
m.tdot(0, m_el[1]), m.tdot(1, m_el[1]), m.tdot(2, m_el[1]),
m.tdot(0, m_el[2]), m.tdot(1, m_el[2]), m.tdot(2, m_el[2]));
return *this;
}
GEN_INLINE MT_Scalar MT_Matrix3x3::determinant() const {
return MT_triple((*this)[0], (*this)[1], (*this)[2]);
}
GEN_INLINE MT_Matrix3x3 MT_Matrix3x3::absolute() const {
return
MT_Matrix3x3(MT_abs(m_el[0][0]), MT_abs(m_el[0][1]), MT_abs(m_el[0][2]),
MT_abs(m_el[1][0]), MT_abs(m_el[1][1]), MT_abs(m_el[1][2]),
MT_abs(m_el[2][0]), MT_abs(m_el[2][1]), MT_abs(m_el[2][2]));
}
GEN_INLINE MT_Matrix3x3 MT_Matrix3x3::transposed() const {
return MT_Matrix3x3(m_el[0][0], m_el[1][0], m_el[2][0],
m_el[0][1], m_el[1][1], m_el[2][1],
m_el[0][2], m_el[1][2], m_el[2][2]);
}
GEN_INLINE void MT_Matrix3x3::transpose() {
*this = transposed();
}
GEN_INLINE MT_Matrix3x3 MT_Matrix3x3::adjoint() const {
return
MT_Matrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2),
cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0),
cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1));
}
GEN_INLINE MT_Matrix3x3 MT_Matrix3x3::inverse() const {
MT_Vector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1));
MT_Scalar det = MT_dot((*this)[0], co);
MT_assert(!MT_fuzzyZero2(det));
MT_Scalar s = MT_Scalar(1.0) / det;
return
MT_Matrix3x3(co[0] * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s,
co[1] * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s,
co[2] * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s);
}
GEN_INLINE void MT_Matrix3x3::invert() {
*this = inverse();
}
GEN_INLINE MT_Vector3 operator*(const MT_Matrix3x3& m, const MT_Vector3& v) {
return MT_Vector3(MT_dot(m[0], v), MT_dot(m[1], v), MT_dot(m[2], v));
}
GEN_INLINE MT_Vector3 operator*(const MT_Vector3& v, const MT_Matrix3x3& m) {
return MT_Vector3(m.tdot(0, v), m.tdot(1, v), m.tdot(2, v));
}
GEN_INLINE MT_Matrix3x3 operator*(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2) {
return
MT_Matrix3x3(m2.tdot(0, m1[0]), m2.tdot(1, m1[0]), m2.tdot(2, m1[0]),
m2.tdot(0, m1[1]), m2.tdot(1, m1[1]), m2.tdot(2, m1[1]),
m2.tdot(0, m1[2]), m2.tdot(1, m1[2]), m2.tdot(2, m1[2]));
}
GEN_INLINE MT_Matrix3x3 MT_multTransposeLeft(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2) {
return MT_Matrix3x3(
m1[0][0] * m2[0][0] + m1[1][0] * m2[1][0] + m1[2][0] * m2[2][0],
m1[0][0] * m2[0][1] + m1[1][0] * m2[1][1] + m1[2][0] * m2[2][1],
m1[0][0] * m2[0][2] + m1[1][0] * m2[1][2] + m1[2][0] * m2[2][2],
m1[0][1] * m2[0][0] + m1[1][1] * m2[1][0] + m1[2][1] * m2[2][0],
m1[0][1] * m2[0][1] + m1[1][1] * m2[1][1] + m1[2][1] * m2[2][1],
m1[0][1] * m2[0][2] + m1[1][1] * m2[1][2] + m1[2][1] * m2[2][2],
m1[0][2] * m2[0][0] + m1[1][2] * m2[1][0] + m1[2][2] * m2[2][0],
m1[0][2] * m2[0][1] + m1[1][2] * m2[1][1] + m1[2][2] * m2[2][1],
m1[0][2] * m2[0][2] + m1[1][2] * m2[1][2] + m1[2][2] * m2[2][2]);
}
GEN_INLINE MT_Matrix3x3 MT_multTransposeRight(const MT_Matrix3x3& m1, const MT_Matrix3x3& m2) {
return
MT_Matrix3x3(m1[0].dot(m2[0]), m1[0].dot(m2[1]), m1[0].dot(m2[2]),
m1[1].dot(m2[0]), m1[1].dot(m2[1]), m1[1].dot(m2[2]),
m1[2].dot(m2[0]), m1[2].dot(m2[1]), m1[2].dot(m2[2]));
}

View File

@@ -0,0 +1,250 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* $Id$
* Copyright (C) 2001 NaN Technologies B.V.
* A 4x4 matrix compatible with other stuff.
*/
#ifndef MT_MATRIX4X4_H
#define MT_MATRIX4X4_H
#include <MT_assert.h>
#include "MT_Vector4.h"
#include "MT_Transform.h"
// Row-major 4x4 matrix
class MT_Matrix4x4 {
public:
/**
* Empty contructor.
*/
MT_Matrix4x4() {}
/**
* Initialize all fields with the values pointed at by m. A
* contigous block of 16 values is read. */
MT_Matrix4x4(const float *m) { setValue(m); }
/**
* Initialize all fields with the values pointed at by m. A
* contigous block of 16 values is read. */
MT_Matrix4x4(const double *m) { setValue(m); }
/**
* Initialise with these 16 explicit values.
*/
MT_Matrix4x4(MT_Scalar xx, MT_Scalar xy, MT_Scalar xz, MT_Scalar xw,
MT_Scalar yx, MT_Scalar yy, MT_Scalar yz, MT_Scalar yw,
MT_Scalar zx, MT_Scalar zy, MT_Scalar zz, MT_Scalar zw,
MT_Scalar wx, MT_Scalar wy, MT_Scalar wz, MT_Scalar ww) {
setValue(xx, xy, xz, xw,
yx, yy, yz, yw,
zx, zy, zz, zw,
wx, wy, wz, ww);
}
/**
* Initialize from an MT_Transform.
*/
MT_Matrix4x4(const MT_Transform &t) {
const MT_Matrix3x3 &basis = t.getBasis();
const MT_Vector3 &origin = t.getOrigin();
setValue(
basis[0][0],basis[0][1],basis[0][2],origin[0],
basis[1][0],basis[1][1],basis[1][2],origin[1],
basis[2][0],basis[2][1],basis[2][2],origin[2],
MT_Scalar(0),MT_Scalar(0),MT_Scalar(0),MT_Scalar(1)
);
}
/**
* Get the i-th row.
*/
MT_Vector4& operator[](int i) { return m_el[i]; }
/**
* Get the i-th row.
*/
const MT_Vector4& operator[](int i) const { return m_el[i]; }
/**
* Set the matrix to the values pointer at by m. A contiguous
* block of 16 values is copied. */
void setValue(const float *m) {
m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m_el[3][0] = *m++;
m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m_el[3][1] = *m++;
m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m++; m_el[3][2] = *m++;
m_el[0][3] = *m++; m_el[1][3] = *m++; m_el[2][3] = *m++; m_el[3][3] = *m;
}
/**
* Set the matrix to the values pointer at by m. A contiguous
* block of 16 values is copied.
*/
void setValue(const double *m) {
m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m_el[3][0] = *m++;
m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m_el[3][1] = *m++;
m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m++; m_el[3][2] = *m++;
m_el[0][3] = *m++; m_el[1][3] = *m++; m_el[2][3] = *m++; m_el[3][3] = *m;
}
/**
* Set the matrix to these 16 explicit values.
*/
void setValue(MT_Scalar xx, MT_Scalar xy, MT_Scalar xz, MT_Scalar xw,
MT_Scalar yx, MT_Scalar yy, MT_Scalar yz, MT_Scalar yw,
MT_Scalar zx, MT_Scalar zy, MT_Scalar zz, MT_Scalar zw,
MT_Scalar wx, MT_Scalar wy, MT_Scalar wz, MT_Scalar ww) {
m_el[0][0] = xx; m_el[0][1] = xy; m_el[0][2] = xz; m_el[0][3] = xw;
m_el[1][0] = yx; m_el[1][1] = yy; m_el[1][2] = yz; m_el[1][3] = yw;
m_el[2][0] = zx; m_el[2][1] = zy; m_el[2][2] = zz; m_el[2][3] = zw;
m_el[3][0] = wx; m_el[3][1] = wy; m_el[3][2] = wz; m_el[3][3] = ww;
}
/**
* Scale the columns of this matrix with x, y, z, w respectively.
*/
void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) {
m_el[0][0] *= x; m_el[0][1] *= y; m_el[0][2] *= z; m_el[0][3] *= w;
m_el[1][0] *= x; m_el[1][1] *= y; m_el[1][2] *= z; m_el[1][3] *= w;
m_el[2][0] *= x; m_el[2][1] *= y; m_el[2][2] *= z; m_el[2][3] *= w;
m_el[3][0] *= x; m_el[3][1] *= y; m_el[3][2] *= z; m_el[3][3] *= w;
}
/**
* Return a column-scaled version of this matrix.
*/
MT_Matrix4x4 scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) const {
return MT_Matrix4x4(m_el[0][0] * x, m_el[0][1] * y, m_el[0][2] * z, m_el[0][3] * w,
m_el[1][0] * x, m_el[1][1] * y, m_el[1][2] * z, m_el[1][3] * w,
m_el[2][0] * x, m_el[2][1] * y, m_el[2][2] * z, m_el[2][3] * w,
m_el[3][0] * x, m_el[3][1] * y, m_el[3][2] * z, m_el[3][3] * w);
}
/**
* Set this matrix to I.
*/
void setIdentity() {
setValue(MT_Scalar(1.0), MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(0.0),
MT_Scalar(0.0), MT_Scalar(1.0), MT_Scalar(0.0), MT_Scalar(0.0),
MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(1.0), MT_Scalar(0.0),
MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(1.0));
}
/**
* Read the element from row i, column j.
*/
float getElement(int i, int j) {
return m_el[i][j];
}
/**
* Copy the contents to a contiguous block of 16 floats.
*/
void getValue(float *m) const {
*m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = m_el[3][0];
*m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = m_el[3][1];
*m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m++ = m_el[3][2];
*m++ = m_el[0][3]; *m++ = m_el[1][3]; *m++ = m_el[2][3]; *m = m_el[3][3];
}
/**
* Copy the contents to a contiguous block of 16 doubles.
*/
void getValue(double *m) const {
*m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = m_el[3][0];
*m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = m_el[3][1];
*m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m++ = m_el[3][2];
*m++ = m_el[0][3]; *m++ = m_el[1][3]; *m++ = m_el[2][3]; *m = m_el[3][3];
}
/**
* Left-multiply this matrix with the argument.
*/
MT_Matrix4x4& operator*=(const MT_Matrix4x4& m);
/**
* Left-multiply column c with row vector c.
*/
MT_Scalar tdot(int c, const MT_Vector4& v) const {
return m_el[0][c] * v[0]
+ m_el[1][c] * v[1]
+ m_el[2][c] * v[2]
+ m_el[3][c] * v[3];
}
/* I'll postpone this for now... - nzc*/
/* MT_Scalar determinant() const; */
/* MT_Matrix4x4 adjoint() const; */
/* MT_Matrix4x4 inverse() const; */
MT_Matrix4x4 absolute() const;
MT_Matrix4x4 transposed() const;
void transpose();
void invert();
protected:
/**
* Access with [row index][column index]
*/
MT_Vector4 m_el[4];
};
/* These multiplicators do exactly what you ask from them: they
* multiply in the indicated order. */
MT_Vector4 operator*(const MT_Matrix4x4& m, const MT_Vector4& v);
MT_Vector4 operator*(const MT_Vector4& v, const MT_Matrix4x4& m);
MT_Matrix4x4 operator*(const MT_Matrix4x4& m1, const MT_Matrix4x4& m2);
/* MT_Matrix4x4 MT_multTransposeLeft(const MT_Matrix4x4& m1, const MT_Matrix4x4& m2); */
/* MT_Matrix4x4 MT_multTransposeRight(const MT_Matrix4x4& m1, const MT_Matrix4x4& m2); */
inline MT_OStream& operator<<(MT_OStream& os, const MT_Matrix4x4& m) {
return os << m[0] << GEN_endl
<< m[1] << GEN_endl
<< m[2] << GEN_endl
<< m[3] << GEN_endl;
}
#ifdef GEN_INLINED
#include "MT_Matrix4x4.inl"
#endif
#endif

View File

@@ -0,0 +1,108 @@
#include "MT_Optimize.h"
/*
* This is a supposedly faster inverter than the cofactor
* computation. It uses an LU decomposition sort of thing. */
GEN_INLINE void MT_Matrix4x4::invert() {
/* normalize row 0 */
int i,j,k;
for (i=1; i < 4; i++) m_el[0][i] /= m_el[0][0];
for (i=1; i < 4; i++) {
for (j=i; j < 4; j++) { // do a column of L
MT_Scalar sum = 0.0;
for (k = 0; k < i; k++)
sum += m_el[j][k] * m_el[k][i];
m_el[j][i] -= sum;
}
if (i == 3) continue;
for (j=i+1; j < 4; j++) { // do a row of U
MT_Scalar sum = 0.0;
for (k = 0; k < i; k++)
sum += m_el[i][k]*m_el[k][j];
m_el[i][j] =
(m_el[i][j]-sum) / m_el[i][i];
}
}
for (i = 0; i < 4; i++ ) // invert L
for (j = i; j < 4; j++ ) {
MT_Scalar x = 1.0;
if ( i != j ) {
x = 0.0;
for (k = i; k < j; k++ )
x -= m_el[j][k]*m_el[k][i];
}
m_el[j][i] = x / m_el[j][j];
}
for (i = 0; i < 4; i++ ) // invert U
for (j = i; j < 4; j++ ) {
if ( i == j ) continue;
MT_Scalar sum = 0.0;
for (k = i; k < j; k++ )
sum += m_el[k][j]*( (i==k) ? 1.0 : m_el[i][k] );
m_el[i][j] = -sum;
}
for (i = 0; i < 4; i++ ) // final inversion
for (j = 0; j < 4; j++ ) {
MT_Scalar sum = 0.0;
for (k = ((i>j)?i:j); k < 4; k++ )
sum += ((j==k)?1.0:m_el[j][k])*m_el[k][i];
m_el[j][i] = sum;
}
}
/* We do things slightly different here, because the invert() modifies
* the buffer itself. This makes it impossible to make this op right
* away. Like other, still missing facilities, I will repair this
* later. */
/* GEN_INLINE T_Matrix4x4 MT_Matrix4x4::inverse() const */
/* { */
/* } */
GEN_INLINE MT_Matrix4x4& MT_Matrix4x4::operator*=(const MT_Matrix4x4& m)
{
setValue(m.tdot(0, m_el[0]), m.tdot(1, m_el[0]), m.tdot(2, m_el[0]), m.tdot(3, m_el[0]),
m.tdot(0, m_el[1]), m.tdot(1, m_el[1]), m.tdot(2, m_el[1]), m.tdot(3, m_el[1]),
m.tdot(0, m_el[2]), m.tdot(1, m_el[2]), m.tdot(2, m_el[2]), m.tdot(3, m_el[2]),
m.tdot(0, m_el[3]), m.tdot(1, m_el[3]), m.tdot(2, m_el[3]), m.tdot(3, m_el[3]));
return *this;
}
GEN_INLINE MT_Vector4 operator*(const MT_Matrix4x4& m, const MT_Vector4& v) {
return MT_Vector4(MT_dot(m[0], v), MT_dot(m[1], v), MT_dot(m[2], v), MT_dot(m[3], v));
}
GEN_INLINE MT_Vector4 operator*(const MT_Vector4& v, const MT_Matrix4x4& m) {
return MT_Vector4(m.tdot(0, v), m.tdot(1, v), m.tdot(2, v), m.tdot(3, v));
}
GEN_INLINE MT_Matrix4x4 operator*(const MT_Matrix4x4& m1, const MT_Matrix4x4& m2) {
return
MT_Matrix4x4(m2.tdot(0, m1[0]), m2.tdot(1, m1[0]), m2.tdot(2, m1[0]), m2.tdot(3, m1[0]),
m2.tdot(0, m1[1]), m2.tdot(1, m1[1]), m2.tdot(2, m1[1]), m2.tdot(3, m1[1]),
m2.tdot(0, m1[2]), m2.tdot(1, m1[2]), m2.tdot(2, m1[2]), m2.tdot(3, m1[2]),
m2.tdot(0, m1[3]), m2.tdot(1, m1[3]), m2.tdot(2, m1[3]), m2.tdot(3, m1[3]));
}
GEN_INLINE MT_Matrix4x4 MT_Matrix4x4::transposed() const {
return MT_Matrix4x4(m_el[0][0], m_el[1][0], m_el[2][0], m_el[3][0],
m_el[0][1], m_el[1][1], m_el[2][1], m_el[3][1],
m_el[0][2], m_el[1][2], m_el[2][2], m_el[3][2],
m_el[0][3], m_el[1][3], m_el[2][3], m_el[3][3]);
}
GEN_INLINE void MT_Matrix4x4::transpose() {
*this = transposed();
}
GEN_INLINE MT_Matrix4x4 MT_Matrix4x4::absolute() const {
return
MT_Matrix4x4(MT_abs(m_el[0][0]), MT_abs(m_el[0][1]), MT_abs(m_el[0][2]), MT_abs(m_el[0][3]),
MT_abs(m_el[1][0]), MT_abs(m_el[1][1]), MT_abs(m_el[1][2]), MT_abs(m_el[1][3]),
MT_abs(m_el[2][0]), MT_abs(m_el[2][1]), MT_abs(m_el[2][2]), MT_abs(m_el[2][3]),
MT_abs(m_el[3][0]), MT_abs(m_el[3][1]), MT_abs(m_el[3][2]), MT_abs(m_el[3][3]));
}

69
intern/moto/include/MT_MinMax.h Executable file
View File

@@ -0,0 +1,69 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_MINMAX_H
#define MT_MINMAX_H
template <class T>
inline const T& MT_min(const T& a, const T& b) {
return b < a ? b : a;
}
template <class T>
inline const T& MT_max(const T& a, const T& b) {
return a < b ? b : a;
}
template <class T>
inline void MT_set_min(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
inline void MT_set_max(T& a, const T& b) {
if (a < b) a = b;
}
#endif

View File

@@ -0,0 +1,42 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef GEN_OPTIMIZE_H
#define GEN_OPTIMIZE_H
#ifdef GEN_INLINED
#define GEN_INLINE inline
#else
#define GEN_INLINE
#endif
#endif

View File

@@ -0,0 +1,139 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef MT_PLANE3
#define MT_PLANE3
#include "MT_Tuple4.h"
#include "MT_Point3.h"
/**
* A simple 3d plane class.
*
* This class represents a plane in 3d. The internal parameterization used
* is n.x + d =0 where n is a unit vector and d is a scalar.
*
* It inherits data from MT_Tuple4 please see this class for low level
* access to the internal representation.
*
*/
class MT_Plane3 : public MT_Tuple4
{
public :
/**
* Constructor from 3 points
*/
MT_Plane3(
const MT_Vector3 &a,
const MT_Vector3 &b,
const MT_Vector3 &c
);
/**
* Construction from vector and a point.
*/
MT_Plane3(
const MT_Vector3 &n,
const MT_Vector3 &p
);
/**
* Default constructor
*/
MT_Plane3(
);
/**
* Default constructor
*/
MT_Plane3(
const MT_Plane3 & p
):
MT_Tuple4(p)
{
}
/**
* Return plane normal
*/
MT_Vector3
Normal(
) const;
/**
* Return plane scalar i.e the d from n.x + d = 0
*/
MT_Scalar
Scalar(
) const ;
/**
* Invert the plane - just swaps direction of normal.
*/
void
Invert(
);
/**
* Assignment operator
*/
MT_Plane3 &
operator = (
const MT_Plane3 & rhs
);
/**
* Return the signed perpendicular distance from a point to the plane
*/
MT_Scalar
signedDistance(
const MT_Vector3 &
) const;
};
#ifdef GEN_INLINED
#include "MT_Plane3.inl"
#endif
#endif

View File

@@ -0,0 +1,128 @@
#include "MT_Optimize.h"
GEN_INLINE
MT_Plane3::
MT_Plane3(
const MT_Vector3 &a,
const MT_Vector3 &b,
const MT_Vector3 &c
){
MT_Vector3 l1 = b-a;
MT_Vector3 l2 = c-b;
MT_Vector3 n = l1.cross(l2);
n = n.safe_normalized();
MT_Scalar d = n.dot(a);
m_co[0] = n.x();
m_co[1] = n.y();
m_co[2] = n.z();
m_co[3] = -d;
}
/**
* Construction from vector and a point.
*/
GEN_INLINE
MT_Plane3::
MT_Plane3(
const MT_Vector3 &n,
const MT_Vector3 &p
){
MT_Vector3 mn = n.safe_normalized();
MT_Scalar md = mn.dot(p);
m_co[0] = mn.x();
m_co[1] = mn.y();
m_co[2] = mn.z();
m_co[3] = -md;
}
/**
* Default constructor
*/
GEN_INLINE
MT_Plane3::
MT_Plane3(
):
MT_Tuple4()
{
m_co[0] = MT_Scalar(1);
m_co[1] = MT_Scalar(0);
m_co[2] = MT_Scalar(0);
m_co[3] = MT_Scalar(0);
}
/**
* Return plane normal
*/
GEN_INLINE
MT_Vector3
MT_Plane3::
Normal(
) const {
return MT_Vector3(m_co[0],m_co[1],m_co[2]);
}
/**
* Return plane scalar i.e the d from n.x + d = 0
*/
GEN_INLINE
MT_Scalar
MT_Plane3::
Scalar(
) const {
return m_co[3];
}
GEN_INLINE
void
MT_Plane3::
Invert(
) {
m_co[0] = -m_co[0];
m_co[1] = -m_co[1];
m_co[2] = -m_co[2];
m_co[3] = -m_co[3];
}
/**
* Assignment operator
*/
GEN_INLINE
MT_Plane3 &
MT_Plane3::
operator = (
const MT_Plane3 & rhs
) {
m_co[0] = rhs.m_co[0];
m_co[1] = rhs.m_co[1];
m_co[2] = rhs.m_co[2];
m_co[3] = rhs.m_co[3];
return *this;
}
/**
* Return the distance from a point to the plane
*/
GEN_INLINE
MT_Scalar
MT_Plane3::
signedDistance(
const MT_Vector3 &v
) const {
return Normal().dot(v) + m_co[3];
}

View File

@@ -0,0 +1,81 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_POINT2_H
#define MT_POINT2_H
#include "MT_Vector2.h"
class MT_Point2 : public MT_Vector2 {
public:
MT_Point2() {}
MT_Point2(const float *v) : MT_Vector2(v) {}
MT_Point2(const double *v) : MT_Vector2(v) {}
MT_Point2(MT_Scalar x, MT_Scalar y) : MT_Vector2(x, y) {}
MT_Point2& operator+=(const MT_Vector2& v);
MT_Point2& operator-=(const MT_Vector2& v);
MT_Point2& operator=(const MT_Vector2& v);
MT_Scalar distance(const MT_Point2& p) const;
MT_Scalar distance2(const MT_Point2& p) const;
MT_Point2 lerp(const MT_Point2& p, MT_Scalar t) const;
};
MT_Point2 operator+(const MT_Point2& p, const MT_Vector2& v);
MT_Point2 operator-(const MT_Point2& p, const MT_Vector2& v);
MT_Vector2 operator-(const MT_Point2& p1, const MT_Point2& p2);
MT_Scalar MT_distance(const MT_Point2& p1, const MT_Point2& p2);
MT_Scalar MT_distance2(const MT_Point2& p1, const MT_Point2& p2);
MT_Point2 MT_lerp(const MT_Point2& p1, const MT_Point2& p2, MT_Scalar t);
#ifdef GEN_INLINED
#include "MT_Point2.inl"
#endif
#endif

View File

@@ -0,0 +1,54 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Point2& MT_Point2::operator+=(const MT_Vector2& v) {
m_co[0] += v[0]; m_co[1] += v[1];
return *this;
}
GEN_INLINE MT_Point2& MT_Point2::operator-=(const MT_Vector2& v) {
m_co[0] -= v[0]; m_co[1] -= v[1];
return *this;
}
GEN_INLINE MT_Point2& MT_Point2::operator=(const MT_Vector2& v) {
m_co[0] = v[0]; m_co[1] = v[1];
return *this;
}
GEN_INLINE MT_Scalar MT_Point2::distance(const MT_Point2& p) const {
return (p - *this).length();
}
GEN_INLINE MT_Scalar MT_Point2::distance2(const MT_Point2& p) const {
return (p - *this).length2();
}
GEN_INLINE MT_Point2 MT_Point2::lerp(const MT_Point2& p, MT_Scalar t) const {
return MT_Point2(m_co[0] + (p[0] - m_co[0]) * t,
m_co[1] + (p[1] - m_co[1]) * t);
}
GEN_INLINE MT_Point2 operator+(const MT_Point2& p, const MT_Vector2& v) {
return MT_Point2(p[0] + v[0], p[1] + v[1]);
}
GEN_INLINE MT_Point2 operator-(const MT_Point2& p, const MT_Vector2& v) {
return MT_Point2(p[0] - v[0], p[1] - v[1]);
}
GEN_INLINE MT_Vector2 operator-(const MT_Point2& p1, const MT_Point2& p2) {
return MT_Vector2(p1[0] - p2[0], p1[1] - p2[1]);
}
GEN_INLINE MT_Scalar MT_distance(const MT_Point2& p1, const MT_Point2& p2) {
return p1.distance(p2);
}
GEN_INLINE MT_Scalar MT_distance2(const MT_Point2& p1, const MT_Point2& p2) {
return p1.distance2(p2);
}
GEN_INLINE MT_Point2 MT_lerp(const MT_Point2& p1, const MT_Point2& p2, MT_Scalar t) {
return p1.lerp(p2, t);
}

View File

@@ -0,0 +1,81 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_POINT_H
#define MT_POINT_H
#include "MT_Vector3.h"
class MT_Point3 : public MT_Vector3 {
public:
MT_Point3() {}
MT_Point3(const float *v) : MT_Vector3(v) {}
MT_Point3(const double *v) : MT_Vector3(v) {}
MT_Point3(MT_Scalar x, MT_Scalar y, MT_Scalar z) : MT_Vector3(x, y, z) {}
MT_Point3& operator+=(const MT_Vector3& v);
MT_Point3& operator-=(const MT_Vector3& v);
MT_Point3& operator=(const MT_Vector3& v);
MT_Scalar distance(const MT_Point3& p) const;
MT_Scalar distance2(const MT_Point3& p) const;
MT_Point3 lerp(const MT_Point3& p, MT_Scalar t) const;
};
MT_Point3 operator+(const MT_Point3& p, const MT_Vector3& v);
MT_Point3 operator-(const MT_Point3& p, const MT_Vector3& v);
MT_Vector3 operator-(const MT_Point3& p1, const MT_Point3& p2);
MT_Scalar MT_distance(const MT_Point3& p1, const MT_Point3& p2);
MT_Scalar MT_distance2(const MT_Point3& p1, const MT_Point3& p2);
MT_Point3 MT_lerp(const MT_Point3& p1, const MT_Point3& p2, MT_Scalar t);
#ifdef GEN_INLINED
#include "MT_Point3.inl"
#endif
#endif

View File

@@ -0,0 +1,54 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Point3& MT_Point3::operator+=(const MT_Vector3& v) {
m_co[0] += v[0]; m_co[1] += v[1]; m_co[2] += v[2];
return *this;
}
GEN_INLINE MT_Point3& MT_Point3::operator-=(const MT_Vector3& v) {
m_co[0] -= v[0]; m_co[1] -= v[1]; m_co[2] -= v[2];
return *this;
}
GEN_INLINE MT_Point3& MT_Point3::operator=(const MT_Vector3& v) {
m_co[0] = v[0]; m_co[1] = v[1]; m_co[2] = v[2];
return *this;
}
GEN_INLINE MT_Scalar MT_Point3::distance(const MT_Point3& p) const {
return (p - *this).length();
}
GEN_INLINE MT_Scalar MT_Point3::distance2(const MT_Point3& p) const {
return (p - *this).length2();
}
GEN_INLINE MT_Point3 MT_Point3::lerp(const MT_Point3& p, MT_Scalar t) const {
return MT_Point3(m_co[0] + (p[0] - m_co[0]) * t,
m_co[1] + (p[1] - m_co[1]) * t,
m_co[2] + (p[2] - m_co[2]) * t);
}
GEN_INLINE MT_Point3 operator+(const MT_Point3& p, const MT_Vector3& v) {
return MT_Point3(p[0] + v[0], p[1] + v[1], p[2] + v[2]);
}
GEN_INLINE MT_Point3 operator-(const MT_Point3& p, const MT_Vector3& v) {
return MT_Point3(p[0] - v[0], p[1] - v[1], p[2] - v[2]);
}
GEN_INLINE MT_Vector3 operator-(const MT_Point3& p1, const MT_Point3& p2) {
return MT_Vector3(p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2]);
}
GEN_INLINE MT_Scalar MT_distance(const MT_Point3& p1, const MT_Point3& p2) {
return p1.distance(p2);
}
GEN_INLINE MT_Scalar MT_distance2(const MT_Point3& p1, const MT_Point3& p2) {
return p1.distance2(p2);
}
GEN_INLINE MT_Point3 MT_lerp(const MT_Point3& p1, const MT_Point3& p2, MT_Scalar t) {
return p1.lerp(p2, t);
}

View File

@@ -0,0 +1,112 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_QUATERNION_H
#define MT_QUATERNION_H
#include <MT_assert.h>
#include "MT_Vector3.h"
#include "MT_Vector4.h"
class MT_Quaternion : public MT_Vector4 {
public:
MT_Quaternion() {}
MT_Quaternion(const MT_Vector4& v) : MT_Vector4(v) {}
MT_Quaternion(const float v[4]) : MT_Vector4(v) {}
MT_Quaternion(const double v[4]) : MT_Vector4(v) {}
MT_Quaternion(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) :
MT_Vector4(x, y, z, w) {}
MT_Quaternion(const MT_Vector3& axis, MT_Scalar angle) {
setRotation(axis, angle);
}
MT_Quaternion(MT_Scalar yaw, MT_Scalar pitch, MT_Scalar roll) {
setEuler(yaw, pitch, roll);
}
void setRotation(const MT_Vector3& axis, MT_Scalar angle) {
MT_Scalar d = axis.length();
MT_assert(!MT_fuzzyZero(d));
MT_Scalar s = sin(angle * MT_Scalar(0.5)) / d;
setValue(axis[0] * s, axis[1] * s, axis[2] * s,
cos(angle * MT_Scalar(0.5)));
}
void setEuler(MT_Scalar yaw, MT_Scalar pitch, MT_Scalar roll) {
MT_Scalar cosYaw = cos(yaw * MT_Scalar(0.5));
MT_Scalar sinYaw = sin(yaw * MT_Scalar(0.5));
MT_Scalar cosPitch = cos(pitch * MT_Scalar(0.5));
MT_Scalar sinPitch = sin(pitch * MT_Scalar(0.5));
MT_Scalar cosRoll = cos(roll * MT_Scalar(0.5));
MT_Scalar sinRoll = sin(roll * MT_Scalar(0.5));
setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
}
MT_Quaternion& operator*=(const MT_Quaternion& q);
void conjugate();
MT_Quaternion conjugate() const;
void invert();
MT_Quaternion inverse() const;
static MT_Quaternion random();
};
MT_Quaternion operator*(const MT_Quaternion& q1, const MT_Quaternion& q2);
MT_Quaternion operator*(const MT_Quaternion& q, const MT_Vector3& w);
MT_Quaternion operator*(const MT_Vector3& w, const MT_Quaternion& q);
#ifdef GEN_INLINED
#include "MT_Quaternion.inl"
#endif
#endif

View File

@@ -0,0 +1,62 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Quaternion& MT_Quaternion::operator*=(const MT_Quaternion& q) {
setValue(m_co[3] * q[0] + m_co[0] * q[3] + m_co[1] * q[2] - m_co[2] * q[1],
m_co[3] * q[1] + m_co[1] * q[3] + m_co[2] * q[0] - m_co[0] * q[2],
m_co[3] * q[2] + m_co[2] * q[3] + m_co[0] * q[1] - m_co[1] * q[0],
m_co[3] * q[3] - m_co[0] * q[0] - m_co[1] * q[1] - m_co[2] * q[2]);
return *this;
}
GEN_INLINE void MT_Quaternion::conjugate() {
m_co[0] = -m_co[0]; m_co[1] = -m_co[1]; m_co[2] = -m_co[2];
}
GEN_INLINE MT_Quaternion MT_Quaternion::conjugate() const {
return MT_Quaternion(-m_co[0], -m_co[1], -m_co[2], m_co[3]);
}
GEN_INLINE void MT_Quaternion::invert() {
conjugate();
*this /= length2();
}
GEN_INLINE MT_Quaternion MT_Quaternion::inverse() const {
return conjugate() / length2();
}
// From: "Uniform Random Rotations", Ken Shoemake, Graphics Gems III,
// pg. 124-132
GEN_INLINE MT_Quaternion MT_Quaternion::random() {
MT_Scalar x0 = MT_random();
MT_Scalar r1 = sqrt(MT_Scalar(1.0) - x0), r2 = sqrt(x0);
MT_Scalar t1 = MT_2_PI * MT_random(), t2 = MT_2_PI * MT_random();
MT_Scalar c1 = cos(t1), s1 = sin(t1);
MT_Scalar c2 = cos(t2), s2 = sin(t2);
return MT_Quaternion(s1 * r1, c1 * r1, s2 * r2, c2 * r2);
}
GEN_INLINE MT_Quaternion operator*(const MT_Quaternion& q1,
const MT_Quaternion& q2) {
return MT_Quaternion(q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1],
q1[3] * q2[1] + q1[1] * q2[3] + q1[2] * q2[0] - q1[0] * q2[2],
q1[3] * q2[2] + q1[2] * q2[3] + q1[0] * q2[1] - q1[1] * q2[0],
q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2]);
}
GEN_INLINE MT_Quaternion operator*(const MT_Quaternion& q, const MT_Vector3& w)
{
return MT_Quaternion( q[3] * w[0] + q[1] * w[2] - q[2] * w[1],
q[3] * w[1] + q[2] * w[0] - q[0] * w[2],
q[3] * w[2] + q[0] * w[1] - q[1] * w[0],
-q[0] * w[0] - q[1] * w[1] - q[2] * w[2]);
}
GEN_INLINE MT_Quaternion operator*(const MT_Vector3& w, const MT_Quaternion& q)
{
return MT_Quaternion( w[0] * q[3] + w[1] * q[2] - w[2] * q[1],
w[1] * q[3] + w[2] * q[0] - w[0] * q[2],
w[2] * q[3] + w[0] * q[1] - w[1] * q[0],
-w[0] * q[0] - w[1] * q[1] - w[2] * q[2]);
}

88
intern/moto/include/MT_Scalar.h Executable file
View File

@@ -0,0 +1,88 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_SCALAR_H
#define MT_SCALAR_H
#include <math.h>
#include <float.h>
#include "MT_random.h"
#include "NM_Scalar.h"
typedef double MT_Scalar;
const MT_Scalar MT_DEGS_PER_RAD(57.29577951308232286465);
const MT_Scalar MT_RADS_PER_DEG(0.01745329251994329547);
const MT_Scalar MT_PI(3.14159265358979323846);
const MT_Scalar MT_2_PI(6.28318530717958623200);
const MT_Scalar MT_EPSILON(1.0e-10);
const MT_Scalar MT_EPSILON2(1.0e-20);
const MT_Scalar MT_INFINITY(1.0e50);
inline int MT_sign(MT_Scalar x) {
return x < 0.0 ? -1 : x > 0.0 ? 1 : 0;
}
inline MT_Scalar MT_abs(MT_Scalar x) { return fabs(x); }
inline bool MT_fuzzyZero(MT_Scalar x) { return MT_abs(x) < MT_EPSILON; }
inline bool MT_fuzzyZero2(MT_Scalar x) { return MT_abs(x) < MT_EPSILON2; }
inline MT_Scalar MT_radians(MT_Scalar x) {
return x * MT_RADS_PER_DEG;
}
inline MT_Scalar MT_degrees(MT_Scalar x) {
return x * MT_DEGS_PER_RAD;
}
inline MT_Scalar MT_random() {
return MT_Scalar(MT_rand()) / MT_Scalar(MT_RAND_MAX);
}
#endif

58
intern/moto/include/MT_Stream.h Executable file
View File

@@ -0,0 +1,58 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef GEN_STREAM_H
#define GEN_STREAM_H
#ifdef __CUSTOM_STREAM
class MT_OStream
{
public:
inline MT_OStream& operator<<(double);
inline MT_OStream& operator<<(int);
inline MT_OStream& operator<<(char*);
};
const char GEN_endl = '\n';
#else
#include <iostream>
typedef std::ostream MT_OStream;
inline MT_OStream& GEN_endl(MT_OStream& os) { return std::endl(os); }
#endif
#endif

View File

@@ -0,0 +1,172 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
MoTo - 3D Motion Toolkit
Copyright (C) 2000 Gino van den Bergen <gino@acm.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef MT_TRANSFORM_H
#define MT_TRANSFORM_H
#include "MT_Point3.h"
#include "MT_Matrix3x3.h"
class MT_Transform {
public:
MT_Transform() {}
MT_Transform(const float *m) { setValue(m); }
MT_Transform(const double *m) { setValue(m); }
MT_Transform(const MT_Point3& p, const MT_Quaternion& q) {
setOrigin(p);
setRotation(q);
}
MT_Transform(const MT_Point3& p, const MT_Matrix3x3& m) {
setOrigin(p);
setBasis(m);
}
MT_Point3 operator()(const MT_Point3& p) const {
return MT_Point3(MT_dot(m_basis[0], p) + m_origin[0],
MT_dot(m_basis[1], p) + m_origin[1],
MT_dot(m_basis[2], p) + m_origin[2]);
}
MT_Point3 operator*(const MT_Point3& p) const {
return (*this)(p);
}
MT_Matrix3x3& getBasis() { return m_basis; }
const MT_Matrix3x3& getBasis() const { return m_basis; }
MT_Point3& getOrigin() { return m_origin; }
const MT_Point3& getOrigin() const { return m_origin; }
MT_Quaternion getRotation() const { return m_basis.getRotation(); }
void setValue(const float *m);
void setValue(const double *m);
void setOrigin(const MT_Point3& origin) {
m_origin = origin;
m_type |= TRANSLATION;
}
void setBasis(const MT_Matrix3x3& basis) {
m_basis = basis;
m_type |= LINEAR;
}
void setRotation(const MT_Quaternion& q) {
m_basis.setRotation(q);
m_type &= ~SCALING;
m_type |= ROTATION;
}
void getValue(float *m) const;
void getValue(double *m) const;
void setIdentity();
MT_Transform& operator*=(const MT_Transform& t);
/**
* Translate the origin of the transform according to the vector.
* @param v The vector to translate over. The vector is specified
* in the coordinate system of the transform itself.
*/
void translate(const MT_Vector3& v);
void rotate(const MT_Quaternion& q);
void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z);
void invert(const MT_Transform& t);
void mult(const MT_Transform& t1, const MT_Transform& t2);
void multInverseLeft(const MT_Transform& t1, const MT_Transform& t2);
private:
enum {
IDENTITY = 0x00,
TRANSLATION = 0x01,
ROTATION = 0x02,
RIGID = TRANSLATION | ROTATION,
SCALING = 0x04,
LINEAR = ROTATION | SCALING,
AFFINE = TRANSLATION | LINEAR
};
MT_Transform(const MT_Matrix3x3& basis, const MT_Point3& origin,
unsigned int type) {
setValue(basis, origin, type);
}
void setValue(const MT_Matrix3x3& basis, const MT_Point3& origin,
unsigned int type) {
m_basis = basis;
m_origin = origin;
m_type = type;
}
friend MT_Transform operator*(const MT_Transform& t1, const MT_Transform& t2);
MT_Matrix3x3 m_basis;
MT_Point3 m_origin;
unsigned int m_type;
};
inline MT_Transform operator*(const MT_Transform& t1, const MT_Transform& t2) {
return MT_Transform(t1.m_basis * t2.m_basis,
t1(t2.m_origin),
t1.m_type | t2.m_type);
}
#endif

109
intern/moto/include/MT_Tuple2.h Executable file
View File

@@ -0,0 +1,109 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_Tuple2_H
#define MT_Tuple2_H
#include "MT_Stream.h"
#include "MT_Scalar.h"
class MT_Tuple2 {
public:
MT_Tuple2() {}
MT_Tuple2(const float *v) { setValue(v); }
MT_Tuple2(const double *v) { setValue(v); }
MT_Tuple2(MT_Scalar x, MT_Scalar y) { setValue(x, y); }
MT_Scalar& operator[](int i) { return m_co[i]; }
const MT_Scalar& operator[](int i) const { return m_co[i]; }
MT_Scalar& x() { return m_co[0]; }
const MT_Scalar& x() const { return m_co[0]; }
MT_Scalar& y() { return m_co[1]; }
const MT_Scalar& y() const { return m_co[1]; }
MT_Scalar& u() { return m_co[0]; }
const MT_Scalar& u() const { return m_co[0]; }
MT_Scalar& v() { return m_co[1]; }
const MT_Scalar& v() const { return m_co[1]; }
MT_Scalar *getValue() { return m_co; }
const MT_Scalar *getValue() const { return m_co; }
void getValue(float *v) const {
v[0] = m_co[0]; v[1] = m_co[1];
}
void getValue(double *v) const {
v[0] = m_co[0]; v[1] = m_co[1];
}
void setValue(const float *v) {
m_co[0] = v[0]; m_co[1] = v[1];
}
void setValue(const double *v) {
m_co[0] = v[0]; m_co[1] = v[1];
}
void setValue(MT_Scalar x, MT_Scalar y) {
m_co[0] = x; m_co[1] = y;
}
protected:
MT_Scalar m_co[2];
};
inline bool operator==(const MT_Tuple2& t1, const MT_Tuple2& t2) {
return t1[0] == t2[0] && t1[1] == t2[1];
}
inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple2& t) {
return os << t[0] << ' ' << t[1];
}
#endif

114
intern/moto/include/MT_Tuple3.h Executable file
View File

@@ -0,0 +1,114 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_TUPLE3_H
#define MT_TUPLE3_H
#include "MT_Stream.h"
#include "MT_Scalar.h"
class MT_Tuple3 {
public:
MT_Tuple3() {}
MT_Tuple3(const float *v) { setValue(v); }
MT_Tuple3(const double *v) { setValue(v); }
MT_Tuple3(MT_Scalar x, MT_Scalar y, MT_Scalar z) { setValue(x, y, z); }
MT_Scalar& operator[](int i) { return m_co[i]; }
const MT_Scalar& operator[](int i) const { return m_co[i]; }
MT_Scalar& x() { return m_co[0]; }
const MT_Scalar& x() const { return m_co[0]; }
MT_Scalar& y() { return m_co[1]; }
const MT_Scalar& y() const { return m_co[1]; }
MT_Scalar& z() { return m_co[2]; }
const MT_Scalar& z() const { return m_co[2]; }
MT_Scalar *getValue() { return m_co; }
const MT_Scalar *getValue() const { return m_co; }
void getValue(float *v) const {
v[0] = float(m_co[0]);
v[1] = float(m_co[1]);
v[2] = float(m_co[2]);
}
void getValue(double *v) const {
v[0] = double(m_co[0]);
v[1] = double(m_co[1]);
v[2] = double(m_co[2]);
}
void setValue(const float *v) {
m_co[0] = MT_Scalar(v[0]);
m_co[1] = MT_Scalar(v[1]);
m_co[2] = MT_Scalar(v[2]);
}
void setValue(const double *v) {
m_co[0] = MT_Scalar(v[0]);
m_co[1] = MT_Scalar(v[1]);
m_co[2] = MT_Scalar(v[2]);
}
void setValue(MT_Scalar x, MT_Scalar y, MT_Scalar z) {
m_co[0] = x; m_co[1] = y; m_co[2] = z;
}
protected:
MT_Scalar m_co[3];
};
inline bool operator==(const MT_Tuple3& t1, const MT_Tuple3& t2) {
return t1[0] == t2[0] && t1[1] == t2[1] && t1[2] == t2[2];
}
inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple3& t) {
return os << t[0] << ' ' << t[1] << ' ' << t[2];
}
#endif

124
intern/moto/include/MT_Tuple4.h Executable file
View File

@@ -0,0 +1,124 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_TUPLE4_H
#define MT_TUPLE4_H
#include "MT_Stream.h"
#include "MT_Scalar.h"
class MT_Tuple4 {
public:
MT_Tuple4() {}
MT_Tuple4(const float *v) { setValue(v); }
MT_Tuple4(const double *v) { setValue(v); }
MT_Tuple4(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) {
setValue(x, y, z, w);
}
MT_Scalar& operator[](int i) { return m_co[i]; }
const MT_Scalar& operator[](int i) const { return m_co[i]; }
MT_Scalar& x() { return m_co[0]; }
const MT_Scalar& x() const { return m_co[0]; }
MT_Scalar& y() { return m_co[1]; }
const MT_Scalar& y() const { return m_co[1]; }
MT_Scalar& z() { return m_co[2]; }
const MT_Scalar& z() const { return m_co[2]; }
MT_Scalar& w() { return m_co[3]; }
const MT_Scalar& w() const { return m_co[3]; }
MT_Scalar *getValue() { return m_co; }
const MT_Scalar *getValue() const { return m_co; }
void getValue(float *v) const {
v[0] = float(m_co[0]);
v[1] = float(m_co[1]);
v[2] = float(m_co[2]);
v[3] = float(m_co[3]);
}
void getValue(double *v) const {
v[0] = double(m_co[0]);
v[1] = double(m_co[1]);
v[2] = double(m_co[2]);
v[3] = double(m_co[3]);
}
void setValue(const float *v) {
m_co[0] = MT_Scalar(v[0]);
m_co[1] = MT_Scalar(v[1]);
m_co[2] = MT_Scalar(v[2]);
m_co[3] = MT_Scalar(v[3]);
}
void setValue(const double *v) {
m_co[0] = MT_Scalar(v[0]);
m_co[1] = MT_Scalar(v[1]);
m_co[2] = MT_Scalar(v[2]);
m_co[3] = MT_Scalar(v[3]);
}
void setValue(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) {
m_co[0] = x; m_co[1] = y; m_co[2] = z; m_co[3] = w;
}
protected:
MT_Scalar m_co[4];
};
inline bool operator==(const MT_Tuple4& t1, const MT_Tuple4& t2) {
return t1[0] == t2[0] && t1[1] == t2[1] && t1[2] == t2[2] && t1[3] == t2[3];
}
inline MT_OStream& operator<<(MT_OStream& os, const MT_Tuple4& t) {
return os << t[0] << ' ' << t[1] << ' ' << t[2] << ' ' << t[3];
}
#endif

View File

@@ -0,0 +1,112 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_VECTOR2_H
#define MT_VECTOR2_H
#include <MT_assert.h>
#include "MT_Tuple2.h"
class MT_Vector2 : public MT_Tuple2 {
public:
MT_Vector2() {}
MT_Vector2(const float *v) : MT_Tuple2(v) {}
MT_Vector2(const double *v) : MT_Tuple2(v) {}
MT_Vector2(MT_Scalar x, MT_Scalar y) : MT_Tuple2(x, y) {}
MT_Vector2& operator+=(const MT_Vector2& v);
MT_Vector2& operator-=(const MT_Vector2& v);
MT_Vector2& operator*=(MT_Scalar s);
MT_Vector2& operator/=(MT_Scalar s);
MT_Scalar dot(const MT_Vector2& v) const;
MT_Scalar length2() const;
MT_Scalar length() const;
MT_Vector2 absolute() const;
void normalize();
MT_Vector2 normalized() const;
void scale(MT_Scalar x, MT_Scalar y);
MT_Vector2 scaled(MT_Scalar x, MT_Scalar y) const;
bool fuzzyZero() const;
MT_Scalar angle(const MT_Vector2& v) const;
MT_Vector2 cross(const MT_Vector2& v) const;
MT_Scalar triple(const MT_Vector2& v1, const MT_Vector2& v2) const;
int closestAxis() const;
static MT_Vector2 random();
};
MT_Vector2 operator+(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Vector2 operator-(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Vector2 operator-(const MT_Vector2& v);
MT_Vector2 operator*(const MT_Vector2& v, MT_Scalar s);
MT_Vector2 operator*(MT_Scalar s, const MT_Vector2& v);
MT_Vector2 operator/(const MT_Vector2& v, MT_Scalar s);
MT_Scalar MT_dot(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Scalar MT_length2(const MT_Vector2& v);
MT_Scalar MT_length(const MT_Vector2& v);
bool MT_fuzzyZero(const MT_Vector2& v);
bool MT_fuzzyEqual(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Scalar MT_angle(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Vector2 MT_cross(const MT_Vector2& v1, const MT_Vector2& v2);
MT_Scalar MT_triple(const MT_Vector2& v1, const MT_Vector2& v2,
const MT_Vector2& v3);
#ifdef GEN_INLINED
#include "MT_Vector2.inl"
#endif
#endif

View File

@@ -0,0 +1,89 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Vector2& MT_Vector2::operator+=(const MT_Vector2& v) {
m_co[0] += v[0]; m_co[1] += v[1];
return *this;
}
GEN_INLINE MT_Vector2& MT_Vector2::operator-=(const MT_Vector2& v) {
m_co[0] -= v[0]; m_co[1] -= v[1];
return *this;
}
GEN_INLINE MT_Vector2& MT_Vector2::operator*=(MT_Scalar s) {
m_co[0] *= s; m_co[1] *= s;
return *this;
}
GEN_INLINE MT_Vector2& MT_Vector2::operator/=(MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return *this *= 1.0 / s;
}
GEN_INLINE MT_Vector2 operator+(const MT_Vector2& v1, const MT_Vector2& v2) {
return MT_Vector2(v1[0] + v2[0], v1[1] + v2[1]);
}
GEN_INLINE MT_Vector2 operator-(const MT_Vector2& v1, const MT_Vector2& v2) {
return MT_Vector2(v1[0] - v2[0], v1[1] - v2[1]);
}
GEN_INLINE MT_Vector2 operator-(const MT_Vector2& v) {
return MT_Vector2(-v[0], -v[1]);
}
GEN_INLINE MT_Vector2 operator*(const MT_Vector2& v, MT_Scalar s) {
return MT_Vector2(v[0] * s, v[1] * s);
}
GEN_INLINE MT_Vector2 operator*(MT_Scalar s, const MT_Vector2& v) { return v * s; }
GEN_INLINE MT_Vector2 operator/(const MT_Vector2& v, MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return v * (1.0 / s);
}
GEN_INLINE MT_Scalar MT_Vector2::dot(const MT_Vector2& v) const {
return m_co[0] * v[0] + m_co[1] * v[1];
}
GEN_INLINE MT_Scalar MT_Vector2::length2() const { return dot(*this); }
GEN_INLINE MT_Scalar MT_Vector2::length() const { return sqrt(length2()); }
GEN_INLINE MT_Vector2 MT_Vector2::absolute() const {
return MT_Vector2(MT_abs(m_co[0]), MT_abs(m_co[1]));
}
GEN_INLINE bool MT_Vector2::fuzzyZero() const { return MT_fuzzyZero2(length2()); }
GEN_INLINE void MT_Vector2::normalize() { *this /= length(); }
GEN_INLINE MT_Vector2 MT_Vector2::normalized() const { return *this / length(); }
GEN_INLINE void MT_Vector2::scale(MT_Scalar x, MT_Scalar y) {
m_co[0] *= x; m_co[1] *= y;
}
GEN_INLINE MT_Vector2 MT_Vector2::scaled(MT_Scalar x, MT_Scalar y) const {
return MT_Vector2(m_co[0] * x, m_co[1] * y);
}
GEN_INLINE MT_Scalar MT_Vector2::angle(const MT_Vector2& v) const {
MT_Scalar s = sqrt(length2() * v.length2());
MT_assert(!MT_fuzzyZero(s));
return acos(dot(v) / s);
}
GEN_INLINE MT_Scalar MT_dot(const MT_Vector2& v1, const MT_Vector2& v2) {
return v1.dot(v2);
}
GEN_INLINE MT_Scalar MT_length2(const MT_Vector2& v) { return v.length2(); }
GEN_INLINE MT_Scalar MT_length(const MT_Vector2& v) { return v.length(); }
GEN_INLINE bool MT_fuzzyZero(const MT_Vector2& v) { return v.fuzzyZero(); }
GEN_INLINE bool MT_fuzzyEqual(const MT_Vector2& v1, const MT_Vector2& v2) {
return MT_fuzzyZero(v1 - v2);
}
GEN_INLINE MT_Scalar MT_angle(const MT_Vector2& v1, const MT_Vector2& v2) { return v1.angle(v2); }

View File

@@ -0,0 +1,118 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_VECTOR3_H
#define MT_VECTOR3_H
#include <MT_assert.h>
#include "MT_Tuple3.h"
class MT_Vector3 : public MT_Tuple3 {
public:
MT_Vector3() {}
MT_Vector3(const float *v) : MT_Tuple3(v) {}
MT_Vector3(const double *v) : MT_Tuple3(v) {}
MT_Vector3(MT_Scalar x, MT_Scalar y, MT_Scalar z) : MT_Tuple3(x, y, z) {}
MT_Vector3& operator+=(const MT_Vector3& v);
MT_Vector3& operator-=(const MT_Vector3& v);
MT_Vector3& operator*=(MT_Scalar s);
MT_Vector3& operator/=(MT_Scalar s);
MT_Scalar dot(const MT_Vector3& v) const;
MT_Scalar length2() const;
MT_Scalar length() const;
MT_Vector3 absolute() const;
void noiseGate(MT_Scalar threshold);
void normalize();
MT_Vector3 normalized() const;
MT_Vector3 safe_normalized() const;
void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z);
MT_Vector3 scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z) const;
bool fuzzyZero() const;
MT_Scalar angle(const MT_Vector3& v) const;
MT_Vector3 cross(const MT_Vector3& v) const;
MT_Scalar triple(const MT_Vector3& v1, const MT_Vector3& v2) const;
int closestAxis() const;
static MT_Vector3 random();
};
MT_Vector3 operator+(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Vector3 operator-(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Vector3 operator-(const MT_Vector3& v);
MT_Vector3 operator*(const MT_Vector3& v, MT_Scalar s);
MT_Vector3 operator*(MT_Scalar s, const MT_Vector3& v);
MT_Vector3 operator/(const MT_Vector3& v, MT_Scalar s);
MT_Vector3 operator*(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Scalar MT_dot(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Scalar MT_length2(const MT_Vector3& v);
MT_Scalar MT_length(const MT_Vector3& v);
bool MT_fuzzyZero(const MT_Vector3& v);
bool MT_fuzzyEqual(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Scalar MT_angle(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Vector3 MT_cross(const MT_Vector3& v1, const MT_Vector3& v2);
MT_Scalar MT_triple(const MT_Vector3& v1, const MT_Vector3& v2,
const MT_Vector3& v3);
#ifdef GEN_INLINED
#include "MT_Vector3.inl"
#endif
#endif

View File

@@ -0,0 +1,134 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Vector3& MT_Vector3::operator+=(const MT_Vector3& v) {
m_co[0] += v[0]; m_co[1] += v[1]; m_co[2] += v[2];
return *this;
}
GEN_INLINE MT_Vector3& MT_Vector3::operator-=(const MT_Vector3& v) {
m_co[0] -= v[0]; m_co[1] -= v[1]; m_co[2] -= v[2];
return *this;
}
GEN_INLINE MT_Vector3& MT_Vector3::operator*=(MT_Scalar s) {
m_co[0] *= s; m_co[1] *= s; m_co[2] *= s;
return *this;
}
GEN_INLINE MT_Vector3& MT_Vector3::operator/=(MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return *this *= MT_Scalar(1.0) / s;
}
GEN_INLINE MT_Vector3 operator+(const MT_Vector3& v1, const MT_Vector3& v2) {
return MT_Vector3(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]);
}
GEN_INLINE MT_Vector3 operator-(const MT_Vector3& v1, const MT_Vector3& v2) {
return MT_Vector3(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]);
}
GEN_INLINE MT_Vector3 operator-(const MT_Vector3& v) {
return MT_Vector3(-v[0], -v[1], -v[2]);
}
GEN_INLINE MT_Vector3 operator*(const MT_Vector3& v, MT_Scalar s) {
return MT_Vector3(v[0] * s, v[1] * s, v[2] * s);
}
GEN_INLINE MT_Vector3 operator*(MT_Scalar s, const MT_Vector3& v) { return v * s; }
GEN_INLINE MT_Vector3 operator/(const MT_Vector3& v, MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return v * (MT_Scalar(1.0) / s);
}
GEN_INLINE MT_Vector3 operator*(const MT_Vector3& v1, const MT_Vector3& v2) {
return MT_Vector3(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]);
}
GEN_INLINE MT_Scalar MT_Vector3::dot(const MT_Vector3& v) const {
return m_co[0] * v[0] + m_co[1] * v[1] + m_co[2] * v[2];
}
GEN_INLINE MT_Scalar MT_Vector3::length2() const { return dot(*this); }
GEN_INLINE MT_Scalar MT_Vector3::length() const { return sqrt(length2()); }
GEN_INLINE MT_Vector3 MT_Vector3::absolute() const {
return MT_Vector3(MT_abs(m_co[0]), MT_abs(m_co[1]), MT_abs(m_co[2]));
}
GEN_INLINE bool MT_Vector3::fuzzyZero() const {
return MT_fuzzyZero(length2());
}
GEN_INLINE void MT_Vector3::noiseGate(MT_Scalar threshold) {
if (length2() < threshold) {
setValue(MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(0.0));
}
}
GEN_INLINE void MT_Vector3::normalize() { *this /= length(); }
GEN_INLINE MT_Vector3 MT_Vector3::normalized() const { return *this / length(); }
GEN_INLINE MT_Vector3 MT_Vector3::safe_normalized() const {
MT_Scalar len = length();
return MT_fuzzyZero(len) ?
MT_Vector3(MT_Scalar(1.0), MT_Scalar(0.0), MT_Scalar(0.0)) :
*this / len;
}
GEN_INLINE void MT_Vector3::scale(MT_Scalar x, MT_Scalar y, MT_Scalar z) {
m_co[0] *= x; m_co[1] *= y; m_co[2] *= z;
}
GEN_INLINE MT_Vector3 MT_Vector3::scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z) const {
return MT_Vector3(m_co[0] * x, m_co[1] * y, m_co[2] * z);
}
GEN_INLINE MT_Scalar MT_Vector3::angle(const MT_Vector3& v) const {
MT_Scalar s = sqrt(length2() * v.length2());
MT_assert(!MT_fuzzyZero(s));
return acos(dot(v) / s);
}
GEN_INLINE MT_Vector3 MT_Vector3::cross(const MT_Vector3& v) const {
return MT_Vector3(m_co[1] * v[2] - m_co[2] * v[1],
m_co[2] * v[0] - m_co[0] * v[2],
m_co[0] * v[1] - m_co[1] * v[0]);
}
GEN_INLINE MT_Scalar MT_Vector3::triple(const MT_Vector3& v1, const MT_Vector3& v2) const {
return m_co[0] * (v1[1] * v2[2] - v1[2] * v2[1]) +
m_co[1] * (v1[2] * v2[0] - v1[0] * v2[2]) +
m_co[2] * (v1[0] * v2[1] - v1[1] * v2[0]);
}
GEN_INLINE int MT_Vector3::closestAxis() const {
MT_Vector3 a = absolute();
return a[0] < a[1] ? (a[1] < a[2] ? 2 : 1) : (a[0] < a[2] ? 2 : 0);
}
GEN_INLINE MT_Vector3 MT_Vector3::random() {
MT_Scalar z = MT_Scalar(2.0) * MT_random() - MT_Scalar(1.0);
MT_Scalar r = sqrt(MT_Scalar(1.0) - z * z);
MT_Scalar t = MT_2_PI * MT_random();
return MT_Vector3(r * cos(t), r * sin(t), z);
}
GEN_INLINE MT_Scalar MT_dot(const MT_Vector3& v1, const MT_Vector3& v2) {
return v1.dot(v2);
}
GEN_INLINE MT_Scalar MT_length2(const MT_Vector3& v) { return v.length2(); }
GEN_INLINE MT_Scalar MT_length(const MT_Vector3& v) { return v.length(); }
GEN_INLINE bool MT_fuzzyZero(const MT_Vector3& v) { return v.fuzzyZero(); }
GEN_INLINE bool MT_fuzzyEqual(const MT_Vector3& v1, const MT_Vector3& v2) {
return MT_fuzzyZero(v1 - v2);
}
GEN_INLINE MT_Scalar MT_angle(const MT_Vector3& v1, const MT_Vector3& v2) { return v1.angle(v2); }
GEN_INLINE MT_Vector3 MT_cross(const MT_Vector3& v1, const MT_Vector3& v2) { return v1.cross(v2); }
GEN_INLINE MT_Scalar MT_triple(const MT_Vector3& v1, const MT_Vector3& v2, const MT_Vector3& v3) {
return v1.triple(v2, v3);
}

View File

@@ -0,0 +1,102 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/*
* Copyright (c) 2000 Gino van den Bergen <gino@acm.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Gino van den Bergen makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef MT_VECTOR4_H
#define MT_VECTOR4_H
#include <MT_assert.h>
#include "MT_Tuple4.h"
class MT_Vector4 : public MT_Tuple4 {
public:
MT_Vector4() {}
MT_Vector4(const float *v) : MT_Tuple4(v) {}
MT_Vector4(const double *v) : MT_Tuple4(v) {}
MT_Vector4(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) :
MT_Tuple4(x, y, z, w) {}
MT_Vector4& operator+=(const MT_Vector4& v);
MT_Vector4& operator-=(const MT_Vector4& v);
MT_Vector4& operator*=(MT_Scalar s);
MT_Vector4& operator/=(MT_Scalar s);
MT_Scalar dot(const MT_Vector4& v) const;
MT_Scalar length2() const;
MT_Scalar length() const;
MT_Vector4 absolute() const;
void normalize();
MT_Vector4 normalized() const;
void scale(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w);
MT_Vector4 scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) const;
bool fuzzyZero() const;
};
MT_Vector4 operator+(const MT_Vector4& v1, const MT_Vector4& v2);
MT_Vector4 operator-(const MT_Vector4& v1, const MT_Vector4& v2);
MT_Vector4 operator-(const MT_Vector4& v);
MT_Vector4 operator*(const MT_Vector4& v, MT_Scalar s);
MT_Vector4 operator*(MT_Scalar s, const MT_Vector4& v);
MT_Vector4 operator/(const MT_Vector4& v, MT_Scalar s);
MT_Scalar MT_dot(const MT_Vector4& v1, const MT_Vector4& v2);
MT_Scalar MT_length2(const MT_Vector4& v);
MT_Scalar MT_length(const MT_Vector4& v);
bool MT_fuzzyZero(const MT_Vector4& v);
bool MT_fuzzyEqual(const MT_Vector4& v1, const MT_Vector4& v2);
#ifdef GEN_INLINED
#include "MT_Vector4.inl"
#endif
#endif

View File

@@ -0,0 +1,80 @@
#include "MT_Optimize.h"
GEN_INLINE MT_Vector4& MT_Vector4::operator+=(const MT_Vector4& v) {
m_co[0] += v[0]; m_co[1] += v[1]; m_co[2] += v[2]; m_co[3] += v[3];
return *this;
}
GEN_INLINE MT_Vector4& MT_Vector4::operator-=(const MT_Vector4& v) {
m_co[0] -= v[0]; m_co[1] -= v[1]; m_co[2] -= v[2]; m_co[3] -= v[3];
return *this;
}
GEN_INLINE MT_Vector4& MT_Vector4::operator*=(MT_Scalar s) {
m_co[0] *= s; m_co[1] *= s; m_co[2] *= s; m_co[3] *= s;
return *this;
}
GEN_INLINE MT_Vector4& MT_Vector4::operator/=(MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return *this *= MT_Scalar(1.0) / s;
}
GEN_INLINE MT_Vector4 operator+(const MT_Vector4& v1, const MT_Vector4& v2) {
return MT_Vector4(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2], v1[3] + v2[3]);
}
GEN_INLINE MT_Vector4 operator-(const MT_Vector4& v1, const MT_Vector4& v2) {
return MT_Vector4(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2], v1[3] - v2[3]);
}
GEN_INLINE MT_Vector4 operator-(const MT_Vector4& v) {
return MT_Vector4(-v[0], -v[1], -v[2], -v[3]);
}
GEN_INLINE MT_Vector4 operator*(const MT_Vector4& v, MT_Scalar s) {
return MT_Vector4(v[0] * s, v[1] * s, v[2] * s, v[3] * s);
}
GEN_INLINE MT_Vector4 operator*(MT_Scalar s, const MT_Vector4& v) { return v * s; }
GEN_INLINE MT_Vector4 operator/(const MT_Vector4& v, MT_Scalar s) {
MT_assert(!MT_fuzzyZero(s));
return v * (MT_Scalar(1.0) / s);
}
GEN_INLINE MT_Scalar MT_Vector4::dot(const MT_Vector4& v) const {
return m_co[0] * v[0] + m_co[1] * v[1] + m_co[2] * v[2] + m_co[3] * v[3];
}
GEN_INLINE MT_Scalar MT_Vector4::length2() const { return MT_dot(*this, *this); }
GEN_INLINE MT_Scalar MT_Vector4::length() const { return sqrt(length2()); }
GEN_INLINE MT_Vector4 MT_Vector4::absolute() const {
return MT_Vector4(MT_abs(m_co[0]), MT_abs(m_co[1]), MT_abs(m_co[2]), MT_abs(m_co[3]));
}
GEN_INLINE void MT_Vector4::scale(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) {
m_co[0] *= x; m_co[1] *= y; m_co[2] *= z; m_co[3] *= w;
}
GEN_INLINE MT_Vector4 MT_Vector4::scaled(MT_Scalar x, MT_Scalar y, MT_Scalar z, MT_Scalar w) const {
return MT_Vector4(m_co[0] * x, m_co[1] * y, m_co[2] * z, m_co[3] * w);
}
GEN_INLINE bool MT_Vector4::fuzzyZero() const { return MT_fuzzyZero2(length2()); }
GEN_INLINE void MT_Vector4::normalize() { *this /= length(); }
GEN_INLINE MT_Vector4 MT_Vector4::normalized() const { return *this / length(); }
GEN_INLINE MT_Scalar MT_dot(const MT_Vector4& v1, const MT_Vector4& v2) {
return v1.dot(v2);
}
GEN_INLINE MT_Scalar MT_length2(const MT_Vector4& v) { return v.length2(); }
GEN_INLINE MT_Scalar MT_length(const MT_Vector4& v) { return v.length(); }
GEN_INLINE bool MT_fuzzyZero(const MT_Vector4& v) { return v.fuzzyZero(); }
GEN_INLINE bool MT_fuzzyEqual(const MT_Vector4& v1, const MT_Vector4& v2) {
return MT_fuzzyZero(v1 - v2);
}

View File

@@ -0,0 +1,51 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef MT_ASSERT_H
#define MT_ASSERT_H
#ifdef MT_NDEBUG
#define MT_assert(predicate) ((void)0)
#else
#include <assert.h>
#define MT_assert(predicate) assert(predicate)
#endif /* MT_NDEBUG */
#endif

44
intern/moto/include/MT_random.h Executable file
View File

@@ -0,0 +1,44 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef MT_RANDOM_H
#define MT_RANDOM_H
#include <limits.h>
#define MT_RAND_MAX ULONG_MAX
extern void MT_srand(unsigned long);
extern unsigned long MT_rand();
#endif

View File

@@ -0,0 +1,166 @@
/**
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h>
#include <iostream>
template <class T>
class NM_Scalar {
public:
NM_Scalar() {}
explicit NM_Scalar(T value, T error = 0.0) :
m_value(value), m_error(error) {}
T getValue() const { return m_value; }
T getError() const { return m_error; }
operator T() const { return m_value; }
NM_Scalar operator-() const {
return NM_Scalar<T>(-m_value, m_error);
}
NM_Scalar& operator=(T value) {
m_value = value;
m_error = 0.0;
return *this;
}
NM_Scalar& operator+=(const NM_Scalar& x) {
m_value += x.m_value;
m_error = (fabs(m_value) * (m_error + 1.0) +
fabs(x.m_value) * (x.m_error + 1.0)) /
fabs(m_value + x.m_value);
return *this;
}
NM_Scalar& operator-=(const NM_Scalar& x) {
m_value -= x.m_value;
m_error = (fabs(m_value) * (m_error + 1.0) +
fabs(x.m_value) * (x.m_error + 1.0)) /
fabs(m_value - x.m_value);
return *this;
}
NM_Scalar& operator*=(const NM_Scalar& x) {
m_value *= x.m_value;
m_error += x.m_error + 1.0;
return *this;
}
NM_Scalar& operator/=(const NM_Scalar& x) {
m_value /= x.m_value;
m_error += x.m_error + 1.0;
return *this;
}
private:
T m_value;
T m_error;
};
template <class T>
inline NM_Scalar<T> operator+(const NM_Scalar<T>& x, const NM_Scalar<T>& y) {
return x.getValue() == 0.0 && y.getValue() == 0.0 ?
NM_Scalar<T>(0.0, 0.0) :
NM_Scalar<T>(x.getValue() + y.getValue(),
(fabs(x.getValue()) * (x.getError() + 1.0) +
fabs(y.getValue()) * (y.getError() + 1.0)) /
fabs(x.getValue() + y.getValue()));
}
template <class T>
inline NM_Scalar<T> operator-(const NM_Scalar<T>& x, const NM_Scalar<T>& y) {
return x.getValue() == 0.0 && y.getValue() == 0.0 ?
NM_Scalar<T>(0.0, 0.0) :
NM_Scalar<T>(x.getValue() - y.getValue(),
(fabs(x.getValue()) * (x.getError() + 1.0) +
fabs(y.getValue()) * (y.getError() + 1.0)) /
fabs(x.getValue() - y.getValue()));
}
template <class T>
inline NM_Scalar<T> operator*(const NM_Scalar<T>& x, const NM_Scalar<T>& y) {
return NM_Scalar<T>(x.getValue() * y.getValue(),
x.getError() + y.getError() + 1.0);
}
template <class T>
inline NM_Scalar<T> operator/(const NM_Scalar<T>& x, const NM_Scalar<T>& y) {
return NM_Scalar<T>(x.getValue() / y.getValue(),
x.getError() + y.getError() + 1.0);
}
template <class T>
inline std::ostream& operator<<(std::ostream& os, const NM_Scalar<T>& x) {
return os << x.getValue() << '[' << x.getError() << ']';
}
template <class T>
inline NM_Scalar<T> sqrt(const NM_Scalar<T>& x) {
return NM_Scalar<T>(sqrt(x.getValue()),
0.5 * x.getError() + 1.0);
}
template <class T>
inline NM_Scalar<T> acos(const NM_Scalar<T>& x) {
return NM_Scalar<T>(acos(x.getValue()), x.getError() + 1.0);
}
template <class T>
inline NM_Scalar<T> cos(const NM_Scalar<T>& x) {
return NM_Scalar<T>(cos(x.getValue()), x.getError() + 1.0);
}
template <class T>
inline NM_Scalar<T> sin(const NM_Scalar<T>& x) {
return NM_Scalar<T>(sin(x.getValue()), x.getError() + 1.0);
}
template <class T>
inline NM_Scalar<T> fabs(const NM_Scalar<T>& x) {
return NM_Scalar<T>(fabs(x.getValue()), x.getError());
}
template <class T>
inline NM_Scalar<T> pow(const NM_Scalar<T>& x, const NM_Scalar<T>& y) {
return NM_Scalar<T>(pow(x.getValue(), y.getValue()),
fabs(y.getValue()) * x.getError() + 1.0);
}