Partially implemented the level and end scene

This commit is contained in:
Fredrick Amnehagen 2020-08-29 01:42:23 +02:00
parent ac8d75a1c1
commit 88a3db8d72
21 changed files with 765 additions and 116 deletions

Binary file not shown.

Binary file not shown.

BIN
assets/meshes/road.bcosm Normal file

Binary file not shown.

BIN
assets/meshes/road.bcosp Normal file

Binary file not shown.

BIN
assets/meshes/sign.bcosm Normal file

Binary file not shown.

BIN
assets/meshes/tunnel.bcosm Normal file

Binary file not shown.

BIN
assets/meshes/tunnel.bcosp Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -12,8 +12,6 @@ namespace JamSpook {
JamSpookGame::JamSpookGame(): JamSpookGame::JamSpookGame():
ecos::core::Game() ecos::core::Game()
{ {
Log::write(LogLevel::info, "Game - Constructor"); Log::write(LogLevel::info, "Game - Constructor");
setGameState(ecos::core::GameState::Launching); setGameState(ecos::core::GameState::Launching);
@ -108,15 +106,30 @@ JamSpookGame::JamSpookGame():
0.1f, 0.1f,
1000.0f); 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<float>(mWindow->getWindowSize().x)/mWindow->getWindowSize().y,
0.1f,
100.0f);
delete camFactory; delete camFactory;
mRenderer->setCamera(mCamera); mRenderer->setCamera(mCamera);
// mRenderer->setCamera(mCameraEndScene);
// Create render layers // Create render layers
// Add render layers // Add render layers
RenderLayerFactory* renderLayerFactory = new RenderLayerFactory(assetSystem, mWindow); 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-game", mCamera));
graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-gui", mCamera)); // graphicsSystem->addRenderLayer(renderLayerFactory->createRenderLayer("rl-gui", mCamera));
delete renderLayerFactory; delete renderLayerFactory;
// Add Sound system // Add Sound system
@ -176,75 +189,43 @@ void JamSpookGame::set()
// Prepare scene // Prepare scene
shared_ptr<GraphicsSystem> graphicsSystem = dynamic_pointer_cast<GraphicsSystem>(findSystem(IDCache::get("GraphicsSystem"))); shared_ptr<GraphicsSystem> graphicsSystem = dynamic_pointer_cast<GraphicsSystem>(findSystem(IDCache::get("GraphicsSystem")));
shared_ptr<RenderLayer> renderLayerBackground = graphicsSystem->getRenderLayer(IDCache::get("rl-bg"));
shared_ptr<RenderLayer> renderLayerGame = graphicsSystem->getRenderLayer(IDCache::get("rl-game")); shared_ptr<RenderLayer> renderLayerGame = graphicsSystem->getRenderLayer(IDCache::get("rl-game"));
// // Add lighting // Create lighting
// unique_ptr<LightingFactory> lightingFactoryGame = make_unique<LightingFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), unique_ptr<LightingFactory> lightingFactory = make_unique<LightingFactory>(
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
graphicsSystem,
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
dynamic_pointer_cast<InteractionSystem>(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<SpriteFactory> bakgroundSpriteFactory = make_unique<SpriteFactory>(
// dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem, // graphicsSystem,
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), // renderLayerBackground);
// dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))));
// //
// lightingFactoryGame->createPointLight(vec3(10, 10, 0), // bakgroundSpriteFactory->createBackground("sky-plane", "sky-diffuse.png");
// 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);
// //
// unique_ptr<LightingFactory> lightingFactoryGUI = make_unique<LightingFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), // bakgroundSpriteFactory.reset();
//
// // Create background
// unique_ptr<SpriteFactory> spriteFactory = make_unique<SpriteFactory>(
// dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem, // graphicsSystem,
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
// renderLayerGui,
// dynamic_pointer_cast<InteractionSystem>(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
//
// // Add entities
// FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem,
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
// renderLayerGame); // renderLayerGame);
// floorFactory->createFloor(vec3(0,-5,0));
// floorFactory->createStaticFloor(vec3(0,-8,0));
// delete floorFactory;
// //
//// 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 // Create 2 jump180s
unique_ptr<Jump180Factory> jump180Factory = make_unique<Jump180Factory>( unique_ptr<Jump180Factory> jump180Factory = make_unique<Jump180Factory>(
@ -270,18 +251,24 @@ void JamSpookGame::set()
goalFactory.reset(); goalFactory.reset();
// Create the reset trigger // Create the track pieces
unique_ptr<ResetTriggerFactory> resetTriggerFactory = make_unique<ResetTriggerFactory>( unique_ptr<TrackPieceFactory> trackPieceFactory = make_unique<TrackPieceFactory>(
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), 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);
resetTriggerFactory->createResetTrigger(vec3(-1, -30, -12), // trackPieceFactory->createRoad();
vec3(1)); // trackPieceFactory->createTunnel();
// goalFactory->createGoal(vec3(0, 0, 0)); // 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 // // Create the ball
// unique_ptr<BallFactory> ballFactory = make_unique<BallFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), // unique_ptr<BallFactory> ballFactory = make_unique<BallFactory>(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
@ -299,59 +286,69 @@ void JamSpookGame::set()
// ballFactory.reset(); // ballFactory.reset();
// Create the player kart // Create the player kart
unique_ptr<KartFactory> kartFactory = make_unique<KartFactory>( shared_ptr<KartFactory> kartFactory = make_unique<KartFactory>(
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), 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"))),
dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))), dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))),
dynamic_pointer_cast<AnimationSystem>(findSystem(IDCache::get("AnimationSystem"))),
renderLayerGame); renderLayerGame);
shared_ptr<Entity> kartEntity = kartFactory->createKart( shared_ptr<Entity> kartEntity = kartFactory->createKart(
vec3(0, 3, 0), // position vec3(0, 3, 0), // position
vec3(0, 180, 0)); // euler degrees rotation, XYZ vec3(0, 180, 0)); // euler degrees rotation, XYZ
kartFactory.reset();
// kartFactory.reset();
// Create the follow camera, and lock it to the kart // Create the follow camera, and lock it to the kart
unique_ptr<CameraFactory> cameraFactory = make_unique<CameraFactory>(); unique_ptr<CameraFactory> cameraFactory = make_unique<CameraFactory>();
cameraFactory->createActiveFollowCamera("followKartCamera", cameraFactory->createActiveFollowCamera("followKartCamera",
mCamera, mCamera,
kartEntity, kartEntity,
vec3(0 ,10 ,-25), vec3(0 ,10 ,-25),
vec3(0, 5, 0)); vec3(0, 5, 0));
shared_ptr<Entity> endSceneCamera = cameraFactory->createStaticCamera("endSceneCamera",
mCameraEndScene);
cameraFactory.reset(); cameraFactory.reset();
// Create the reset trigger
unique_ptr<ResetTriggerFactory> resetTriggerFactory = make_unique<ResetTriggerFactory>(
dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
graphicsSystem,
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame);
/** // shared_ptr<Entity> endGameEntity = resetTriggerFactory->
const string name, // createResetTrigger(vec3(-1, -30, -12),
shared_ptr<Camera>, // vec3(1));
weak_ptr<Entity> wTargetEntity,
const vec3 cameraPositionOffset,
const vec3 targetPositionOffset
*/
shared_ptr<Entity> endGameEntity = resetTriggerFactory->
createResetTrigger(vec3(0, 0, 0),
vec3(1));
// Add the leaking ICCResponse component to // ContactWithPlayer
weak_ptr<GraphicsSystem> wGraphicsSystem = graphicsSystem;
weak_ptr<Camera> wEndSceneCamera = mCameraEndScene;
endGameEntity->addComponent(make_shared<ICCResponseComponent>(endGameEntity, [wGraphicsSystem, wEndSceneCamera, kartFactory] (shared_ptr<Message> message) {
if (message->getMessageType() == IDCache::get("ContactWithPlayer"))
{
Log::write(LogLevel::debug, "endGameEntity - ContactWithPlayer");
shared_ptr<GraphicsSystem> graphicsSystem = getShared(wGraphicsSystem);
shared_ptr<RenderLayer> renderLayerGame = graphicsSystem->getRenderLayer(IDCache::get("rl-game"));
renderLayerGame->setCamera(getShared(wEndSceneCamera));
// Create the end scene rotating kart
shared_ptr<Entity> rotatingKartEntity = kartFactory->createRotatingKart(vec3(1000, 0, 1000));
}
}));
resetTriggerFactory.reset();
// Set game state // Set game state
setGameState(ecos::core::GameState::InGame); setGameState(ecos::core::GameState::InGame);

View File

@ -62,7 +62,9 @@
#include <ecos/sound/SoundSystem.h> #include <ecos/sound/SoundSystem.h>
#include <ecos/sound/loaders/SoundEffectLoader.h> #include <ecos/sound/loaders/SoundEffectLoader.h>
#include "entities/SpriteFactory.h"
#include "entities/LightingFactory.h" #include "entities/LightingFactory.h"
#include "entities/TrackPieceFactory.h"
#include "entities/Jump180Factory.h" #include "entities/Jump180Factory.h"
#include "entities/GoalFactory.h" #include "entities/GoalFactory.h"
#include "entities/BallFactory.h" #include "entities/BallFactory.h"
@ -155,6 +157,8 @@ private:
BroadcastObservable<const InputDeviceState>::CallbackID mInputDeviceCallbackId; BroadcastObservable<const InputDeviceState>::CallbackID mInputDeviceCallbackId;
shared_ptr<GL4Renderer> mRenderer; shared_ptr<GL4Renderer> mRenderer;
shared_ptr<Camera> mCamera; shared_ptr<Camera> mCamera;
shared_ptr<Camera> mCameraBackground;
shared_ptr<Camera> mCameraEndScene;
public: public:
JamSpookGame(); JamSpookGame();

View File

@ -13,11 +13,13 @@ KartFactory::KartFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem, weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem, weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<InteractionSystem> interactionSystem, weak_ptr<InteractionSystem> interactionSystem,
weak_ptr<AnimationSystem> animationSystem,
weak_ptr<RenderLayer> renderLayer): weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem), mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem), mGraphicsSystem(graphicsSystem),
mPhysicsSystem(physicsSystem), mPhysicsSystem(physicsSystem),
mInteractionSystem(interactionSystem), mInteractionSystem(interactionSystem),
mAnimationSystem(animationSystem),
mRenderLayer(renderLayer) mRenderLayer(renderLayer)
{} {}
@ -76,7 +78,7 @@ shared_ptr<Entity> KartFactory::createKart(const vec3 position,
mRenderLayer); mRenderLayer);
entity->addComponent(graphicsComponent); entity->addComponent(graphicsComponent);
// Add the ModelRenderable of a ball // Add the ModelRenderable
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem); ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderableKart = modelFactory->createModel("kart-vehicle.bcosm", shared_ptr<ModelRenderable> modelRenderableKart = modelFactory->createModel("kart-vehicle.bcosm",
@ -91,14 +93,14 @@ shared_ptr<Entity> KartFactory::createKart(const vec3 position,
delete modelFactory; delete modelFactory;
// Add internal pointlight // // Add internal pointlight
LightSourceFactory* lightSourceFactory = new LightSourceFactory(mAssetSystem, mGraphicsSystem); // LightSourceFactory* lightSourceFactory = new LightSourceFactory(mAssetSystem, mGraphicsSystem);
shared_ptr<LightSource> lightSource = lightSourceFactory->createPointLight(vec3(1,1,1), // shared_ptr<LightSource> lightSource = lightSourceFactory->createPointLight(vec3(1,1,1),
0.02f, // 0.1f,
0.03f, // 0.001f,
transform); // translate(transform, vec3(0,0,0)));
graphicsComponent->setLightSource(lightSource); // graphicsComponent->setLightSource(lightSource);
delete lightSourceFactory; // delete lightSourceFactory;
// Add interaction component // Add interaction component
shared_ptr<KartInteractionComponent> interactionComponent = shared_ptr<KartInteractionComponent> interactionComponent =
@ -114,4 +116,146 @@ shared_ptr<Entity> KartFactory::createKart(const vec3 position,
return entity; return entity;
} }
shared_ptr<Entity> KartFactory::createRotatingKart(const vec3 position)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("rotatingKart");
SceneGraph::addEntity(entity);
// Create transform
mat4 translation = translate(mat4(1.0f), position);
mat4 transform = translation;
// Add graphics component
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
entity,
getShared(mGraphicsSystem),
mRenderLayer);
entity->addComponent(graphicsComponent);
// Add the ModelRenderable
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderableKart = modelFactory->createModel("kart-vehicle.bcosm",
"kart-vehicle-diffuse.png",
"kart-vehicle-model");
graphicsComponent->addRenderable(modelRenderableKart);
shared_ptr<ModelRenderable> modelRenderableDriver = modelFactory->createModel("kart-driver.bcosm",
"kart-driver-diffuse.png",
"kart-driver-model");
graphicsComponent->addRenderable(modelRenderableDriver);
delete modelFactory;
// Add Physics component
unique_ptr<ColliderFactory> colliderFactory = make_unique<ColliderFactory>(mPhysicsSystem, mAssetSystem);
shared_ptr<PhysicsComponent> physicsComponent =
make_shared<PhysicsComponent>(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<PhysicsComponent> wPhysicsComponent(physicsComponent);
// Animation component, to make the kart rotate continuously
shared_ptr<AnimationComponent> animationComponent =
make_shared<AnimationComponent>(entity,
mAnimationSystem);
entity->addComponent(animationComponent);
// Add falling animation
animationComponent->addAnimation(AnimationFactory::createLinearAnimation(
make_shared<Attribute<PhysicsComponent, vec3> >(
physicsComponent,
[wPhysicsComponent]()->vec3{
if (wPhysicsComponent.expired()) return vec3();
shared_ptr<PhysicsComponent> physicsComponent = wPhysicsComponent.lock();
if (!physicsComponent) return vec3();
return physicsComponent->getPosition();
},
[wPhysicsComponent](vec3 i){
if (wPhysicsComponent.expired()) return;
shared_ptr<PhysicsComponent> physicsComponent = wPhysicsComponent.lock();
if (!physicsComponent) return;
physicsComponent->setPosition(i);
}),
vec3(1000, 10, 1000),
vec3(1000, 0, 1000),
static_cast<milliseconds>(1500),
[] () {Log::write(LogLevel::debug, "Translation end"); } ));
// Add rotation animation
animationComponent->addAnimation(AnimationFactory::createLinearAnimation(
make_shared<Attribute<PhysicsComponent, vec3> >(
physicsComponent,
[wPhysicsComponent]()->vec3{
if (wPhysicsComponent.expired()) return vec3();
shared_ptr<PhysicsComponent> physicsComponent = wPhysicsComponent.lock();
if (!physicsComponent) return vec3();
return getRotationDegrees(physicsComponent->getTransform());
},
[wPhysicsComponent](vec3 i){
if (wPhysicsComponent.expired()) return;
shared_ptr<PhysicsComponent> physicsComponent = wPhysicsComponent.lock();
if (!physicsComponent) return;
physicsComponent->setOrientationEulerDegreesXYZ(i);
}),
vec3(0, 45, 0),
vec3(0, 0, 0),
static_cast<milliseconds>(1500),
[] () {Log::write(LogLevel::debug, "Rotation end"); } ));
// Return instance
return entity;
}
} // namespace JamSpook } // namespace JamSpook

