JAMSPOOK-18
- Implemented reset trigger - Implemented the reset trigger functionality
This commit is contained in:
parent
c10f39ed21
commit
2e688b9f62
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
|
@ -266,6 +266,19 @@ void JamSpookGame::set()
|
|||
|
||||
goalFactory.reset();
|
||||
|
||||
// Create the reset trigger
|
||||
unique_ptr<ResetTriggerFactory> resetTriggerFactory = make_unique<ResetTriggerFactory>(
|
||||
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
|
||||
graphicsSystem,
|
||||
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
|
||||
renderLayerGame);
|
||||
|
||||
resetTriggerFactory->createResetTrigger(vec3(-1, -30, -12),
|
||||
vec3(1));
|
||||
// goalFactory->createGoal(vec3(0, 0, 0));
|
||||
|
||||
resetTriggerFactory.reset();
|
||||
|
||||
// // Create the ball
|
||||
// unique_ptr<BallFactory> ballFactory = make_unique<BallFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
|
||||
// graphicsSystem,
|
||||
|
@ -290,7 +303,7 @@ void JamSpookGame::set()
|
|||
renderLayerGame);
|
||||
|
||||
kartFactory->createKart(vec3(0, 3, 0), // position
|
||||
vec3(0, 0, 0)); // euler degrees rotation, XYZ
|
||||
vec3(0, 180, 0)); // euler degrees rotation, XYZ
|
||||
|
||||
kartFactory.reset();
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include "entities/BallFactory.h"
|
||||
#include "entities/BoxFactory.h"
|
||||
#include "entities/KartFactory.h"
|
||||
#include "entities/ResetTriggerFactory.h"
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
|
|
|
@ -107,6 +107,9 @@ shared_ptr<Entity> KartFactory::createKart(const vec3 position,
|
|||
getShared(mInteractionSystem));
|
||||
entity->addComponent(interactionComponent);
|
||||
|
||||
// Add position reset ICCR component
|
||||
// ICCResponseComponent
|
||||
|
||||
// Return instance
|
||||
return entity;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,14 @@ void KartPhysicsComponent::onCollision(const string& tag)
|
|||
{
|
||||
ICCBroadcast(make_shared<Message>(IDCache::get("GroundCollisionMessage")));
|
||||
}
|
||||
|
||||
if (tag == "reset-trigger")
|
||||
{
|
||||
// ICCBroadcast(make_shared<Message>(IDCache::get("GroundCollisionMessage")));
|
||||
Log::write(LogLevel::debug, "KartPhysicsComponent - onCollision: reset-trigger");
|
||||
setPosition(vec3(0, 3, 0), true);
|
||||
setOrientationEulerDegreesXYZ(vec3(0, 180, 0), true);
|
||||
}
|
||||
}
|
||||
|
||||
void KartPhysicsComponent::onSeparation(const string& tag)
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* ResetTriggerFactory.cpp
|
||||
*
|
||||
* Created on: Aug 19, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#include "ResetTriggerFactory.h"
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
ResetTriggerFactory::ResetTriggerFactory(weak_ptr<AssetSystem> assetSystem,
|
||||
weak_ptr<GraphicsSystem> graphicsSystem,
|
||||
weak_ptr<PhysicsSystem> physicsSystem,
|
||||
weak_ptr<RenderLayer> renderLayer):
|
||||
mAssetSystem(assetSystem),
|
||||
mGraphicsSystem(graphicsSystem),
|
||||
mPhysicsSystem(physicsSystem),
|
||||
mRenderLayer(renderLayer)
|
||||
{}
|
||||
|
||||
ResetTriggerFactory::~ResetTriggerFactory()
|
||||
{}
|
||||
|
||||
shared_ptr<Entity> ResetTriggerFactory::createResetTrigger(const vec3 position,
|
||||
const vec3 dimensions)
|
||||
{
|
||||
// Create instance
|
||||
shared_ptr<Entity> entity = make_shared<Entity>();
|
||||
entity->setEntityTag("reset-trigger");
|
||||
SceneGraph::addEntity(entity);
|
||||
mat4 transform = translate(mat4(1), position);
|
||||
|
||||
// Add physics component
|
||||
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem);
|
||||
shared_ptr<ResetTriggerPhysicsComponent> physicsComponent =
|
||||
make_shared<ResetTriggerPhysicsComponent>(
|
||||
transform,
|
||||
entity,
|
||||
getShared(mPhysicsSystem),
|
||||
getShared(mPhysicsSystem),
|
||||
getShared(mPhysicsSystem),
|
||||
colliderFactory->createBoxTriggerVolume(position,
|
||||
quat(vec3(0,0,0)),
|
||||
vec3(dimensions.x/2, dimensions.y/2, dimensions.z/2),
|
||||
1.0f,
|
||||
entity,
|
||||
entity->getEntityTag()));
|
||||
delete colliderFactory;
|
||||
// Note: Editing of rigid body params, maybe only has effect is it has been added to the world.
|
||||
physicsComponent->getCollider()->getRigidBody()->setLinearFactor(btVector3(0, 0, 0)); // deny positional movement movement in any axis
|
||||
physicsComponent->getCollider()->getRigidBody()->setAngularFactor(btVector3(0, 0, 0)); // deny rotational movement movement in any axis
|
||||
physicsComponent->getCollider()->getRigidBody()->setRestitution(1);
|
||||
entity->addComponent(physicsComponent);
|
||||
|
||||
// Add graphics component
|
||||
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
|
||||
entity,
|
||||
getShared(mGraphicsSystem),
|
||||
mRenderLayer);
|
||||
entity->addComponent(graphicsComponent);
|
||||
|
||||
// Add the ModelRenderable
|
||||
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
|
||||
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("cube.bcosm",
|
||||
"trigger-diffuse.png",
|
||||
"cube-model");
|
||||
delete modelFactory;
|
||||
graphicsComponent->addRenderable(modelRenderable);
|
||||
|
||||
// Return instance
|
||||
return entity;
|
||||
}
|
||||
|
||||
} // namespace JamSpook
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* ResetTriggerFactory.h
|
||||
*
|
||||
* Created on: Aug 19, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#ifndef RESETTRIGGERFACTORY_H_
|
||||
#define RESETTRIGGERFACTORY_H_
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include <ecos/utility/Memory.h>
|
||||
|
||||
#include <ecos/core/IDCache.h>
|
||||
#include <ecos/core/Log.h>
|
||||
#include <ecos/core/BroadcastObservable.h>
|
||||
#include <ecos/core/Message.h>
|
||||
#include <ecos/core/Entity.h>
|
||||
#include <ecos/core/SceneGraph.h>
|
||||
#include <ecos/core/ICCResponseComponent.h>
|
||||
|
||||
#include <ecos/asset/AssetSystem.h>
|
||||
#include <ecos/asset/DataManagementMode.h>
|
||||
|
||||
#include <ecos/physics/PhysicsSystem.h>
|
||||
#include <ecos/physics/PhysicsComponent.h>
|
||||
#include <ecos/physics/ColliderFactory.h>
|
||||
#include <ecos/physics/Collider.h>
|
||||
|
||||
#include <ecos/graphics/GraphicsSystem.h>
|
||||
#include <ecos/graphics/GraphicsComponent.h>
|
||||
#include <ecos/graphics/RenderLayer.h>
|
||||
#include <ecos/graphics/TextureFactory.h>
|
||||
#include <ecos/graphics/Texture.h>
|
||||
#include <ecos/graphics/assets/ShaderAsset.h>
|
||||
#include <ecos/graphics/ShaderProgram.h>
|
||||
#include <ecos/graphics/ShaderProgramFactory.h>
|
||||
#include <ecos/graphics/Material.h>
|
||||
#include <ecos/graphics/MaterialFactory.h>
|
||||
#include <ecos/graphics/Mesh.h>
|
||||
#include <ecos/graphics/MeshFactory.h>
|
||||
#include <ecos/graphics/ModelRenderable.h>
|
||||
#include <ecos/graphics/ModelRenderableFactory.h>
|
||||
#include <ecos/graphics/ShaderType.h>
|
||||
|
||||
#include "ResetTriggerPhysicsComponent.h"
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
using std::string;
|
||||
using std::shared_ptr;
|
||||
using std::make_shared;
|
||||
using std::weak_ptr;
|
||||
using std::dynamic_pointer_cast;
|
||||
using std::function;
|
||||
using std::bind;
|
||||
using std::vector;
|
||||
|
||||
using glm::vec3;
|
||||
using glm::mat4;
|
||||
using glm::quat;
|
||||
using glm::quat_cast;
|
||||
using glm::translate;
|
||||
using glm::scale;
|
||||
|
||||
using ecos::utility::getShared;
|
||||
|
||||
using ecos::core::IDCache;
|
||||
using ecos::core::logging::Log;
|
||||
using ecos::core::logging::LogLevel;
|
||||
using ecos::core::BroadcastObservable;
|
||||
using ecos::core::Message;
|
||||
using ecos::core::Entity;
|
||||
using ecos::core::SceneGraph;
|
||||
using ecos::core::ICCResponseComponent;
|
||||
|
||||
using ecos::asset::AssetSystem;
|
||||
using ecos::asset::DataManagementMode;
|
||||
|
||||
using ecos::graphics::GraphicsSystem;
|
||||
using ecos::graphics::GraphicsComponent;
|
||||
using ecos::graphics::RenderLayer;
|
||||
using ecos::graphics::TextureFactory;
|
||||
using ecos::graphics::Texture;
|
||||
using ecos::graphics::ShaderType;
|
||||
using ecos::graphics::ShaderAsset;
|
||||
using ecos::graphics::ShaderProgram;
|
||||
using ecos::graphics::ShaderProgramFactory;
|
||||
using ecos::graphics::Material;
|
||||
using ecos::graphics::MaterialFactory;
|
||||
using ecos::graphics::Mesh;
|
||||
using ecos::graphics::MeshFactory;
|
||||
using ecos::graphics::ModelRenderableFactory;
|
||||
using ecos::graphics::ModelRenderable;
|
||||
|
||||
using ecos::physics::PhysicsSystem;
|
||||
using ecos::physics::PhysicsComponent;
|
||||
using ecos::physics::ColliderFactory;
|
||||
using ecos::physics::Collider;
|
||||
|
||||
/// Factory to simplify entity creation
|
||||
class ResetTriggerFactory
|
||||
{
|
||||
private:
|
||||
weak_ptr<AssetSystem> mAssetSystem;
|
||||
weak_ptr<GraphicsSystem> mGraphicsSystem;
|
||||
weak_ptr<PhysicsSystem> mPhysicsSystem;
|
||||
weak_ptr<RenderLayer> mRenderLayer;
|
||||
|
||||
public:
|
||||
ResetTriggerFactory(weak_ptr<AssetSystem> assetSystem,
|
||||
weak_ptr<GraphicsSystem> graphicsSystem,
|
||||
weak_ptr<PhysicsSystem> physicsSystem,
|
||||
weak_ptr<RenderLayer> renderLayer);
|
||||
virtual ~ResetTriggerFactory();
|
||||
|
||||
/// Compose a reset trigger entity
|
||||
shared_ptr<Entity> createResetTrigger(const vec3 position,
|
||||
const vec3 dimensions);
|
||||
};
|
||||
|
||||
} // namespace JamSpook
|
||||
|
||||
#endif // RESETTRIGGERFACTORY_H_
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* ResetTriggerPhysicsComponent.cpp
|
||||
*
|
||||
* Created on: Aug 19, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#include "ResetTriggerPhysicsComponent.h"
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
ResetTriggerPhysicsComponent::ResetTriggerPhysicsComponent(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)
|
||||
{}
|
||||
|
||||
ResetTriggerPhysicsComponent::~ResetTriggerPhysicsComponent()
|
||||
{}
|
||||
|
||||
void ResetTriggerPhysicsComponent::update(const milliseconds dtms)
|
||||
{
|
||||
// Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
|
||||
PhysicsComponent::update(dtms);
|
||||
}
|
||||
|
||||
void ResetTriggerPhysicsComponent::onICCMessage(shared_ptr<Message> message)
|
||||
{
|
||||
PhysicsComponent::onICCMessage(message);
|
||||
}
|
||||
|
||||
void ResetTriggerPhysicsComponent::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
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* ResetTriggerPhysicsComponent.h
|
||||
*
|
||||
* Created on: Aug 19, 2020
|
||||
* Author: fredrick
|
||||
*/
|
||||
|
||||
#ifndef RESETTRIGGERPHYSICSCOMPONENT_H_
|
||||
#define RESETTRIGGERPHYSICSCOMPONENT_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <ecos/core/IDCache.h>
|
||||
#include <ecos/core/Log.h>
|
||||
#include <ecos/core/Message.h>
|
||||
#include <ecos/core/BroadcastObservable.h>
|
||||
|
||||
#include <ecos/physics/PhysicsSystem.h>
|
||||
#include <ecos/physics/TransformChangeMessage.h>
|
||||
#include <ecos/physics/CollisionStateChangeMessage.h>
|
||||
#include <ecos/physics/ColliderQueryMessage.h>
|
||||
#include <ecos/physics/PhysicsComponent.h>
|
||||
#include <ecos/physics/Collider.h>
|
||||
|
||||
namespace JamSpook {
|
||||
|
||||
using std::chrono::milliseconds;
|
||||
using std::weak_ptr;
|
||||
using std::shared_ptr;
|
||||
using std::make_shared;
|
||||
using std::dynamic_pointer_cast;
|
||||
using std::string;
|
||||
|
||||
using glm::vec3;
|
||||
using glm::mat4;
|
||||
using glm::translate;
|
||||
using glm::scale;
|
||||
|
||||
using ecos::core::IDCache;
|
||||
using ecos::core::logging::Log;
|
||||
using ecos::core::logging::LogLevel;
|
||||
using ecos::core::Message;
|
||||
using ecos::core::BroadcastObservable;
|
||||
|
||||
using ecos::physics::PhysicsSystem;
|
||||
using ecos::physics::PhysicsComponent;
|
||||
using ecos::physics::Collider;
|
||||
using ecos::physics::TransformChangeMessage;
|
||||
using ecos::physics::CollisionStateChangeMessage;
|
||||
using ecos::physics::ColliderQueryMessage;
|
||||
|
||||
///
|
||||
class ResetTriggerPhysicsComponent:
|
||||
public PhysicsComponent
|
||||
{
|
||||
public:
|
||||
ResetTriggerPhysicsComponent(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);
|
||||
virtual ~ResetTriggerPhysicsComponent();
|
||||
|
||||
virtual void update(const milliseconds dtms);
|
||||
virtual void onICCMessage(shared_ptr<Message> message);
|
||||
virtual void onCollision(const string& tag);
|
||||
};
|
||||
|
||||
} // namespace JamSpook
|
||||
|
||||
#endif // RESETTRIGGERPHYSICSCOMPONENT_H_
|
Loading…
Reference in New Issue