JAMSPOOK-10 - Implementing track pieces

- Created factories.
- Created textures.
- Turned off lighting.
- Refactored a bit.
This commit is contained in:
Fredrick Amnehagen 2020-08-14 18:27:57 +02:00
parent 966352a638
commit 43cbe8af9b
31 changed files with 524 additions and 393 deletions

View File

@ -15,5 +15,6 @@ void main() {
// Final color // Final color
outColor = albedoTexel * (lightTexel); outColor = albedoTexel * (lightTexel);
outColor = albedoTexel;// * (lightTexel);
outColor.a = albedoTexel.a; outColor.a = albedoTexel.a;
} }

View File

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB

BIN
assets/textures/goal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

BIN
assets/textures/goal.xcf Normal file

Binary file not shown.

BIN
assets/textures/jump180.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -1,139 +0,0 @@
/*
* FloorFactory.cpp
*
* Created on: Aug 12, 2019
* Author: fredrick
*/
#include "FloorFactory.h"
namespace JamSpook {
FloorFactory::FloorFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem),
mPhysicsSystem(physicsSystem),
mRenderLayer(renderLayer)
{}
FloorFactory::~FloorFactory()
{}
shared_ptr<Entity> FloorFactory::createFloor(const vec3 position)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("floor");
SceneGraph::addEntity(entity);
mat4 transform = translate(mat4(1), position);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem);
shared_ptr<FloorPhysicsComponent> physicsComponent =
make_shared<FloorPhysicsComponent>(
transform,
entity,
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
colliderFactory->createBoxCollider(position,
quat(vec3(0,0,0)),
vec3(10,1,10), // radius
100.0f, // mass
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,1,0)); // allow all positional movement movement
physicsComponent->getCollider()->getRigidBody()->setAngularFactor(btVector3(1,1,1)); // allow all rotational movement movement
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 of a ball
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("floor.f3d",
"floor.png",
"floor-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// // Add ICC response component for the collectable system
// weak_ptr<Entity> wEntity = entity;
// entity->addComponent(make_shared<ICCResponseComponent>(entity, [this, wEntity](shared_ptr<Message> message){
// if (message->getMessageType() == IDCache::get("CollectedMessage"))
// {
// shared_ptr<Entity> entity = dynamic_pointer_cast<Entity>(getShared(wEntity));
// if (entity->getEntityTag() == "pellet")
// {
// Log::write(LogLevel::debug, "collected pellet!");
// }
// }
// }));
// Return instance
return entity;
}
shared_ptr<Entity> FloorFactory::createStaticFloor(const vec3 position)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("floor");
SceneGraph::addEntity(entity);
mat4 transform = translate(mat4(1), position);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem);
shared_ptr<FloorPhysicsComponent> physicsComponent =
make_shared<FloorPhysicsComponent>(
transform,
entity,
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
colliderFactory->createBoxCollider(position,
quat(vec3(0,0,0)),
vec3(10,1,10), // radius
0.0f, // mass
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)); // allow all positional movement movement
physicsComponent->getCollider()->getRigidBody()->setAngularFactor(btVector3(0,0,0)); // allow all rotational movement movement
physicsComponent->getCollider()->getRigidBody()->setRestitution(0.9f);
entity->addComponent(physicsComponent);
// Add graphics component
// shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
// entity,
// getShared(mGraphicsSystem),
// mRenderLayer);
// graphicsComponent->setScale(vec3(2.0f, 1.0f, 2.0f));
// entity->addComponent(graphicsComponent);
// // Add the ModelRenderable of a ball
// ModelFactory* modelFactory = new ModelFactory(mAssetSystem);
// shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("floor.f3d",
// "floor.png",
// "floor-model");
// delete modelFactory;
// graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -1,50 +0,0 @@
/*
* FloorPhysicsComponent.cpp
*
* Created on: Aug 12, 2019
* Author: fredrick
*/
#include "FloorPhysicsComponent.h"
namespace JamSpook {
FloorPhysicsComponent::FloorPhysicsComponent(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)
{}
FloorPhysicsComponent::~FloorPhysicsComponent()
{}
void FloorPhysicsComponent::update(const milliseconds dtms)
{
// Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
PhysicsComponent::update(dtms);
}
void FloorPhysicsComponent::onICCMessage(shared_ptr<Message> message)
{
PhysicsComponent::onICCMessage(message);
}
void FloorPhysicsComponent::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

View File

@ -224,187 +224,57 @@ void JamSpookGame::set()
// 1.0f, // 1.0f,
// renderLayerGui); // renderLayerGui);
// // Add test boxes
// unique_ptr<BoxFactory> boxFactoryGame = make_unique<BoxFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem,
// renderLayerGame);
//
// boxFactoryGame->createBox(vec3(0, 0, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactoryGame->createBox(vec3(-2, 1, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactoryGame->createBox(vec3(2, 2, 0),
// vec3(1.0f, 1.0f, 1.0f)); // 2x2x2
//
// boxFactoryGame->createBox(vec3(0, -1, 0),
// vec3(5.0f, .5f, 5.0f)); // 10x1x10
// unique_ptr<BoxFactory> boxFactoryGUI = make_unique<BoxFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem,
// renderLayerGui);
// boxFactoryGUI->createBox(vec3(-4, 0, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactoryGUI->createBox(vec3(2, 0, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactoryGUI->createBox(vec3(0, 2, 0),
// vec3(.25f, .25f, .25f)); // 1x1x1
//
// boxFactoryGUI->createBox(vec3(0, 0, -2),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactoryGUI->createBox(vec3(0, 0, 2),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
//
// boxFactoryGame->createBox(vec3(0, -1, 0),
// vec3(5.0f, .5f, 5.0f)); // 10x1x10
// boxFactory->createBox(vec3(-100, 0, 0),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// boxFactory->createBox(vec3(100, 0, 0),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// boxFactory->createBox(vec3(0, 100, 0),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// boxFactory->createBox(vec3(0, -100, 0),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// boxFactory->createBox(vec3(0, 0, 100),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// boxFactory->createBox(vec3(0, 0, -100),
// vec3(.5f, 0.5f, .5f)); // 1x1x1
// Note: this was enabled
// boxFactory->createBox(vec3(0, 1, 0),
// vec3(5.0f, 0.5f, 5.0f)); // 10x1x10
// boxFactory->createBox(vec3(0, 1, 0),
// vec3(.5f, 0.5f, .5f)); // 10x1x10
// //
// boxFactory->createBox(vec3(0, 3, 0), // // Add entities
// vec3(.5f, .5f, .5f)); // 1x1x1 // FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
//
// boxFactory->createBox(vec3(-2, 4, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
//
// boxFactory->createBox(vec3(2, 5, 0),
// vec3(.5f, .5f, .5f)); // 1x1x1
// unique_ptr<BallFactory> ballFactory = make_unique<BallFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem, // graphicsSystem,
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), // dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
// renderLayerGame); // renderLayerGame);
// floorFactory->createFloor(vec3(0,-5,0));
// floorFactory->createStaticFloor(vec3(0,-8,0));
// delete floorFactory;
// //
// ballFactory->createBall(vec3(0, 10, 0),
// .5f,
// 1.0f,
// 0.9f,
// "pink-rubber",
// vec3(0,1,0));
//
// unique_ptr<FloorFactory> floorFactory = make_unique<FloorFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem,
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
// renderLayerGame);
// floorFactory->createFloor(vec3(0,1,0)); // Create 2 jump180s
// floorFactory->createStaticFloor(vec3(0, 0, 0)); unique_ptr<Jump180Factory> jump180Factory = make_unique<Jump180Factory>(
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// Add entities
FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
graphicsSystem,
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame);
floorFactory->createFloor(vec3(0,-5,0));
floorFactory->createStaticFloor(vec3(0,-8,0));
delete floorFactory;
BallFactory* ballFactory = new BallFactory(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
graphicsSystem, graphicsSystem,
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame); renderLayerGame);
// ballFactory->createBall(vec3(0, 30, 0), jump180Factory->createJump180(vec3(0,-1, 0));
// 2.0f, jump180Factory->createJump180(vec3(0,-2, 1));
// 1.0f,
// 0.1f,
// "pink-rubber",
// vec3(0,1,0));
for (unsigned int i = 0; jump180Factory.reset();
i < static_cast<unsigned int>(getFloatInRange(30,100));
i++)
{
string ballName = "";
float size = 0.0f;
float restitution = 1.0f;
vec3 lightColor = vec3(1);
switch (getIntInRange(0, 5))
{
case 0:
{
ballName = "tennis";
size = 1.1f;
restitution = 0.6f;
lightColor = vec3(0,1,0);
break;
}
case 1:
{
ballName = "base";
size = 1.0f;
restitution = 0.4f;
lightColor = vec3(1,1,1);
break;
}
case 2:
{
ballName = "white-rubber";
size = 0.4f;
restitution = 0.7f;
lightColor = vec3(1,1,1);
break;
}
case 3:
{
ballName = "pink-rubber";
size = 1.5f;
restitution = 0.7f;
lightColor = vec3(1,0,0);
break;
}
case 4:
{
ballName = "blue-rubber";
size = 0.8f;
restitution = 0.7f;
lightColor = vec3(0,0,1);
break;
}
case 5:
{
ballName = "red-rubber";
size = 0.6f;
restitution = 0.7f;
lightColor = vec3(1,0,0);
break;
}
}
ballFactory->createBall(vec3(getFloatInRange(-10.0f, 10.0f), // Create the goal
getFloatInRange(10.0f, 50.0f), unique_ptr<GoalFactory> goalFactory = make_unique<GoalFactory>(
getFloatInRange(-10.0f, 10.0f)), dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
size, graphicsSystem,
size*2, dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
restitution, renderLayerGame);
ballName,
lightColor); goalFactory->createGoal(vec3(-8,-4, -2));
}
delete ballFactory; goalFactory.reset();
// Create the ball
unique_ptr<BallFactory> ballFactory = make_unique<BallFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
graphicsSystem,
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame);
ballFactory->createBall(vec3(0, 3, 0), // position
1.0f, // size
1.0f*2, // size*2
1.0f, // restitution
"base", // ballName
vec3(1,1,1)); // lightColor
ballFactory.reset();
// Set game state // Set game state
setGameState(ecos::core::GameState::InGame); setGameState(ecos::core::GameState::InGame);

