diff --git a/assets/shaders/compositor-fragment.glsl b/assets/shaders/compositor-fragment.glsl index 6454ec6..696d620 100755 --- a/assets/shaders/compositor-fragment.glsl +++ b/assets/shaders/compositor-fragment.glsl @@ -15,5 +15,6 @@ void main() { // Final color outColor = albedoTexel * (lightTexel); + outColor = albedoTexel;// * (lightTexel); outColor.a = albedoTexel.a; } diff --git a/assets/meshes/goal-uv.png b/assets/textures/goal-uv.png similarity index 100% rename from assets/meshes/goal-uv.png rename to assets/textures/goal-uv.png diff --git a/assets/textures/goal.png b/assets/textures/goal.png new file mode 100644 index 0000000..8e6c235 Binary files /dev/null and b/assets/textures/goal.png differ diff --git a/assets/textures/goal.xcf b/assets/textures/goal.xcf new file mode 100644 index 0000000..68f1366 Binary files /dev/null and b/assets/textures/goal.xcf differ diff --git a/assets/textures/jump180.png b/assets/textures/jump180.png new file mode 100644 index 0000000..0258717 Binary files /dev/null and b/assets/textures/jump180.png differ diff --git a/src/FloorFactory.cpp b/src/FloorFactory.cpp deleted file mode 100644 index 162ac96..0000000 --- a/src/FloorFactory.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * FloorFactory.cpp - * - * Created on: Aug 12, 2019 - * Author: fredrick - */ - -#include "FloorFactory.h" - -namespace JamSpook { - -FloorFactory::FloorFactory(weak_ptr assetSystem, - weak_ptr graphicsSystem, - weak_ptr physicsSystem, - weak_ptr renderLayer): - mAssetSystem(assetSystem), - mGraphicsSystem(graphicsSystem), - mPhysicsSystem(physicsSystem), - mRenderLayer(renderLayer) -{} - -FloorFactory::~FloorFactory() -{} - -shared_ptr FloorFactory::createFloor(const vec3 position) -{ - // Create instance - shared_ptr entity = make_shared(); - entity->setEntityTag("floor"); - SceneGraph::addEntity(entity); - mat4 transform = translate(mat4(1), position); - - // Add physics component - ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem); - shared_ptr physicsComponent = - make_shared( - 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 = make_shared(transform, - entity, - getShared(mGraphicsSystem), - mRenderLayer); - entity->addComponent(graphicsComponent); - - // Add the ModelRenderable of a ball - ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); - shared_ptr modelRenderable = modelFactory->createModel("floor.f3d", - "floor.png", - "floor-model"); - delete modelFactory; - graphicsComponent->addRenderable(modelRenderable); - -// // Add ICC response component for the collectable system -// weak_ptr wEntity = entity; -// entity->addComponent(make_shared(entity, [this, wEntity](shared_ptr message){ -// if (message->getMessageType() == IDCache::get("CollectedMessage")) -// { -// shared_ptr entity = dynamic_pointer_cast(getShared(wEntity)); -// if (entity->getEntityTag() == "pellet") -// { -// Log::write(LogLevel::debug, "collected pellet!"); -// } -// } -// })); - - // Return instance - return entity; -} - -shared_ptr FloorFactory::createStaticFloor(const vec3 position) -{ - // Create instance - shared_ptr entity = make_shared(); - entity->setEntityTag("floor"); - SceneGraph::addEntity(entity); - mat4 transform = translate(mat4(1), position); - - // Add physics component - ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem); - shared_ptr physicsComponent = - make_shared( - 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 = make_shared(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 = modelFactory->createModel("floor.f3d", -// "floor.png", -// "floor-model"); -// delete modelFactory; -// graphicsComponent->addRenderable(modelRenderable); - - // Return instance - return entity; -} - -} // namespace JamSpook diff --git a/src/FloorPhysicsComponent.cpp b/src/FloorPhysicsComponent.cpp deleted file mode 100644 index 2100709..0000000 --- a/src/FloorPhysicsComponent.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * FloorPhysicsComponent.cpp - * - * Created on: Aug 12, 2019 - * Author: fredrick - */ - -#include "FloorPhysicsComponent.h" - -namespace JamSpook { - -FloorPhysicsComponent::FloorPhysicsComponent(mat4 transform, - shared_ptr > > entity, - weak_ptr > physicsSystem, - weak_ptr > > physicsCollisionSubSystem, - weak_ptr > > physicsColliderQuerySubSystem, - shared_ptr 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) -{ - 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(IDCache::get("GroundContactMessage"))); -// } -} - -} // namespace JamSpook diff --git a/src/JamSpookGame.cpp b/src/JamSpookGame.cpp index 0616cd3..9bc41ab 100644 --- a/src/JamSpookGame.cpp +++ b/src/JamSpookGame.cpp @@ -224,187 +224,57 @@ void JamSpookGame::set() // 1.0f, // renderLayerGui); -// // Add test boxes -// unique_ptr boxFactoryGame = make_unique(dynamic_pointer_cast(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 boxFactoryGUI = make_unique(dynamic_pointer_cast(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 - -// 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 + // Note: this was enabled // -// boxFactory->createBox(vec3(0, 3, 0), -// vec3(.5f, .5f, .5f)); // 1x1x1 +// // Add entities +// FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), +// graphicsSystem, +// dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), +// renderLayerGame); +// floorFactory->createFloor(vec3(0,-5,0)); +// floorFactory->createStaticFloor(vec3(0,-8,0)); +// delete floorFactory; // -// boxFactory->createBox(vec3(-2, 4, 0), -// vec3(.5f, .5f, .5f)); // 1x1x1 -// -// boxFactory->createBox(vec3(2, 5, 0), -// vec3(.5f, .5f, .5f)); // 1x1x1 + // Create 2 jump180s + unique_ptr jump180Factory = make_unique( + dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), + graphicsSystem, + dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), + renderLayerGame); -// unique_ptr ballFactory = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), -// graphicsSystem, -// dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), -// renderLayerGame); -// -// ballFactory->createBall(vec3(0, 10, 0), -// .5f, -// 1.0f, -// 0.9f, -// "pink-rubber", -// vec3(0,1,0)); -// -// unique_ptr floorFactory = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), -// graphicsSystem, -// dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), -// renderLayerGame); + jump180Factory->createJump180(vec3(0,-1, 0)); + jump180Factory->createJump180(vec3(0,-2, 1)); -// floorFactory->createFloor(vec3(0,1,0)); -// floorFactory->createStaticFloor(vec3(0, 0, 0)); + jump180Factory.reset(); + // Create the goal + unique_ptr goalFactory = make_unique( + dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), + graphicsSystem, + dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), + renderLayerGame); - // Add entities - FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), - graphicsSystem, - dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), - renderLayerGame); - floorFactory->createFloor(vec3(0,-5,0)); - floorFactory->createStaticFloor(vec3(0,-8,0)); - delete floorFactory; + goalFactory->createGoal(vec3(-8,-4, -2)); - BallFactory* ballFactory = new BallFactory(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), + goalFactory.reset(); + + // Create the ball + unique_ptr ballFactory = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), graphicsSystem, dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), renderLayerGame); -// ballFactory->createBall(vec3(0, 30, 0), -// 2.0f, -// 1.0f, -// 0.1f, -// "pink-rubber", -// vec3(0,1,0)); + 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 - for (unsigned int i = 0; - i < static_cast(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), - getFloatInRange(10.0f, 50.0f), - getFloatInRange(-10.0f, 10.0f)), - size, - size*2, - restitution, - ballName, - lightColor); - } - delete ballFactory; + ballFactory.reset(); // Set game state setGameState(ecos::core::GameState::InGame); diff --git a/src/JamSpookGame.h b/src/JamSpookGame.h index 53fcabe..af3ade8 100644 --- a/src/JamSpookGame.h +++ b/src/JamSpookGame.h @@ -50,10 +50,11 @@ #include #include -#include "BallFactory.h" -#include "FloorFactory.h" -#include "BoxFactory.h" -#include "LightingFactory.h" +#include "entities/LightingFactory.h" +#include "entities/Jump180Factory.h" +#include "entities/GoalFactory.h" +#include "entities/BallFactory.h" +#include "entities/BoxFactory.h" namespace JamSpook { diff --git a/src/BallFactory.cpp b/src/entities/BallFactory.cpp similarity index 100% rename from src/BallFactory.cpp rename to src/entities/BallFactory.cpp diff --git a/src/BallFactory.h b/src/entities/BallFactory.h similarity index 100% rename from src/BallFactory.h rename to src/entities/BallFactory.h diff --git a/src/BallPhysicsComponent.cpp b/src/entities/BallPhysicsComponent.cpp similarity index 100% rename from src/BallPhysicsComponent.cpp rename to src/entities/BallPhysicsComponent.cpp diff --git a/src/BallPhysicsComponent.h b/src/entities/BallPhysicsComponent.h similarity index 100% rename from src/BallPhysicsComponent.h rename to src/entities/BallPhysicsComponent.h diff --git a/src/BoxFactory.cpp b/src/entities/BoxFactory.cpp similarity index 100% rename from src/BoxFactory.cpp rename to src/entities/BoxFactory.cpp diff --git a/src/BoxFactory.h b/src/entities/BoxFactory.h similarity index 100% rename from src/BoxFactory.h rename to src/entities/BoxFactory.h diff --git a/src/entities/GoalFactory.cpp b/src/entities/GoalFactory.cpp new file mode 100644 index 0000000..2ed5e9c --- /dev/null +++ b/src/entities/GoalFactory.cpp @@ -0,0 +1,74 @@ +/* + * GoalFactory.cpp + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#include "GoalFactory.h" + +namespace JamSpook { + +GoalFactory::GoalFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer): + mAssetSystem(assetSystem), + mGraphicsSystem(graphicsSystem), + mPhysicsSystem(physicsSystem), + mRenderLayer(renderLayer) +{} + +GoalFactory::~GoalFactory() +{} + +shared_ptr GoalFactory::createGoal(const vec3 position) +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("goal"); + SceneGraph::addEntity(entity); + mat4 transform = translate(mat4(1), position); + + // Add physics component + ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem); + shared_ptr physicsComponent = + make_shared( + 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 = make_shared(transform, + entity, + getShared(mGraphicsSystem), + mRenderLayer); + entity->addComponent(graphicsComponent); + + // Add the ModelRenderable of a ball + ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); + shared_ptr modelRenderable = modelFactory->createModel("goal.f3d", + "goal.png", + "goal-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +} // namespace JamSpook diff --git a/src/FloorFactory.h b/src/entities/GoalFactory.h similarity index 84% rename from src/FloorFactory.h rename to src/entities/GoalFactory.h index 22f2664..15c823c 100644 --- a/src/FloorFactory.h +++ b/src/entities/GoalFactory.h @@ -1,12 +1,12 @@ /* - * FloorFactory.h + * GoalFactory.h * - * Created on: Aug 12, 2019 + * Created on: Aug 14, 2020 * Author: fredrick */ -#ifndef FLOORFACTORY_H_ -#define FLOORFACTORY_H_ +#ifndef GOALFACTORY_H_ +#define GOALFACTORY_H_ #include #include @@ -46,7 +46,7 @@ #include #include -#include "FloorPhysicsComponent.h" +#include "GoalPhysicsComponent.h" namespace JamSpook { @@ -63,6 +63,7 @@ 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; @@ -94,7 +95,8 @@ using ecos::physics::PhysicsComponent; using ecos::physics::ColliderFactory; using ecos::physics::Collider; -class FloorFactory +/// Factory to simplify jump180 entity creation +class GoalFactory { private: weak_ptr mAssetSystem; @@ -103,16 +105,16 @@ private: weak_ptr mRenderLayer; public: - FloorFactory(weak_ptr assetSystem, - weak_ptr graphicsSystem, - weak_ptr physicsSystem, - weak_ptr renderLayer); - virtual ~FloorFactory(); + GoalFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer); + virtual ~GoalFactory(); - shared_ptr createFloor(const vec3 position); - shared_ptr createStaticFloor(const vec3 position); + /// Compose a jump180 entity + shared_ptr createGoal(const vec3 position); }; } // namespace JamSpook -#endif // FLOORFACTORY_H_ +#endif // GOALFACTORY_H_ diff --git a/src/entities/GoalPhysicsComponent.cpp b/src/entities/GoalPhysicsComponent.cpp new file mode 100644 index 0000000..3e6366c --- /dev/null +++ b/src/entities/GoalPhysicsComponent.cpp @@ -0,0 +1,50 @@ +/* + * GoalPhysicsComponent.cpp + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#include "GoalPhysicsComponent.h" + +namespace JamSpook { + +GoalPhysicsComponent::GoalPhysicsComponent(mat4 transform, + shared_ptr > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr 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) +{ + 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(IDCache::get("GroundContactMessage"))); +// } +} + +} // namespace JamSpook diff --git a/src/FloorPhysicsComponent.h b/src/entities/GoalPhysicsComponent.h similarity index 65% rename from src/FloorPhysicsComponent.h rename to src/entities/GoalPhysicsComponent.h index 69c2757..b9415c3 100644 --- a/src/FloorPhysicsComponent.h +++ b/src/entities/GoalPhysicsComponent.h @@ -1,12 +1,12 @@ /* - * FloorPhysicsComponent.h + * GoalPhysicsComponent.h * - * Created on: Aug 12, 2019 + * Created on: Aug 14, 2020 * Author: fredrick */ -#ifndef FLOORPHYSICSCOMPONENT_H_ -#define FLOORPHYSICSCOMPONENT_H_ +#ifndef GOALPHYSICSCOMPONENT_H_ +#define GOALPHYSICSCOMPONENT_H_ #include #include @@ -51,17 +51,17 @@ using ecos::physics::TransformChangeMessage; using ecos::physics::CollisionStateChangeMessage; using ecos::physics::ColliderQueryMessage; -class FloorPhysicsComponent: +class GoalPhysicsComponent: public PhysicsComponent { public: - FloorPhysicsComponent(mat4 transform, - shared_ptr > > entity, - weak_ptr > physicsSystem, - weak_ptr > > physicsCollisionSubSystem, - weak_ptr > > physicsColliderQuerySubSystem, - shared_ptr collider); - virtual ~FloorPhysicsComponent(); + GoalPhysicsComponent(mat4 transform, + shared_ptr > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr collider); + virtual ~GoalPhysicsComponent(); virtual void update(const milliseconds dtms); virtual void onICCMessage(shared_ptr message); @@ -70,4 +70,4 @@ public: } // namespace JamSpook -#endif // FLOORPHYSICSCOMPONENT_H_ +#endif // GOALPHYSICSCOMPONENT_H_ diff --git a/src/entities/Jump180Factory.cpp b/src/entities/Jump180Factory.cpp new file mode 100644 index 0000000..42bc93d --- /dev/null +++ b/src/entities/Jump180Factory.cpp @@ -0,0 +1,74 @@ +/* + * Jump180Factory.cpp + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#include "Jump180Factory.h" + +namespace JamSpook { + +Jump180Factory::Jump180Factory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer): + mAssetSystem(assetSystem), + mGraphicsSystem(graphicsSystem), + mPhysicsSystem(physicsSystem), + mRenderLayer(renderLayer) +{} + +Jump180Factory::~Jump180Factory() +{} + +shared_ptr Jump180Factory::createJump180(const vec3 position) +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("jump180"); + SceneGraph::addEntity(entity); + mat4 transform = translate(mat4(1), position); + + // Add physics component + ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem); + shared_ptr physicsComponent = + make_shared( + 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 = make_shared(transform, + entity, + getShared(mGraphicsSystem), + mRenderLayer); + entity->addComponent(graphicsComponent); + + // Add the ModelRenderable of a ball + ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); + shared_ptr modelRenderable = modelFactory->createModel("jump180.f3d", + "jump180.png", + "jump180-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +} // namespace JamSpook diff --git a/src/entities/Jump180Factory.h b/src/entities/Jump180Factory.h new file mode 100644 index 0000000..fbf0628 --- /dev/null +++ b/src/entities/Jump180Factory.h @@ -0,0 +1,120 @@ +/* + * Jump180Factory.h + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#ifndef JUMP180FACTORY_H_ +#define JUMP180FACTORY_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 mAssetSystem; + weak_ptr mGraphicsSystem; + weak_ptr mPhysicsSystem; + weak_ptr mRenderLayer; + +public: + Jump180Factory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer); + virtual ~Jump180Factory(); + + /// Compose a jump180 entity + shared_ptr createJump180(const vec3 position); +}; + +} // namespace JamSpook + +#endif // JUMP180FACTORY_H_ diff --git a/src/entities/Jump180PhysicsComponent.cpp b/src/entities/Jump180PhysicsComponent.cpp new file mode 100644 index 0000000..fcab63b --- /dev/null +++ b/src/entities/Jump180PhysicsComponent.cpp @@ -0,0 +1,50 @@ +/* + * Jump180PhysicsComponent.cpp + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#include "Jump180PhysicsComponent.h" + +namespace JamSpook { + +Jump180PhysicsComponent::Jump180PhysicsComponent(mat4 transform, + shared_ptr > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr 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) +{ + 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(IDCache::get("GroundContactMessage"))); +// } +} + +} // namespace JamSpook diff --git a/src/entities/Jump180PhysicsComponent.h b/src/entities/Jump180PhysicsComponent.h new file mode 100644 index 0000000..314a1ee --- /dev/null +++ b/src/entities/Jump180PhysicsComponent.h @@ -0,0 +1,73 @@ +/* + * Jump180PhysicsComponent.h + * + * Created on: Aug 14, 2020 + * Author: fredrick + */ + +#ifndef JUMP180PHYSICSCOMPONENT_H_ +#define JUMP180PHYSICSCOMPONENT_H_ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr collider); + virtual ~Jump180PhysicsComponent(); + + virtual void update(const milliseconds dtms); + virtual void onICCMessage(shared_ptr message); + virtual void onCollision(const string& tag); +}; + +} // namespace JamSpook + +#endif // JUMP180PHYSICSCOMPONENT_H_ diff --git a/src/LightInteractionComponent.cpp b/src/entities/LightInteractionComponent.cpp similarity index 91% rename from src/LightInteractionComponent.cpp rename to src/entities/LightInteractionComponent.cpp index 2d15f66..63268f9 100755 --- a/src/LightInteractionComponent.cpp +++ b/src/entities/LightInteractionComponent.cpp @@ -60,9 +60,9 @@ void LightInteractionComponent::onInputDeviceStateChange(const InputDeviceState // mTransform = translate(mTransform, accumulatedDirection); ICCBroadcast(dynamic_pointer_cast(make_shared(mTransform))); -// ICCBroadcast(dynamic_pointer_cast(make_shared(getTranslation(mTransform), -// oldDirection, -// accumulatedDirection))); +// ICCBroadcast(dynamic_pointer_cast(make_shared(getTranslation(mTransform), +// oldDirection, +// accumulatedDirection))); // oldDirection = accumulatedDirection; } diff --git a/src/LightInteractionComponent.h b/src/entities/LightInteractionComponent.h similarity index 96% rename from src/LightInteractionComponent.h rename to src/entities/LightInteractionComponent.h index 702718c..9cb5026 100755 --- a/src/LightInteractionComponent.h +++ b/src/entities/LightInteractionComponent.h @@ -1,5 +1,5 @@ /* - * PlayerInteractionComponent.h + * LightInteractionComponent.h * * Created on: Mar 1, 2019 * Author: fredrick @@ -24,7 +24,7 @@ #include #include -#include "DirectionChangeMessage.h" +#include "../messages/DirectionChangeMessage.h" namespace JamSpook { diff --git a/src/LightPhysicsComponent.cpp b/src/entities/LightPhysicsComponent.cpp similarity index 94% rename from src/LightPhysicsComponent.cpp rename to src/entities/LightPhysicsComponent.cpp index 5a693e3..40e2f27 100644 --- a/src/LightPhysicsComponent.cpp +++ b/src/entities/LightPhysicsComponent.cpp @@ -41,7 +41,7 @@ void LightPhysicsComponent::onICCMessage(shared_ptr message) { Log::write(LogLevel::debug, "PlayerPhysicsComponent - onICCMessage - DirectionChangeMessage"); - shared_ptr msg = dynamic_pointer_cast(message); + shared_ptr msg = dynamic_pointer_cast(message); if (msg->getNewDirection() != vec3(0,0,0)) { mDirection = msg->getNewDirection(); diff --git a/src/LightPhysicsComponent.h b/src/entities/LightPhysicsComponent.h similarity index 97% rename from src/LightPhysicsComponent.h rename to src/entities/LightPhysicsComponent.h index f6b8f3d..1b89406 100644 --- a/src/LightPhysicsComponent.h +++ b/src/entities/LightPhysicsComponent.h @@ -27,7 +27,7 @@ #include #include -#include "DirectionChangeMessage.h" +#include "../messages/DirectionChangeMessage.h" namespace JamSpook { diff --git a/src/LightingFactory.cpp b/src/entities/LightingFactory.cpp similarity index 100% rename from src/LightingFactory.cpp rename to src/entities/LightingFactory.cpp diff --git a/src/LightingFactory.h b/src/entities/LightingFactory.h similarity index 100% rename from src/LightingFactory.h rename to src/entities/LightingFactory.h diff --git a/src/DirectionChangeMessage.cpp b/src/messages/DirectionChangeMessage.cpp similarity index 94% rename from src/DirectionChangeMessage.cpp rename to src/messages/DirectionChangeMessage.cpp index 95bf17e..7421c23 100755 --- a/src/DirectionChangeMessage.cpp +++ b/src/messages/DirectionChangeMessage.cpp @@ -8,6 +8,8 @@ #include "DirectionChangeMessage.h" namespace JamSpook { +namespace messages { + DirectionChangeMessage::DirectionChangeMessage(const vec3 position, const vec3 oldDirection, @@ -36,4 +38,5 @@ const vec3 DirectionChangeMessage::getNewDirection() const return mNewDirection; } +} // namespace messages } // namespace JamSpook diff --git a/src/DirectionChangeMessage.h b/src/messages/DirectionChangeMessage.h similarity index 95% rename from src/DirectionChangeMessage.h rename to src/messages/DirectionChangeMessage.h index 811959c..d986a57 100755 --- a/src/DirectionChangeMessage.h +++ b/src/messages/DirectionChangeMessage.h @@ -14,6 +14,7 @@ #include namespace JamSpook { +namespace messages { using glm::vec3; using ecos::core::IDCache; @@ -39,6 +40,7 @@ public: const vec3 getNewDirection() const; }; +} // namespace messages } // namespace JamSpook #endif // DIRECTIONCHANGEMESSAGE_H_