34 #include "LinearMath/btVector3.h"
35 #include "BulletCollision/CollisionShapes/btBoxShape.h"
83 std::cout <<
"creating tgBoxMoreAnchors with tags " << getTags() << std::endl;
95 std::set<tgRigidInfo*> leaves;
111 std::string boxOrientation;
122 if( lengthVector.dot( btVector3(1, 0, 0)) != 0.0 ) {
125 if( lengthVector.dot( btVector3(0, 1, 0)) != 0.0 ) {
127 throw std::invalid_argument(
"tgBoxMoreAnchors is not aligned along an axis! This class currently only supports boxes aligned along a single axis. Nonzeros exist in at least both x and y.");
129 else if( lengthVector.dot( btVector3(0, 0, 1)) != 0.0 ) {
131 throw std::invalid_argument(
"tgBoxMoreAnchors is not aligned along an axis! This class currently only supports boxes aligned along a single axis. Nonzeros exist in both x and z.");
134 boxOrientation =
"x";
136 else if( lengthVector.dot( btVector3(0, 1, 0)) != 0.0) {
139 if( lengthVector.dot( btVector3(0, 0, 1)) != 0.0) {
141 throw std::invalid_argument(
"tgBoxMoreAnchors is not aligned along an axis! This class currently only supports boxes aligned along a single axis. Nonzeros exist in both y and z.");
144 boxOrientation =
"y";
146 else if( lengthVector.dot( btVector3(0, 0, 1)) != 0.0) {
148 boxOrientation =
"z";
152 throw std::runtime_error(
"tgBoxMoreAnchors appears to have length zero. That's not possible. Error thrown inside tgBoxMoreAnchorsInfo::getBoxOrientation.");
156 return boxOrientation;
177 btVector3 tgBoxMoreAnchorsInfo::getHalfExtentsOrientedY()
const {
184 btVector3 tgBoxMoreAnchorsInfo::getHalfExtentsOrientedZ()
const {
202 btVector3 halfExtents;
214 if( orientation ==
"x" ) {
219 else if( orientation ==
"y" ) {
222 halfExtents = getHalfExtentsOrientedY();
224 else if( orientation ==
"z" ) {
227 halfExtents = getHalfExtentsOrientedZ();
230 throw std::runtime_error(
"Inside tgBoxMoreAnchorsInfo::getHalfExtents, orientation is neither x nor y nor z! This class currently only works with boxes aligned along one axis.");
256 std::cout <<
"Box has half extents: " << halfExtents << std::endl;
261 std::cout <<
"Checking tgBoxMoreAnchorsInfo::isNodeOnBoxSurface for box with "
262 <<
"pair " <<
getFrom() <<
", " <<
getTo() <<
", " << std::endl
263 <<
"...center of " << boxCenter <<
", " << std::endl
264 <<
"...half-extents " << halfExtents <<
", " << std::endl
265 <<
"...and node vector " << nodeVector <<
"." << std::endl;
266 std::cout <<
"NOTE that this computation uses fuzzy logic: a very small number"
267 <<
" is added or subtracted to the half extents. " << std::endl
268 <<
"Currently, this number is taken from Bullet Physics' SIMD_EPSILON"
269 <<
" and is equal to " << tgEpsilon <<
"." << std::endl;
287 bool result = (nodeVector.x() <= (boxCenter.x() + halfExtents.x() + tgEpsilon)) &&
288 (nodeVector.x() >= (boxCenter.x() - halfExtents.x() - tgEpsilon)) &&
289 (nodeVector.y() <= (boxCenter.y() + halfExtents.y() + tgEpsilon)) &&
290 (nodeVector.y() >= (boxCenter.y() - halfExtents.y() - tgEpsilon)) &&
291 (nodeVector.z() <= (boxCenter.z() + halfExtents.z() + tgEpsilon)) &&
292 (nodeVector.z() >= (boxCenter.z() - halfExtents.z() - tgEpsilon));
322 std::cout <<
"Result of node surface check: " << result << std::endl;
334 std::cout <<
"Called containsNode inside tgBoxMoreAnchorsInfo with pair "
336 <<
" and tags " << getTags()
337 <<
" for nodeVector "
338 << nodeVector <<
" ..." << std::endl;
341 if( ((
getFrom() - nodeVector).fuzzyZero() || (
getTo() - nodeVector).fuzzyZero()) ){
Contains the definition of class tgWorldBulletPhysicsImpl.
virtual void initRigidBody(tgWorld &world)
tgBoxMoreAnchorsInfo(const tgBox::Config &config)
const btVector3 & getFrom() const
tgRigidInfo * createRigidInfo(const tgPair &pair)
const tgBox::Config & getConfig() const
btVector3 getHalfExtents() const
const btVector3 & getTo() const
std::string getBoxOrientation() const
btVector3 getHalfExtentsOrientedX() const
virtual btRigidBody * getRigidBody()
virtual tgModel * createModel(tgWorld &world)
bool isNodeOnBoxSurface(const btVector3 &nodeVector) const
virtual std::set< tgRigidInfo * > getLeafRigids()
Class that interfaces with Bullet to build the boxes, specifically for boxes that support more than 2...
virtual bool containsNode(const btVector3 &nodeVector) const