View File

@ -13,6 +13,7 @@
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <vector> #include <vector>
#include <chrono>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
@ -20,6 +21,7 @@
#include <glm/gtx/string_cast.hpp> #include <glm/gtx/string_cast.hpp>
#include <ecos/utility/Memory.h> #include <ecos/utility/Memory.h>
#include <ecos/utility/Math.h>
#include <ecos/core/IDCache.h> #include <ecos/core/IDCache.h>
#include <ecos/core/Log.h> #include <ecos/core/Log.h>
@ -32,6 +34,11 @@
#include <ecos/asset/AssetSystem.h> #include <ecos/asset/AssetSystem.h>
#include <ecos/asset/DataManagementMode.h> #include <ecos/asset/DataManagementMode.h>
#include <ecos/animation/AnimationSystem.h>
#include <ecos/animation/Animation.h>
#include <ecos/animation/AnimationFactory.h>
#include <ecos/animation/AnimationComponent.h>
#include <ecos/physics/PhysicsSystem.h> #include <ecos/physics/PhysicsSystem.h>
#include <ecos/physics/PhysicsComponent.h> #include <ecos/physics/PhysicsComponent.h>
#include <ecos/physics/ColliderFactory.h> #include <ecos/physics/ColliderFactory.h>
@ -66,10 +73,13 @@ using std::string;
using std::shared_ptr; using std::shared_ptr;
using std::make_shared; using std::make_shared;
using std::weak_ptr; using std::weak_ptr;
using std::unique_ptr;
using std::make_unique;
using std::dynamic_pointer_cast; using std::dynamic_pointer_cast;
using std::function; using std::function;
using std::bind; using std::bind;
using std::vector; using std::vector;
using std::chrono::milliseconds;
using glm::vec3; using glm::vec3;
using glm::mat4; using glm::mat4;
@ -82,6 +92,7 @@ using glm::eulerAngleXYZ;
using glm::radians; using glm::radians;
using ecos::utility::getShared; using ecos::utility::getShared;
using ecos::utility::getRotationDegrees;
using ecos::core::IDCache; using ecos::core::IDCache;
using ecos::core::logging::Log; using ecos::core::logging::Log;
@ -95,6 +106,12 @@ using ecos::core::ICCResponseComponent;
using ecos::asset::AssetSystem; using ecos::asset::AssetSystem;
using ecos::asset::DataManagementMode; 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::GraphicsSystem;
using ecos::graphics::GraphicsComponent; using ecos::graphics::GraphicsComponent;
using ecos::graphics::RenderLayer; using ecos::graphics::RenderLayer;
@ -128,6 +145,7 @@ private:
weak_ptr<GraphicsSystem> mGraphicsSystem; weak_ptr<GraphicsSystem> mGraphicsSystem;
weak_ptr<PhysicsSystem> mPhysicsSystem; weak_ptr<PhysicsSystem> mPhysicsSystem;
weak_ptr<InteractionSystem> mInteractionSystem; weak_ptr<InteractionSystem> mInteractionSystem;
weak_ptr<AnimationSystem> mAnimationSystem;
weak_ptr<RenderLayer> mRenderLayer; weak_ptr<RenderLayer> mRenderLayer;
public: public:
@ -135,12 +153,16 @@ public:
weak_ptr<GraphicsSystem> graphicsSystem, weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem, weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<InteractionSystem> interactionSystem, weak_ptr<InteractionSystem> interactionSystem,
weak_ptr<AnimationSystem> animationSystem,
weak_ptr<RenderLayer> renderLayer); weak_ptr<RenderLayer> renderLayer);
virtual ~KartFactory(); virtual ~KartFactory();
/// Compose a kart entity /// Compose a kart entity
shared_ptr<Entity> createKart(const vec3 position, shared_ptr<Entity> createKart(const vec3 position,
const vec3 eulerRotationXYZDegrees); const vec3 eulerRotationXYZDegrees);
/// Compose a rotating kart entity
shared_ptr<Entity> createRotatingKart(const vec3 position);
}; };
} // namespace JamSpook } // namespace JamSpook

