33 #include "btBulletDynamicsCommon.h"
34 #include "LinearMath/btQuaternion.h"
35 #include "LinearMath/btTransform.h"
36 #include "LinearMath/btVector3.h"
58 return btVector3(0.0, 1.0, 0.0);
76 inline static btVector3
center(
const btVector3& start,
79 return (start + end) / 2.0;
92 inline static btTransform
getTransform(
const btVector3& startOrientation,
93 const btVector3& start,
97 const btVector3 origin =
center(start, end);
98 btTransform t = btTransform();
115 const btVector3& end)
122 btTransform t = btTransform();
168 const btVector3 norm = axis.cross(target);
170 axis.rotate(norm, (M_PI / 2.0));
186 return from.distance(to) < pow(10.0, (precision < 0 ? 5 : -precision));
199 static btQuaternion
getQuaternionBetween(btVector3 a, btVector3 b,
const btVector3& fallbackAxis = btVector3(0,0,0))
209 result = btQuaternion::getIdentity();
213 if (!fallbackAxis.isZero())
215 result = btQuaternion(fallbackAxis, M_PI).normalize();
217 else if (a.dot(btVector3(1.0, 0.0, 0.0)) == 0.0)
220 result = btQuaternion (-1.0, 0.0, 0.0, 0.0);
224 const btVector3 arb =
226 const btVector3 c = (a.cross(arb)).normalize();
227 result = btQuaternion(c, M_PI).normalize();
231 const btVector3 c = (a.cross(b)).normalize();
235 result = btQuaternion(c, acos(a.dot(b))).normalize();
246 static btVector3
getCentroid(
const std::vector<btVector3>& points) {
247 int numPoints = points.size();
248 btVector3 centroid = btVector3(0, 0, 0);
249 for (
int i = 0; i < numPoints; i++) {
250 centroid += points[i];
252 centroid /= numPoints;
266 arb = btVector3(rand()%10, rand()%10, rand()%10).normalize();
267 }
while (arb == v || arb == -v);
275 const btVector3& fixedPoint,
276 const btVector3& axis,
280 btVector3 relative = v - fixedPoint;
283 btVector3 rotated = relative.rotate(axis, angle);
286 v.setX(fixedPoint.x() + rotated.x());
287 v.setY(fixedPoint.y() + rotated.y());
288 v.setZ(fixedPoint.z() + rotated.z());
295 const btVector3& fixedPoint,
296 const btVector3& fromOrientation,
297 const btVector3& toOrientation)
307 const btVector3& fixedPoint,
308 const btQuaternion& rotation)
310 addRotation(v, fixedPoint, rotation.getAxis(), rotation.getAngle());
326 return radians * 180.0 / M_PI;
337 return degrees * (M_PI / 180.0);
347 inline static std::string
strDeg(
double degrees) {
348 std::ostringstream s;
354 inline static double round(
double d,
int precision = 5)
356 const double base = 10.0;
357 const int m =
static_cast<int>(pow(base, precision));
358 return floor(d * m + 0.5)/m;
361 static void seedRandom();
365 static void seedRandom(
int seed);
378 os <<
"btQuaternion( "
379 << q.x() <<
", " << q.y() <<
", " << q.z() <<
", " << q.w()
394 os <<
"btVector3( " << v.x() <<
", " << v.y() <<
", " << v.z() <<
" )";
408 os <<
"btTransform: origin = " << xf.getOrigin()
409 <<
"; rotation = " << xf.getRotation();
423 os <<
"btRigidBody: " << rb.getCollisionShape();
437 os <<
"btCollisionShape: " << cs.getShapeType();
451 os <<
"btCompoundShape: " << cs.getShapeType() << std::endl
452 <<
" # Children: " << cs.getNumChildShapes() << std::endl;
static btQuaternion getQuaternionBetween(btVector3 a, btVector3 b, const btVector3 &fallbackAxis=btVector3(0, 0, 0))
Definition of abstract class tgRigidInfo.
std::ostream & operator<<(std::ostream &os, const btQuaternion &q)
static btVector3 getVector(const btVector3 &from, const btVector3 &to)
static btVector3 getArbitraryNonParallelVector(btVector3 v)
static std::string degSymbol()
static bool almostEqual(const btVector3 &from, const btVector3 &to, int precision=5)
static btVector3 upVector()
static void addRotation(btVector3 &v, const btVector3 &fixedPoint, const btVector3 &fromOrientation, const btVector3 &toOrientation)
static double deg2rad(double degrees)
static btVector3 center(const btVector3 &start, const btVector3 &end)
static btVector3 getCentroid(const std::vector< btVector3 > &points)
static void addRotation(btVector3 &v, const btVector3 &fixedPoint, const btQuaternion &rotation)
static btVector3 getRadiusVector(btVector3 axis, double radius, btVector3 target)
static btTransform getTransform(const btVector3 &startOrientation, const btVector3 &start, const btVector3 &end)
static btTransform getTransform(const btVector3 &start, const btVector3 &end)
static std::string strDeg(double degrees)
static void addRotation(btVector3 &v, const btVector3 &fixedPoint, const btVector3 &axis, double angle)
static double rad2deg(double radians)