diff --git a/assets/meshes/mountain.bcosm b/assets/meshes/mountain.bcosm new file mode 100644 index 0000000..b0dd386 Binary files /dev/null and b/assets/meshes/mountain.bcosm differ diff --git a/assets/meshes/plane-1x1.bcosm b/assets/meshes/plane-1x1.bcosm new file mode 100644 index 0000000..a8ca174 Binary files /dev/null and b/assets/meshes/plane-1x1.bcosm differ diff --git a/assets/meshes/road.bcosm b/assets/meshes/road.bcosm new file mode 100644 index 0000000..4d69a24 Binary files /dev/null and b/assets/meshes/road.bcosm differ diff --git a/assets/meshes/road.bcosp b/assets/meshes/road.bcosp new file mode 100644 index 0000000..7a7e650 Binary files /dev/null and b/assets/meshes/road.bcosp differ diff --git a/assets/meshes/sign.bcosm b/assets/meshes/sign.bcosm new file mode 100644 index 0000000..9797f06 Binary files /dev/null and b/assets/meshes/sign.bcosm differ diff --git a/assets/meshes/tunnel.bcosm b/assets/meshes/tunnel.bcosm new file mode 100644 index 0000000..b0d9e75 Binary files /dev/null and b/assets/meshes/tunnel.bcosm differ diff --git a/assets/meshes/tunnel.bcosp b/assets/meshes/tunnel.bcosp new file mode 100644 index 0000000..8c95e55 Binary files /dev/null and b/assets/meshes/tunnel.bcosp differ diff --git a/assets/textures/mountain-diffuse.png b/assets/textures/mountain-diffuse.png new file mode 100644 index 0000000..89fd058 Binary files /dev/null and b/assets/textures/mountain-diffuse.png differ diff --git a/assets/textures/road-diffuse.png b/assets/textures/road-diffuse.png new file mode 100644 index 0000000..81c284f Binary files /dev/null and b/assets/textures/road-diffuse.png differ diff --git a/assets/textures/sign-thanks-diffuse.png b/assets/textures/sign-thanks-diffuse.png new file mode 100644 index 0000000..33bcb2c Binary files /dev/null and b/assets/textures/sign-thanks-diffuse.png differ diff --git a/assets/textures/tunnel-diffuse.png b/assets/textures/tunnel-diffuse.png new file mode 100644 index 0000000..d4b7829 Binary files /dev/null and b/assets/textures/tunnel-diffuse.png differ diff --git a/src/JamSpookGame.cpp b/src/JamSpookGame.cpp index f48aa25..0e60f4e 100644 --- a/src/JamSpookGame.cpp +++ b/src/JamSpookGame.cpp @@ -12,8 +12,6 @@ namespace JamSpook { JamSpookGame::JamSpookGame(): ecos::core::Game() { - - Log::write(LogLevel::info, "Game - Constructor"); setGameState(ecos::core::GameState::Launching); @@ -108,15 +106,30 @@ JamSpookGame::JamSpookGame(): 0.1f, 1000.0f); + + mCameraBackground = camFactory->createOrthogonal(translate(mat4(1), vec3(0, 0, -1)), + vec4(10,10,10,10), + 0.1f, + 20); + + mCameraEndScene = camFactory->createPerspective(vec3(1010.0f, 4.0f, 1010.0f), + vec3(0.0f, 0.0f, 0.0f), + vec3(0.0f, 1.0f, 0.0f), + 90.0f/2, + static_cast(mWindow->getWindowSize().x)/mWindow->getWindowSize().y, + 0.1f, + 100.0f); + delete camFactory; mRenderer->setCamera(mCamera); +// mRenderer->setCamera(mCameraEndScene); // Create render layers // Add render layers RenderLayerFactory* renderLayerFactory = new RenderLayerFactory(assetSystem, mWindow); -// graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-bg", mCamera)); + graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-bg", mCameraBackground)); graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-game", mCamera)); - graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-gui", mCamera)); +// graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-gui", mCamera)); delete renderLayerFactory; // Add Sound system @@ -176,75 +189,43 @@ void JamSpookGame::set() // Prepare scene shared_ptr graphicsSystem = dynamic_pointer_cast(findSystem(IDCache::get("GraphicsSystem"))); + shared_ptr renderLayerBackground = graphicsSystem->getRenderLayer(IDCache::get("rl-bg")); shared_ptr renderLayerGame = graphicsSystem->getRenderLayer(IDCache::get("rl-game")); -// // Add lighting -// unique_ptr lightingFactoryGame = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), -// graphicsSystem, -// dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), -// dynamic_pointer_cast(findSystem(IDCache::get("InteractionSystem")))); + // Create lighting + unique_ptr lightingFactory = make_unique( + dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), + graphicsSystem, + dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), + dynamic_pointer_cast(findSystem(IDCache::get("InteractionSystem")))); + + lightingFactory->createSun(10.0f, + vec3(0,0,0), + vec3(1,1,1), + 0.1f, + renderLayerGame); + + lightingFactory.reset(); +// // Create background +// unique_ptr bakgroundSpriteFactory = make_unique( +// dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), +// graphicsSystem, +// renderLayerBackground); // -// lightingFactoryGame->createPointLight(vec3(10, 10, 0), -// vec3(1.0f, 0.93f, 0.68f), -// .6f, -// renderLayerGame); -// lightingFactoryGame->createPointLight(vec3(-10, 2, 0), -// vec3(0.78f, 0.82f, 1.0f), -// .6f, -// renderLayerGame); - -// lightingFactoryGame->createSun(100.0f, -// vec3(0,0,0), -// vec3(1,0,0), -// 1.0f, -// renderLayerGame); - - -// lightingFactoryGame->createDirectionalLight(vec3(10, 10, 0), -// vec3(-90, 0, 0), -// vec3(1,0,0), -// 1.0f, -// renderLayerGame); -// lightingFactoryGame->createDirectionalLight(vec3(-10, 10, 0), -// vec3(0, 0, 0), -// vec3(0,1,0), -// 1.0f, -// renderLayerGame); -// lightingFactoryGame->createDirectionalLight(vec3(-10, 10, 0), -// vec3(0, 0, 0), -// vec3(0,0,1), -// 1.0f, -// renderLayerGame); +// bakgroundSpriteFactory->createBackground("sky-plane", "sky-diffuse.png"); // -// unique_ptr lightingFactoryGUI = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), -// graphicsSystem, -// dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), -// renderLayerGui, -// dynamic_pointer_cast(findSystem(IDCache::get("InteractionSystem")))); -// lightingFactoryGUI->createDirectionalLight(vec3(10, 10, 0), -// vec3(0, 0, 0), -// vec3(1,0,0), -// 1.0f, -// renderLayerGui); -// lightingFactoryGUI->createDirectionalLight(vec3(-10, 10, 0), -// vec3(0, 0, 0), -// vec3(0,1,0), -// 1.0f, -// renderLayerGui); - - - - // Note: this was enabled +// bakgroundSpriteFactory.reset(); // -// // 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; +// // Create background +// unique_ptr spriteFactory = make_unique( +// dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), +// graphicsSystem, +// renderLayerGame); // +//// bakgroundSpriteFactory->createBackground("ball-test-plane", "ball-diffuse.png"); +// spriteFactory->createPlane("water", "water-diffuse.png", vec3(0, 4, 0), vec3(90, 0, 0), vec3(100, 100, 0)); +// +// spriteFactory.reset(); // Create 2 jump180s unique_ptr jump180Factory = make_unique( @@ -270,18 +251,24 @@ void JamSpookGame::set() goalFactory.reset(); - // Create the reset trigger - unique_ptr resetTriggerFactory = make_unique( + // Create the track pieces + unique_ptr trackPieceFactory = make_unique( dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), graphicsSystem, dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), renderLayerGame); - resetTriggerFactory->createResetTrigger(vec3(-1, -30, -12), - vec3(1)); -// goalFactory->createGoal(vec3(0, 0, 0)); +// trackPieceFactory->createRoad(); +// trackPieceFactory->createTunnel(); +// trackPieceFactory->createMountain(); + trackPieceFactory->createSign("ThankYouSign", + "sign-thanks-diffuse.png", + vec3(994, 0, 1000), + quat(vec3(radians(0.0f), radians(60.0f), radians(0.0f)))); + + trackPieceFactory.reset(); + - resetTriggerFactory.reset(); // // Create the ball // unique_ptr ballFactory = make_unique(dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), @@ -299,59 +286,69 @@ void JamSpookGame::set() // ballFactory.reset(); // Create the player kart - unique_ptr kartFactory = make_unique( + shared_ptr kartFactory = make_unique( dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), graphicsSystem, dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), dynamic_pointer_cast(findSystem(IDCache::get("InteractionSystem"))), + dynamic_pointer_cast(findSystem(IDCache::get("AnimationSystem"))), renderLayerGame); shared_ptr kartEntity = kartFactory->createKart( vec3(0, 3, 0), // position vec3(0, 180, 0)); // euler degrees rotation, XYZ - kartFactory.reset(); + + +// kartFactory.reset(); // Create the follow camera, and lock it to the kart unique_ptr cameraFactory = make_unique(); + cameraFactory->createActiveFollowCamera("followKartCamera", mCamera, kartEntity, vec3(0 ,10 ,-25), vec3(0, 5, 0)); + + shared_ptr endSceneCamera = cameraFactory->createStaticCamera("endSceneCamera", + mCameraEndScene); + cameraFactory.reset(); + // Create the reset trigger + unique_ptr resetTriggerFactory = make_unique( + dynamic_pointer_cast(findSystem(IDCache::get("AssetSystem"))), + graphicsSystem, + dynamic_pointer_cast(findSystem(IDCache::get("PhysicsSystem"))), + renderLayerGame); - /** - const string name, - shared_ptr, - weak_ptr wTargetEntity, - const vec3 cameraPositionOffset, - const vec3 targetPositionOffset - */ - - - - - - - - - - - - - - - - - - +// shared_ptr endGameEntity = resetTriggerFactory-> +// createResetTrigger(vec3(-1, -30, -12), +// vec3(1)); + shared_ptr endGameEntity = resetTriggerFactory-> + createResetTrigger(vec3(0, 0, 0), + vec3(1)); + // Add the leaking ICCResponse component to // ContactWithPlayer + weak_ptr wGraphicsSystem = graphicsSystem; + weak_ptr wEndSceneCamera = mCameraEndScene; + endGameEntity->addComponent(make_shared(endGameEntity, [wGraphicsSystem, wEndSceneCamera, kartFactory] (shared_ptr message) { + if (message->getMessageType() == IDCache::get("ContactWithPlayer")) + { + Log::write(LogLevel::debug, "endGameEntity - ContactWithPlayer"); + shared_ptr graphicsSystem = getShared(wGraphicsSystem); + shared_ptr renderLayerGame = graphicsSystem->getRenderLayer(IDCache::get("rl-game")); + renderLayerGame->setCamera(getShared(wEndSceneCamera)); + // Create the end scene rotating kart + shared_ptr rotatingKartEntity = kartFactory->createRotatingKart(vec3(1000, 0, 1000)); + } + })); + resetTriggerFactory.reset(); // Set game state setGameState(ecos::core::GameState::InGame); diff --git a/src/JamSpookGame.h b/src/JamSpookGame.h index eed9071..719f0bc 100644 --- a/src/JamSpookGame.h +++ b/src/JamSpookGame.h @@ -62,7 +62,9 @@ #include #include +#include "entities/SpriteFactory.h" #include "entities/LightingFactory.h" +#include "entities/TrackPieceFactory.h" #include "entities/Jump180Factory.h" #include "entities/GoalFactory.h" #include "entities/BallFactory.h" @@ -155,6 +157,8 @@ private: BroadcastObservable::CallbackID mInputDeviceCallbackId; shared_ptr mRenderer; shared_ptr mCamera; + shared_ptr mCameraBackground; + shared_ptr mCameraEndScene; public: JamSpookGame(); diff --git a/src/entities/KartFactory.cpp b/src/entities/KartFactory.cpp index 7faf85b..63cbc00 100644 --- a/src/entities/KartFactory.cpp +++ b/src/entities/KartFactory.cpp @@ -13,11 +13,13 @@ KartFactory::KartFactory(weak_ptr assetSystem, weak_ptr graphicsSystem, weak_ptr physicsSystem, weak_ptr interactionSystem, + weak_ptr animationSystem, weak_ptr renderLayer): mAssetSystem(assetSystem), mGraphicsSystem(graphicsSystem), mPhysicsSystem(physicsSystem), mInteractionSystem(interactionSystem), + mAnimationSystem(animationSystem), mRenderLayer(renderLayer) {} @@ -76,7 +78,7 @@ shared_ptr KartFactory::createKart(const vec3 position, mRenderLayer); entity->addComponent(graphicsComponent); - // Add the ModelRenderable of a ball + // Add the ModelRenderable ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); shared_ptr modelRenderableKart = modelFactory->createModel("kart-vehicle.bcosm", @@ -91,14 +93,14 @@ shared_ptr KartFactory::createKart(const vec3 position, delete modelFactory; - // Add internal pointlight - LightSourceFactory* lightSourceFactory = new LightSourceFactory(mAssetSystem, mGraphicsSystem); - shared_ptr lightSource = lightSourceFactory->createPointLight(vec3(1,1,1), - 0.02f, - 0.03f, - transform); - graphicsComponent->setLightSource(lightSource); - delete lightSourceFactory; +// // Add internal pointlight +// LightSourceFactory* lightSourceFactory = new LightSourceFactory(mAssetSystem, mGraphicsSystem); +// shared_ptr lightSource = lightSourceFactory->createPointLight(vec3(1,1,1), +// 0.1f, +// 0.001f, +// translate(transform, vec3(0,0,0))); +// graphicsComponent->setLightSource(lightSource); +// delete lightSourceFactory; // Add interaction component shared_ptr interactionComponent = @@ -114,4 +116,146 @@ shared_ptr KartFactory::createKart(const vec3 position, return entity; } +shared_ptr KartFactory::createRotatingKart(const vec3 position) +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("rotatingKart"); + SceneGraph::addEntity(entity); + + // Create transform + mat4 translation = translate(mat4(1.0f), position); + mat4 transform = translation; + + // Add graphics component + shared_ptr graphicsComponent = make_shared(transform, + entity, + getShared(mGraphicsSystem), + mRenderLayer); + entity->addComponent(graphicsComponent); + + // Add the ModelRenderable + ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); + + shared_ptr modelRenderableKart = modelFactory->createModel("kart-vehicle.bcosm", + "kart-vehicle-diffuse.png", + "kart-vehicle-model"); + graphicsComponent->addRenderable(modelRenderableKart); + + shared_ptr modelRenderableDriver = modelFactory->createModel("kart-driver.bcosm", + "kart-driver-diffuse.png", + "kart-driver-model"); + graphicsComponent->addRenderable(modelRenderableDriver); + + delete modelFactory; + + // Add Physics component + unique_ptr colliderFactory = make_unique(mPhysicsSystem, mAssetSystem); + shared_ptr physicsComponent = + make_shared(transform, + entity, + mPhysicsSystem, + mPhysicsSystem, + mPhysicsSystem, + colliderFactory->createBoxCollider( + vec3(1000,0,1000), + glm::quat_cast(mat4(1)), + vec3(1), + 0, + entity, + "rotatingKart")); + entity->addComponent(physicsComponent); + weak_ptr wPhysicsComponent(physicsComponent); + + // Animation component, to make the kart rotate continuously + shared_ptr animationComponent = + make_shared(entity, + mAnimationSystem); + entity->addComponent(animationComponent); + + // Add falling animation + animationComponent->addAnimation(AnimationFactory::createLinearAnimation( + make_shared >( + physicsComponent, + [wPhysicsComponent]()->vec3{ + if (wPhysicsComponent.expired()) return vec3(); + shared_ptr physicsComponent = wPhysicsComponent.lock(); + if (!physicsComponent) return vec3(); + + return physicsComponent->getPosition(); + }, + [wPhysicsComponent](vec3 i){ + if (wPhysicsComponent.expired()) return; + shared_ptr physicsComponent = wPhysicsComponent.lock(); + if (!physicsComponent) return; + + physicsComponent->setPosition(i); + }), + vec3(1000, 10, 1000), + vec3(1000, 0, 1000), + static_cast(1500), + [] () {Log::write(LogLevel::debug, "Translation end"); } )); + + // Add rotation animation + animationComponent->addAnimation(AnimationFactory::createLinearAnimation( + make_shared >( + physicsComponent, + [wPhysicsComponent]()->vec3{ + if (wPhysicsComponent.expired()) return vec3(); + shared_ptr physicsComponent = wPhysicsComponent.lock(); + if (!physicsComponent) return vec3(); + + return getRotationDegrees(physicsComponent->getTransform()); + }, + [wPhysicsComponent](vec3 i){ + if (wPhysicsComponent.expired()) return; + shared_ptr physicsComponent = wPhysicsComponent.lock(); + if (!physicsComponent) return; + + physicsComponent->setOrientationEulerDegreesXYZ(i); + }), + vec3(0, 45, 0), + vec3(0, 0, 0), + static_cast(1500), + [] () {Log::write(LogLevel::debug, "Rotation end"); } )); + + + // Return instance + return entity; +} + } // namespace JamSpook + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/entities/KartFactory.h b/src/entities/KartFactory.h index 9a9f2f4..b19523b 100644 --- a/src/entities/KartFactory.h +++ b/src/entities/KartFactory.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ #include #include +#include #include #include @@ -32,6 +34,11 @@ #include #include +#include +#include +#include +#include + #include #include #include @@ -66,10 +73,13 @@ using std::string; using std::shared_ptr; using std::make_shared; using std::weak_ptr; +using std::unique_ptr; +using std::make_unique; using std::dynamic_pointer_cast; using std::function; using std::bind; using std::vector; +using std::chrono::milliseconds; using glm::vec3; using glm::mat4; @@ -82,6 +92,7 @@ using glm::eulerAngleXYZ; using glm::radians; using ecos::utility::getShared; +using ecos::utility::getRotationDegrees; using ecos::core::IDCache; using ecos::core::logging::Log; @@ -95,6 +106,12 @@ using ecos::core::ICCResponseComponent; using ecos::asset::AssetSystem; using ecos::asset::DataManagementMode; +using ecos::animation::AnimationSystem; +using ecos::animation::Animation; +using ecos::animation::AnimationFactory; +using ecos::animation::AnimationComponent; +using ecos::animation::Attribute; + using ecos::graphics::GraphicsSystem; using ecos::graphics::GraphicsComponent; using ecos::graphics::RenderLayer; @@ -128,6 +145,7 @@ private: weak_ptr mGraphicsSystem; weak_ptr mPhysicsSystem; weak_ptr mInteractionSystem; + weak_ptr mAnimationSystem; weak_ptr mRenderLayer; public: @@ -135,12 +153,16 @@ public: weak_ptr graphicsSystem, weak_ptr physicsSystem, weak_ptr interactionSystem, + weak_ptr animationSystem, weak_ptr renderLayer); virtual ~KartFactory(); /// Compose a kart entity shared_ptr createKart(const vec3 position, const vec3 eulerRotationXYZDegrees); + + /// Compose a rotating kart entity + shared_ptr createRotatingKart(const vec3 position); }; } // namespace JamSpook diff --git a/src/entities/ResetTriggerFactory.cpp b/src/entities/ResetTriggerFactory.cpp index a80c8b5..e35c27f 100644 --- a/src/entities/ResetTriggerFactory.cpp +++ b/src/entities/ResetTriggerFactory.cpp @@ -27,7 +27,7 @@ shared_ptr ResetTriggerFactory::createResetTrigger(const vec3 position, { // Create instance shared_ptr entity = make_shared(); - entity->setEntityTag("reset-trigger"); + entity->setEntityTag("end-trigger"); SceneGraph::addEntity(entity); mat4 transform = translate(mat4(1), position); diff --git a/src/entities/ResetTriggerPhysicsComponent.cpp b/src/entities/ResetTriggerPhysicsComponent.cpp index dafe03d..6ad88cf 100644 --- a/src/entities/ResetTriggerPhysicsComponent.cpp +++ b/src/entities/ResetTriggerPhysicsComponent.cpp @@ -39,12 +39,7 @@ void ResetTriggerPhysicsComponent::onICCMessage(shared_ptr 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(IDCache::get("GroundContactMessage"))); -// } + ICCBroadcast(make_shared(IDCache::get("ContactWithPlayer"))); } } // namespace JamSpook diff --git a/src/entities/TrackPieceFactory.cpp b/src/entities/TrackPieceFactory.cpp new file mode 100644 index 0000000..64d0762 --- /dev/null +++ b/src/entities/TrackPieceFactory.cpp @@ -0,0 +1,221 @@ +/* + * TrackPieceFactory.cpp + * + * Created on: Aug 27, 2020 + * Author: fredrick + */ + +#include "TrackPieceFactory.h" + +namespace JamSpook { + +TrackPieceFactory::TrackPieceFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer): + mAssetSystem(assetSystem), + mGraphicsSystem(graphicsSystem), + mPhysicsSystem(physicsSystem), + mRenderLayer(renderLayer) +{} + +TrackPieceFactory::~TrackPieceFactory() +{} + +/// Compose a road entity +shared_ptr TrackPieceFactory::createRoad() +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("road"); + SceneGraph::addEntity(entity); + + // Create transform + mat4 transform = mat4(1); + + // Add physics component + ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem); + shared_ptr physicsComponent = + make_shared( + transform, + entity, + getShared(mPhysicsSystem), + getShared(mPhysicsSystem), + getShared(mPhysicsSystem), + colliderFactory->createConvexHullCollider(vec3(0), + quat_cast(mat4(1)), + "road.bcosp", // filePath + "road-shape", // name + 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("road.bcosm", + "road-diffuse.png", + "road-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +/// Compose a tunnel entity +shared_ptr TrackPieceFactory::createTunnel() +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("tunnel"); + SceneGraph::addEntity(entity); + + // Create transform + mat4 transform = mat4(1); + + // Add physics component + ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem); + shared_ptr physicsComponent = + make_shared( + transform, + entity, + getShared(mPhysicsSystem), + getShared(mPhysicsSystem), + getShared(mPhysicsSystem), + colliderFactory->createConvexHullCollider(vec3(0), + quat_cast(mat4(1)), + "tunnel.bcosp", // filePath + "tunnel-shape", // name + 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("tunnel.bcosm", + "tunnel-diffuse.png", + "tunnel-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +/// Compose a mountain entity +shared_ptr TrackPieceFactory::createMountain() +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag("mountain"); + SceneGraph::addEntity(entity); + + // Create transform + mat4 transform = mat4(1); + +// // Add physics component +// ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem); +// shared_ptr physicsComponent = +// make_shared( +// transform, +// entity, +// getShared(mPhysicsSystem), +// getShared(mPhysicsSystem), +// getShared(mPhysicsSystem), +// colliderFactory->createConvexHullCollider(vec3(0), +// quat_cast(mat4(1)), +// "mountain.bcosp", // filePath +// "mountain-shape", // name +// 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("mountain.bcosm", + "mountain-diffuse.png", + "mountain-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +shared_ptr TrackPieceFactory::createSign( + const string name, + const string diffuseTextureFilePath, + vec3 position, + quat orientation) +{ + // Create instance + shared_ptr entity = make_shared(); + entity->setEntityTag(name + "_sign"); + SceneGraph::addEntity(entity); + + // Create transform + mat4 rotation = glm::toMat4(orientation); + + mat4 translation = translate(mat4(1.0f), position); + + mat4 transform = translation * rotation;// * rotateToCenter; + + // 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("sign.bcosm", + diffuseTextureFilePath, + "sign-model"); + delete modelFactory; + graphicsComponent->addRenderable(modelRenderable); + + // Return instance + return entity; +} + +} // namespace JamSpook diff --git a/src/entities/TrackPieceFactory.h b/src/entities/TrackPieceFactory.h new file mode 100644 index 0000000..1769c5b --- /dev/null +++ b/src/entities/TrackPieceFactory.h @@ -0,0 +1,147 @@ +/* + * TrackPieceFactory.h + * + * Created on: Aug 27, 2020 + * Author: fredrick + */ + +#ifndef ENTITIES_TRACKPIECEFACTORY_H_ +#define ENTITIES_TRACKPIECEFACTORY_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 +#include + +#include "TrackPiecePhysicsComponent.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 glm::rotate; +using glm::eulerAngleXYZ; +using glm::radians; + +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 track piece entity creation +class TrackPieceFactory +{ +private: + weak_ptr mAssetSystem; + weak_ptr mGraphicsSystem; + weak_ptr mPhysicsSystem; + weak_ptr mRenderLayer; + +public: + TrackPieceFactory(weak_ptr assetSystem, + weak_ptr graphicsSystem, + weak_ptr physicsSystem, + weak_ptr renderLayer); + virtual ~TrackPieceFactory(); + + /// Compose a road entity + shared_ptr createRoad(); + + /// Compose a tunnel entity + shared_ptr createTunnel(); + +// /// Compose a tunnel entity +// shared_ptr createTunnel(); + + /// Compose a mountain entity + shared_ptr createMountain(); + + /// Compose a sign entity + shared_ptr createSign(const string name, + const string diffuseTextureFilePath, + vec3 position, + quat orientation); +}; + +} // namespace JamSpook + +#endif // ENTITIES_TRACKPIECEFACTORY_H_ diff --git a/src/entities/TrackPiecePhysicsComponent.cpp b/src/entities/TrackPiecePhysicsComponent.cpp new file mode 100644 index 0000000..a27d9e4 --- /dev/null +++ b/src/entities/TrackPiecePhysicsComponent.cpp @@ -0,0 +1,42 @@ +/* + * TrackPiecePhysicsComponent.cpp + * + * Created on: Aug 27, 2020 + * Author: fredrick + */ + +#include "TrackPiecePhysicsComponent.h" + +namespace JamSpook { + +TrackPiecePhysicsComponent::TrackPiecePhysicsComponent(mat4 transform, + shared_ptr > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr collider): + PhysicsComponent(transform, + entity, + physicsSystem, + physicsCollisionSubSystem, + physicsColliderQuerySubSystem, + collider) +{} + +TrackPiecePhysicsComponent::~TrackPiecePhysicsComponent() +{} + +void TrackPiecePhysicsComponent::update(const milliseconds dtms) +{ + PhysicsComponent::update(dtms); +} + +void TrackPiecePhysicsComponent::onICCMessage(shared_ptr message) +{ + PhysicsComponent::onICCMessage(message); +} + +void TrackPiecePhysicsComponent::onCollision(const string& tag) +{} + +} // namespace JamSpook diff --git a/src/entities/TrackPiecePhysicsComponent.h b/src/entities/TrackPiecePhysicsComponent.h new file mode 100644 index 0000000..ac75b42 --- /dev/null +++ b/src/entities/TrackPiecePhysicsComponent.h @@ -0,0 +1,77 @@ +/* + * TrackPiecePhysicsComponent.h + * + * Created on: Aug 27, 2020 + * Author: fredrick + */ + +#ifndef TRACKPIECEPHYSICSCOMPONENT_H_ +#define TRACKPIECEPHYSICSCOMPONENT_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 TrackPiecePhysicsComponent: + public PhysicsComponent +{ +public: + TrackPiecePhysicsComponent(mat4 transform, + shared_ptr > > entity, + weak_ptr > physicsSystem, + weak_ptr > > physicsCollisionSubSystem, + weak_ptr > > physicsColliderQuerySubSystem, + shared_ptr collider); + virtual ~TrackPiecePhysicsComponent(); + + virtual void update(const milliseconds dtms); + virtual void onICCMessage(shared_ptr message); + virtual void onCollision(const string& tag); +}; + +} // namespace JamSpook + +#endif // TRACKPIECEPHYSICSCOMPONENT_H_