31 #include "btBulletDynamicsCommon.h"
32 #include "LinearMath/btQuaternion.h"
33 #include "LinearMath/btTransform.h"
34 #include "LinearMath/btVector3.h"
56 return btVector3(0.0, 1.0, 0.0);
74 inline static btVector3
center(
const btVector3& start,
77 return (start + end) / 2.0;
90 inline static btTransform
getTransform(
const btVector3& startOrientation,
91 const btVector3& start,
95 const btVector3 origin =
center(start, end);
96 btTransform t = btTransform();
113 const btVector3& end)
120 btTransform t = btTransform();
166 const btVector3 norm = axis.cross(target);
168 axis.rotate(norm, (M_PI / 2.0));
184 return from.distance(to) < pow(10.0, (precision < 0 ? 5 : -precision));
206 result = btQuaternion::getIdentity();
210 btVector3 xAxis(1.0, 0.0, 0.0);
211 if (a.dot(xAxis) == 0.0)
214 result = btQuaternion (-1.0, 0.0, 0.0, 0.0);
218 const btVector3 arb =
220 const btVector3 c = (a.cross(arb)).normalize();
221 result = btQuaternion(c, M_PI).normalize();
225 const btVector3 c = (a.cross(b)).normalize();
229 result = btQuaternion(c, acos(a.dot(b))).normalize();
244 arb = btVector3(rand()%10, rand()%10, rand()%10).normalize();
245 }
while (arb == v || arb == -v);
253 const btVector3& fixedPoint,
254 const btVector3& axis,
258 btVector3 relative = v - fixedPoint;
261 btVector3 rotated = relative.rotate(axis, angle);
264 v.setX(fixedPoint.x() + rotated.x());
265 v.setY(fixedPoint.y() + rotated.y());
266 v.setZ(fixedPoint.z() + rotated.z());
273 const btVector3& fixedPoint,
274 const btVector3& fromOrientation,
275 const btVector3& toOrientation)
285 const btVector3& fixedPoint,
286 const btQuaternion& rotation)
288 addRotation(v, fixedPoint, rotation.getAxis(), rotation.getAngle());
304 return radians * 180.0 / M_PI;
315 return degrees * (M_PI / 180.0);
325 inline static std::string
strDeg(
double degrees) {
326 std::ostringstream s;
332 inline static double round(
double d,
int precision = 5)
334 const double base = 10.0;
335 const int m =
static_cast<int>(pow(base, precision));
336 return floor(d * m + 0.5)/m;
351 os <<
"btQuaternion( "
352 << q.x() <<
", " << q.y() <<
", " << q.z() <<
", " << q.w()
367 os <<
"btVector3( " << v.x() <<
", " << v.y() <<
", " << v.z() <<
" )";
381 os <<
"btTransform: origin = " << xf.getOrigin()
382 <<
"; rotation = " << xf.getRotation();
396 os <<
"btRigidBody: " << rb.getCollisionShape();
410 os <<
"btCollisionShape: " << cs.getShapeType();
424 os <<
"btCompoundShape: " << cs.getShapeType() << std::endl
425 <<
" # Children: " << cs.getNumChildShapes() << std::endl;
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 btQuaternion getQuaternionBetween(btVector3 a, btVector3 b)
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 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)