View File

@ -27,7 +27,7 @@ shared_ptr<Entity> ResetTriggerFactory::createResetTrigger(const vec3 position,
{ {
// Create instance // Create instance
shared_ptr<Entity> entity = make_shared<Entity>(); shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("reset-trigger"); entity->setEntityTag("end-trigger");
SceneGraph::addEntity(entity); SceneGraph::addEntity(entity);
mat4 transform = translate(mat4(1), position); mat4 transform = translate(mat4(1), position);

View File

@ -39,12 +39,7 @@ void ResetTriggerPhysicsComponent::onICCMessage(shared_ptr<Message> message)
void ResetTriggerPhysicsComponent::onCollision(const string& tag) void ResetTriggerPhysicsComponent::onCollision(const string& tag)
{ {
// if (tag == "ground-plane") ICCBroadcast(make_shared<Message>(IDCache::get("ContactWithPlayer")));
// {
// vec3 position = getPosition();
// setPosition(vec3(position.x, 10.0f, position.z));
// ICCBroadcast(make_shared<Message>(IDCache::get("GroundContactMessage")));
// }
} }
} // namespace JamSpook } // namespace JamSpook

View File

@ -0,0 +1,221 @@
/*
* TrackPieceFactory.cpp
*
* Created on: Aug 27, 2020
* Author: fredrick
*/
#include "TrackPieceFactory.h"
namespace JamSpook {
TrackPieceFactory::TrackPieceFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem),
mPhysicsSystem(physicsSystem),
mRenderLayer(renderLayer)
{}
TrackPieceFactory::~TrackPieceFactory()
{}
/// Compose a road entity
shared_ptr<Entity> TrackPieceFactory::createRoad()
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("road");
SceneGraph::addEntity(entity);
// Create transform
mat4 transform = mat4(1);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem);
shared_ptr<TrackPiecePhysicsComponent> physicsComponent =
make_shared<TrackPiecePhysicsComponent>(
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> 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("road.bcosm",
"road-diffuse.png",
"road-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
/// Compose a tunnel entity
shared_ptr<Entity> TrackPieceFactory::createTunnel()
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("tunnel");
SceneGraph::addEntity(entity);
// Create transform
mat4 transform = mat4(1);
// Add physics component
ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem);
shared_ptr<TrackPiecePhysicsComponent> physicsComponent =
make_shared<TrackPiecePhysicsComponent>(
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> 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("tunnel.bcosm",
"tunnel-diffuse.png",
"tunnel-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
/// Compose a mountain entity
shared_ptr<Entity> TrackPieceFactory::createMountain()
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("mountain");
SceneGraph::addEntity(entity);
// Create transform
mat4 transform = mat4(1);
// // Add physics component
// ColliderFactory* colliderFactory = new ColliderFactory(mPhysicsSystem, mAssetSystem);
// shared_ptr<TrackPiecePhysicsComponent> physicsComponent =
// make_shared<TrackPiecePhysicsComponent>(
// 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> 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("mountain.bcosm",
"mountain-diffuse.png",
"mountain-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
shared_ptr<Entity> TrackPieceFactory::createSign(
const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
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> 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("sign.bcosm",
diffuseTextureFilePath,
"sign-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -0,0 +1,147 @@
/*
* TrackPieceFactory.h
*
* Created on: Aug 27, 2020
* Author: fredrick
*/
#ifndef ENTITIES_TRACKPIECEFACTORY_H_
#define ENTITIES_TRACKPIECEFACTORY_H_
#include <string>
#include <memory>
#include <functional>
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/quaternion.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 "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<AssetSystem> mAssetSystem;
weak_ptr<GraphicsSystem> mGraphicsSystem;
weak_ptr<PhysicsSystem> mPhysicsSystem;
weak_ptr<RenderLayer> mRenderLayer;
public:
TrackPieceFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<PhysicsSystem> physicsSystem,
weak_ptr<RenderLayer> renderLayer);
virtual ~TrackPieceFactory();
/// Compose a road entity
shared_ptr<Entity> createRoad();
/// Compose a tunnel entity
shared_ptr<Entity> createTunnel();
// /// Compose a tunnel entity
// shared_ptr<Entity> createTunnel();
/// Compose a mountain entity
shared_ptr<Entity> createMountain();
/// Compose a sign entity
shared_ptr<Entity> createSign(const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation);
};
} // namespace JamSpook
#endif // ENTITIES_TRACKPIECEFACTORY_H_

View File

@ -0,0 +1,42 @@
/*
* TrackPiecePhysicsComponent.cpp
*
* Created on: Aug 27, 2020
* Author: fredrick
*/
#include "TrackPiecePhysicsComponent.h"
namespace JamSpook {
TrackPiecePhysicsComponent::TrackPiecePhysicsComponent(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)
{}
TrackPiecePhysicsComponent::~TrackPiecePhysicsComponent()
{}
void TrackPiecePhysicsComponent::update(const milliseconds dtms)
{
PhysicsComponent::update(dtms);
}
void TrackPiecePhysicsComponent::onICCMessage(shared_ptr<Message> message)
{
PhysicsComponent::onICCMessage(message);
}
void TrackPiecePhysicsComponent::onCollision(const string& tag)
{}
} // namespace JamSpook

View File

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