void OrientedBox3F::set( const MatrixF& transform, const Box3F& aabb ) { mCenter = aabb.getCenter(); transform.mulP( mCenter ); mAxes[ RightVector ] = transform.getRightVector(); mAxes[ ForwardVector ] = transform.getForwardVector(); mAxes[ UpVector ] = transform.getUpVector(); mHalfExtents[ 0 ] = aabb.len_x() / 2.f; mHalfExtents[ 1 ] = aabb.len_y() / 2.f; mHalfExtents[ 2 ] = aabb.len_z() / 2.f; _initPoints(); }
void ColladaShapeLoader::computeBounds(Box3F& bounds) { TSShapeLoader::computeBounds(bounds); // Check if the model origin needs adjusting if ( bounds.isValidBox() && (ColladaUtils::getOptions().adjustCenter || ColladaUtils::getOptions().adjustFloor) ) { // Compute shape offset Point3F shapeOffset = Point3F::Zero; if ( ColladaUtils::getOptions().adjustCenter ) { bounds.getCenter( &shapeOffset ); shapeOffset = -shapeOffset; } if ( ColladaUtils::getOptions().adjustFloor ) shapeOffset.z = -bounds.minExtents.z; // Adjust bounds bounds.minExtents += shapeOffset; bounds.maxExtents += shapeOffset; // Now adjust all positions for root level nodes (nodes with no parent) for (S32 iNode = 0; iNode < shape->nodes.size(); iNode++) { if ( !appNodes[iNode]->isParentRoot() ) continue; // Adjust default translation shape->defaultTranslations[iNode] += shapeOffset; // Adjust animated translations for (S32 iSeq = 0; iSeq < shape->sequences.size(); iSeq++) { const TSShape::Sequence& seq = shape->sequences[iSeq]; if ( seq.translationMatters.test(iNode) ) { for (S32 iFrame = 0; iFrame < seq.numKeyframes; iFrame++) { S32 index = seq.baseTranslation + seq.translationMatters.count(iNode)*seq.numKeyframes + iFrame; shape->nodeTranslations[index] += shapeOffset; } } } } } }
void GroundPlane::buildConvex( const Box3F& box, Convex* convex ) { mConvexList->collectGarbage(); Box3F planeBox = getPlaneBox(); if ( !box.isOverlapped( planeBox ) ) return; // See if we already have a convex in the working set. BoxConvex *boxConvex = NULL; CollisionWorkingList &wl = convex->getWorkingList(); CollisionWorkingList *itr = wl.wLink.mNext; for ( ; itr != &wl; itr = itr->wLink.mNext ) { if ( itr->mConvex->getType() == BoxConvexType && itr->mConvex->getObject() == this ) { boxConvex = (BoxConvex*)itr->mConvex; break; } } if ( !boxConvex ) { boxConvex = new BoxConvex; mConvexList->registerObject( boxConvex ); boxConvex->init( this ); convex->addToWorkingList( boxConvex ); } // Update our convex to best match the queried box if ( boxConvex ) { Point3F queryCenter = box.getCenter(); boxConvex->mCenter = Point3F( queryCenter.x, queryCenter.y, -GROUND_PLANE_BOX_HEIGHT_HALF ); boxConvex->mSize = Point3F( box.getExtents().x, box.getExtents().y, GROUND_PLANE_BOX_HEIGHT_HALF ); } }
//---------------------------------------------------------------------------- void RigidBody::createPhysShape() { //Physics* physics = isServerObject() ? gServerPhysics : gClientPhysics; Physics* physics = Physics::getPhysics(isServerObject()); if (physics) { PhysInfo physDescr; //transform into radian VectorF angleRadians = mDataBlock->mRotation/180.f*float(M_PI); physDescr.transform.set(angleRadians, mDataBlock->mPos); physDescr.owner = this; physDescr.shapeType = (PhysInfo::ShapeType)mDataBlock->mShapeType; physDescr.mass = mDataBlock->mass; if (physDescr.shapeType==PhysInfo::ST_SPHERE) { Box3F scaledObjBox = mObjBox; scaledObjBox.minExtents.convolve(mObjScale); scaledObjBox.maxExtents.convolve(mObjScale); F32 radius = (scaledObjBox.maxExtents - scaledObjBox.getCenter()).len(); physDescr.params = VectorF(radius,0.f,0.f); } else //if (physDescr.shapeType==PhysInfo::ST_BOX) { Box3F rotBox = mObjBox; physDescr.transform.mul(rotBox); VectorF length = VectorF(rotBox.len_x(),rotBox.len_y(),rotBox.len_z()); length.convolve(mObjScale); physDescr.params = length; } //physDescr.params = VectorF(1.f,1.f,1.f); //physDescr.shapeType = PhysInfo::ST_SPHERE; //physDescr.mass = 5.f; //physDescr.params = VectorF(0.5f,0.f,0.f); mPhysShape = physics->createPhysShape(physDescr); mPhysShape->setTransform(mObjToWorld); mPhysShape->setForce(mForce); mPhysShape->setTorque(mTorque); mPhysShape->setLinVelocity(mLinVelocity); mPhysShape->setAngVelocity(mAngVelocity); } }
void GFXDrawUtil::drawCube( const GFXStateBlockDesc &desc, const Box3F &box, const ColorI &color, const MatrixF *xfm ) { drawCube( desc, box.getExtents(), box.getCenter(), color, xfm ); }