View File

@ -50,10 +50,11 @@
#include <ecos/sound/SoundSystem.h> #include <ecos/sound/SoundSystem.h>
#include <ecos/sound/loaders/SoundEffectLoader.h> #include <ecos/sound/loaders/SoundEffectLoader.h>
#include "BallFactory.h" #include "entities/LightingFactory.h"
#include "FloorFactory.h" #include "entities/Jump180Factory.h"
#include "BoxFactory.h" #include "entities/GoalFactory.h"
#include "LightingFactory.h" #include "entities/BallFactory.h"
#include "entities/BoxFactory.h"
namespace JamSpook { namespace JamSpook {

View File

@ -0,0 +1,74 @@
/*
* GoalFactory.cpp
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#include "GoalFactory.h"
namespace JamSpook {
GoalFactory::GoalFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem),
mPhysicsSystem(physicsSystem),
mRenderLayer(renderLayer)
{}
GoalFactory::~GoalFactory()
{}
shared_ptr<Entity> GoalFactory::createGoal(const vec3 position)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("goal");
SceneGraph::addEntity(entity);
mat4 transform = translate(mat4(1), position);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem);
shared_ptr<GoalPhysicsComponent> physicsComponent =
make_shared<GoalPhysicsComponent>(
transform,
entity,
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
colliderFactory->createBoxCollider(position,
quat(vec3(0,0,0)),
vec3(10,1,10), // radius
100.0f, // mass
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 of a ball
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("goal.f3d",
"goal.png",
"goal-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -1,12 +1,12 @@
/* /*
* FloorFactory.h * GoalFactory.h
* *
* Created on: Aug 12, 2019 * Created on: Aug 14, 2020
* Author: fredrick * Author: fredrick
*/ */
#ifndef FLOORFACTORY_H_ #ifndef GOALFACTORY_H_
#define FLOORFACTORY_H_ #define GOALFACTORY_H_
#include <string> #include <string>
#include <memory> #include <memory>
@ -46,7 +46,7 @@
#include <ecos/graphics/ModelRenderableFactory.h> #include <ecos/graphics/ModelRenderableFactory.h>
#include <ecos/graphics/ShaderType.h> #include <ecos/graphics/ShaderType.h>
#include "FloorPhysicsComponent.h" #include "GoalPhysicsComponent.h"
namespace JamSpook { namespace JamSpook {
@ -63,6 +63,7 @@ using glm::mat4;
using glm::quat; using glm::quat;
using glm::translate; using glm::translate;
using glm::scale; using glm::scale;
using ecos::utility::getShared; using ecos::utility::getShared;
using ecos::core::IDCache; using ecos::core::IDCache;
using ecos::core::logging::Log; using ecos::core::logging::Log;
@ -94,7 +95,8 @@ using ecos::physics::PhysicsComponent;
using ecos::physics::ColliderFactory; using ecos::physics::ColliderFactory;
using ecos::physics::Collider; using ecos::physics::Collider;
class FloorFactory /// Factory to simplify jump180 entity creation
class GoalFactory
{ {
private: private:
weak_ptr<AssetSystem> mAssetSystem; weak_ptr<AssetSystem> mAssetSystem;
@ -103,16 +105,16 @@ private:
weak_ptr<RenderLayer> mRenderLayer; weak_ptr<RenderLayer> mRenderLayer;
public: public:
FloorFactory(weak_ptr<AssetSystem> assetSystem, GoalFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem, weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem, weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer); weak_ptr<RenderLayer> renderLayer);
virtual ~FloorFactory(); virtual ~GoalFactory();
shared_ptr<Entity> createFloor(const vec3 position); /// Compose a jump180 entity
shared_ptr<Entity> createStaticFloor(const vec3 position); shared_ptr<Entity> createGoal(const vec3 position);
}; };
} // namespace JamSpook } // namespace JamSpook
#endif // FLOORFACTORY_H_ #endif // GOALFACTORY_H_

View File

@ -0,0 +1,50 @@
/*
* GoalPhysicsComponent.cpp
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#include "GoalPhysicsComponent.h"
namespace JamSpook {
GoalPhysicsComponent::GoalPhysicsComponent(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)
{}
GoalPhysicsComponent::~GoalPhysicsComponent()
{}
void GoalPhysicsComponent::update(const milliseconds dtms)
{
// Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
PhysicsComponent::update(dtms);
}
void GoalPhysicsComponent::onICCMessage(shared_ptr<Message> message)
{
PhysicsComponent::onICCMessage(message);
}
void GoalPhysicsComponent::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

View File

@ -1,12 +1,12 @@
/* /*
* FloorPhysicsComponent.h * GoalPhysicsComponent.h
* *
* Created on: Aug 12, 2019 * Created on: Aug 14, 2020
* Author: fredrick * Author: fredrick
*/ */
#ifndef FLOORPHYSICSCOMPONENT_H_ #ifndef GOALPHYSICSCOMPONENT_H_
#define FLOORPHYSICSCOMPONENT_H_ #define GOALPHYSICSCOMPONENT_H_
#include <chrono> #include <chrono>
#include <memory> #include <memory>
@ -51,17 +51,17 @@ using ecos::physics::TransformChangeMessage;
using ecos::physics::CollisionStateChangeMessage; using ecos::physics::CollisionStateChangeMessage;
using ecos::physics::ColliderQueryMessage; using ecos::physics::ColliderQueryMessage;
class FloorPhysicsComponent: class GoalPhysicsComponent:
public PhysicsComponent public PhysicsComponent
{ {
public: public:
FloorPhysicsComponent(mat4 transform, GoalPhysicsComponent(mat4 transform,
shared_ptr<BroadcastObservable<shared_ptr<Message> > > entity, shared_ptr<BroadcastObservable<shared_ptr<Message> > > entity,
weak_ptr<BroadcastObservable<const milliseconds> > physicsSystem, weak_ptr<BroadcastObservable<const milliseconds> > physicsSystem,
weak_ptr<BroadcastObservable<shared_ptr<CollisionStateChangeMessage> > > physicsCollisionSubSystem, weak_ptr<BroadcastObservable<shared_ptr<CollisionStateChangeMessage> > > physicsCollisionSubSystem,
weak_ptr<BroadcastObservable<shared_ptr<ColliderQueryMessage> > > physicsColliderQuerySubSystem, weak_ptr<BroadcastObservable<shared_ptr<ColliderQueryMessage> > > physicsColliderQuerySubSystem,
shared_ptr<Collider> collider); shared_ptr<Collider> collider);
virtual ~FloorPhysicsComponent(); virtual ~GoalPhysicsComponent();
virtual void update(const milliseconds dtms); virtual void update(const milliseconds dtms);
virtual void onICCMessage(shared_ptr<Message> message); virtual void onICCMessage(shared_ptr<Message> message);
@ -70,4 +70,4 @@ public:
} // namespace JamSpook } // namespace JamSpook
#endif // FLOORPHYSICSCOMPONENT_H_ #endif // GOALPHYSICSCOMPONENT_H_

View File

@ -0,0 +1,74 @@
/*
* Jump180Factory.cpp
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#include "Jump180Factory.h"
namespace JamSpook {
Jump180Factory::Jump180Factory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem),
mPhysicsSystem(physicsSystem),
mRenderLayer(renderLayer)
{}
Jump180Factory::~Jump180Factory()
{}
shared_ptr<Entity> Jump180Factory::createJump180(const vec3 position)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("jump180");
SceneGraph::addEntity(entity);
mat4 transform = translate(mat4(1), position);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem);
shared_ptr<Jump180PhysicsComponent> physicsComponent =
make_shared<Jump180PhysicsComponent>(
transform,
entity,
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
getShared(mPhysicsSystem),
colliderFactory->createBoxCollider(position,
quat(vec3(0,0,0)),
vec3(10,1,10), // radius
100.0f, // mass
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 of a ball
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("jump180.f3d",
"jump180.png",
"jump180-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -0,0 +1,120 @@
/*
* Jump180Factory.h
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#ifndef JUMP180FACTORY_H_
#define JUMP180FACTORY_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 "Jump180PhysicsComponent.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::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 jump180 entity creation
class Jump180Factory
{
private:
weak_ptr<AssetSystem> mAssetSystem;
weak_ptr<GraphicsSystem> mGraphicsSystem;
weak_ptr<PhysicsSystem> mPhysicsSystem;
weak_ptr<RenderLayer> mRenderLayer;
public:
Jump180Factory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer);
virtual ~Jump180Factory();
/// Compose a jump180 entity
shared_ptr<Entity> createJump180(const vec3 position);
};
} // namespace JamSpook
#endif // JUMP180FACTORY_H_

View File

@ -0,0 +1,50 @@
/*
* Jump180PhysicsComponent.cpp
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#include "Jump180PhysicsComponent.h"
namespace JamSpook {
Jump180PhysicsComponent::Jump180PhysicsComponent(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)
{}
Jump180PhysicsComponent::~Jump180PhysicsComponent()
{}
void Jump180PhysicsComponent::update(const milliseconds dtms)
{
// Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
PhysicsComponent::update(dtms);
}
void Jump180PhysicsComponent::onICCMessage(shared_ptr<Message> message)
{
PhysicsComponent::onICCMessage(message);
}
void Jump180PhysicsComponent::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

View File

@ -0,0 +1,73 @@
/*
* Jump180PhysicsComponent.h
*
* Created on: Aug 14, 2020
* Author: fredrick
*/
#ifndef JUMP180PHYSICSCOMPONENT_H_
#define JUMP180PHYSICSCOMPONENT_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 Jump180PhysicsComponent:
public PhysicsComponent
{
public:
Jump180PhysicsComponent(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 ~Jump180PhysicsComponent();
virtual void update(const milliseconds dtms);
virtual void onICCMessage(shared_ptr<Message> message);
virtual void onCollision(const string& tag);
};
} // namespace JamSpook
#endif // JUMP180PHYSICSCOMPONENT_H_

View File

@ -60,7 +60,7 @@ void LightInteractionComponent::onInputDeviceStateChange(const InputDeviceState
// mTransform = translate(mTransform, accumulatedDirection); // mTransform = translate(mTransform, accumulatedDirection);
ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<TransformChangeMessage>(mTransform))); ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<TransformChangeMessage>(mTransform)));
// ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<DirectionChangeMessage>(getTranslation(mTransform), // ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<messages::DirectionChangeMessage>(getTranslation(mTransform),
// oldDirection, // oldDirection,
// accumulatedDirection))); // accumulatedDirection)));
// oldDirection = accumulatedDirection; // oldDirection = accumulatedDirection;

