//---------------------------------------------------------------------------- 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 WorldEditorSelection::scale(const VectorF & scale) { for( iterator iter = begin(); iter != end(); ++ iter ) { SceneObject* object = dynamic_cast< SceneObject* >( *iter ); if( !object ) continue; VectorF current = object->getScale(); current.convolve(scale); // clamp scale to sensible limits current.setMax( Point3F( 0.01f ) ); current.setMin( Point3F( 1000.0f ) ); object->setScale(current); } mCentroidValid = false; }
void WorldEditorSelection::scale(const VectorF & scale, const Point3F & center) { for( iterator iter = begin(); iter != end(); ++ iter ) { SceneObject* object = dynamic_cast< SceneObject* >( *iter ); if( !object ) continue; VectorF current = object->getScale(); current.convolve(scale); // clamp scale to sensible limits current.setMax( Point3F( 0.01f ) ); current.setMin( Point3F( 1000.0f ) ); // Apply the scale first. If the object's scale doesn't change with // this operation then this object doesn't scale. In this case // we don't want to continue with the offset operation. VectorF prevScale = object->getScale(); object->setScale(current); if( !object->getScale().equal(current) ) continue; // determine the actual scale factor to apply to the object offset // need to account for the scale limiting above to prevent offsets // being reduced to 0 which then cannot be restored by unscaling VectorF adjustedScale = current / prevScale; MatrixF mat = object->getTransform(); Point3F pos; mat.getColumn(3, &pos); Point3F offset = pos - center; offset *= adjustedScale; object->setPosition(offset + center); } }