Compare commits

..

10 Commits

Author SHA1 Message Date
Fredrick Amnehagen bf46723715 JAMSPOOK-27 - Added ghosts 2020-08-30 23:58:49 +02:00
Fredrick Amnehagen e55db1dd14 Repositioned the follow camera 2020-08-29 16:37:48 +02:00
Fredrick Amnehagen 2233015e7b Faster end scene falling animation. 2020-08-29 15:52:15 +02:00
Fredrick Amnehagen 1372ac4a6b Updated the out-of-bounds reset
- Now resets to initial position, and not a random one.
2020-08-29 15:49:18 +02:00
Fredrick Amnehagen b3b270ae67 Camera update
- Now using the angularly locked camera
2020-08-29 15:48:18 +02:00
Fredrick Amnehagen 88a3db8d72 Partially implemented the level and end scene 2020-08-29 01:42:23 +02:00
Fredrick Amnehagen ac8d75a1c1 Partial implementation of sprites and backgrounds 2020-08-29 01:42:04 +02:00
Fredrick Amnehagen 7bd9cb930f re-implemented lighting 2020-08-29 01:41:14 +02:00
Fredrick Amnehagen 588830df0a Renamed a texture 2020-08-29 01:40:30 +02:00
Fredrick Amnehagen 6226457580 JAMSPOOK-23 - Camera system in place
- Implemented the camera system into the engine.
- Implemented an active follow camera into the game.
2020-08-24 20:35:24 +02:00
37 changed files with 1163 additions and 119 deletions

BIN
assets/meshes/ghost.bcosm Normal file

Binary file not shown.

Binary file not shown.

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.

Binary file not shown.

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.

View File

@ -10,11 +10,13 @@ layout (binding = 1) uniform sampler2D light;
void main() { void main() {
// Texturing // Texturing
vec4 albedoTexel = texture2D(albedo, vTexCoords); vec4 diffuseTexel = texture2D(albedo, vTexCoords);
vec4 lightTexel = texture2D(light, vTexCoords); vec4 lightTexel = texture2D(light, vTexCoords);
// Final color // Final color
outColor = albedoTexel * (lightTexel); outColor = diffuseTexel * (lightTexel);
outColor = albedoTexel;// * (lightTexel); // outColor = diffuseTexel;// * (lightTexel);
outColor.a = albedoTexel.a; outColor.a = diffuseTexel.a;
// outColor = lightTexel;
} }

View File

