start to replace old C-style casts with static_cast or reinterpret_cast, avoid implicit casts
This commit is contained in:
@@ -419,7 +419,7 @@ inline bool BoundBox3<_Precision>::GetOctantFromVector (const Vector3<_Precision
|
||||
usNdx |= 2;
|
||||
if (isOnRayS ((MinZ + MaxZ)/2, MaxZ, rclVct.z)) // back/FRONT
|
||||
usNdx |= 4;
|
||||
rclOctant = (OCTANT) usNdx;
|
||||
rclOctant = static_cast<OCTANT>(usNdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -615,7 +615,7 @@ inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision>
|
||||
// does intersection point lie in desired direction
|
||||
// or was found the opposing side?
|
||||
// -> scalar product of both direction vectors > 0 (angle < 90)
|
||||
rc = ((cVctRes - rcVct) * rcVctDir) >= (_Precision)0.0;
|
||||
rc = ((cVctRes - rcVct) * rcVctDir) >= 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,9 +274,9 @@ void Builder3D::addTransformation(const Base::Matrix4D& transform)
|
||||
Base::Vector3f cAxis, cBase;
|
||||
float fAngle, fTranslation;
|
||||
transform.toAxisAngle(cBase, cAxis,fAngle,fTranslation);
|
||||
cBase.x = (float)transform[0][3];
|
||||
cBase.y = (float)transform[1][3];
|
||||
cBase.z = (float)transform[2][3];
|
||||
cBase.x = static_cast<float>(transform[0][3]);
|
||||
cBase.y = static_cast<float>(transform[1][3]);
|
||||
cBase.z = static_cast<float>(transform[2][3]);
|
||||
addTransformation(cBase,cAxis,fAngle);
|
||||
}
|
||||
|
||||
@@ -896,9 +896,9 @@ void InventorBuilder::addTransformation(const Matrix4D& transform)
|
||||
Vector3f cAxis, cBase;
|
||||
float fAngle, fTranslation;
|
||||
transform.toAxisAngle(cBase, cAxis,fAngle,fTranslation);
|
||||
cBase.x = (float)transform[0][3];
|
||||
cBase.y = (float)transform[1][3];
|
||||
cBase.z = (float)transform[2][3];
|
||||
cBase.x = static_cast<float>(transform[0][3]);
|
||||
cBase.y = static_cast<float>(transform[1][3]);
|
||||
cBase.z = static_cast<float>(transform[2][3]);
|
||||
addTransformation(cBase,cAxis,fAngle);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ void ScriptFactorySingleton::Destruct (void)
|
||||
|
||||
const char* ScriptFactorySingleton::ProduceScript (const char* sScriptName) const
|
||||
{
|
||||
const char* script = (const char*)Produce(sScriptName);
|
||||
const char* script = static_cast<const char*>(Produce(sScriptName));
|
||||
|
||||
if ( !script )
|
||||
{
|
||||
|
||||
@@ -41,9 +41,9 @@ template <typename T>
|
||||
inline Vector3<T> getVectorFromTuple(PyObject* o)
|
||||
{
|
||||
Py::Sequence tuple(o);
|
||||
T x = (T)Py::Float(tuple.getItem(0));
|
||||
T y = (T)Py::Float(tuple.getItem(1));
|
||||
T z = (T)Py::Float(tuple.getItem(2));
|
||||
T x = static_cast<T>(Py::Float(tuple.getItem(0)));
|
||||
T y = static_cast<T>(Py::Float(tuple.getItem(1)));
|
||||
T z = static_cast<T>(Py::Float(tuple.getItem(2)));
|
||||
return Vector3<T>(x,y,z);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ Handled::Handled()
|
||||
|
||||
Handled::~Handled()
|
||||
{
|
||||
if ((int)(*_lRefCount) != 0)
|
||||
if (static_cast<int>(*_lRefCount) != 0)
|
||||
std::cerr << "Reference counter of deleted object is not zero!!!!!" << std::endl;
|
||||
delete _lRefCount;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ void Handled::unref() const
|
||||
|
||||
int Handled::getRefCount(void) const
|
||||
{
|
||||
return (int)(*_lRefCount);
|
||||
return static_cast<int>(*_lRefCount);
|
||||
}
|
||||
|
||||
const Handled& Handled::operator = (const Handled&)
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
|
||||
#include "Matrix.h"
|
||||
#include "Converter.h"
|
||||
|
||||
using namespace Base;
|
||||
|
||||
@@ -43,10 +44,22 @@ Matrix4D::Matrix4D (float a11, float a12, float a13, float a14,
|
||||
float a31, float a32, float a33, float a34,
|
||||
float a41, float a42, float a43, float a44 )
|
||||
{
|
||||
dMtrx4D[0][0] = a11; dMtrx4D[0][1] = a12; dMtrx4D[0][2] = a13; dMtrx4D[0][3] = a14;
|
||||
dMtrx4D[1][0] = a21; dMtrx4D[1][1] = a22; dMtrx4D[1][2] = a23; dMtrx4D[1][3] = a24;
|
||||
dMtrx4D[2][0] = a31; dMtrx4D[2][1] = a32; dMtrx4D[2][2] = a33; dMtrx4D[2][3] = a34;
|
||||
dMtrx4D[3][0] = a41; dMtrx4D[3][1] = a42; dMtrx4D[3][2] = a43; dMtrx4D[3][3] = a44;
|
||||
dMtrx4D[0][0] = static_cast<double>(a11);
|
||||
dMtrx4D[0][1] = static_cast<double>(a12);
|
||||
dMtrx4D[0][2] = static_cast<double>(a13);
|
||||
dMtrx4D[0][3] = static_cast<double>(a14);
|
||||
dMtrx4D[1][0] = static_cast<double>(a21);
|
||||
dMtrx4D[1][1] = static_cast<double>(a22);
|
||||
dMtrx4D[1][2] = static_cast<double>(a23);
|
||||
dMtrx4D[1][3] = static_cast<double>(a24);
|
||||
dMtrx4D[2][0] = static_cast<double>(a31);
|
||||
dMtrx4D[2][1] = static_cast<double>(a32);
|
||||
dMtrx4D[2][2] = static_cast<double>(a33);
|
||||
dMtrx4D[2][3] = static_cast<double>(a34);
|
||||
dMtrx4D[3][0] = static_cast<double>(a41);
|
||||
dMtrx4D[3][1] = static_cast<double>(a42);
|
||||
dMtrx4D[3][2] = static_cast<double>(a43);
|
||||
dMtrx4D[3][3] = static_cast<double>(a44);
|
||||
}
|
||||
|
||||
Matrix4D::Matrix4D (double a11, double a12, double a13, double a14,
|
||||
@@ -114,9 +127,7 @@ double Matrix4D::determinant() const
|
||||
|
||||
void Matrix4D::move (const Vector3f& rclVct)
|
||||
{
|
||||
dMtrx4D[0][3] += rclVct.x;
|
||||
dMtrx4D[1][3] += rclVct.y;
|
||||
dMtrx4D[2][3] += rclVct.z;
|
||||
move(convertTo<Vector3d>(rclVct));
|
||||
}
|
||||
|
||||
void Matrix4D::move (const Vector3d& rclVct)
|
||||
@@ -128,12 +139,7 @@ void Matrix4D::move (const Vector3d& rclVct)
|
||||
|
||||
void Matrix4D::scale (const Vector3f& rclVct)
|
||||
{
|
||||
Matrix4D clMat;
|
||||
|
||||
clMat.dMtrx4D[0][0] = rclVct.x;
|
||||
clMat.dMtrx4D[1][1] = rclVct.y;
|
||||
clMat.dMtrx4D[2][2] = rclVct.z;
|
||||
(*this) = clMat * (*this);
|
||||
scale(convertTo<Vector3d>(rclVct));
|
||||
}
|
||||
|
||||
void Matrix4D::scale (const Vector3d& rclVct)
|
||||
@@ -242,8 +248,8 @@ void Matrix4D::rotLine(const Vector3d& rclVct, double fAngle)
|
||||
|
||||
void Matrix4D::rotLine(const Vector3f& rclVct, float fAngle)
|
||||
{
|
||||
Vector3d tmp(rclVct.x,rclVct.y,rclVct.z);
|
||||
rotLine(tmp,fAngle);
|
||||
Vector3d tmp = convertTo<Vector3d>(rclVct);
|
||||
rotLine(tmp, static_cast<double>(fAngle));
|
||||
}
|
||||
|
||||
void Matrix4D::rotLine(const Vector3d& rclBase, const Vector3d& rclDir, double fAngle)
|
||||
@@ -255,9 +261,9 @@ void Matrix4D::rotLine(const Vector3d& rclBase, const Vector3d& rclDir, double f
|
||||
|
||||
void Matrix4D::rotLine(const Vector3f& rclBase, const Vector3f& rclDir, float fAngle)
|
||||
{
|
||||
Vector3d pnt(rclBase.x,rclBase.y,rclBase.z);
|
||||
Vector3d dir(rclDir.x,rclDir.y,rclDir.z);
|
||||
rotLine(pnt,dir,fAngle);
|
||||
Vector3d pnt = convertTo<Vector3d>(rclBase);
|
||||
Vector3d dir = convertTo<Vector3d>(rclDir);
|
||||
rotLine(pnt,dir,static_cast<double>(fAngle));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,129 +279,20 @@ void Matrix4D::rotLine(const Vector3f& rclBase, const Vector3f& rclDir, float fA
|
||||
*/
|
||||
bool Matrix4D::toAxisAngle (Vector3f& rclBase, Vector3f& rclDir, float& rfAngle, float& fTranslation) const
|
||||
{
|
||||
// First check if the 3x3 submatrix is orthogonal
|
||||
for ( int i=0; i<3; i++ ) {
|
||||
// length must be one
|
||||
if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][i]+dMtrx4D[1][i]*dMtrx4D[1][i]+dMtrx4D[2][i]*dMtrx4D[2][i]-1.0) > 0.01 )
|
||||
return false;
|
||||
// scalar product with other rows must be zero
|
||||
if ( fabs(dMtrx4D[0][i]*dMtrx4D[0][(i+1)%3]+dMtrx4D[1][i]*dMtrx4D[1][(i+1)%3]+dMtrx4D[2][i]*dMtrx4D[2][(i+1)%3]) > 0.01 )
|
||||
return false;
|
||||
}
|
||||
Vector3d pnt = convertTo<Vector3d>(rclBase);
|
||||
Vector3d dir = convertTo<Vector3d>(rclDir);
|
||||
double dAngle = static_cast<double>(rfAngle);
|
||||
double dTranslation = static_cast<double>(fTranslation);
|
||||
|
||||
// Okay, the 3x3 matrix is orthogonal.
|
||||
// Note: The section to get the rotation axis and angle was taken from WildMagic Library.
|
||||
//
|
||||
// Let (x,y,z) be the unit-length axis and let A be an angle of rotation.
|
||||
// The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where
|
||||
// I is the identity and
|
||||
//
|
||||
// +- -+
|
||||
// P = | 0 -z +y |
|
||||
// | +z 0 -x |
|
||||
// | -y +x 0 |
|
||||
// +- -+
|
||||
//
|
||||
// If A > 0, R represents a counterclockwise rotation about the axis in
|
||||
// the sense of looking from the tip of the axis vector towards the
|
||||
// origin. Some algebra will show that
|
||||
//
|
||||
// cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P
|
||||
//
|
||||
// In the event that A = pi, R-R^t = 0 which prevents us from extracting
|
||||
// the axis through P. Instead note that R = I+2*P^2 when A = pi, so
|
||||
// P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and
|
||||
// z^2-1. We can solve these for axis (x,y,z). Because the angle is pi,
|
||||
// it does not matter which sign you choose on the square roots.
|
||||
//
|
||||
// For more details see also http://www.math.niu.edu/~rusin/known-math/97/rotations
|
||||
|
||||
double fTrace = dMtrx4D[0][0] + dMtrx4D[1][1] + dMtrx4D[2][2];
|
||||
double fCos = 0.5*(fTrace-1.0);
|
||||
rfAngle = (float)acos(fCos); // in [0,PI]
|
||||
|
||||
if ( rfAngle > 0.0f )
|
||||
{
|
||||
if ( rfAngle < F_PI )
|
||||
{
|
||||
rclDir.x = (float)(dMtrx4D[2][1]-dMtrx4D[1][2]);
|
||||
rclDir.y = (float)(dMtrx4D[0][2]-dMtrx4D[2][0]);
|
||||
rclDir.z = (float)(dMtrx4D[1][0]-dMtrx4D[0][1]);
|
||||
rclDir.Normalize();
|
||||
bool ok = toAxisAngle(pnt, dir, dAngle, dTranslation);
|
||||
if (ok) {
|
||||
rclBase = convertTo<Vector3f>(pnt);
|
||||
rclDir = convertTo<Vector3f>(dir);
|
||||
rfAngle = static_cast<float>(dAngle);
|
||||
fTranslation = static_cast<float>(dTranslation);
|
||||
}
|
||||
else
|
||||
{
|
||||
// angle is PI
|
||||
double fHalfInverse;
|
||||
if ( dMtrx4D[0][0] >= dMtrx4D[1][1] )
|
||||
{
|
||||
// r00 >= r11
|
||||
if ( dMtrx4D[0][0] >= dMtrx4D[2][2] )
|
||||
{
|
||||
// r00 is maximum diagonal term
|
||||
rclDir.x = (float)(0.5*sqrt(dMtrx4D[0][0] - dMtrx4D[1][1] - dMtrx4D[2][2] + 1.0));
|
||||
fHalfInverse = 0.5/rclDir.x;
|
||||
rclDir.y = (float)(fHalfInverse*dMtrx4D[0][1]);
|
||||
rclDir.z = (float)(fHalfInverse*dMtrx4D[0][2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// r22 is maximum diagonal term
|
||||
rclDir.z = (float)(0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0));
|
||||
fHalfInverse = 0.5/rclDir.z;
|
||||
rclDir.x = (float)(fHalfInverse*dMtrx4D[0][2]);
|
||||
rclDir.y = (float)(fHalfInverse*dMtrx4D[1][2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// r11 > r00
|
||||
if ( dMtrx4D[1][1] >= dMtrx4D[2][2] )
|
||||
{
|
||||
// r11 is maximum diagonal term
|
||||
rclDir.y = (float)(0.5*sqrt(dMtrx4D[1][1] - dMtrx4D[0][0] - dMtrx4D[2][2] + 1.0));
|
||||
fHalfInverse = 0.5/rclDir.y;
|
||||
rclDir.x = (float)(fHalfInverse*dMtrx4D[0][1]);
|
||||
rclDir.z = (float)(fHalfInverse*dMtrx4D[1][2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// r22 is maximum diagonal term
|
||||
rclDir.z = (float)(0.5*sqrt(dMtrx4D[2][2] - dMtrx4D[0][0] - dMtrx4D[1][1] + 1.0));
|
||||
fHalfInverse = 0.5/rclDir.z;
|
||||
rclDir.x = (float)(fHalfInverse*dMtrx4D[0][2]);
|
||||
rclDir.y = (float)(fHalfInverse*dMtrx4D[1][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// The angle is 0 and the matrix is the identity. Any axis will
|
||||
// work, so just use the x-axis.
|
||||
rclDir.x = 1.0f;
|
||||
rclDir.y = 0.0f;
|
||||
rclDir.z = 0.0f;
|
||||
rclBase.x = 0.0f;
|
||||
rclBase.y = 0.0f;
|
||||
rclBase.z = 0.0f;
|
||||
}
|
||||
|
||||
// This is the translation part in axis direction
|
||||
fTranslation = (float)(dMtrx4D[0][3]*rclDir.x+dMtrx4D[1][3]*rclDir.y+dMtrx4D[2][3]*rclDir.z);
|
||||
Vector3f cPnt((float)dMtrx4D[0][3],(float)dMtrx4D[1][3],(float)dMtrx4D[2][3]);
|
||||
cPnt = cPnt - fTranslation * rclDir;
|
||||
|
||||
// This is the base point of the rotation axis
|
||||
if ( rfAngle > 0.0f )
|
||||
{
|
||||
double factor = 0.5*(1.0+fTrace)/sin(rfAngle);
|
||||
rclBase.x = (float)(0.5*(cPnt.x+factor*(rclDir.y*cPnt.z-rclDir.z*cPnt.y)));
|
||||
rclBase.y = (float)(0.5*(cPnt.y+factor*(rclDir.z*cPnt.x-rclDir.x*cPnt.z)));
|
||||
rclBase.z = (float)(0.5*(cPnt.z+factor*(rclDir.x*cPnt.y-rclDir.y*cPnt.x)));
|
||||
}
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle, double& fTranslation) const
|
||||
@@ -441,9 +338,9 @@ bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle
|
||||
double fCos = 0.5*(fTrace-1.0);
|
||||
rfAngle = acos(fCos); // in [0,PI]
|
||||
|
||||
if ( rfAngle > 0.0f )
|
||||
if ( rfAngle > 0.0 )
|
||||
{
|
||||
if ( rfAngle < F_PI )
|
||||
if ( rfAngle < D_PI )
|
||||
{
|
||||
rclDir.x = (dMtrx4D[2][1]-dMtrx4D[1][2]);
|
||||
rclDir.y = (dMtrx4D[0][2]-dMtrx4D[2][0]);
|
||||
@@ -514,7 +411,7 @@ bool Matrix4D::toAxisAngle (Vector3d& rclBase, Vector3d& rclDir, double& rfAngle
|
||||
cPnt = cPnt - fTranslation * rclDir;
|
||||
|
||||
// This is the base point of the rotation axis
|
||||
if ( rfAngle > 0.0f )
|
||||
if ( rfAngle > 0.0 )
|
||||
{
|
||||
double factor = 0.5*(1.0+fTrace)/sin(rfAngle);
|
||||
rclBase.x = (0.5*(cPnt.x+factor*(rclDir.y*cPnt.z-rclDir.z*cPnt.y)));
|
||||
@@ -601,7 +498,7 @@ void Matrix_gauss(Matrix a, Matrix b)
|
||||
}
|
||||
indxr[i] = irow;
|
||||
indxc[i] = icol;
|
||||
if (a[4*icol+icol] == 0) return;
|
||||
if (a[4*icol+icol] == 0.0) return;
|
||||
pivinv = 1.0/a[4*icol+icol];
|
||||
a[4*icol+icol] = 1.0;
|
||||
for (l = 0; l < 4; l++)
|
||||
@@ -820,8 +717,8 @@ std::string Matrix4D::analyse(void) const
|
||||
trp.transpose();
|
||||
trp = trp * sub;
|
||||
bool ortho = true;
|
||||
for (int i=0; i<4 && ortho; i++) {
|
||||
for (int j=0; j<4 && ortho; j++) {
|
||||
for (unsigned short i=0; i<4 && ortho; i++) {
|
||||
for (unsigned short j=0; j<4 && ortho; j++) {
|
||||
if (i != j) {
|
||||
if (fabs(trp[i][j]) > eps) {
|
||||
ortho = false;
|
||||
@@ -876,17 +773,7 @@ Matrix4D& Matrix4D::Outer(const Vector3f& rV1, const Vector3f& rV2)
|
||||
{
|
||||
setToUnity();
|
||||
|
||||
dMtrx4D[0][0] = rV1.x * rV2.x;
|
||||
dMtrx4D[0][1] = rV1.x * rV2.y;
|
||||
dMtrx4D[0][2] = rV1.x * rV2.z;
|
||||
|
||||
dMtrx4D[1][0] = rV1.y * rV2.x;
|
||||
dMtrx4D[1][1] = rV1.y * rV2.y;
|
||||
dMtrx4D[1][2] = rV1.y * rV2.z;
|
||||
|
||||
dMtrx4D[2][0] = rV1.z * rV2.x;
|
||||
dMtrx4D[2][1] = rV1.z * rV2.y;
|
||||
dMtrx4D[2][2] = rV1.z * rV2.z;
|
||||
Outer(convertTo<Vector3d>(rV1), convertTo<Vector3d>(rV2));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -914,17 +801,7 @@ Matrix4D& Matrix4D::Hat(const Vector3f& rV)
|
||||
{
|
||||
setToUnity();
|
||||
|
||||
dMtrx4D[0][0] = 0.0;
|
||||
dMtrx4D[0][1] = -rV.z;
|
||||
dMtrx4D[0][2] = rV.y;
|
||||
|
||||
dMtrx4D[1][0] = rV.z;
|
||||
dMtrx4D[1][1] = 0.0;
|
||||
dMtrx4D[1][2] = -rV.x;
|
||||
|
||||
dMtrx4D[2][0] = -rV.y;
|
||||
dMtrx4D[2][1] = rV.x;
|
||||
dMtrx4D[2][2] = 0.0;
|
||||
Hat(convertTo<Vector3d>(rV));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -948,24 +825,27 @@ Matrix4D& Matrix4D::Hat(const Vector3d& rV)
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Matrix4D::hasScale(double tol) const {
|
||||
int Matrix4D::hasScale(double tol) const
|
||||
{
|
||||
// check for uniform scaling
|
||||
//
|
||||
// scaling factors are the column vector length. We use square distance and
|
||||
// ignore the actual scaling signess
|
||||
//
|
||||
if(tol == 0.0)
|
||||
if (tol == 0.0)
|
||||
tol = 1e-9;
|
||||
double dx = Vector3d(dMtrx4D[0][0],dMtrx4D[1][0],dMtrx4D[2][0]).Sqr();
|
||||
double dy = Vector3d(dMtrx4D[0][1],dMtrx4D[1][1],dMtrx4D[2][1]).Sqr();
|
||||
if(fabs(dx-dy)>tol)
|
||||
if (fabs(dx-dy) > tol) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
double dz = Vector3d(dMtrx4D[0][2],dMtrx4D[1][2],dMtrx4D[2][2]).Sqr();
|
||||
if(fabs(dy-dz)>tol)
|
||||
if (fabs(dy-dz) > tol)
|
||||
return -1;
|
||||
}
|
||||
if(fabs(dx-1.0)>tol)
|
||||
|
||||
if (fabs(dx-1.0) > tol)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
|
||||
@@ -180,7 +180,7 @@ private:
|
||||
inline Matrix4D Matrix4D::operator + (const Matrix4D& rclMtrx) const
|
||||
{
|
||||
Matrix4D clMat;
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -193,7 +193,7 @@ inline Matrix4D Matrix4D::operator + (const Matrix4D& rclMtrx) const
|
||||
|
||||
inline Matrix4D& Matrix4D::operator += (const Matrix4D& rclMtrx)
|
||||
{
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -207,7 +207,7 @@ inline Matrix4D& Matrix4D::operator += (const Matrix4D& rclMtrx)
|
||||
inline Matrix4D Matrix4D::operator - (const Matrix4D& rclMtrx) const
|
||||
{
|
||||
Matrix4D clMat;
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -220,7 +220,7 @@ inline Matrix4D Matrix4D::operator - (const Matrix4D& rclMtrx) const
|
||||
|
||||
inline Matrix4D& Matrix4D::operator -= (const Matrix4D& rclMtrx)
|
||||
{
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -234,7 +234,7 @@ inline Matrix4D& Matrix4D::operator -= (const Matrix4D& rclMtrx)
|
||||
inline Matrix4D& Matrix4D::operator *= (const Matrix4D& rclMtrx)
|
||||
{
|
||||
Matrix4D clMat;
|
||||
short ie, iz, is;
|
||||
unsigned short ie, iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++)
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -252,7 +252,7 @@ inline Matrix4D& Matrix4D::operator *= (const Matrix4D& rclMtrx)
|
||||
inline Matrix4D Matrix4D::operator * (const Matrix4D& rclMtrx) const
|
||||
{
|
||||
Matrix4D clMat;
|
||||
short ie, iz, is;
|
||||
unsigned short ie, iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++)
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -267,7 +267,7 @@ inline Matrix4D Matrix4D::operator * (const Matrix4D& rclMtrx) const
|
||||
|
||||
inline Matrix4D& Matrix4D::operator= (const Matrix4D& rclMtrx)
|
||||
{
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
@@ -280,12 +280,17 @@ inline Matrix4D& Matrix4D::operator= (const Matrix4D& rclMtrx)
|
||||
|
||||
inline Vector3f Matrix4D::operator* (const Vector3f& rclVct) const
|
||||
{
|
||||
return Vector3f((float)(dMtrx4D[0][0]*rclVct.x + dMtrx4D[0][1]*rclVct.y +
|
||||
dMtrx4D[0][2]*rclVct.z + dMtrx4D[0][3]),
|
||||
(float)(dMtrx4D[1][0]*rclVct.x + dMtrx4D[1][1]*rclVct.y +
|
||||
dMtrx4D[1][2]*rclVct.z + dMtrx4D[1][3]),
|
||||
(float)(dMtrx4D[2][0]*rclVct.x + dMtrx4D[2][1]*rclVct.y +
|
||||
dMtrx4D[2][2]*rclVct.z + dMtrx4D[2][3]));
|
||||
double x = static_cast<double>(rclVct.x);
|
||||
double y = static_cast<double>(rclVct.y);
|
||||
double z = static_cast<double>(rclVct.z);
|
||||
return Vector3f(
|
||||
static_cast<float>(dMtrx4D[0][0]*x + dMtrx4D[0][1]*y +
|
||||
dMtrx4D[0][2]*z + dMtrx4D[0][3]),
|
||||
static_cast<float>(dMtrx4D[1][0]*x + dMtrx4D[1][1]*y +
|
||||
dMtrx4D[1][2]*z + dMtrx4D[1][3]),
|
||||
static_cast<float>(dMtrx4D[2][0]*x + dMtrx4D[2][1]*y +
|
||||
dMtrx4D[2][2]*z + dMtrx4D[2][3])
|
||||
);
|
||||
}
|
||||
|
||||
inline Vector3d Matrix4D::operator* (const Vector3d& rclVct) const
|
||||
@@ -311,12 +316,16 @@ inline void Matrix4D::multVec(const Vector3d & src, Vector3d & dst) const
|
||||
|
||||
inline void Matrix4D::multVec(const Vector3f & src, Vector3f & dst) const
|
||||
{
|
||||
double x = (dMtrx4D[0][0]*src.x + dMtrx4D[0][1]*src.y +
|
||||
dMtrx4D[0][2]*src.z + dMtrx4D[0][3]);
|
||||
double y = (dMtrx4D[1][0]*src.x + dMtrx4D[1][1]*src.y +
|
||||
dMtrx4D[1][2]*src.z + dMtrx4D[1][3]);
|
||||
double z = (dMtrx4D[2][0]*src.x + dMtrx4D[2][1]*src.y +
|
||||
dMtrx4D[2][2]*src.z + dMtrx4D[2][3]);
|
||||
double sx = static_cast<double>(src.x);
|
||||
double sy = static_cast<double>(src.y);
|
||||
double sz = static_cast<double>(src.z);
|
||||
|
||||
double x = (dMtrx4D[0][0]*sx + dMtrx4D[0][1]*sy +
|
||||
dMtrx4D[0][2]*sz + dMtrx4D[0][3]);
|
||||
double y = (dMtrx4D[1][0]*sx + dMtrx4D[1][1]*sy +
|
||||
dMtrx4D[1][2]*sz + dMtrx4D[1][3]);
|
||||
double z = (dMtrx4D[2][0]*sx + dMtrx4D[2][1]*sy +
|
||||
dMtrx4D[2][2]*sz + dMtrx4D[2][3]);
|
||||
dst.Set(static_cast<float>(x),
|
||||
static_cast<float>(y),
|
||||
static_cast<float>(z));
|
||||
@@ -324,12 +333,14 @@ inline void Matrix4D::multVec(const Vector3f & src, Vector3f & dst) const
|
||||
|
||||
inline bool Matrix4D::operator== (const Matrix4D& rclMtrx) const
|
||||
{
|
||||
short iz, is;
|
||||
unsigned short iz, is;
|
||||
|
||||
for (iz = 0; iz < 4; iz++)
|
||||
for (is = 0; is < 4; is++)
|
||||
for (iz = 0; iz < 4; iz++) {
|
||||
for (is = 0; is < 4; is++) {
|
||||
if (fabs(dMtrx4D[iz][is] - rclMtrx.dMtrx4D[iz][is]) > traits_type::epsilon())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,8 +122,8 @@ void Rotation::evaluateVector()
|
||||
//
|
||||
// Note: -1 < w < +1 (|w| == 1 not allowed, with w:=quat[3])
|
||||
if((this->quat[3] > -1.0) && (this->quat[3] < 1.0)) {
|
||||
double rfAngle = double(acos(this->quat[3])) * 2.0;
|
||||
double scale = (double)sin(rfAngle / 2.0);
|
||||
double rfAngle = acos(this->quat[3]) * 2.0;
|
||||
double scale = sin(rfAngle / 2.0);
|
||||
// Get a normalized vector
|
||||
double l = this->_axis.Length();
|
||||
if (l < Base::Vector3d::epsilon()) l = 1;
|
||||
@@ -211,32 +211,32 @@ void Rotation::setValue(const double q[4])
|
||||
|
||||
void Rotation::setValue(const Matrix4D & m)
|
||||
{
|
||||
double trace = (double)(m[0][0] + m[1][1] + m[2][2]);
|
||||
double trace = (m[0][0] + m[1][1] + m[2][2]);
|
||||
if (trace > 0.0) {
|
||||
double s = sqrt(1.0+trace);
|
||||
this->quat[3] = 0.5 * s;
|
||||
s = 0.5 / s;
|
||||
this->quat[0] = (double)((m[2][1] - m[1][2]) * s);
|
||||
this->quat[1] = (double)((m[0][2] - m[2][0]) * s);
|
||||
this->quat[2] = (double)((m[1][0] - m[0][1]) * s);
|
||||
this->quat[0] = ((m[2][1] - m[1][2]) * s);
|
||||
this->quat[1] = ((m[0][2] - m[2][0]) * s);
|
||||
this->quat[2] = ((m[1][0] - m[0][1]) * s);
|
||||
}
|
||||
else {
|
||||
// Described in RotationIssues.pdf from <http://www.geometrictools.com>
|
||||
//
|
||||
// Get the max. element of the trace
|
||||
int i = 0;
|
||||
unsigned short i = 0;
|
||||
if (m[1][1] > m[0][0]) i = 1;
|
||||
if (m[2][2] > m[i][i]) i = 2;
|
||||
|
||||
int j = (i+1)%3;
|
||||
int k = (i+2)%3;
|
||||
unsigned short j = (i+1)%3;
|
||||
unsigned short k = (i+2)%3;
|
||||
|
||||
double s = (double)sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0);
|
||||
double s = sqrt((m[i][i] - (m[j][j] + m[k][k])) + 1.0);
|
||||
this->quat[i] = s * 0.5;
|
||||
s = 0.5 / s;
|
||||
this->quat[3] = (double)((m[k][j] - m[j][k]) * s);
|
||||
this->quat[j] = (double)((m[j][i] + m[i][j]) * s);
|
||||
this->quat[k] = (double)((m[k][i] + m[i][k]) * s);
|
||||
this->quat[3] = ((m[k][j] - m[j][k]) * s);
|
||||
this->quat[j] = ((m[j][i] + m[i][j]) * s);
|
||||
this->quat[k] = ((m[k][i] + m[i][k]) * s);
|
||||
}
|
||||
|
||||
this->evaluateVector();
|
||||
@@ -249,7 +249,7 @@ void Rotation::setValue(const Vector3d & axis, const double fAngle)
|
||||
// normalization of the angle to be in [0, 2pi[
|
||||
_angle = fAngle;
|
||||
double theAngle = fAngle - floor(fAngle / (2.0 * D_PI))*(2.0 * D_PI);
|
||||
this->quat[3] = (double)cos(theAngle/2.0);
|
||||
this->quat[3] = cos(theAngle/2.0);
|
||||
|
||||
Vector3d norm = axis;
|
||||
norm.Normalize();
|
||||
@@ -263,7 +263,7 @@ void Rotation::setValue(const Vector3d & axis, const double fAngle)
|
||||
norm.Normalize();
|
||||
}
|
||||
|
||||
double scale = (double)sin(theAngle/2.0);
|
||||
double scale = sin(theAngle/2.0);
|
||||
this->quat[0] = norm.x * scale;
|
||||
this->quat[1] = norm.y * scale;
|
||||
this->quat[2] = norm.z * scale;
|
||||
@@ -295,18 +295,18 @@ void Rotation::setValue(const Vector3d & rotateFrom, const Vector3d & rotateTo)
|
||||
else { // Vectors are not parallel
|
||||
// Note: A quaternion is not well-defined by specifying a point and its transformed point.
|
||||
// Every quaternion with a rotation axis having the same angle to the vectors of both points is okay.
|
||||
double angle = (double)acos(dot);
|
||||
double angle = acos(dot);
|
||||
this->setValue(w, angle);
|
||||
}
|
||||
}
|
||||
|
||||
void Rotation::normalize()
|
||||
{
|
||||
double len = (double)sqrt(this->quat[0]*this->quat[0]+
|
||||
this->quat[1]*this->quat[1]+
|
||||
this->quat[2]*this->quat[2]+
|
||||
this->quat[3]*this->quat[3]);
|
||||
if (len != 0) {
|
||||
double len = sqrt(this->quat[0]*this->quat[0]+
|
||||
this->quat[1]*this->quat[1]+
|
||||
this->quat[2]*this->quat[2]+
|
||||
this->quat[3]*this->quat[3]);
|
||||
if (len > 0.0) {
|
||||
this->quat[0] /= len;
|
||||
this->quat[1] /= len;
|
||||
this->quat[2] /= len;
|
||||
@@ -461,8 +461,8 @@ Rotation Rotation::slerp(const Rotation & q0, const Rotation & q1, double t)
|
||||
}
|
||||
|
||||
if ((1.0 - dot) > Base::Vector3d::epsilon()) {
|
||||
double angle = (double)acos(dot);
|
||||
double sinangle = (double)sin(angle);
|
||||
double angle = acos(dot);
|
||||
double sinangle = sin(angle);
|
||||
// If possible calculate spherical interpolation, otherwise use linear interpolation
|
||||
if (sinangle > Base::Vector3d::epsilon()) {
|
||||
scale0 = double(sin((1.0 - t) * angle)) / sinangle;
|
||||
@@ -553,7 +553,7 @@ Rotation Rotation::makeRotationByAxes(Vector3d xdir, Vector3d ydir, Vector3d zdi
|
||||
if (i == 1)
|
||||
hintDir = Vector3d(); //no vector can be used as hint direction. Zero it out, to indicate that a guess is needed.
|
||||
}
|
||||
if (hintDir.Length() == 0){
|
||||
if (hintDir.Length() == 0.0){
|
||||
switch (order[0]){
|
||||
case X: { //xdir is main
|
||||
//align zdir to OZ
|
||||
@@ -698,17 +698,17 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const
|
||||
|
||||
bool Rotation::isIdentity() const
|
||||
{
|
||||
return ((this->quat[0] == 0 &&
|
||||
this->quat[1] == 0 &&
|
||||
this->quat[2] == 0) &&
|
||||
(this->quat[3] == 1 ||
|
||||
this->quat[3] == -1));
|
||||
return ((this->quat[0] == 0.0 &&
|
||||
this->quat[1] == 0.0 &&
|
||||
this->quat[2] == 0.0) &&
|
||||
(this->quat[3] == 1.0 ||
|
||||
this->quat[3] == -1.0));
|
||||
}
|
||||
|
||||
bool Rotation::isNull() const
|
||||
{
|
||||
return (this->quat[0] == 0 &&
|
||||
this->quat[1] == 0 &&
|
||||
this->quat[2] == 0 &&
|
||||
this->quat[3] == 0);
|
||||
return (this->quat[0] == 0.0 &&
|
||||
this->quat[1] == 0.0 &&
|
||||
this->quat[2] == 0.0 &&
|
||||
this->quat[3] == 0.0);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
//@}
|
||||
|
||||
/// Construction
|
||||
explicit Vector3 (_Precision fx = 0.0f, _Precision fy = 0.0f, _Precision fz = 0.0f);
|
||||
explicit Vector3 (_Precision fx = 0.0, _Precision fy = 0.0, _Precision fz = 0.0);
|
||||
/// Construction
|
||||
Vector3 (const Vector3<_Precision>& rcVct);
|
||||
|
||||
@@ -217,7 +217,7 @@ template <class _Precision>
|
||||
inline _Precision Distance (const Vector3<_Precision> &v1, const Vector3<_Precision> &v2)
|
||||
{
|
||||
_Precision x=v1.x-v2.x, y=v1.y-v2.y, z=v1.z-v2.z;
|
||||
return (_Precision)sqrt((x * x) + (y * y) + (z * z));
|
||||
return static_cast<_Precision>(sqrt((x * x) + (y * y) + (z * z)));
|
||||
}
|
||||
|
||||
/// Returns the squared distance between two points
|
||||
@@ -238,7 +238,7 @@ inline Vector3<_Precision> operator * (_Precision fFac, const Vector3<_Precision
|
||||
template <class _Pr1, class _Pr2>
|
||||
inline Vector3<_Pr1> toVector(const Vector3<_Pr2>& v)
|
||||
{
|
||||
return Vector3<_Pr1>((_Pr1)v.x,(_Pr1)v.y,(_Pr1)v.z);
|
||||
return Vector3<_Pr1>(static_cast<_Pr1>(v.x),static_cast<_Pr1>(v.y),static_cast<_Pr1>(v.z));
|
||||
}
|
||||
|
||||
typedef Vector3<float> Vector3f;
|
||||
|
||||
@@ -154,7 +154,7 @@ inline StrXUTF8::StrXUTF8(const XMLCh* const toTranscode)
|
||||
while (inputLength)
|
||||
{
|
||||
outputLength = transcoder->transcodeTo(toTranscode + offset, inputLength, outBuff, 128, eaten, XMLTranscoder::UnRep_RepChar);
|
||||
str.append((const char*)outBuff, outputLength);
|
||||
str.append(reinterpret_cast<const char*>(outBuff), outputLength);
|
||||
offset += eaten;
|
||||
inputLength -= eaten;
|
||||
|
||||
@@ -258,7 +258,7 @@ inline XUTF8Str::XUTF8Str(const char* const fromTranscode)
|
||||
}
|
||||
|
||||
static XMLCh outBuff[128];
|
||||
XMLByte* xmlBytes = (XMLByte*)fromTranscode;
|
||||
const XMLByte* xmlBytes = reinterpret_cast<const XMLByte*>(fromTranscode);
|
||||
#if (XERCES_VERSION_MAJOR == 2)
|
||||
unsigned int outputLength;
|
||||
unsigned int eaten = 0;
|
||||
|
||||
Reference in New Issue
Block a user