// ---------------------------------------------------------------- // From Game Programming in C++ by Sanjay Madhav // Copyright (C) 2017 Sanjay Madhav. All rights reserved. // // Released under the BSD License // See LICENSE in root directory for full details. // ---------------------------------------------------------------- #include "BoxComponent.h" #include "Actor.h" #include "Game.h" #include "PhysWorld.h" BoxComponent::BoxComponent(Actor* owner, int updateOrder) :Component(owner, updateOrder) ,mObjectBox(Vector3::Zero, Vector3::Zero) ,mWorldBox(Vector3::Zero, Vector3::Zero) ,mShouldRotate(true) { mOwner->GetGame()->GetPhysWorld()->AddBox(this); } BoxComponent::~BoxComponent() { mOwner->GetGame()->GetPhysWorld()->RemoveBox(this); } void BoxComponent::OnUpdateWorldTransform() { // Reset to object space box mWorldBox = mObjectBox; // Scale mWorldBox.mMin *= mOwner->GetScale(); mWorldBox.mMax *= mOwner->GetScale(); // Rotate (if we want to) if (mShouldRotate) { mWorldBox.Rotate(mOwner->GetRotation()); } // Translate mWorldBox.mMin += mOwner->GetPosition(); mWorldBox.mMax += mOwner->GetPosition(); }