@ -55,7 +55,12 @@ void main()
{ {
// Lighting calc // Lighting calc
vec3 a = vec3(0.0); vec3 a = vec3(0.0);
vec3 ds = pointLightADS(texture(albedoMap, vertexTexCoords),
// vec3 ds = pointLightADS(texture(albedoMap, vertexTexCoords),
// texture(viewSpacePositionMap, vertexTexCoords).xyz,
// texture(normalMap, vertexTexCoords).xyz);
vec3 ds = pointLightADS(vec4(1,1,1,1),
texture(viewSpacePositionMap, vertexTexCoords).xyz, texture(viewSpacePositionMap, vertexTexCoords).xyz,
texture(normalMap, vertexTexCoords).xyz); texture(normalMap, vertexTexCoords).xyz);

View File

Before

Width:  |  Height:  |  Size: 207 KiB

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

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: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 806 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 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);
@ -31,8 +29,9 @@ JamSpookGame::JamSpookGame():
addSystem(assetSystem); addSystem(assetSystem);
// Create window // Create window
// Resolution (256x224 scaled to whatever)
Log::write(LogLevel::info, "Game - Constructor - Creating window"); Log::write(LogLevel::info, "Game - Constructor - Creating window");
mWindow = make_shared<Window>("BouncyBalls", 1024, 1024, Window::WindowMode::window); mWindow = make_shared<Window>("Spooky Game", 480, 272, Window::WindowMode::window);
mWindow->hide(); mWindow->hide();
// Create renderer // Create renderer
@ -42,11 +41,15 @@ JamSpookGame::JamSpookGame():
addSystem(make_shared<PhysicsSystem>()); addSystem(make_shared<PhysicsSystem>());
// Add physics related asset loaders // Add physics related asset loaders
assetSystem->addLoader(make_shared<CollisionShapeLoader>(assetPath), "CollisionShapeLoader"); assetSystem->addLoader(make_shared<CollisionShapeLoader>(assetPath), "CollisionShapeLoader");
assetSystem->addLoader(make_shared<StaticCollisionShapeLoader>(assetPath), "StaticCollisionShapeLoader");
// Create animation system // Create animation system
addSystem(make_shared<AnimationSystem>()); addSystem(make_shared<AnimationSystem>());
// Create camera system
addSystem(make_shared<CameraSystem>());
// Create interaction system // Create interaction system
addSystem(make_shared<InteractionSystem>()); addSystem(make_shared<InteractionSystem>());
shared_ptr<InteractionSystem> interactionSystem = dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))); shared_ptr<InteractionSystem> interactionSystem = dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem")));
@ -64,11 +67,11 @@ JamSpookGame::JamSpookGame():
addSystem(make_shared<DevILSystem>()); addSystem(make_shared<DevILSystem>());
// Add graphics related asset loaders // Add graphics related asset loaders
assetSystem->addLoader(make_shared<MeshLoader>(assetPath), "MeshLoader"); assetSystem->addLoader(make_shared<MeshLoader>(assetPath), "MeshLoader");
assetSystem->addLoader(make_shared<ShaderLoader>(assetPath), "ShaderLoader"); assetSystem->addLoader(make_shared<ShaderLoader>(assetPath), "ShaderLoader");
assetSystem->addLoader(make_shared<ShaderProgramLoader>(assetPath), "ShaderProgramLoader"); assetSystem->addLoader(make_shared<ShaderProgramLoader>(assetPath), "ShaderProgramLoader");
assetSystem->addLoader(make_shared<TextureFileLoader>(assetPath), "TextureFileLoader"); assetSystem->addLoader(make_shared<TextureFileLoader>(assetPath), "TextureFileLoader");
assetSystem->addLoader(make_shared<TextureBlankLoader>(assetPath), "TextureBlankLoader"); assetSystem->addLoader(make_shared<TextureBlankLoader>(assetPath), "TextureBlankLoader");
// Add render layer compositor shader // Add render layer compositor shader
ShaderProgramFactory* shaderProgramFactory = new ShaderProgramFactory(assetSystem); ShaderProgramFactory* shaderProgramFactory = new ShaderProgramFactory(assetSystem);
@ -96,7 +99,7 @@ JamSpookGame::JamSpookGame():
// 16.0f/9.0f, // 16.0f/9.0f,
// mCamera = camFactory->createPerspective(vec3(1.0f, 100.0f, 0.0f), // mCamera = camFactory->createPerspective(vec3(1.0f, 100.0f, 0.0f),
mCamera = camFactory->createPerspective(vec3(-60.0f, 40.0f, 60.0f), mCamera = camFactory->createPerspective(vec3(0.0f, 0.0f, 0.0f), // The follow cam implementation will change the position during runtime.
vec3(0.0f, -20.0f, 0.0f), vec3(0.0f, -20.0f, 0.0f),
vec3(0.0f, 1.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f),
90.0f/2, 90.0f/2,
@ -104,15 +107,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
@ -172,75 +190,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>(
// graphicsSystem, dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), graphicsSystem,
// dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem")))); dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
dynamic_pointer_cast<InteractionSystem>(findSystem(IDCache::get("InteractionSystem"))));
lightingFactory->createSun(10.0f,
vec3(45,-45,0),
vec3(1,1,1),
0.5f,
renderLayerGame);
lightingFactory.reset();
// // Create background
// unique_ptr<SpriteFactory> bakgroundSpriteFactory = make_unique<SpriteFactory>(
// dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// graphicsSystem,
// renderLayerBackground);
// //
// 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();
// 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 // // Create background
// FloorFactory* floorFactory = new FloorFactory(dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))), // unique_ptr<SpriteFactory> spriteFactory = make_unique<SpriteFactory>(
// graphicsSystem, // dynamic_pointer_cast<AssetSystem>(findSystem(IDCache::get("AssetSystem"))),
// dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), // graphicsSystem,
// 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>(
@ -249,8 +235,8 @@ void JamSpookGame::set()
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame); renderLayerGame);
jump180Factory->createJump180(vec3(0, 0, 0), vec3(0, 0, 0)); jump180Factory->createJump180(vec3(0, -1, 0), vec3(0, 0, 0));
jump180Factory->createJump180(vec3(25,-15, 14), vec3(0, 180, 0)); jump180Factory->createJump180(vec3(25,-16, 14), vec3(0, 180, 0));
jump180Factory.reset(); jump180Factory.reset();
@ -261,23 +247,54 @@ void JamSpookGame::set()
dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))), dynamic_pointer_cast<PhysicsSystem>(findSystem(IDCache::get("PhysicsSystem"))),
renderLayerGame); renderLayerGame);
goalFactory->createGoal(vec3(-1, -30, -12)); goalFactory->createGoal(vec3(-1, -31, -12));
// goalFactory->createGoal(vec3(0, 0, 0)); // goalFactory->createGoal(vec3(0, 0, 0));
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->createStaticPlatform();
trackPieceFactory->createGhost("SadGhost",
"ghost-white-diffuse.png",
vec3(20, -15, 10),
quat(vec3(radians(0.0f), radians(45.0f), radians(0.0f))),
5.0f);
trackPieceFactory->createGhost("AngryGhost",
"ghost-red-diffuse.png",
vec3(-8, -25, -18),
quat(vec3(radians(0.0f), radians(15.0f), radians(0.0f))),
5.0f);
// End scene entities
trackPieceFactory->createGhost("SadGhost",
"ghost-white-diffuse.png",
vec3(1005, 4, 1001),
quat(vec3(radians(0.0f), radians(45.0f), radians(0.0f))));
trackPieceFactory->createSign("ThankYouSign",
"sign-thanks-diffuse.png",
vec3(994, 0, 1000),
quat(vec3(radians(0.0f), radians(90.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"))),
@ -295,17 +312,70 @@ 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);
kartFactory->createKart(vec3(0, 3, 0), // position shared_ptr<Entity> kartEntity = kartFactory->createKart(
vec3(0, 180, 0)); // euler degrees rotation, XYZ 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> cameraFactory = make_unique<CameraFactory>();
cameraFactory->createActiveFollowCamera("followKartCamera",
mCamera,
kartEntity,
vec3(0 ,25 ,25),
vec3(0, 5, 0),
bvec3(0, 0, 0));
shared_ptr<Entity> endSceneCamera = cameraFactory->createStaticCamera("endSceneCamera",
mCameraEndScene);
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->
createResetTrigger(vec3(-1, -31, -12),
vec3(1));
// 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

@ -36,9 +36,14 @@
#include <ecos/physics/PhysicsSystem.h> #include <ecos/physics/PhysicsSystem.h>
#include <ecos/physics/loaders/CollisionShapeLoader.h> #include <ecos/physics/loaders/CollisionShapeLoader.h>
#include <ecos/physics/loaders/StaticCollisionShapeLoader.h>
#include <ecos/animation/AnimationSystem.h> #include <ecos/animation/AnimationSystem.h>
#include <ecos/camera/CameraSystem.h>
#include <ecos/camera/CameraFactory.h>
#include <ecos/camera/Camera.h>
#include <ecos/interaction/InteractionSystem.h> #include <ecos/interaction/InteractionSystem.h>
#include <ecos/graphics/GraphicsSystem.h> #include <ecos/graphics/GraphicsSystem.h>
@ -49,8 +54,6 @@
#include <ecos/graphics/ShaderProgramFactory.h> #include <ecos/graphics/ShaderProgramFactory.h>
#include <ecos/graphics/DevILSystem.h> #include <ecos/graphics/DevILSystem.h>
#include <ecos/graphics/GL4Renderer.h> #include <ecos/graphics/GL4Renderer.h>
#include <ecos/graphics/camera/CameraFactory.h>
#include <ecos/graphics/camera/Camera.h>
#include <ecos/graphics/loaders/MeshLoader.h> #include <ecos/graphics/loaders/MeshLoader.h>
#include <ecos/graphics/loaders/ShaderLoader.h> #include <ecos/graphics/loaders/ShaderLoader.h>
#include <ecos/graphics/loaders/ShaderProgramLoader.h> #include <ecos/graphics/loaders/ShaderProgramLoader.h>
@ -60,7 +63,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"
@ -83,6 +88,7 @@ using std::to_string;
using glm::ivec2; using glm::ivec2;
using glm::vec2; using glm::vec2;
using glm::bvec3;
using glm::vec3; using glm::vec3;
using glm::vec4; using glm::vec4;
using glm::mat4; using glm::mat4;
@ -111,9 +117,14 @@ using ecos::asset::DataManagementMode;
using ecos::physics::PhysicsSystem; using ecos::physics::PhysicsSystem;
using ecos::physics::CollisionShapeLoader; using ecos::physics::CollisionShapeLoader;
using ecos::physics::StaticCollisionShapeLoader;
using ecos::animation::AnimationSystem; using ecos::animation::AnimationSystem;
using ecos::camera::CameraSystem;
using ecos::camera::CameraFactory;
using ecos::camera::Camera;
using ecos::interaction::InteractionSystem; using ecos::interaction::InteractionSystem;
using ecos::interaction::InputDeviceState; using ecos::interaction::InputDeviceState;
using ecos::interaction::ButtonState; using ecos::interaction::ButtonState;
@ -127,8 +138,6 @@ using ecos::graphics::ShaderProgramFactory;
using ecos::graphics::DevILSystem; using ecos::graphics::DevILSystem;
using ecos::graphics::Renderer; using ecos::graphics::Renderer;
using ecos::graphics::GL4Renderer; using ecos::graphics::GL4Renderer;
using ecos::graphics::Camera;
using ecos::graphics::CameraFactory;
using ecos::graphics::MeshLoader; using ecos::graphics::MeshLoader;
using ecos::graphics::ShaderLoader; using ecos::graphics::ShaderLoader;
using ecos::graphics::ShaderProgramLoader; using ecos::graphics::ShaderProgramLoader;
@ -151,6 +160,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>(800),
[] () {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>(800),
[] () {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

@ -20,7 +20,8 @@ KartPhysicsComponent::KartPhysicsComponent(mat4 transform,
physicsSystem, physicsSystem,
physicsCollisionSubSystem, physicsCollisionSubSystem,
physicsColliderQuerySubSystem, physicsColliderQuerySubSystem,
collider) collider),
mInitialTransform(transform)
{} {}
KartPhysicsComponent::~KartPhysicsComponent() KartPhysicsComponent::~KartPhysicsComponent()
@ -33,9 +34,8 @@ void KartPhysicsComponent::update(const milliseconds dtms)
if (getPosition().y < -100.0f) if (getPosition().y < -100.0f)
{ {
setPosition(vec3(getFloatInRange(-10.0f, 10.0f), setPosition(vec3(0, 0, 0), true);
10, /// above the ball setTransform(mInitialTransform);
getFloatInRange(-10.0f, 10.0f)));
} }
if (glm::length(mDirection) > 0) if (glm::length(mDirection) > 0)
@ -76,7 +76,8 @@ void KartPhysicsComponent::onICCMessage(shared_ptr<Message> message)
void KartPhysicsComponent::onCollision(const string& tag) void KartPhysicsComponent::onCollision(const string& tag)
{ {
if (tag == "goal") if (tag == "goal"
|| tag == "jump180")
{ {
ICCBroadcast(make_shared<Message>(IDCache::get("GroundCollisionMessage"))); ICCBroadcast(make_shared<Message>(IDCache::get("GroundCollisionMessage")));
} }
@ -92,7 +93,8 @@ void KartPhysicsComponent::onCollision(const string& tag)
void KartPhysicsComponent::onSeparation(const string& tag) void KartPhysicsComponent::onSeparation(const string& tag)
{ {
if (tag == "goal") if (tag == "goal"
|| tag == "jump180")
{ {
ICCBroadcast(make_shared<Message>(IDCache::get("GroundSeparationMessage"))); ICCBroadcast(make_shared<Message>(IDCache::get("GroundSeparationMessage")));
} }

View File

@ -77,6 +77,7 @@ class KartPhysicsComponent:
{ {
private: private:
vec3 mDirection; vec3 mDirection;
mat4 mInitialTransform; ///< Used for reset.
public: public:
KartPhysicsComponent(mat4 transform, KartPhysicsComponent(mat4 transform,

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,82 @@
/*
* SpriteFactory.cpp
*
* Created on: Aug 24, 2020
* Author: fredrick
*/
#include "SpriteFactory.h"
namespace JamSpook {
SpriteFactory::SpriteFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<RenderLayer> renderLayer):
mAssetSystem(assetSystem),
mGraphicsSystem(graphicsSystem),
mRenderLayer(renderLayer)
{}
SpriteFactory::~SpriteFactory()
{}
shared_ptr<Entity> SpriteFactory::createPlane(const string name,
const string filePath,
const vec3 position,
const vec3 rotation,
const vec3 scaleFactor)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag(name);
SceneGraph::addEntity(entity);
mat4 transform = scale(mat4(1), scaleFactor) * translate(mat4(1), position);
// 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("plane-1x1.bcosm",
filePath,
name+"_model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
shared_ptr<Entity> SpriteFactory::createBackground(const string name,
const string filePath)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag(name);
SceneGraph::addEntity(entity);
mat4 transform = scale(mat4(1), vec3(1, 1, 1)) * translate(mat4(1), vec3(-1, -1, -1));
// 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("plane-1x1.bcosm",
filePath,
name+"_model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -0,0 +1,123 @@
/*
* SpriteFactory.h
*
* Created on: Aug 24, 2020
* Author: fredrick
*/
#ifndef SPRITEFACTORY_H_
#define SPRITEFACTORY_H_
#include <cstdint>
#include <string>
#include <memory>
#include <functional>
#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.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/lighting/LightSource.h>
#include <ecos/graphics/lighting/LightSourceFactory.h>
#include <ecos/graphics/ModelRenderableFactory.h>
#include <ecos/graphics/ShaderType.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 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::graphics::lighting::LightSource;
using ecos::graphics::lighting::LightSourceFactory;
///
class SpriteFactory
{
private:
weak_ptr<AssetSystem> mAssetSystem;
weak_ptr<GraphicsSystem> mGraphicsSystem;
weak_ptr<RenderLayer> mRenderLayer;
public:
SpriteFactory(weak_ptr<AssetSystem> assetSystem,
weak_ptr<GraphicsSystem> graphicsSystem,
weak_ptr<RenderLayer> renderLayer);
virtual ~SpriteFactory();
shared_ptr<Entity> createPlane(const string name,
const string filePath,
const vec3 position,
const vec3 rotation,
const vec3 scaleFactor);
shared_ptr<Entity> createBackground(const string name,
const string filePath);
};
} // namespace JamSpook
#endif // SPRITEFACTORY_H_

View File

@ -0,0 +1,312 @@
/*
* 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;
}
shared_ptr<Entity> TrackPieceFactory::createGhost(
const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation,
float scaling)
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag(name + "_ghost");
SceneGraph::addEntity(entity);
// Create transform
mat4 translationMatrix = translate(mat4(1.0f), position);
mat4 rotationMatrix = glm::toMat4(orientation);
mat4 scalingMatrix = glm::scale(mat4(1), vec3(scaling));
mat4 transform = translationMatrix * rotationMatrix * scalingMatrix;// * rotateToCenter;
// Add graphics component
shared_ptr<GraphicsComponent> graphicsComponent = make_shared<GraphicsComponent>(transform,
entity,
getShared(mGraphicsSystem),
mRenderLayer);
entity->addComponent(graphicsComponent);
// Add the ModelRenderable
ModelRenderableFactory* modelFactory = new ModelRenderableFactory(mAssetSystem);
shared_ptr<ModelRenderable> modelRenderable = modelFactory->createModel("ghost.bcosm",
diffuseTextureFilePath,
name + "-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
shared_ptr<Entity> TrackPieceFactory::createStaticPlatform()
{
// Create instance
shared_ptr<Entity> entity = make_shared<Entity>();
entity->setEntityTag("staticPlatform");
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->createStaticMeshCollider(vec3(0),
quat_cast(mat4(1)),
"static-platform.bcosps", // filePath
"static-platform-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("static-platform.bcosm",
"static-platform-diffuse.png",
"static-platform-model");
delete modelFactory;
graphicsComponent->addRenderable(modelRenderable);
// Return instance
return entity;
}
} // namespace JamSpook

View File

@ -0,0 +1,156 @@
/*
* 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);
/// Compose a ghost entity
shared_ptr<Entity> createGhost(const string name,
const string diffuseTextureFilePath,
vec3 position,
quat orientation,
float scaling = 1.0f);
shared_ptr<Entity> createStaticPlatform();
};
} // 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_