Perform some optimizations on the Matrix and Vector
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@377 92aac97c-a6ce-11dd-a772-7fcde58d38e6
This commit is contained in:
parent
756c050890
commit
f0d7117a66
|
@ -45,14 +45,6 @@ Matrix::Matrix(int nbRow, int nbColumn) throw(std::invalid_argument)
|
||||||
array[i] = new double[nbColumn];
|
array[i] = new double[nbColumn];
|
||||||
assert(array[i] != 0);
|
assert(array[i] != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : This initialization loop must be removed carefully
|
|
||||||
// Fill the matrix with zero's
|
|
||||||
for (int i=0; i<nbRow; ++i) {
|
|
||||||
for(int j=0; j<nbColumn; ++j) {
|
|
||||||
setValue(i,j, 0.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
|
|
|
@ -155,11 +155,6 @@ void Vector::changeSize(uint newSize) {
|
||||||
|
|
||||||
nbComponent = newSize;
|
nbComponent = newSize;
|
||||||
tab = new double[nbComponent];
|
tab = new double[nbComponent];
|
||||||
|
|
||||||
// Fill the array with the value of the vector
|
|
||||||
for (int i=0; i<nbComponent; ++i) {
|
|
||||||
tab[i] = 0.0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overloaded operator for addition
|
// Overloaded operator for addition
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include "mathematics_functions.h"
|
#include "mathematics_functions.h"
|
||||||
|
|
||||||
|
// TODO : Remove the methods getX(), getY(), getZ(), setX(), setY(), setZ() and replace the attributes
|
||||||
|
// x, y and z by an array values[3]
|
||||||
|
|
||||||
|
|
||||||
// ReactPhysics3D namespace
|
// ReactPhysics3D namespace
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
@ -45,6 +48,8 @@ class Vector3D {
|
||||||
Vector3D(double x, double y, double z); // Constructor with arguments
|
Vector3D(double x, double y, double z); // Constructor with arguments
|
||||||
Vector3D(const Vector3D& vector); // Copy-constructor
|
Vector3D(const Vector3D& vector); // Copy-constructor
|
||||||
virtual ~Vector3D(); // Destructor
|
virtual ~Vector3D(); // Destructor
|
||||||
|
double getValue(int index) const throw(std::invalid_argument); // Get a component of the vector
|
||||||
|
void setValue(int index, double value) throw(std::invalid_argument); // Set a component of the vector
|
||||||
double getX() const; // Get the x component of the vector
|
double getX() const; // Get the x component of the vector
|
||||||
double getY() const; // Get the y component of the vector
|
double getY() const; // Get the y component of the vector
|
||||||
double getZ() const; // Get the z component of the vector
|
double getZ() const; // Get the z component of the vector
|
||||||
|
@ -100,6 +105,28 @@ inline void Vector3D::setZ(double z) {
|
||||||
this->z = z;
|
this->z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a component of the vector
|
||||||
|
inline double Vector3D::getValue(int index) const throw(std::invalid_argument) {
|
||||||
|
switch(index) {
|
||||||
|
case 0: return x;
|
||||||
|
case 1: return y;
|
||||||
|
case 2: return z;
|
||||||
|
default: // Throw an exception because of the wrong argument
|
||||||
|
throw std::invalid_argument("The argument is outside the bounds of the Vector3D");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a component of the vector
|
||||||
|
inline void Vector3D::setValue(int index, double value) throw(std::invalid_argument) {
|
||||||
|
switch(index) {
|
||||||
|
case 0: x = value;
|
||||||
|
case 1: y = value;
|
||||||
|
case 2: z = value;
|
||||||
|
default: // Throw an exception because of the wrong argument
|
||||||
|
throw std::invalid_argument("The argument is outside the bounds of the Vector3D");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set all the values of the vector (inline)
|
// Set all the values of the vector (inline)
|
||||||
inline void Vector3D::setAllValues(double x, double y, double z) {
|
inline void Vector3D::setAllValues(double x, double y, double z) {
|
||||||
this->x = x;
|
this->x = x;
|
||||||
|
|
|
@ -408,10 +408,10 @@ inline std::vector<reactphysics3d::Vector3D> clipPolygonWithRectangleInPlane(con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (planeNormal.scalarProduct(S-A) > 0.0) {
|
else if (planeNormal.scalarProduct(S-A) > 0.0) {
|
||||||
// Compute the intersection point between the segment SP and the clip plane
|
// Compute the intersection point between the segment SP and the clip plane
|
||||||
reactphysics3d::Vector3D intersectPoint = computeLinesIntersection(S, P-S, A, B-A);
|
reactphysics3d::Vector3D intersectPoint = computeLinesIntersection(S, P-S, A, B-A);
|
||||||
|
|
||||||
outputPolygon.push_back(intersectPoint);
|
outputPolygon.push_back(intersectPoint);
|
||||||
}
|
}
|
||||||
S = P;
|
S = P;
|
||||||
}
|
}
|
||||||
|
@ -422,6 +422,23 @@ inline std::vector<reactphysics3d::Vector3D> clipPolygonWithRectangleInPlane(con
|
||||||
return outputPolygon;
|
return outputPolygon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute the intersection point between a line and a plane in 3D space. There must be an intersection, therefore the
|
||||||
|
// the lineVector must not be orthogonal to the planeNormal.
|
||||||
|
inline reactphysics3d::Vector3D intersectLineWithPlane(const reactphysics3d::Vector3D& linePoint, const reactphysics3d::Vector3D& lineVector,
|
||||||
|
const reactphysics3d::Vector3D& planePoint, const reactphysics3d::Vector3D& planeNormal) {
|
||||||
|
assert(!approxEqual(lineVector.scalarProduct(planeNormal), 0.0));
|
||||||
|
|
||||||
|
// The plane is represented by the equation planeNormal dot X = d where X is a point of the plane
|
||||||
|
double d = planeNormal.scalarProduct(planePoint);
|
||||||
|
|
||||||
|
// Compute the parameter t
|
||||||
|
double t = (d - planeNormal.scalarProduct(linePoint)) / planeNormal.scalarProduct(lineVector);
|
||||||
|
|
||||||
|
// Compute the intersection point
|
||||||
|
return linePoint + lineVector * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // End of the ReactPhysics3D namespace
|
} // End of the ReactPhysics3D namespace
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user