View File

@ -1,5 +1,5 @@
/* /*
* PlayerInteractionComponent.h * LightInteractionComponent.h
* *
* Created on: Mar 1, 2019 * Created on: Mar 1, 2019
* Author: fredrick * Author: fredrick
@ -24,7 +24,7 @@
#include <ecos/interaction/InteractionSystem.h> #include <ecos/interaction/InteractionSystem.h>
#include <ecos/interaction/InteractionComponent.h> #include <ecos/interaction/InteractionComponent.h>
#include "DirectionChangeMessage.h" #include "../messages/DirectionChangeMessage.h"
namespace JamSpook { namespace JamSpook {

View File

@ -41,7 +41,7 @@ void LightPhysicsComponent::onICCMessage(shared_ptr<Message> message)
{ {
Log::write(LogLevel::debug, "PlayerPhysicsComponent - onICCMessage - DirectionChangeMessage"); Log::write(LogLevel::debug, "PlayerPhysicsComponent - onICCMessage - DirectionChangeMessage");
shared_ptr<DirectionChangeMessage> msg = dynamic_pointer_cast<DirectionChangeMessage>(message); shared_ptr<messages::DirectionChangeMessage> msg = dynamic_pointer_cast<messages::DirectionChangeMessage>(message);
if (msg->getNewDirection() != vec3(0,0,0)) if (msg->getNewDirection() != vec3(0,0,0))
{ {
mDirection = msg->getNewDirection(); mDirection = msg->getNewDirection();

View File

@ -27,7 +27,7 @@
#include <ecos/physics/PhysicsComponent.h> #include <ecos/physics/PhysicsComponent.h>
#include <ecos/physics/Collider.h> #include <ecos/physics/Collider.h>
#include "DirectionChangeMessage.h" #include "../messages/DirectionChangeMessage.h"
namespace JamSpook { namespace JamSpook {

View File

@ -8,6 +8,8 @@
#include "DirectionChangeMessage.h" #include "DirectionChangeMessage.h"
namespace JamSpook { namespace JamSpook {
namespace messages {
DirectionChangeMessage::DirectionChangeMessage(const vec3 position, DirectionChangeMessage::DirectionChangeMessage(const vec3 position,
const vec3 oldDirection, const vec3 oldDirection,
@ -36,4 +38,5 @@ const vec3 DirectionChangeMessage::getNewDirection() const
return mNewDirection; return mNewDirection;
} }
} // namespace messages
} // namespace JamSpook } // namespace JamSpook

View File

@ -14,6 +14,7 @@
#include <ecos/core/Message.h> #include <ecos/core/Message.h>
namespace JamSpook { namespace JamSpook {
namespace messages {
using glm::vec3; using glm::vec3;
using ecos::core::IDCache; using ecos::core::IDCache;
@ -39,6 +40,7 @@ public:
const vec3 getNewDirection() const; const vec3 getNewDirection() const;
}; };
} // namespace messages
} // namespace JamSpook } // namespace JamSpook
#endif // DIRECTIONCHANGEMESSAGE_H_ #endif // DIRECTIONCHANGEMESSAGE_H_