void SpatialObject::SetLocation(const Transformation& t){ mBoundingVolumeWorld->SetCenter(mBoundingVolume->GetCenter() + t.GetTranslation()); mBoundingVolumeWorld->SetRadius(mBoundingVolume->GetRadius() * t.GetScale().GetMax()); mLocation = t; if (mAnimatedLocation){ *mAnimatedLocation = mLocation * mAnim->GetResult(); } mTransformChanged = true; }
//--------------------------------------------------------------------------- Impl(ColisionShapeType::Enum e, const Transformation& t, MeshObjectPtr colMesh) : mColShape(e) , mColMesh(colMesh) , mTransformation(t) { switch (e) { case ColisionShapeType::SPHERE: { mBV = BoundingVolume::Create(BoundingVolume::BV_SPHERE); auto scale = t.GetScale(); if (scale.x != scale.z || scale.x != scale.y) { Logger::Log(FB_ERROR_LOG_ARG, "Collision Sphere should be uniform scaled!"); assert(0); } mBV->SetRadius(1 * t.GetScale().x); mBV->SetCenter(Vec3::ZERO); } break; case ColisionShapeType::CUBE: { mBV = BoundingVolume::Create(BoundingVolume::BV_AABB); AABB aabb; aabb.SetMax(Vec3(1, 1, 1) * t.GetScale()); aabb.SetMin(Vec3(-1, -1, -1) * t.GetScale()); BVaabb* bvaabb = (BVaabb*)mBV.get(); bvaabb->SetAABB(aabb); } break; default: break; } }
Vec3 GetScale() const{ return mTransformation.GetScale(); }