58 lines
1.8 KiB
C++
58 lines
1.8 KiB
C++
|
/*
|
||
|
* KartPhysicsComponent.cpp
|
||
|
*
|
||
|
* Created on: Aug 19, 2020
|
||
|
* Author: fredrick
|
||
|
*/
|
||
|
|
||
|
#include "KartPhysicsComponent.h"
|
||
|
|
||
|
namespace JamSpook {
|
||
|
|
||
|
KartPhysicsComponent::KartPhysicsComponent(mat4 transform,
|
||
|
shared_ptr<BroadcastObservable<shared_ptr<Message> > > entity,
|
||
|
weak_ptr<BroadcastObservable<const milliseconds> > physicsSystem,
|
||
|
weak_ptr<BroadcastObservable<shared_ptr<CollisionStateChangeMessage> > > physicsCollisionSubSystem,
|
||
|
weak_ptr<BroadcastObservable<shared_ptr<ColliderQueryMessage> > > physicsColliderQuerySubSystem,
|
||
|
shared_ptr<Collider> collider):
|
||
|
PhysicsComponent(transform,
|
||
|
entity,
|
||
|
physicsSystem,
|
||
|
physicsCollisionSubSystem,
|
||
|
physicsColliderQuerySubSystem,
|
||
|
collider)
|
||
|
{}
|
||
|
|
||
|
KartPhysicsComponent::~KartPhysicsComponent()
|
||
|
{}
|
||
|
|
||
|
void KartPhysicsComponent::update(const milliseconds dtms)
|
||
|
{
|
||
|
// Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
|
||
|
PhysicsComponent::update(dtms);
|
||
|
|
||
|
if (getPosition().y < -100.0f)
|
||
|
{
|
||
|
setPosition(vec3(getFloatInRange(-10.0f, 10.0f),
|
||
|
10, /// above the ball
|
||
|
getFloatInRange(-10.0f, 10.0f)));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KartPhysicsComponent::onICCMessage(shared_ptr<Message> message)
|
||
|
{
|
||
|
PhysicsComponent::onICCMessage(message);
|
||
|
}
|
||
|
|
||
|
void KartPhysicsComponent::onCollision(const string& tag)
|
||
|
{
|
||
|
if (tag == "ground-plane")
|
||
|
{
|
||
|
vec3 position = getPosition();
|
||
|
setPosition(vec3(position.x, 10.0f, position.z));
|
||
|
ICCBroadcast(make_shared<Message>(IDCache::get("GroundContactMessage")));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
} // namespace JamSpook
|