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); } }