124 Commits

Author SHA1 Message Date
Jace ae71fde88c Updated submodule remotes to something more manageable and accessible. 2017-01-04 16:00:51 +01:00
Jace 13a0d1521c Fixed filters 2014-08-18 21:41:30 +02:00
Jace 53e137f50d Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance
Conflicts:
	src/Systems/PhysicsSystem.cpp
2014-06-05 16:45:50 +02:00
Jace 428ad2bae0 Fixez 2014-06-05 16:45:15 +02:00
Jace 2f0d17a386 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 16:27:03 +02:00
Jace 09bbb5ac0b Proper entity removal. 2014-06-05 16:26:01 +02:00
Tleety e42c2c49ef Light on tank shells 2014-06-05 16:25:20 +02:00
Stiffly 2f617727a4 dead in water 2014-06-05 07:05:55 +02:00
Stiffly 9a7d0463a0 Merge remote-tracking branch 'origin/master' into Sound+Particles 2014-06-05 07:01:53 +02:00
Stiffly 7b5e0045f6 broken one deadn 2014-06-05 07:01:33 +02:00
ViktorLjung 75a19fbfe0 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:57:46 +02:00
ViktorLjung 36ecbf8b73 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:56:53 +02:00
ViktorLjung d3dca03f47 fix 2014-06-05 06:56:42 +02:00
Tleety 83e28d48f8 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:54:27 +02:00
Tleety b4cec1747e turrets now aiming as they should 2014-06-05 06:53:34 +02:00
ViktorLjung ce2e0b192c Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:46:05 +02:00
ViktorLjung 97994f9af7 Collisions 2014-06-05 06:42:19 +02:00
Tleety 4d5c4c8fc7 Added towers to the map 2014-06-05 06:25:12 +02:00
Tleety 7773580da6 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-05 06:14:00 +02:00
Tleety 3f6933da76 tower destroy debris 2014-06-05 06:13:51 +02:00
ViktorLjung a001cad9bc Merge branch 'master' into havok
Conflicts:
	src/GameWorld.cpp
	src/Systems/GameStateSystem.cpp
	src/Systems/TankSteeringSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:04:32 +02:00
ViktorLjung e4a59cec61 Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 06:01:49 +02:00
Jace 41ca0e832f Merge branch 'deffered_rendering' 2014-06-05 05:58:57 +02:00
Jace dcede48453 Fixed particles not rendering over skybox 2014-06-05 05:53:13 +02:00
Tleety 8f1f87512f Merge remote-tracking branch 'origin/Sound+Particles' 2014-06-05 05:22:33 +02:00
Tleety c7a37e1b9b Merge remote-tracking branch 'origin/master' into deffered_rendering 2014-06-05 05:21:28 +02:00
Tleety 85d5f209a3 Merge branch 'deffered_rendering' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance into deffered_rendering 2014-06-05 05:21:09 +02:00
Tleety fd92f37902 Skybox working, flag for averaging normals working. 2014-06-05 05:20:51 +02:00
Stiffly 16e4129d70 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/Components/Vehicle.h
	src/Systems/TankSteeringSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 05:16:57 +02:00
Stiffly ccc2c49317 Vehicle component has "CurrentRPM" 2014-06-05 05:11:04 +02:00
Jace 9ed2f04036 Fixed particles not rendering to both viewports 2014-06-05 04:50:06 +02:00
Jace 866c65514d Decorations! 2014-06-05 03:54:41 +02:00
Stiffly 09971b2d77 Publishes some bgm sounds 2014-06-05 03:14:45 +02:00
Tleety a6941c0fb6 Merge remote-tracking branch 'origin/master' into deffered_rendering
Conflicts:
	src/GameWorld.cpp
	src/GameWorld.h
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-05 03:03:00 +02:00
Tleety ccb3d6d84f Turret able to shoot, no collision event yet. 2014-06-05 02:54:44 +02:00
Tleety 93c4805a22 Tower not aiming towards the player. 2014-06-05 00:35:15 +02:00
Jace 56e6545f0f Direct damage and VulnerableToSplash flag on Health component 2014-06-04 23:54:52 +02:00
Jace 2d716e2998 Merge branch 'master' into havok
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 22:01:25 +02:00
Stiffly 76a9081d4b Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 18:22:16 +02:00
Stiffly 6e9eeaf991 Dust particles from tank wheels. 2014-06-04 18:15:47 +02:00
ViktorLjung 1b20204897 Player/Team specific triggers 2014-06-04 18:12:58 +02:00
Jace bf5106e5b6 Merge remote-tracking branch 'origin/deffered_rendering' 2014-06-04 17:14:34 +02:00
Jace 8b2fc86159 Main menu hidden for your debugging pleasure 2014-06-04 17:06:08 +02:00
Jace 5f1feffe0d Main menu finished 2014-06-04 16:59:30 +02:00
ViktorLjung c06c436cd1 Merge remote-tracking branch 'origin/master' into havok 2014-06-04 15:43:51 +02:00
ViktorLjung 70960c9eba Jeep working 2014-06-04 15:43:20 +02:00
Stiffly f2ae46efa5 Merge remote-tracking branch 'origin/master' into Sound+Particles 2014-06-04 15:22:00 +02:00
Stiffly 2ef5d49f7e Added Destructor. (improved StopSound and PlayBGM events) 2014-06-04 15:21:05 +02:00
Tleety 6cae09c5d8 Walls are now destroyable 2014-06-04 14:48:40 +02:00
Jace 7b90e54899 Merge branch 'master' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance 2014-06-04 13:40:23 +02:00
Jace d3f8ef2d9c Wallz 2014-06-04 06:20:22 +02:00
Stiffly f9426745f7 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	assets
2014-06-04 06:17:05 +02:00
Stiffly 5e78fdc930 Not deleting in a "foreach"-loop 2014-06-04 06:09:59 +02:00
Tleety 5a6ae2a24e Merge remote-tracking branch 'origin/master' into deffered_rendering
Conflicts:
	assets
	src/GameWorld.cpp
2014-06-04 06:02:21 +02:00
Tleety d5dcb0b72c Fixed normals nor averaging when at a corner. 2014-06-04 05:56:38 +02:00
ViktorLjung 94178098ea Merge remote-tracking branch 'origin/master' into havok
Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-04 05:48:48 +02:00
Jace 62dd85349f A gate and better bridges. 2014-06-04 05:47:29 +02:00
ViktorLjung f9f20535ba Jeep and tank tuning 2014-06-04 05:47:17 +02:00
Tleety 74b86bc6d4 Lights working without much visable bugs. 2014-06-04 05:44:12 +02:00
Stiffly 27b735325a Improved splashes 2014-06-04 05:31:05 +02:00
Stiffly e39e1eda89 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
2014-06-04 05:30:42 +02:00
Jace 3c17ab6037 Bridges 2014-06-04 05:12:06 +02:00
Stiffly 7f017bfaed Tanks now have listeners. 2014-06-04 04:40:16 +02:00
Jace 9813e9a058 Merge remote-tracking branch 'origin/Sound+Particles'
Conflicts:
	src/GameWorld.cpp
2014-06-04 04:24:10 +02:00
Tleety cf2040f038 Inget funkar, broken commit, dont use. 2014-06-04 04:20:15 +02:00
Jace e11f656b3d Fixed physics relative orientations! 2014-06-04 04:18:44 +02:00
Stiffly 72a8ee9080 Water splash 2014-06-04 03:26:29 +02:00
Jace 7d9f1a7ac7 Merge remote-tracking branch 'origin/havok' 2014-06-04 02:36:59 +02:00
Stiffly 90a92d05e4 Merge remote-tracking branch 'origin/master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
2014-06-04 01:27:15 +02:00
Stiffly 9f1d5206bd Muzzle Flash 2014-06-04 01:23:15 +02:00
Jace 397188b855 Fixed frame scissor test 2014-06-04 00:46:03 +02:00
ViktorLjung ac855f554b Fixed local physics orientation 2014-06-04 00:45:43 +02:00
Stiffly 909ee94e26 Billboarding working again 2014-06-03 23:48:13 +02:00
Stiffly df32a3b07d PlaySFX now uses Position instead of Emitter ID for playing a sound. 2014-06-03 21:02:39 +02:00
Stiffly 2833b8df36 Merge branch 'master' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-03 20:39:44 +02:00
Jace 0addc672b4 Multiple vehicle selection 2014-06-03 20:36:35 +02:00
Jace 80846a29ad Terrain creation stuff 2014-06-03 20:36:23 +02:00
Stiffly 87b02711f4 Doppler scale ruined everything 2014-06-03 20:05:31 +02:00
Stiffly 96a608db27 Merge branch 'FMOD' into Sound+Particles 2014-06-03 19:47:01 +02:00
Stiffly 5265fb9734 assets commit 2014-06-03 19:46:48 +02:00
Stiffly a5105e5859 tank modifications 2014-06-03 19:44:33 +02:00
Jace e15474c3d4 Fixed filters 2014-06-03 19:09:10 +02:00
ViktorLjung 486922a7c5 Tank tuning 2014-06-03 18:59:41 +02:00
Jace a00c145616 Safety check for spawns 2014-06-03 18:47:08 +02:00
Jace aeb29cde8b Merge branch 'deffered_rendering'
Conflicts:
	assets
	src/Components/Physics.h
	src/GameWorld.cpp
	src/GameWorld.h
	src/Systems/PhysicsSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-03 18:46:49 +02:00
Jace 7f328332c4 Merge branch 'master' into particles
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-03 17:19:53 +02:00
Stiffly e7eca74b03 Merge branch 'particles' into Sound+Particles
Conflicts:
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-02 22:59:58 +02:00
Tleety f5f6a5cf3a Fixed transparency 2014-06-02 22:15:52 +02:00
Tleety 179c5c1feb Merge remote-tracking branch 'origin/particles' into deffered_rendering
Conflicts:
	assets
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-02 20:20:36 +02:00
Tleety f1a9afc097 Fixed a createWall function. 2014-06-02 20:01:28 +02:00
Tleety 00268f027a Walls are now destroyable! 2014-06-02 18:21:39 +02:00
Stiffly 349fab54a4 Merge remote-tracking branch 'origin/master' into particles
Conflicts:
	src/GUI/GameFrame.h
	src/GUI/TextureFrame.h
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-02 17:37:25 +02:00
Tleety 0e2934647c Added a movable tree or somthing dunno lol tired-. 2014-06-01 03:01:37 +02:00
Stiffly 756107363e Some pretty darn cool explosions 2014-06-01 01:15:53 +02:00
Stiffly 804b0cac60 Now uses now sorts and renders sprites by depth.
Merge remote-tracking branch 'origin/deffered_rendering' into particles

Conflicts:
	assets
	src/GameWorld.cpp
2014-05-31 23:40:21 +02:00
Tleety 2d1d4f02f3 Fixed some things in gameworld and added a new skymap. 2014-05-31 23:14:33 +02:00
Stiffly cea2faaaf8 Removed unnecessary info messages 2014-05-31 23:14:13 +02:00
Tleety 1af8d4909a Fixed things with the skybox and placed some items in the world. 2014-05-31 23:14:11 +02:00
Stiffly d407502432 CreateExplosion event published on shell collision now. 2014-05-31 22:15:44 +02:00
Stiffly a31e3faa1f Linear fade added to particles 2014-05-31 22:15:00 +02:00
Tleety 6e78307249 Merge remote-tracking branch 'origin/master' into deffered_rendering
Conflicts:
	src/GUI/GameFrame.h
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-05-31 17:16:29 +02:00
Tleety 260c1295ec WIP on deffered_rendering: a459a1c Skybox bugfix 2014-05-31 17:12:31 +02:00
Tleety 1b252c95e0 index on deffered_rendering: a459a1c Skybox bugfix 2014-05-31 17:12:31 +02:00
Tleety ad075f185e untracked files on deffered_rendering: a459a1c Skybox bugfix 2014-05-31 17:12:31 +02:00
Tleety a459a1c69b Skybox bugfix 2014-05-31 02:03:50 +02:00
Tleety ee2f7fcecf Added some water to see how it looks 2014-05-31 01:11:14 +02:00
Stiffly 370dbb96ad Merge, now you can see sprites.
Merge remote-tracking branch 'origin/deffered_rendering' into particles

Conflicts:
	src/GameWorld.cpp
2014-05-31 00:00:00 +02:00
Tleety 0bba9e40d4 Merge branch 'deffered_rendering' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance into deffered_rendering
Conflicts:
	src/Renderer.cpp
2014-05-30 22:47:23 +02:00
Tleety 0e612cb3f3 Colors now working correcly. 2014-05-30 22:45:00 +02:00
Stiffly 28c3cf5e16 Optimized ParticleSystem. Still can't see particles though D: 2014-05-30 22:19:03 +02:00
Jace 6c8fff9ed0 Non-retardedly slow sprite rendering 2014-05-30 22:00:20 +02:00
Stiffly dbebd5a6e9 Merge remote-tracking branch 'origin/deffered_rendering' into particles 2014-05-30 20:04:17 +02:00
Stiffly 31348e774e Trying some stuff, this build did not support sprite rendering 2014-05-30 20:00:09 +02:00
Tleety ed803733da Merged ASSets 2014-05-30 19:55:49 +02:00
Tleety 9ccf8ecc42 Fixed being able to draw sprites and normal/specular maps for terrain 2014-05-30 19:53:00 +02:00
Stiffly bf77fba963 Omg dem filter merge skillz
Merge remote-tracking branch 'origin/deffered_rendering' into particles

Conflicts:
	src/GameWorld.cpp
	src/Systems/ParticleSystem.cpp
	src/Systems/ParticleSystem.h
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-05-30 19:11:52 +02:00
Stiffly d17450b554 Some Explosion stuff 2014-05-30 00:12:28 +02:00
Tleety cc84f04542 Transparent objects working. 2014-05-29 23:59:36 +02:00
Tleety eb37cc2296 Fixed blendmaps
Merge remote-tracking branch 'origin/gui' into deffered_rendering

Conflicts:
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-05-28 22:08:50 +02:00
Tleety 761b8e21e1 Added blendmap component
Added renderque for models with a blendmap component
Added shaders for blendmaps
2014-05-28 20:24:31 +02:00
Tleety a5f4c9daa0 Fixed so OBJ-loader now loads map_Bump options correctly. 2014-05-28 20:05:28 +02:00
Stiffly 571edbc214 ... even more event-based 2014-05-27 07:09:22 +02:00
Stiffly 5d53472286 CreateExplosion now Event-based (not tested) 2014-05-27 07:08:39 +02:00
Stiffly 4b2f324d60 Merge remote-tracking branch 'origin/master' into particles
Conflicts:
	src/GameWorld.cpp
	src/Systems/ParticleSystem.cpp
2014-05-27 06:55:44 +02:00
95 changed files with 5117 additions and 1080 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[submodule "assets"]
path = assets
url = returngeance@shard.imon.nu:Assets
url = https://imon.nu/git/BTH/FishTanks-assets.git
branch = master
+1 -1
Submodule assets updated: 3c4d81137f...de87617060
+38
View File
@@ -0,0 +1,38 @@
#ifndef Components_BlendMap_h__
#define Components_BlendMap_h__
#include "Component.h"
#include "Entity.h"
namespace Components
{
struct BlendMap : Component
{
BlendMap()
: TextureRed("Textures/ErrorTextureRed.png")
, TextureRedNormal("Textures/NeutralNormalMap.png")
, TextureRedSpecular("Textures/NeutralSpecularMap.png")
, TextureGreen("Textures/ErrorTextureGreen.png")
, TextureGreenNormal("Textures/NeutralNormalMap.png")
, TextureGreenSpecular("Textures/NeutralSpecularMap.png")
, TextureBlue("Textures/ErrorTextureBlue.png")
, TextureBlueNormal("Textures/NeutralNormalMap.png")
, TextureBlueSpecular("Textures/NeutralSpecularMap.png")
, TextureRepeats(100.f) { }
std::string TextureRed;
std::string TextureRedNormal;
std::string TextureRedSpecular;
std::string TextureGreen;
std::string TextureGreenNormal;
std::string TextureGreenSpecular;
std::string TextureBlue;
std::string TextureBlueNormal;
std::string TextureBlueSpecular;
float TextureRepeats;
virtual BlendMap* Clone() const override { return new BlendMap(*this); }
};
}
#endif // !Components_BlendMap_h__
+27
View File
@@ -0,0 +1,27 @@
#ifndef Components_DamageModel_h__
#define Components_DamageModel_h__
#include <string>
#include "Component.h"
namespace Components
{
struct DamageModel : Component
{
DamageModel()
: Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f))
, ShadowCaster(true)
, Transparent(false)
{ }
std::string ModelFile;
glm::vec4 Color;
bool ShadowCaster;
bool Transparent;
virtual DamageModel* Clone() const override { return new DamageModel(*this); }
};
}
#endif // !Components_DamageModel_h__
+4 -1
View File
@@ -9,9 +9,12 @@ namespace Components
struct Health : Component
{
Health()
: Amount(1.0f) { }
: Amount(1.0f)
, VulnerableToSplash(true)
{ }
float Amount;
bool VulnerableToSplash;
virtual Health* Clone() const override { return new Health(*this); }
};
+14
View File
@@ -0,0 +1,14 @@
#ifndef JeepSteering_h__
#define JeepSteering_h__
#include "Component.h"
namespace Components
{
struct JeepSteering : Component
{
JeepSteering* Clone() const override { return new JeepSteering(*this); }
};
}
#endif // JeepSteering_h__
+4 -3
View File
@@ -4,18 +4,19 @@
#include <string>
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Model : Component
{
Model() : Visible(true), ShadowCaster(true) { }
Model() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)), Visible(true), ShadowCaster(true), Transparent(false), AverageNormals(false) { }
std::string ModelFile;
Color Color;
glm::vec4 Color;
bool Visible;
bool ShadowCaster;
bool Transparent;
bool AverageNormals;
virtual Model* Clone() const override { return new Model(*this); }
};
+2 -1
View File
@@ -11,9 +11,10 @@ namespace Components
struct Particle : Component
{
std::vector<Color> ColorSpectrum;
std::vector<glm::vec3> ScaleSpectrum;
double LifeTime;
double SpawnTime;
bool Fade;
std::vector<glm::vec3> VelocitySpectrum;
std::vector<float> AngularVelocitySpectrum;
std::vector<glm::vec3> OrientationSpectrum; //Keep?
+7 -3
View File
@@ -19,20 +19,24 @@ struct ParticleEmitter : Component
, SpawnCount(0)
, SpreadAngle(0)
, LifeTime(0)
, TimeSinceLastSpawn(100) { } // TEMP fulhack så att partiklarna spawnar direkt
, TimeSinceLastSpawn(100)
, Emitting(false)
, Color(glm::vec4(1)) { }
EntityID ParticleTemplate;
float SpawnFrequency;
float Speed;
int SpawnCount;
std::vector<Color> ColorSpectrum;
glm::vec4 Color;
std::vector<glm::vec3> ScaleSpectrum;
float SpreadAngle;
double LifeTime;
bool UseGoalVelocity;
bool Fade;
bool Emitting;
glm::vec3 GoalVelocity;
std::vector<float> AngularVelocitySpectrum;
std::vector<glm::vec3> OrientationSpectrum; //Keep?
std::vector<glm::vec3> OrientationSpectrum; //Keep? noo..
private:
double TimeSinceLastSpawn;
+29 -4
View File
@@ -16,13 +16,38 @@ struct Physics : Component
EXPLOSION = 4,
};
enum class MotionTypeEnum
{
Dynamic,
Fixed,
Keyframed
};
Physics()
: Mass(1.f), Static(false), Phantom(false), CalculateCenterOfMass(true), CenterOfMass(glm::vec3(0)), InitialLinearVelocity(glm::vec3(0)), InitialAngularVelocity(glm::vec3(0)),
LinearDamping(0.f), AngularDamping(0.05f), GravityFactor(1.f), Friction(0.5f), Restitution(0.4f), MaxLinearVelocity(200.f), MaxAngularVelocity(200.f),
CollisionLayer(0), CollisionSystemGroup(0), CollisionSubSystemId(0), CollisionSubSystemDontCollideWith(0), CollisionEvent(false){}
: Mass(1.f)
//, Static(false)
, MotionType(MotionTypeEnum::Fixed)
, Phantom(false)
, CalculateCenterOfMass(true)
, CenterOfMass(glm::vec3(0))
, InitialLinearVelocity(glm::vec3(0))
, InitialAngularVelocity(glm::vec3(0))
, LinearDamping(0.f)
, AngularDamping(0.05f)
, GravityFactor(1.f)
, Friction(0.5f)
, Restitution(0.4f)
, MaxLinearVelocity(200.f)
, MaxAngularVelocity(200.f)
, CollisionLayer(0)
, CollisionSystemGroup(0)
, CollisionSubSystemId(0)
, CollisionSubSystemDontCollideWith(0)
, CollisionEvent(false)
{ }
float Mass;
bool Static;
MotionTypeEnum MotionType;
bool Phantom;
bool CalculateCenterOfMass;
+2 -1
View File
@@ -10,13 +10,14 @@ namespace Components
struct SoundEmitter : Component
{
enum class SoundType
{
SOUND_3D,
SOUND_2D
};
SoundEmitter() : Gain(1.f), MaxDistance(1.f), MinDistance(1.f), Pitch(1.f), Loop(false) {}
SoundEmitter() : Gain(1.f), MaxDistance(10000.f), MinDistance(1.f), Pitch(1.f), Loop(false) {}
float Gain;
float MaxDistance;
float MinDistance;
+3 -2
View File
@@ -4,15 +4,16 @@
#include <string>
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Sprite : Component
{
Sprite() : Color(glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)) { }
std::string SpriteFile;
Color Color;
glm::vec4 Color;
virtual Sprite* Clone() const override { return new Sprite(*this); }
};
+18
View File
@@ -0,0 +1,18 @@
#ifndef Components_Team_h__
#define Components_Team_h__
#include "Component.h"
#include "Entity.h"
namespace Components
{
struct Team : Component
{
unsigned int TeamID;
virtual Team* Clone() const override { return new Team(*this); }
};
}
#endif // !Components_Team_h__
+24
View File
@@ -0,0 +1,24 @@
#ifndef Tower_h__
#define Tower_h__
#include "Component.h"
namespace Components
{
struct Tower : Component
{
Tower()
: ID(0) { }
int ID;
EntityID GunBase;
EntityID Gun;
virtual Tower* Clone() const override { return new Tower(*this); }
};
}
#endif // Tower_h__
+20
View File
@@ -0,0 +1,20 @@
#ifndef Components_TowerDebris_h__
#define Components_TowerDebris_h__
#include "Component.h"
#include <string>
#include <vector>
namespace Components
{
struct TowerDebris : Component
{
std::vector<EntityID> TowerDebrisIDs;
virtual TowerDebris* Clone() const override { return new TowerDebris(*this); }
};
}
#endif // Components_TowerDebris_h__
+1
View File
@@ -9,6 +9,7 @@ namespace Components
struct Trigger : Component
{
bool TriggerOnce;
int TeamID;
virtual Trigger* Clone() const override { return new Trigger(*this); }
};
+22
View File
@@ -0,0 +1,22 @@
#ifndef Components_Turret_h__
#define Components_Turret_h__
#include "Component.h"
namespace Components
{
struct Turret : Component
{
Turret()
: ShotSpeed(1.0f) { }
EntityID ShotTemplate;
float ShotSpeed;
virtual Turret* Clone() const override { return new Turret(*this); }
};
}
#endif // BarrelSteering_h__
+25
View File
@@ -0,0 +1,25 @@
#ifndef Components_TurretShot_h__
#define Components_TurretShot_h__
#include "Component.h"
namespace Components
{
struct TurretShot : Component
{
TurretShot()
: Damage(1.0f),
ExplosionRadius(1.0f),
ExplosionStrength(100.0f) { }
float Damage;
float ExplosionRadius;
float ExplosionStrength;
virtual TurretShot* Clone() const override { return new TurretShot(*this); }
};
}
#endif // Components_TurretShot_h__
+4 -4
View File
@@ -10,10 +10,9 @@ namespace Components
struct Vehicle : Component
{
Vehicle()
: MaxTorque(1000.0f), MinRPM(0.0f), OptimalRPM(2000.0f), MaxRPM(3000.0f), MaxSteeringAngle(35), TopSpeed(70.0f),
MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(2500.0f), DownshiftRPM(500.0f),
gearsRatio0(4.5f), gearsRatio1(2.5f), gearsRatio2(1.0f), gearsRatio3(0.5f){ }
//gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f)
: MaxTorque(1000.0f), MinRPM(200.0f), OptimalRPM(2500.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(90.0f),
MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(3500.0f), DownshiftRPM(1000.0f),
gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f), currentRPM(0.0f){ }
float MaxTorque;
float MinRPM;
float OptimalRPM;
@@ -30,6 +29,7 @@ struct Vehicle : Component
float gearsRatio1;
float gearsRatio2;
float gearsRatio3;
float currentRPM;
Vehicle* Clone() const override { return new Vehicle(*this); }
};
+20
View File
@@ -0,0 +1,20 @@
#ifndef Components_Wall_h__
#define Components_Wall_h__
#include "Component.h"
#include <string>
#include <vector>
namespace Components
{
struct Wall : Component
{
std::vector<EntityID> Walldebris;
virtual Wall* Clone() const override { return new Wall(*this); }
};
}
#endif // Components_TankShell_h__
+2 -1
View File
@@ -22,7 +22,8 @@ public:
m_ResourceManager = std::make_shared<ResourceManager>();
m_ResourceManager->RegisterType("OBJ", [](std::string resourceName) { return new OBJ(resourceName); });
auto rm = m_ResourceManager;
m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName)); });
m_ResourceManager->RegisterType("Model", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName), false); });
m_ResourceManager->RegisterType("AveragedModel", [rm](std::string resourceName) { return new Model(rm, *rm->Load<OBJ>("OBJ", resourceName), true); });
m_ResourceManager->RegisterType("Texture", [](std::string resourceName) { return new Texture(resourceName); });
m_FrameStack = new GUI::Frame(m_EventBroker, m_ResourceManager);
+35
View File
@@ -0,0 +1,35 @@
#ifndef Event_CreateExplosion_h__
#define Event_CreateExplosion_h__
#include "EventBroker.h"
#include <glm/common.hpp>
#include <glm/gtc/quaternion.hpp>
namespace Events
{
struct CreateExplosion : Event
{
CreateExplosion() :
Color(glm::vec4(0)),
usePointLight(false),
UseGoalVector(false) {}
glm::vec3 Position;
glm::vec4 Color;
double LifeTime;
int ParticlesToSpawn;
std::string spritePath;
glm::quat RelativeUpOrientation;
float Speed;
float SpreadAngle;
float usePointLight;
std::vector<float> ParticleScale;
bool UseGoalVector;
glm::vec3 GoalVelocity;
bool Emitting;
float SpawnFrequency;
};
}
#endif // Event_CreateExplosion_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef Events_Dead_h__
#define Events_Dead_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct Dead : Event
{
EntityID Entity;
};
}
#endif // Events_Dead_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagCaptured_h__
#define Events_FlagCaptured_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagCaptured : Event
{
unsigned int Player;
};
}
#endif // Events_FlagCaptured_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagDropped_h__
#define Events_FlagDropped_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagDropped : Event
{
unsigned int Player;
};
}
#endif // Events_FlagDropped_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagPickup_h__
#define Events_FlagPickup_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagPickup : Event
{
unsigned int Player;
};
}
#endif // Events_FlagPickup_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_FlagReturned_h__
#define Events_FlagReturned_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct FlagReturned : Event
{
unsigned int Player;
};
}
#endif // Events_FlagReturned_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_GameOver_h__
#define Events_GameOver_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct GameOver : Event
{
unsigned int Player;
};
}
#endif // Events_GameOver_h__
+15
View File
@@ -0,0 +1,15 @@
#ifndef Events_GameStart_h__
#define Events_GameStart_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct GameStart : Event
{
};
}
#endif // Events_GameStart_h__
+19
View File
@@ -0,0 +1,19 @@
#ifndef Events_JeepSteer_h__
#define Events_JeepSteer_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct JeepSteer : Event
{
EntityID Entity;
float PositionX;
float PositionY;
bool Handbrake;
};
}
#endif // Events_JeepSteer_h__
+10 -1
View File
@@ -9,8 +9,17 @@ namespace Events
struct PlaySFX : Event
{
EntityID Emitter;
PlaySFX() :
MinDistance(100.f),
MaxDistance(10000.f),
Volume(1.f),
Loop (false) {}
//EntityID Emitter;
glm::vec3 Position;
std::string Resource;
float MinDistance;
float MaxDistance;
float Volume;
bool Loop;
};
+50 -16
View File
@@ -36,6 +36,7 @@ public:
: EventBroker(eventBroker)
, ResourceManager(resourceManager)
, Rectangle()
, m_Parent(nullptr)
, m_Name("UIParent")
, m_Layer(0)
, m_Hidden(false)
@@ -46,12 +47,28 @@ public:
: m_Name(name)
, m_Layer(0)
, m_Hidden(false)
{ SetParent(std::shared_ptr<Frame>(parent)); Initialize(); }
{ SetParent(parent); Initialize(); }
::RenderQueue RenderQueue;
~Frame()
{
/*for (auto layer : m_Children)
{
for (auto child : layer.second)
{
delete child.second;
}
}
std::shared_ptr<Frame> Parent() const { return m_Parent; }
void SetParent(std::shared_ptr<Frame> parent)
if (m_Parent)
{
m_Parent->RemoveChild(this);
}*/
}
::RenderQueuePair RenderQueue;
Frame* Parent() const { return m_Parent; }
void SetParent(Frame* parent)
{
if (parent == nullptr)
{
@@ -62,13 +79,13 @@ public:
Width = parent->Width;
Height = parent->Height;
m_Layer = parent->Layer() + 1;
parent->AddChild(std::shared_ptr<Frame>(this));
parent->AddChild(this);
m_Parent = parent;
EventBroker = parent->EventBroker;
ResourceManager = parent->ResourceManager;
}
void AddChild(std::shared_ptr<Frame> child)
void AddChild(Frame* child)
{
m_Children[child->m_Layer].insert(std::make_pair(child->Name(), child));
if (m_Parent)
@@ -77,7 +94,19 @@ public:
}
}
typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
void RemoveChild(Frame* child)
{
auto it = m_Children.find(child->m_Layer);
if (it != m_Children.end())
{
m_Children.erase(it);
}
if (m_Parent)
{
m_Parent->RemoveChild(child);
}
}
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
@@ -89,8 +118,14 @@ public:
else
return m_Hidden;
}
void Hide() { m_Hidden = true; }
void Show() { m_Hidden = false; }
bool Visible() const
{
return !Hidden();
}
virtual void Hide() { m_Hidden = true; }
virtual void Show() { m_Hidden = false; }
int Left() const override
{
@@ -132,7 +167,11 @@ public:
Rectangle AbsoluteRectangle()
{
int left = Left();
if (m_Parent)
left = std::max(left, m_Parent->Left());
int top = Top();
if (m_Parent)
top = std::max(top, m_Parent->Top());
int width = Right() - left;
int height = Bottom() - top;
return Rectangle(left, top, width, height);
@@ -140,9 +179,6 @@ public:
void UpdateLayered(double dt)
{
if (this->Hidden())
return;
// Update ourselves
this->Update(dt);
@@ -153,8 +189,6 @@ public:
for (auto &pairChild : children)
{
auto child = pairChild.second;
if (child->Hidden())
continue;
child->Update(dt);
}
}
@@ -196,8 +230,8 @@ protected:
int m_Layer;
bool m_Hidden;
std::shared_ptr<Frame> m_Parent;
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
Frame* m_Parent;
typedef std::multimap<std::string, Frame*> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
virtual bool OnKeyDown(const Events::KeyDown &event) { return false; }
+36 -9
View File
@@ -2,13 +2,16 @@
#define GUI_GameFrame_h__
#include "GUI/Frame.h"
#include "GUI/MainMenuFrame.h"
#include "GUI/WorldFrame.h"
#include "GUI/Viewport.h"
#include "GUI/TextureFrame.h"
#include "GUI/PlayerHUD.h"
#include "VehicleSelection.h"
#include "GameWorld.h"
#include "Events/GameStart.h"
#include "Events/GameOver.h"
#include "Events/Dead.h"
namespace GUI
{
@@ -18,35 +21,59 @@ class GameFrame : public Frame
public:
GameFrame(Frame* parent, std::string name)
: Frame(parent, name)
, m_GameOver(false)
{
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &GUI::GameFrame::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::GameFrame::OnGameOver);
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
m_WorldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
{
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1 = new Viewport(m_WorldFrame, "Viewport1", m_World);
vp1->X = 0;
vp1->Width = this->Width / 2.f;
//new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
auto vehicleSelection = new VehicleSelection(vp1, "VehicleSelection", m_World, 1);
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2 = new Viewport(m_WorldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = this->Width / 2.f;
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport = new Viewport(m_WorldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Hide();
}
m_WorldFrame->Hide();
m_World->Initialize();
m_MainMenuFrame = new MainMenuFrame(this, "MainMenu");
}
private:
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
EventRelay<Frame, Events::GameStart> m_EGameStart;
bool OnGameStart(const Events::GameStart &event)
{
m_WorldFrame->Show();
return true;
}
EventRelay<Frame, Events::GameOver> m_EGameOver;
bool OnGameOver(const Events::GameOver &event)
{
m_GameOver = true;
return true;
}
std::shared_ptr<GameWorld> m_World;
MainMenuFrame* m_MainMenuFrame;
WorldFrame* m_WorldFrame;
Viewport* vp1;
Viewport* vp2;
Viewport* m_FreeCamViewport;
bool m_GameOver;
bool OnKeyUp(const Events::KeyUp &event) override
{
if (event.KeyCode == GLFW_KEY_1)
+41
View File
@@ -0,0 +1,41 @@
#ifndef GUI_GameOverFrame_h__
#define GUI_GameOverFrame_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
namespace GUI
{
class GameOverFrame : public Frame
{
public:
GameOverFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
//Hide();
m_Background = new TextureFrame(this, "Background");
m_Background->SetTexture("Textures/GUI/black.png");
m_Background->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.6f));
m_Text = new TextureFrame(this, "Message");
m_Text->SetTexture("Textures/GUI/GloriousVictory.png");
}
void Show(bool victory)
{
if (victory)
m_Text->SetTexture("Textures/GUI/GloriousVictory.png");
else
m_Text->SetTexture("Textures/GUI/ShamefulDefeat.png");
Frame::Show();
}
protected:
bool m_Victory;
TextureFrame* m_Background;
TextureFrame* m_Text;
};
}
#endif // GUI_GameOverFrame_h__
+1 -1
View File
@@ -37,7 +37,7 @@ namespace GUI
if (!health)
return false;
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - health->Amount / 100.f));
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - (health->Amount / 100.f / 2.f)));
return true;
}
+108
View File
@@ -0,0 +1,108 @@
#ifndef GUI_MainMenuFrame_h__
#define GUI_MainMenuFrame_h__
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#include "Events/GameStart.h"
#include "Events/PlayBGM.h"
namespace GUI
{
class MainMenuFrame : public Frame
{
public:
MainMenuFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
m_CurrentSelection = 0;
//Hide();
m_Background = new TextureFrame(this, "Background");
m_Background->SetTexture("Textures/GUI/MainMenu/BackGround.png");
m_Buttons = new TextureFrame(this, "Message");
m_Buttons->SetTexture("Textures/GUI/MainMenu/Buttons.png");
m_CurrentCoordinate = -m_SelectionCoordinates[0] * Scale();
m_TargetCoordinate = m_CurrentCoordinate;
m_Buttons->X = m_CurrentCoordinate.x;
m_Buttons->Y = m_CurrentCoordinate.y;
Events::PlayBGM e;
e.Resource = "Sounds/BGM/DiesIrae.mp3";
EventBroker->Publish(e);
}
void Update(double dt) override
{
if (Hidden())
return;
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 4.f * (float)dt;
m_Buttons->X = m_CurrentCoordinate.x;
m_Buttons->Y = m_CurrentCoordinate.y;
}
protected:
bool m_Victory;
TextureFrame* m_Background;
TextureFrame* m_Buttons;
int m_CurrentSelection;
static glm::vec2 m_SelectionCoordinates[2];
glm::vec2 m_CurrentCoordinate;
glm::vec2 m_TargetCoordinate;
bool OnCommand(const Events::InputCommand &event) override
{
if (Hidden())
return false;
const float deadzone = 0.5f;
if (event.Command == "interface_horizontal")
{
if (event.Value > deadzone)
m_CurrentSelection++;
else if (event.Value < -deadzone)
m_CurrentSelection--;
}
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 1) ? 1 : m_CurrentSelection);
m_TargetCoordinate = -m_SelectionCoordinates[m_CurrentSelection] * Scale();
if (event.Command == "interface_confirm" && event.Value > 0)
{
// Play
if (m_CurrentSelection == 0)
{
Hide();
Events::GameStart e1;
EventBroker->Publish(e1);
Events::PlayBGM e2;
e2.Resource = "Sounds/BGM/FlightOfTheBumblebee.mp3";
EventBroker->Publish(e2);
}
// Quit
else if (m_CurrentSelection == 1)
{
exit(EXIT_SUCCESS);
}
}
return false;
}
};
glm::vec2 MainMenuFrame::m_SelectionCoordinates[2] = {
glm::vec2(0, 0),
glm::vec2(193, 0),
};
}
#endif // GUI_MainMenuFrame_h__
+56
View File
@@ -3,6 +3,12 @@
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#include "GUI/VehicleSelection.h"
#include "GUI/GameOverFrame.h"
#include "Events/GameOver.h"
#include "Events/Dead.h"
#include "Components/Player.h"
namespace GUI
{
@@ -15,7 +21,11 @@ namespace GUI
, m_World(world)
, m_PlayerID(playerID)
{
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &GUI::PlayerHUD::OnGameOver);
EVENT_SUBSCRIBE_MEMBER(m_EDead, &GUI::PlayerHUD::OnDead);
m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID);
m_Crosshair = new TextureFrame(this, "Crosshair");
m_Crosshair->Width = 45;
m_Crosshair->Height = 45;
@@ -23,6 +33,11 @@ namespace GUI
m_Crosshair->Y = this->Height / 2.f - m_Crosshair->Height / 2.f;
m_Crosshair->SetTexture("Textures/GUI/crosshair.png");
m_Crosshair->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.75f));
m_VehicleSelection = new VehicleSelection(this, "VehicleSelection", m_World, m_PlayerID);
m_GameOverFrame = new GameOverFrame(this, "GameOver");
m_GameOverFrame->Hide();
}
protected:
@@ -31,6 +46,47 @@ namespace GUI
HealthOverlay* m_HealthOverlay;
TextureFrame* m_Crosshair;
VehicleSelection* m_VehicleSelection;
GameOverFrame* m_GameOverFrame;
EventRelay<Frame, Events::GameOver> m_EGameOver;
bool OnGameOver(const Events::GameOver &event)
{
if (m_PlayerID == event.Player)
m_GameOverFrame->Show(true);
else
m_GameOverFrame->Show(false);
return true;
}
EventRelay<Frame, Events::Dead> m_EDead;
bool OnDead(const Events::Dead &event)
{
auto playerCo = m_World->GetComponent<Components::Player>(event.Entity);
if (!playerCo || m_PlayerID != playerCo->ID)
return false;
m_VehicleSelection->Show();
m_HealthOverlay->SetColor(glm::vec4(1, 1, 1, 0));
return true;
}
bool OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != m_PlayerID)
return false;
if (event.Command == "interface_confirm" && event.Value > 0)
{
/*if (m_GameOverFrame->Visible())
{
m_GameOverFrame->Hide();
}*/
}
return true;
}
};
}
+2 -2
View File
@@ -32,7 +32,7 @@ public:
job.TextureID = m_Texture->ResourceID;
job.Texture = *m_Texture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a * m_CurrentFade);
RenderQueue.Add(job);
RenderQueue.Forward.Add(job);
}
// Texture while fading
@@ -42,7 +42,7 @@ public:
job.TextureID = m_FadeTexture->ResourceID;
job.Texture = *m_FadeTexture;
job.Color = glm::vec4(m_Color.r, m_Color.g, m_Color.b, m_Color.a);
RenderQueue.Add(job);
RenderQueue.Forward.Add(job);
}
renderer->SetCamera(nullptr);
+9 -4
View File
@@ -40,6 +40,9 @@ namespace GUI
void Update(double dt) override
{
if (Hidden())
return;
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 2.f * (float)dt;
@@ -77,28 +80,30 @@ namespace GUI
if (event.PlayerID != m_PlayerID)
return false;
const float deadzone = 0.5f;
// Menu movement
if (event.Command == "interface_horizontal" || event.Command == "interface_vertical")
{
// Horizontal scrolling
if (event.Command == "interface_horizontal")
{
if (event.Value > 0)
if (event.Value > deadzone)
m_CurrentSelection++;
else if (event.Value < 0)
else if (event.Value < -deadzone)
m_CurrentSelection--;
}
// Vertical scrolling to switch between "rows" in an intuitive way
else if (event.Command == "interface_vertical")
{
if (event.Value > 0)
if (event.Value > deadzone)
{
if (m_CurrentSelection == 0)
m_CurrentSelection++;
else if (m_CurrentSelection == 3)
m_CurrentSelection--;
}
else if (event.Value < 0)
else if (event.Value < -deadzone)
{
if (m_CurrentSelection == 1)
m_CurrentSelection--;
+1 -1
View File
@@ -51,7 +51,7 @@ public:
return;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(m_CameraEntity);
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
+100 -9
View File
@@ -11,6 +11,8 @@
#include "Components/Model.h"
#include "Components/Sprite.h"
#include "Components/PointLight.h"
#include "Components/BlendMap.h"
namespace GUI
{
@@ -42,6 +44,10 @@ public:
{
EntityID entity = pair.first;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if (templateComponent)
continue;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
@@ -49,14 +55,50 @@ public:
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
Model* modelAsset = nullptr;
if (modelComponent->AverageNormals)
{
modelAsset = ResourceManager->Load<Model>("AveragedModel", modelComponent->ModelFile);
}
else
{
modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
}
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelAsset, modelMatrix);
auto blendmapComponent = m_World->GetComponent<Components::BlendMap>(entity);
if (blendmapComponent)
{
BlendMapTexture RedTexture;
RedTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRed);
RedTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedNormal);
RedTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureRedSpecular);
BlendMapTexture GreenTexture;
GreenTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreen);
GreenTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenNormal);
GreenTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureGreenSpecular);
BlendMapTexture BlueTexture;
BlueTexture.Diffuse = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlue);
BlueTexture.Normal = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueNormal);
BlueTexture.Specular = *ResourceManager->Load<Texture>("Texture", blendmapComponent->TextureBlueSpecular);
float textureRepeat = blendmapComponent->TextureRepeats;
EnqueueBlendMapModel(modelAsset, RedTexture, GreenTexture, BlueTexture, textureRepeat, modelMatrix, modelComponent->Color);
}
else
{
EnqueueModel(modelAsset, modelMatrix, modelComponent->Transparent, modelComponent->Color);
}
}
}
@@ -71,7 +113,7 @@ public:
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(textureAsset, modelMatrix);
EnqueueSprite(textureAsset, modelMatrix, spriteComponent->Color);
}
}
@@ -91,12 +133,21 @@ public:
);
}
}
RenderQueue.Sort();
}
protected:
std::shared_ptr<World> m_World;
private:
struct BlendMapTexture
{
GLuint Diffuse;
GLuint Normal;
GLuint Specular;
};
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
{
@@ -104,7 +155,7 @@ private:
auto itpair = m_Children[m_Layer + 1].equal_range(event.ViewportFrame);
for (auto it = itpair.first; it != itpair.second; ++it)
{
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
auto viewportFrame = dynamic_cast<GUI::Viewport*>(it->second);
if (!viewportFrame)
continue;
@@ -116,7 +167,7 @@ private:
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(Model* model, glm::mat4 modelMatrix)
void EnqueueModel(Model* model, glm::mat4 modelMatrix, float transparent, glm::vec4 color)
{
for (auto texGroup : model->TextureGroups)
{
@@ -129,20 +180,60 @@ private:
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
RenderQueue.Add(job);
job.Transparent = transparent;
job.Color = color;
if(job.Transparent)
{
RenderQueue.Forward.Add(job);
}
else
{
RenderQueue.Deferred.Add(job);
}
}
}
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix)
void EnqueueBlendMapModel(Model* model, BlendMapTexture textureRed, BlendMapTexture textureGreen, BlendMapTexture textureBlue, float textureRepeat, glm::mat4 modelMatrix, glm::vec4 color)
{
for (auto texGroup : model->TextureGroups)
{
BlendMapModelJob job;
job.TextureID = texGroup.Texture->ResourceID;
job.DiffuseTexture = *texGroup.Texture;
job.NormalTexture = (texGroup.NormalMap) ? *texGroup.NormalMap : 0;
job.SpecularTexture = (texGroup.SpecularMap) ? *texGroup.SpecularMap : 0;
job.BlendMapTextureRed = textureRed.Diffuse;
job.BlendMapTextureRedNormal = textureRed.Normal;
job.BlendMapTextureRedSpecular = textureRed.Specular;
job.BlendMapTextureGreen = textureGreen.Diffuse;
job.BlendMapTextureGreenNormal = textureGreen.Normal;
job.BlendMapTextureGreenSpecular = textureGreen.Specular;
job.BlendMapTextureBlue = textureBlue.Diffuse;
job.BlendMapTextureBlueNormal = textureBlue.Normal;
job.BlendMapTextureBlueSpecular = textureBlue.Specular;
job.TextureRepeat = textureRepeat;
job.VAO = model->VAO;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Deferred.Add(job);
}
}
void EnqueueSprite(Texture* texture, glm::mat4 modelMatrix, glm::vec4 color)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.Texture = *texture;
job.ModelMatrix = modelMatrix;
job.Color = color;
RenderQueue.Add(job);
RenderQueue.Forward.Add(job);
}
};
}
+1417 -468
View File
File diff suppressed because it is too large Load Diff
+17 -2
View File
@@ -22,12 +22,18 @@
#include "Systems/DamageSystem.h"
#include "Systems/WheelPairSystem.h"
#include "Systems/FollowSystem.h"
#include "Systems/WallSystem.h"
#include "Systems/TowerSystem.h"
#include "Systems/GarageSystem.h"
#include "Systems/JeepSteeringSystem.h"
#include "Systems/FlagSystem.h"
#include "Systems/GameStateSystem.h"
#include "Components/Camera.h"
#include "Components/DirectionalLight.h"
#include "Components/Input.h"
#include "Components/Model.h"
#include "Components/DamageModel.h"
#include "Components/ParticleEmitter.h"
#include "Components/Particle.h"
#include "Components/PointLight.h"
@@ -55,6 +61,7 @@
#include "Components/TriggerRotate.h"
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Team.h"
class GameWorld : public World
{
@@ -77,10 +84,18 @@ private:
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value);
EntityID CreateTank(int playerID);
void CreateGate(glm::vec3 Position);
void CreateGate(EntityID parent, glm::vec3 position, glm::quat orientation, int teamID);
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering);
EntityID CreateJeep(int playerID);
EntityID CreateWall(EntityID parent, glm::vec3 pos, glm::quat orientation);
EntityID CreateTower(EntityID parent, glm::vec3 pos, int teamID);
EntityID CreateGarage(EntityID parent, glm::vec3 Position, glm::quat orientation, int teamID);
void CreateTerrain();
void CreateBase(glm::quat orientation, int playerID);
void CreateFlag(EntityID parent, glm::vec3 position, glm::quat orientation, int TeamID);
std::vector<EntityID> m_WallDebrisTemplates;
std::vector<EntityID> m_TowerDebrisTemplates;
EntityID m_ShotTemplate;
};
#endif // GameWorld_h__
+37 -3
View File
@@ -6,29 +6,63 @@
#include "EventBroker.h"
#include "Events/InputCommand.h"
#include "Events/MouseMove.h"
#include "Events/GameStart.h"
#include "Events/GameOver.h"
template <typename EventContext>
class InputController
{
public:
InputController(std::shared_ptr<::EventBroker> eventBroker)
: EventBroker(eventBroker) { Initialize(); }
: EventBroker(eventBroker)
, InGame(true)
{ Initialize(); }
virtual void Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::OnCommand);
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &InputController::_OnCommand);
EVENT_SUBSCRIBE_MEMBER(m_EMouseMove, &InputController::_OnMouseMove);
EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &InputController::OnGameStart);
EVENT_SUBSCRIBE_MEMBER(m_EGameOver, &InputController::OnGameOver);
}
virtual bool OnCommand(const Events::InputCommand &event) { return false; }
virtual bool OnMouseMove(const Events::MouseMove &event) { return false; }
virtual bool OnGameStart(const Events::GameStart &event)
{
InGame = true;
return true;
}
virtual bool OnGameOver(const Events::GameOver &event)
{
InGame = false;
return true;
}
protected:
std::shared_ptr<::EventBroker> EventBroker;
bool InGame;
private:
EventRelay<EventContext, Events::InputCommand> m_EInputCommand;
EventRelay<EventContext, Events::MouseMove> m_EMouseMove;
EventRelay<EventContext, Events::GameStart> m_EGameStart;
EventRelay<EventContext, Events::GameOver> m_EGameOver;
virtual bool _OnCommand(const Events::InputCommand &event)
{
if (InGame || event.Value == 0)
return OnCommand(event);
else
return false;
}
virtual bool _OnMouseMove(const Events::MouseMove &event)
{
if (InGame)
return OnMouseMove(event);
else
return false;
}
};
#endif // InputController_h__
+23
View File
@@ -85,6 +85,29 @@ void InputManager::Update(double dt)
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_P])
{
Events::StopSound e;
e.Emitter = 1;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_L])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/WilliamTellOverture.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
if(m_CurrentKeyState[GLFW_KEY_O])
{
Events::PlayBGM e;
e.Resource = "Sounds/BGM/DiesIrae.mp3";
e.Loop = true;
EventBroker->Publish(e);
}
// // Lock mouse while holding LMB
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
// {
+3
View File
@@ -13,6 +13,9 @@
#include "Events/GamepadAxis.h"
#include "Events/GamepadButton.h"
#include "Events/StopSound.h"
#include "Events/PlayBGM.h"
class InputManager
{
public:
+13 -7
View File
@@ -1,7 +1,7 @@
#include "PrecompiledHeader.h"
#include "Model.h"
Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj, bool average)
{
OBJ::MaterialInfo* currentMaterial = nullptr;
TextureGroup* currentTexGroup = nullptr;
@@ -93,7 +93,10 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
if (Vertices.size() > 0)
{
CreateTangents();
//getSimilarVertexIndex();
if (average)
{
getSimilarVertexIndex();
}
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
}
else
@@ -105,7 +108,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec3> tangents, std::vector<glm::vec3> biTangents, std::vector<glm::vec2>textureCoords)
{
LOG_INFO("Generating VertexBuffer");
//LOG_INFO("Generating VertexBuffer");
glGenBuffers(1, &VertexBuffer);
if (vertices.size() > 0)
{
@@ -118,7 +121,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty vertex buffer!");
}
LOG_INFO("Generating NormalBuffer");
//LOG_INFO("Generating NormalBuffer");
glGenBuffers(1, &NormalBuffer);
if (normals.size() > 0)
{
@@ -131,7 +134,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty normal buffer!");
}
LOG_INFO("Generating TangentNormalsBuffer");
//LOG_INFO("Generating TangentNormalsBuffer");
glGenBuffers(1, &TangentNormalsBuffer);
if (tangents.size() > 0)
{
@@ -144,7 +147,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty tangent buffer!");
}
LOG_INFO("Generating BiTangentNormalsBuffer");
//LOG_INFO("Generating BiTangentNormalsBuffer");
glGenBuffers(1, &BiTangentNormalsBuffer);
if (biTangents.size() > 0)
{
@@ -158,7 +161,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
}
LOG_INFO("Generating textureCoordBuffer");
//LOG_INFO("Generating textureCoordBuffer");
glGenBuffers(1, &TextureCoordBuffer);
if (textureCoords.size() > 0)
{
@@ -223,6 +226,8 @@ void Model::getSimilarVertexIndex()
{
glm::vec3 tempNormal, tempTangent, tempBiTangent;
if(glm::dot(Normals[i], Normals[t]) > .4f)
{
tempNormal = Normals[i] + Normals[t];
tempTangent = TangentNormals[i] + TangentNormals[t];
tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
@@ -235,6 +240,7 @@ void Model::getSimilarVertexIndex()
BiTangentNormals[i] = tempBiTangent;
BiTangentNormals[t] = tempBiTangent;
}
}
}
}
+1 -1
View File
@@ -17,7 +17,7 @@
class Model : public Resource
{
public:
Model(std::shared_ptr<ResourceManager> resourceManager, OBJ &obj);
Model(std::shared_ptr<ResourceManager> resourceManager, OBJ &obj, bool average);
struct TextureGroup
{
+4 -4
View File
@@ -13,7 +13,7 @@ bool OBJ::LoadFromFile(std::string filename)
return false;
}
LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
//LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
std::string line;
while (std::getline(file, line))
@@ -121,7 +121,7 @@ void OBJ::ParseMaterial()
return;
}
LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
//LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
std::string currentMaterialName;
MaterialInfo* currentMaterial = nullptr;
@@ -144,7 +144,7 @@ void OBJ::ParseMaterial()
{
MaterialInfo mat;
ss >> currentMaterialName;
LOG_INFO("Parsing material %s", currentMaterialName.c_str());
//LOG_INFO("Parsing material %s", currentMaterialName.c_str());
Materials[currentMaterialName] = mat;
currentMaterial = &Materials[currentMaterialName];
continue;
@@ -268,7 +268,7 @@ void OBJ::ParseMaterial()
continue;
}
// Normal map (bump map)
if (prefix == "bump")
if (prefix == "bump" || prefix == "map_Bump" )
{
MaterialInfo::BumpMap bumpMap;
+1 -1
View File
@@ -114,7 +114,7 @@ void VehicleSetup::setupVehicleData(const hkpWorld* world, hkpVehicleData& data
data.m_chassisUnitInertiaYaw = 0.8f;
data.m_chassisUnitInertiaRoll = 1.0f;
data.m_chassisUnitInertiaPitch = 1.0f;
data.m_chassisUnitInertiaPitch = 2.0f;
// Adds or removes torque around the yaw axis
// based on the current steering angle. This will
+46 -9
View File
@@ -14,6 +14,9 @@ struct RenderJob
{
friend class RenderQueue;
glm::mat4 ModelMatrix;
float Depth;
protected:
uint64_t Hash;
@@ -37,7 +40,7 @@ struct ModelJob : RenderJob
GLuint VAO;
unsigned int StartIndex;
unsigned int EndIndex;
glm::mat4 ModelMatrix;
float Transparent;
void CalculateHash() override
{
@@ -45,6 +48,20 @@ struct ModelJob : RenderJob
}
};
struct BlendMapModelJob : ModelJob
{
GLuint BlendMapTextureRed;
GLuint BlendMapTextureRedNormal;
GLuint BlendMapTextureRedSpecular;
GLuint BlendMapTextureGreen;
GLuint BlendMapTextureGreenNormal;
GLuint BlendMapTextureGreenSpecular;
GLuint BlendMapTextureBlue;
GLuint BlendMapTextureBlueNormal;
GLuint BlendMapTextureBlueSpecular;
float TextureRepeat;
};
struct SpriteJob : RenderJob
{
unsigned int ShaderID;
@@ -52,7 +69,6 @@ struct SpriteJob : RenderJob
GLuint Texture;
glm::vec4 Color;
glm::mat4 ModelMatrix;
void CalculateHash() override
{
@@ -67,27 +83,48 @@ public:
void Add(T &job)
{
job.CalculateHash();
m_Jobs.push_front(std::shared_ptr<T>(new T(job)));
m_Jobs.sort();
Jobs.push_front(std::shared_ptr<T>(new T(job)));
}
void Sort()
{
Jobs.sort();
}
void Clear()
{
m_Jobs.clear();
Jobs.clear();
}
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator begin()
{
return m_Jobs.begin();
return Jobs.begin();
}
std::forward_list<std::shared_ptr<RenderJob>>::const_iterator end()
{
return m_Jobs.end();
return Jobs.end();
}
private:
std::forward_list<std::shared_ptr<RenderJob>> m_Jobs;
std::forward_list<std::shared_ptr<RenderJob>> Jobs;
};
struct RenderQueuePair
{
RenderQueue Deferred;
RenderQueue Forward;
void Clear()
{
Deferred.Clear();
Forward.Clear();
}
void Sort()
{
Deferred.Sort();
Forward.Sort();
}
};
#endif // RenderQueue_h__
+349 -131
View File
@@ -21,8 +21,8 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager)
CAtt = 1.0f;
LAtt = 0.0f;
QAtt = 3.0f;
m_ShadowMapRes = 2048*2;
m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f);
m_ShadowMapRes = 1;
m_SunPosition = glm::vec3(0.f, 1.0f, 0.7f);
m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection_height = glm::vec2(-40.f, 40.f);
m_SunProjection_width = glm::vec2(-40.f, 40.f);
@@ -78,10 +78,6 @@ void Renderer::Initialize()
m_Camera->SetPosition(glm::vec3(0.0f, 0.0f, 2.f));
glfwSwapInterval(m_VSync);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glEnable(GL_SCISSOR_TEST);
LoadContent();
}
@@ -112,6 +108,16 @@ void Renderer::LoadContent()
m_ShaderProgramDebugAABB.Compile();
m_ShaderProgramDebugAABB.Link();*/
m_FinalForwardPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalForwardPass.vert.glsl")));
m_FinalForwardPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalForwardPass.frag.glsl")));
m_FinalForwardPassProgram.Compile();
m_FinalForwardPassProgram.Link();
m_BlendMapProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/BlendMap.vert.glsl")));
m_BlendMapProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/BlendMap.frag.glsl")));
m_BlendMapProgram.Compile();
m_BlendMapProgram.Link();
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
m_ShaderProgramSkybox.Compile();
@@ -120,11 +126,13 @@ void Renderer::LoadContent()
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SunPass.vert.glsl")));
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SunPass.frag.glsl")));
m_SunPassProgram.Compile();
glBindFragDataLocation(m_SunPassProgram.GetHandle(), 0, "frag_Light");
m_SunPassProgram.Link();
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl")));
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardRendering.frag.glsl")));
m_ForwardRendering.Compile();
glBindFragDataLocation(m_ForwardRendering.GetHandle(), 0, "frag_Diffuse");
m_ForwardRendering.Link();
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
@@ -135,7 +143,6 @@ void Renderer::LoadContent()
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
m_FirstPassProgram.Compile();
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal");
@@ -144,6 +151,7 @@ void Renderer::LoadContent()
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl")));
m_SecondPassProgram.Compile();
glBindFragDataLocation(m_SecondPassProgram.GetHandle(), 0, "frag_Light");
m_SecondPassProgram.Link();
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
@@ -154,13 +162,14 @@ void Renderer::LoadContent()
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
m_FinalPassProgram.Compile();
glBindFragDataLocation(m_FinalPassProgram.GetHandle(), 0, "frag_Diffuse");
m_FinalPassProgram.Link();
m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes);
FrameBufferTextures();
m_sphereModel = ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sunset", "jpg");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/sky36", "jpg");
}
void Renderer::Draw(double dt)
@@ -260,7 +269,7 @@ void Renderer::Draw(double dt)
glfwSwapBuffers(m_Window);
}
void Renderer::DrawFrame(RenderQueue &rq)
void Renderer::DrawFrame(RenderQueuePair &rq)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
@@ -269,6 +278,7 @@ void Renderer::DrawFrame(RenderQueue &rq)
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
@@ -304,7 +314,7 @@ void Renderer::DrawFrame(RenderQueue &rq)
// }
//}
for (auto &job : rq)
for (auto &job : rq.Forward)
{
//auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
//if (modelJob)
@@ -357,81 +367,251 @@ void Renderer::DrawFrame(RenderQueue &rq)
}
}
void Renderer::DrawWorld(RenderQueue &rq)
void Renderer::DrawWorld(RenderQueuePair &rq)
{
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glEnable(GL_SCISSOR_TEST);
glDepthRange(0.0, 0.999);
DrawShadowMap(rq);
//Sort forward rendering items by z value.
for(auto job : rq.Forward)
{
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = m_Camera->ViewMatrix();
glm::vec3 spritePos = glm::vec3((cameraMatrix * job->ModelMatrix) * glm::vec4(1, 1, 1, 1));
job->Depth = spritePos.z;
}
rq.Forward.Jobs.sort(Renderer::DepthSort);
//DrawShadowMap(rq.Deferred);
/*
Base pass
Base pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffClear);
glClearColor(115.f / 255, 192.f / 255, 255.f / 255, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffOpaque);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
DrawFBOScene(rq);
DrawFBOScene(rq.Deferred);
/*
Lighting pass
Lighting pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
//glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glCullFace(GL_FRONT);
DrawLightScene(rq);
DrawLightScene(rq.Deferred);
glCullFace(GL_BACK);
DrawSunLightScene();
/*
Final pass
*/
glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
//glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
m_FinalPassProgram.Bind();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
//glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
/*
Transparency
*/
ForwardRendering(rq.Forward);
}
void Renderer::ForwardRendering(RenderQueue &rq)
{
/*
Skybochs
*/
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthRange(0.999, 1.0);
DrawSkybox();
glDepthRange(0.0, 0.999);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
//glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
// Clear G-buffer
//GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE, GL_NONE };
//glDrawBuffers(4, attachments);
//glClear(GL_COLOR_BUFFER_BIT);
//glClearColor(0.f, 0.f, 0.f, 0.f);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_ForwardRendering.Bind();
GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle();
for (auto &job : rq)
{
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob)
{
glm::mat4 modelMatrix = modelJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "directionToSun"), 1, glm::value_ptr(glm::normalize(m_SunPosition)));
glBindVertexArray(modelJob->VAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (modelJob->NormalTexture != 0)
{
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
}
if (modelJob->SpecularTexture)
{
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
}
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue;
}
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob)
{
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
glm::mat4 billboardingMatrix = glm::inverse(glm::toMat4(glm::inverse(m_Camera->Orientation())));
MVP = cameraMatrix * modelMatrix * billboardingMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(glm::mat4(MVP)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4(modelMatrix)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4(m_Camera->ViewMatrix())));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4(cameraProjection)));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(spriteJob->Color));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
glBindVertexArray(m_ScreenQuad);
glDrawArrays(GL_TRIANGLES, 0, 6);
continue;
}
}
//glDepthMask (GL_TRUE);
/*
Final pass
*/
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
glClear(GL_DEPTH_BUFFER_BIT);
m_FinalPassProgram.Bind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
m_FinalForwardPassProgram.Bind();
//ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
//glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "La"), 1, glm::value_ptr(glm::vec3(0.7f)));
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
// glActiveTexture(GL_TEXTURE1);
// glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
//for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
//{
// Model* model;
// glm::mat4 modelMatrix;
// bool visible;
// std::tie(model, modelMatrix, visible, std::ignore) = tuple;
// if (!visible)
// continue;
// MVP = cameraMatrix * modelMatrix;
// glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
// glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
// glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
// glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
// glBindVertexArray(model->VAO);
// for (auto texGroup : model->TextureGroups)
// {
// glActiveTexture(GL_TEXTURE0);
// glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
// glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
// }
//}
}
void Renderer::Swap()
@@ -439,18 +619,24 @@ void Renderer::Swap()
glfwSwapBuffers(m_Window);
}
#pragma region TempRegion
void Renderer::DrawSkybox()
{
// glEnable(GL_CULL_FACE);
// glCullFace(GL_BACK);
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glViewport(0, 0, m_Width, m_Height);
//glScissor(0, 0, m_Width, m_Height);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_ShaderProgramSkybox.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * glm::toMat4(glm::inverse(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
//glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
//glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraView = glm::inverse(glm::toMat4(m_Camera->Orientation()));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(cameraView));
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw();
}
@@ -762,8 +948,6 @@ void Renderer::ClearStuff()
Lights.clear();
}
#pragma endregion
void Renderer::FrameBufferTextures()
{
m_fbBasePass = 0;
@@ -778,7 +962,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind diffuse texture
glGenTextures(1, &m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -830,26 +1014,32 @@ void Renderer::FrameBufferTextures()
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fSpecularTexture, 0);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
GLenum FirstPass[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, FirstPass);
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbBasePass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
m_fbLightingPass = 0;
glGenFramebuffers(1, &m_fbLightingPass);
glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
m_fbFinalPass = 0;
glGenFramebuffers(1, &m_fbFinalPass);
glGenTextures(1, &m_fFinalDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fFinalDiffuseTexture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
GLenum FinalPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, FinalPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
@@ -859,7 +1049,29 @@ void Renderer::FrameBufferTextures()
}
m_fbLightingPass = 0;
glGenFramebuffers(1, &m_fbLightingPass);
glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
}
void Renderer::DrawFBO()
@@ -945,9 +1157,8 @@ void Renderer::DrawFBO()
//}
}
void Renderer::DrawFBO2()
void Renderer::DrawFBO2(RenderQueue &rq)
{
ForwardRendering();
}
void Renderer::DrawFBOScene(RenderQueue &rq)
@@ -976,17 +1187,74 @@ void Renderer::DrawFBOScene(RenderQueue &rq)
glm::vec3 sunDirection = m_SunTarget - m_SunPosition;
glm::vec3 sunDirection_cameraview = glm::vec3(cameraProjection * m_Camera->ViewMatrix() * glm::vec4(sunDirection, 1.0));
m_FirstPassProgram.Bind();
GLuint ShaderProgramHandle = m_FirstPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
for (auto &job : rq)
{
auto blendMapJob = std::dynamic_pointer_cast<BlendMapModelJob>(job);
if(blendMapJob)
{
m_BlendMapProgram.Bind();
GLuint ShaderProgramHandle = m_BlendMapProgram.GetHandle();
glm::mat4 modelMatrix = blendMapJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
depthMVP = depthCameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "SunDirection_cameraspace"), 1, glm::value_ptr(sunDirection_cameraview));
glUniform1f(glGetUniformLocation(ShaderProgramHandle, "TextureRepeats"), blendMapJob->TextureRepeat);
glBindVertexArray(blendMapJob->VAO);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, blendMapJob->DiffuseTexture);
if (blendMapJob->NormalTexture != 0)
{
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, blendMapJob->NormalTexture);
}
if (blendMapJob->SpecularTexture)
{
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, blendMapJob->SpecularTexture);
}
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRed);
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedNormal);
glActiveTexture(GL_TEXTURE6);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureRedSpecular);
glActiveTexture(GL_TEXTURE7);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreen);
glActiveTexture(GL_TEXTURE8);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenNormal);
glActiveTexture(GL_TEXTURE9);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureGreenSpecular);
glActiveTexture(GL_TEXTURE10);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlue);
glActiveTexture(GL_TEXTURE11);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueNormal);
glActiveTexture(GL_TEXTURE12);
glBindTexture(GL_TEXTURE_2D, blendMapJob->BlendMapTextureBlueSpecular);
glDrawArrays(GL_TRIANGLES, blendMapJob->StartIndex, blendMapJob->EndIndex - blendMapJob->StartIndex + 1);
continue;
}
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob)
{
m_FirstPassProgram.Bind();
GLuint ShaderProgramHandle = m_FirstPassProgram.GetHandle();
glm::mat4 modelMatrix = modelJob->ModelMatrix;
MVP = cameraMatrix * modelMatrix;
@@ -1046,12 +1314,7 @@ void Renderer::DrawFBOScene(RenderQueue &rq)
void Renderer::DrawLightScene(RenderQueue &rq)
{
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1062,6 +1325,13 @@ void Renderer::DrawLightScene(RenderQueue &rq)
m_SecondPassProgram.Bind();
GLuint ShaderProgramHandle = m_SecondPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
for (auto &light : Lights)
{
MVP = cameraMatrix * light.SphereModelMatrix;
@@ -1084,21 +1354,10 @@ void Renderer::DrawLightScene(RenderQueue &rq)
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
};
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
}
void Renderer::DrawSunLightScene()
{
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
//glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1107,7 +1366,13 @@ void Renderer::DrawSunLightScene()
m_SunPassProgram.Bind();
GLuint ShaderProgramHandle = m_SunPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1, glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -1119,10 +1384,6 @@ void Renderer::DrawSunLightScene()
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
}
void Renderer::SetSphereModel( Model* _model )
@@ -1173,49 +1434,6 @@ void Renderer::UpdateSunProjection()
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
}
void Renderer::ForwardRendering()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix((float)m_Width / m_Height) * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_ForwardRendering.Bind();
GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle();
for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
{
Model* model;
glm::mat4 modelMatrix;
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix((float)m_Width / m_Height)));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
}
}
void Renderer::RegisterCamera(int identifier, float FOV, float nearClip, float farClip)
{
m_Cameras[identifier] = std::make_shared<Camera>(FOV, nearClip, farClip);
+12 -5
View File
@@ -69,8 +69,8 @@ public:
m_Camera = camera;
}
void DrawFrame(RenderQueue &rq);
void DrawWorld(RenderQueue &rq);
void DrawFrame(RenderQueuePair &rq);
void DrawWorld(RenderQueuePair &rq);
void Swap();
#pragma endregion
@@ -167,6 +167,10 @@ private:
GLuint m_ShadowFrameBuffer;
GLuint m_ShadowDepthTexture;
GLuint m_fbFinalPass;
GLuint m_fFinalDiffuseTexture;
GLuint m_fbBasePass;
GLuint m_fDiffuseTexture;
GLuint m_fPositionTexture;
@@ -191,6 +195,8 @@ private:
ShaderProgram m_FinalPassProgram;
ShaderProgram m_SunPassProgram;
ShaderProgram m_ForwardRendering;
ShaderProgram m_BlendMapProgram;
ShaderProgram m_FinalForwardPassProgram;
ShaderProgram m_ShaderProgramNormals;
ShaderProgram m_ShaderProgramShadows;
@@ -207,7 +213,7 @@ private:
void CreateShadowMap(int resolution);
void FrameBufferTextures();
void DrawFBO();
void DrawFBO2();
void DrawFBO2(RenderQueue &rq);
void DrawFBOScene(RenderQueue &rq);
void DrawLightScene(RenderQueue &rq);
void DrawSunLightScene();
@@ -215,9 +221,10 @@ private:
glm::mat4 CreateLightMatrix(Light &_light);
void UpdateSunProjection();
void CreateNormalMapTangent();
void ForwardRendering();
void ForwardRendering(RenderQueue &rq);
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
GLuint CreateQuad();
void DrawDebugShadowMap();
GLuint CreateAABB();
+108
View File
@@ -0,0 +1,108 @@
#version 430
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D ShadowTexture;
layout (binding=2) uniform sampler2D NormalMapTexture;
layout (binding=3) uniform sampler2D SpecularMapTexture;
//TerrainTextures
layout (binding=4) uniform sampler2D TextureRed;
layout (binding=5) uniform sampler2D TextureRedNormal;
layout (binding=6) uniform sampler2D TextureRedSpecular;
layout (binding=7) uniform sampler2D TextureGreen;
layout (binding=8) uniform sampler2D TextureGreenNormal;
layout (binding=9) uniform sampler2D TextureGreenSpecular;
layout (binding=10) uniform sampler2D TextureBlue;
layout (binding=11) uniform sampler2D TextureBlueNormal;
layout (binding=12) uniform sampler2D TextureBlueSpecular;
uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain
uniform vec3 SunDirection_cameraspace;
uniform mat4 V;
in VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
vec4 ShadowCoord;
vec3 Tangent;
vec3 BiTangent;
} Input;
out vec4 frag_Diffuse;
out vec4 frag_Position;
out vec4 frag_Normal;
out vec4 frag_Specular;
float Shadow(vec4 ShadowCoord, vec3 normal)
{
return 1.0;
if (Input.ShadowCoord.x < 0.0 || Input.ShadowCoord.x > 1.0 || Input.ShadowCoord.y < 0.0 || Input.ShadowCoord.y > 1.0)
return 0.9;
//Variable bias
vec3 n = normalize(normal);
vec3 l = normalize(SunDirection_cameraspace);
float cosTheta = clamp(dot(n, l), 0.0, 1.0);
float bias = tan(acos(cosTheta));
bias = clamp(bias, 0.0, 0.00003);
//Fixed bias
bias = 0;
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z + bias)
{
return 0.6;
}
else
{
return 1.0;
}
}
void main()
{
vec4 BlendMap = texture(DiffuseTexture, Input.TextureCoord);
vec4 TextureRedTexel = texture(TextureRed, Input.TextureCoord * TextureRepeats);
vec4 TextureRedTexelNormal = texture(TextureRedNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureRedTexelSpecular = texture(TextureRedSpecular, Input.TextureCoord * TextureRepeats);
vec4 TextureGreenTexel = texture(TextureGreen, Input.TextureCoord * TextureRepeats);
vec4 TextureGreenTexelNormal = texture(TextureGreenNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureGreenTexelSpecular = texture(TextureGreenSpecular, Input.TextureCoord * TextureRepeats);
vec4 TextureBlueTexel = texture(TextureBlue, Input.TextureCoord * TextureRepeats);
vec4 TextureBlueTexelNormal = texture(TextureBlueNormal, Input.TextureCoord * TextureRepeats);
//vec4 TextureBlueTexelSpecular = texture(TextureBlueSpecular, Input.TextureCoord * TextureRepeats);
//Mix the Terrain-textures together
TextureRedTexel *= BlendMap.r;
TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g);
vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b);
TextureRedTexelNormal *= BlendMap.r;
TextureGreenTexelNormal = mix(TextureRedTexelNormal, TextureGreenTexelNormal, BlendMap.g);
vec4 finalBlendTexelNormal = mix(TextureGreenTexelNormal, TextureBlueTexelNormal, BlendMap.b);
//TextureRedTexelSpecular *= BlendMap.r;
//TextureGreenTexelSpecular = mix(TextureRedTexelSpecular, TextureGreenTexelSpecular, BlendMap.g);
//vec4 finalBlendTexelSpecular = mix(TextureGreenTexelSpecular, TextureBlueTexelSpecular, BlendMap.b);
// G-buffer Position
frag_Position = vec4(Input.Position.xyz, 1.0);
// G-buffer Normal
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
frag_Normal = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0));
//frag_Diffuse = normalize(vec4(TBN * vec3(finalBlendTexelNormal), 0.0));
//frag_Normal = vec4(Input.Normal, 0.0);
// Diffuse Texture
frag_Diffuse = finalBlendTexel;
//G-buffer Specular
frag_Specular = texture(SpecularMapTexture, Input.TextureCoord);
}
+35
View File
@@ -0,0 +1,35 @@
#version 430
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 DepthMVP;
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec2 TextureCoord;
layout (location = 3) in vec3 Tangent;
layout (location = 4) in vec3 BiTangent;
out VertexData
{
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
vec4 ShadowCoord;
vec3 Tangent;
vec3 BiTangent;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = vec3(V * M * vec4(Position, 1.0));
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
Output.TextureCoord = TextureCoord;
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
Output.Tangent = normalize(vec3(inverse(transpose(V * M)) * vec4(Tangent, 0.0)));
Output.BiTangent = normalize(vec3(inverse(transpose(V * M)) * vec4(BiTangent, 0.0)));
}
+24
View File
@@ -0,0 +1,24 @@
#version 430
layout (binding=0) uniform sampler2D DiffuseTexture;
in VertexData
{
vec3 Position;
vec2 TextureCoord;
} Input;
out vec4 FragmentColor;
void main()
{
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel;
FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
}
+16
View File
@@ -0,0 +1,16 @@
#version 430
layout(location = 0) in vec3 Position;
out VertexData
{
vec3 Position;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = vec4(Position, 1.0);
Output.Position = Position;
Output.TextureCoord = (vec2(Position) + 1) / 2;
}
+8 -6
View File
@@ -1,11 +1,10 @@
#version 430
//Dicksdickdickdickssssss
uniform vec3 La;
uniform float Gamma;
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D LightingTexture;
layout (binding=2) uniform sampler2D ShadowTexture;
in VertexData
{
@@ -13,18 +12,21 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragmentColor;
out vec4 frag_Diffuse;
void main()
{
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
vec4 ShadowTexel = texture(ShadowTexture, Input.TextureCoord);
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel;
//frag_Diffuse = vec4(LightingTexel.rgb, 0.0);
//frag_Diffuse = DiffuseTexel * ((vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
//frag_Diffuse = LightingTexel;
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
}
+43 -3
View File
@@ -1,8 +1,23 @@
#version 430
uniform vec4 Color;
uniform vec3 La;
uniform vec3 directionToSun;
uniform mat4 V;
layout(binding=0) uniform sampler2D texture0;
layout(binding=1) uniform sampler2D PositionTexture;
layout(binding=2) uniform sampler2D NormalsTexture;
layout(binding=3) uniform sampler2D SpecularTexture;
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 100;
in VertexData {
vec3 Position;
@@ -10,11 +25,36 @@ in VertexData {
vec2 TextureCoord;
} Input;
out vec4 fragmentColor;
out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
//Diffuse Sunlight
vec3 directionToLight = normalize(vec3(V * vec4(directionToSun, 0.0)));
float dotProdLight = dot(directionToLight, normal);
dotProdLight = max(dotProdLight, 0.0);
vec3 sId = kd * SunDiffuseLight * dotProdLight;
//Specular Sunlight
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
}
void main() {
// Texture
vec4 texel = texture(texture0, Input.TextureCoord);
vec4 PositionTexel = texture(PositionTexture, Input.TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, Input.TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, Input.TextureCoord);
frag_Diffuse = texel * Color;
//frag_Diffuse = texel * Color * (vec4(La, 0.0) * phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel)));
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
fragmentColor = texel * Color;
}
-26
View File
@@ -5,13 +5,6 @@ layout (binding=1) uniform sampler2D ShadowTexture;
layout (binding=2) uniform sampler2D NormalMapTexture;
layout (binding=3) uniform sampler2D SpecularMapTexture;
//TerrainTextures
layout (binding=4) uniform sampler2D AsphaltTexture;
layout (binding=5) uniform sampler2D GrassTexture;
layout (binding=6) uniform sampler2D SandTexture;
layout (binding=7) uniform sampler2D BlendMap;
uniform float texScale; //Determines how many times the textures will loop over the terrain
uniform vec3 SunDirection_cameraspace;
uniform mat4 V;
@@ -59,25 +52,6 @@ float Shadow(vec4 ShadowCoord, vec3 normal)
void main()
{
//Fixa så den bara gör detta om modellen har en blend map
//vvvvvv
vec4 Blend = texture2D(BlendMap, Input.TextureCoord.st );
vec4 AsphaltTexel = texture2D(AsphaltTexture, Input.TextureCoord.st * texScale);
vec4 GrassTexel = texture2D(GrassTexture, Input.TextureCoord.st * texScale);
vec4 SandTexel = texture2D(SandTexture, Input.TextureCoord.st * texScale);
//Mix the Terrain-textures together
AsphaltTexel *= Blend.r;
GrassTexel = mix(AsphaltTexel, GrassTexel, Blend.g);
vec4 tex = mix(GrassTexel, SandTexel, Blend.b);
//^^^^^^
//Fixa så den bara gör detta om modellen har en blend map
// G-buffer Position
frag_Position = vec4(Input.Position.xyz, 1.0);
+5 -2
View File
@@ -24,6 +24,7 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData
@@ -32,7 +33,7 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragColor;
out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
@@ -67,6 +68,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * vec4(1.0/La, 0.0) * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0));
//FragColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0)) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0);
//FragColor = NormalTexel;
}
-1
View File
@@ -12,5 +12,4 @@ out vec4 FragColor;
void main()
{
FragColor = texture(CubemapTexture, Input.TextureCoord);
//FragColor = vec4(1.0, 1.0, 1.0, 0.0);
}
+4 -2
View File
@@ -1,6 +1,7 @@
#version 430
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 P;
layout(location = 0) in vec3 Position;
@@ -11,6 +12,7 @@ out VertexData
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
vec4 pos = V * vec4(Position, 1.0);
gl_Position = P * pos;
Output.TextureCoord = Position;
}
+10 -5
View File
@@ -4,6 +4,7 @@ layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture;
layout (binding=2) uniform sampler2D SpecularTexture;
uniform vec2 ViewportSize;
uniform mat4 MVP;
uniform mat4 M;
@@ -16,10 +17,12 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(0.3, 0.3, 0.3);
const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 5;
const float specularExponent = 100;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData
@@ -28,7 +31,7 @@ in VertexData
vec2 TextureCoord;
} Input;
out vec4 FragColor;
out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
@@ -46,7 +49,7 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
return vec4((sId + La), sIs.r);
}
void main()
@@ -56,6 +59,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(normalize(NormalTexel)), vec3(SpecularTexel));
frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0)));
//FragColor = NormalTexel;
}
+9 -2
View File
@@ -1,10 +1,10 @@
#include "PrecompiledHeader.h"
#include "DamageSystem.h"
#include "World.h"
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Health>([]() { return new Components::Health(); });
cf->Register<Components::DamageModel>([]() { return new Components::DamageModel(); });
}
void Systems::DamageSystem::Initialize()
@@ -15,8 +15,15 @@ void Systems::DamageSystem::Initialize()
bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
{
if(!m_World->ValidEntity(event.Entity))
return false;
auto health = m_World->GetComponent<Components::Health>(event.Entity);
health->Amount -= event.Amount;
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
if(health->Amount <= 0)
{
Events::Dead e;
e.Entity = event.Entity;
EventBroker->Publish(e);
}
return true;
}
+2
View File
@@ -4,7 +4,9 @@
#include "System.h"
#include "Components/Health.h"
#include "Components/DamageModel.h"
#include "Events/Damage.h"
#include "Events/Dead.h"
namespace Systems
{
+1 -1
View File
@@ -20,7 +20,7 @@ bool Systems::DebugSystem::OnKeyDown(const Events::KeyDown &event)
if (event.KeyCode == GLFW_KEY_ENTER)
{
Events::PlaySFX e;
e.Emitter = 0;
e.Position = glm::vec3(0);
e.Resource = "Sounds/korvring.wav";
EventBroker->Publish<Events::PlaySFX>(e);
+63
View File
@@ -0,0 +1,63 @@
#include "PrecompiledHeader.h"
#include "FlagSystem.h"
#include "World.h"
void Systems::FlagSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Flag>([]() { return new Components::Flag(); });
}
void Systems::FlagSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EEnterTrigger, &Systems::FlagSystem::OnEnterTrigger);
}
void Systems::FlagSystem::Update( double dt )
{
}
void Systems::FlagSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
}
bool Systems::FlagSystem::OnEnterTrigger( const Events::EnterTrigger &event )
{
auto JeepSteeringComponent = m_World->GetComponent<Components::JeepSteering>(event.Entity);
if(!JeepSteeringComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID == playerComponent->ID)
return false;
auto flagComponent = m_World->GetComponent<Components::Flag>(event.Trigger);
if(!flagComponent)
return false;
PickUpFlag(event.Entity, event.Trigger);
return true;
}
void Systems::FlagSystem::PickUpFlag( EntityID entity, EntityID trigger )
{
m_World->RemoveComponent<Components::Trigger>(trigger);
m_World->SetEntityParent(trigger, entity);
auto triggerTransform = m_World->GetComponent<Components::Transform>(trigger);
triggerTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
auto teamComponent = m_World->GetComponent<Components::Team>(trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
Events::FlagPickup ePickup;
ePickup.Player = playerComponent->ID;
EventBroker->Publish(ePickup);
}
+44
View File
@@ -0,0 +1,44 @@
#ifndef FlagSystem_h__
#define FlagSystem_h__
#include "System.h"
#include "Components/Flag.h"
#include "Components/Player.h"
#include "Components/Team.h"
#include "Components/Trigger.h"
#include "Components/Transform.h"
#include "Components/JeepSteering.h"
#include "Events/FlagCaptured.h"
#include "Events/FlagDropped.h"
#include "Events/FlagPickup.h"
#include "Events/FlagReturned.h"
#include "Events/EnterTrigger.h"
namespace Systems
{
class FlagSystem : public System
{
public:
FlagSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
EventRelay<FlagSystem, Events::EnterTrigger> m_EEnterTrigger;
bool OnEnterTrigger(const Events::EnterTrigger &event);
void PickUpFlag(EntityID entity, EntityID trigger);
};
}
#endif // DamageSystem_h__
+22
View File
@@ -0,0 +1,22 @@
#include "PrecompiledHeader.h"
#include "GameStateSystem.h"
#include "World.h"
void Systems::GameStateSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EFlagCaptured, &Systems::GameStateSystem::OnFlagCaptured);
}
bool Systems::GameStateSystem::OnFlagCaptured(const Events::FlagCaptured &event)
{
m_InGame = false;
Events::GameOver e1;
e1.Player = event.Player;
EventBroker->Publish(e1);
Events::PlayBGM e2;
e2.Resource = "Sounds/BGM/WilliamTellOverture.mp3";
EventBroker->Publish(e2);
return true;
}
+38
View File
@@ -0,0 +1,38 @@
#ifndef GameStateSystem_h__
#define GameStateSystem_h__
#include <set>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Player.h"
#include "Events/FlagCaptured.h"
#include "Events/GameOver.h"
#include "Events/PlayBGM.h"
namespace Systems
{
class GameStateSystem : public System
{
public:
GameStateSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
, m_InGame(true)
{ }
void Initialize() override;
bool InGame() const { return m_InGame; }
private:
bool m_InGame;
EventRelay<GameStateSystem, Events::FlagCaptured> m_EFlagCaptured;
bool OnFlagCaptured(const Events::FlagCaptured &event);
};
}
#endif // GameStateSystem_h__
+49 -5
View File
@@ -34,6 +34,14 @@ bool Systems::GarageSystem::OnEnterTrigger(const Events::EnterTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -56,6 +64,15 @@ bool Systems::GarageSystem::OnLeaveTrigger(const Events::LeaveTrigger &event)
if (!garageComponent)
return false;
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger")
@@ -76,19 +93,46 @@ bool Systems::GarageSystem::OnCommand(const Events::InputCommand &event)
{
EntityID trigger = pair.first;
auto entities = pair.second;
std::string name = m_World->GetProperty<std::string>(trigger, "Name");
if (name != "ElevatorShaftTrigger")
continue;
auto triggerBaseParent = m_World->GetEntityBaseParent(trigger);
auto triggerPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
auto triggerTeamComponent = m_World->GetComponent<Components::Team>(trigger);
if (!triggerTeamComponent)
continue;
for (EntityID entity : entities)
{
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
if (triggerPlayerComponent == entityPlayerComponent)
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(entity);
if(!entityPlayerComponent)
continue;
if (entityPlayerComponent->ID != event.PlayerID)
continue;
if (triggerTeamComponent->TeamID == entityPlayerComponent->ID)
{
auto components = m_World->GetComponentsOfType<Components::Flag>();
for (auto &component : *components)
{
auto teamComponent = m_World->GetComponent<Components::Team>(component->Entity);
if(!teamComponent)
continue;
auto parent = m_World->GetEntityParent(component->Entity);
if(parent != entity)
continue;
if(teamComponent->TeamID != entityPlayerComponent->ID)
{
Events::FlagCaptured e;
e.Player = entityPlayerComponent->ID;
EventBroker->Publish(e);
}
}
EntityID garage = m_World->GetEntityParent(trigger);
auto garageComponent = m_World->GetComponent<Components::Garage>(garage);
ToggleGarage(garageComponent);
+3
View File
@@ -18,6 +18,9 @@
#include "Events/Rotate.h"
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Team.h"
#include "Components/Flag.h"
#include "Events/FlagCaptured.h"
namespace Systems
{
+355
View File
@@ -0,0 +1,355 @@
#include "PrecompiledHeader.h"
#include "JeepSteeringSystem.h"
#include "World.h"
void Systems::JeepSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::JeepSteering>([]() { return new Components::JeepSteering(); });
}
void Systems::JeepSteeringSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::JeepSteeringSystem::OnSpawnVehicle);
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i] = std::shared_ptr<JeepSteeringInputController>(new JeepSteeringInputController(EventBroker, i + 1));
}
}
void Systems::JeepSteeringSystem::Update(double dt)
{
for (int i = 0; i < 4; i++)
{
m_JeepInputControllers[i]->Update(dt);
}
}
void Systems::JeepSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto tankSteeringComponent = m_World->GetComponent<Components::JeepSteering>(entity);
if(!tankSteeringComponent)
return;
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
if (!playerComponent)
return;
if (playerComponent->ID == 0)
return;
auto inputController = m_JeepInputControllers[playerComponent->ID - 1];
Events::JeepSteer eSteering;
eSteering.Entity = entity;
eSteering.PositionX = inputController->PositionX;
eSteering.PositionY = inputController->PositionY;
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
}
bool Systems::JeepSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event)
{
if (event.VehicleType != "Jeep")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
// Create a Jeep
EntityID Jeep = CreateJeep(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(Jeep);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(Jeep, "Camera");
if (event.PlayerID == 1)
e.ViewportFrame = "Viewport1";
else if (event.PlayerID == 2)
e.ViewportFrame = "Viewport2";
EventBroker->Publish(e);
}
return true;
}
EntityID Systems::JeepSteeringSystem::CreateJeep(int playerID)
{
auto jeep = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(jeep);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(jeep);
physics->Mass = 2000;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
physics->CenterOfMass = glm::vec3(0, 0, 0);
auto vehicle = m_World->AddComponent<Components::Vehicle>(jeep);
vehicle->MaxTorque = 500.0f;
vehicle->MaxSteeringAngle = 40.f;
vehicle->MaxSpeedFullSteeringAngle = 12.f;
vehicle->MinRPM = 1000.0f;
vehicle->OptimalRPM = 5500.0f,
vehicle->MaxRPM = 7500.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 5.f;
vehicle->UpshiftRPM = 6500.0f;
vehicle->DownshiftRPM = 3500.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(jeep);
player->ID = playerID;
auto jeepSteering = m_World->AddComponent<Components::JeepSteering>(jeep);
m_World->AddComponent<Components::Input>(jeep);
auto health = m_World->AddComponent<Components::Health>(jeep);
health->Amount = 100.f;
/*{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto meshShape = m_World->AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Jeep/Chassi/ChassiCollision.obj";
m_World->CommitEntity(shape);
}*/
{
auto chassis = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = m_World->AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Jeep/Chassi/Chassi.OBJ";
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.0219f ,0.88937f, -0.48469f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.993f;
box->Height = 0.626f;
box->Depth = 1.316f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-0.02551f ,0.55419f, 1.78935f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.849f;
box->Height = 0.415f;
box->Depth = 1.058f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(-1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
{
auto shape = m_World->CreateEntity(jeep);
auto transform = m_World->AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(1.63274f ,0.98825f, -0.89907f);
auto box = m_World->AddComponent<Components::BoxShape>(shape);
box->Width = 0.697f;
box->Height = 0.401f;
box->Depth = 0.868f;
m_World->CommitEntity(shape);
}
auto cameraTower = m_World->CreateEntity(jeep);
{
auto transform = m_World->AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 16.f;
transform->Position.y = 4.f;
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = m_World->AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
m_World->SetProperty(jeep, "Camera", cameraTower);
}
#pragma region Wheels
//Create wheels
float wheelOffset = 0.f;//-0.83f;
const float suspensionStrength = 15.f;
const float springLength = 0.3f;
AddJeepWheels(jeep);
#pragma endregion
{
auto entity = m_World->CreateEntity(jeep);
auto transformComponent = m_World->AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = m_World->AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
m_World->CommitEntity(entity);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(particleEntity);
}
m_World->CommitEntity(jeep);
return jeep;
}
void Systems::JeepSteeringSystem::AddJeepWheels(EntityID jeepEntity)
{
//Create wheels
float wheelOffset = 0.5f;
float springLength = 0.2f;
float suspensionStrength = 35.f;
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.9f, 0.5546f - wheelOffset, -0.9242f);
transform->Scale = glm::vec3(1.0f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 50;
Wheel->Radius = 0.837f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
{
auto wheel = m_World->CreateEntity(jeepEntity);
auto transform = m_World->AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-0.2726f, 0.2805f - (wheelOffset/2), 1.9307f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
auto model = m_World->AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = m_World->AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 150;
Wheel->Radius = 0.737f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 2.5f;
Wheel->ConnectedToHandbrake = true;
m_World->CommitEntity(wheel);
}
}
void Systems::JeepSteeringSystem::JeepSteeringInputController::Update( double dt )
{
PositionX = m_Horizontal;
PositionY = m_Vertical;
}
bool Systems::JeepSteeringSystem::JeepSteeringInputController::OnCommand(const Events::InputCommand &event)
{
if (event.PlayerID != this->PlayerID)
return false;
float val = event.Value;
// Tank
if (event.Command == "horizontal")
{
m_Horizontal = val;
}
else if (event.Command == "jeep_vertical")
{
m_Vertical = -val;
}
else if (event.Command == "handbrake")
{
Handbrake = val > 0;
}
return true;
}
+93
View File
@@ -0,0 +1,93 @@
#include <array>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Physics.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
#include "Components/Health.h"
#include "Components/Trigger.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Events/SpawnVehicle.h"
#include "Components/SpawnPoint.h"
#include "Components/Wheel.h"
#include "Components/MeshShape.h"
#include "Components/Camera.h"
#include "Components/BoxShape.h"
#include "Components/WheelPair.h"
#include "Components/Input.h"
#include "Components/JeepSteering.h"
#include "Events/JeepSteer.h"
#include "Components/Team.h"
#include "Events/SetViewportCamera.h"
namespace Systems
{
class JeepSteeringSystem : public System
{
public:
JeepSteeringSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
{ }
void RegisterComponents(ComponentFactory* cf) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
std::map<EntityID, double> m_TimeSinceLastShot;
EventRelay<JeepSteeringSystem, Events::SpawnVehicle> m_ESpawnVehicle;
bool OnSpawnVehicle(const Events::SpawnVehicle &e);
class JeepSteeringInputController;
std::array<std::shared_ptr<JeepSteeringInputController>, 4> m_JeepInputControllers;
EntityID CreateJeep(int playerID);
void AddJeepWheels(EntityID jeepEntity);
};
class JeepSteeringSystem::JeepSteeringInputController : InputController<JeepSteeringSystem>
{
public:
JeepSteeringInputController(std::shared_ptr<::EventBroker> eventBroker, int playerID)
: InputController(eventBroker)
{
PlayerID = playerID;
m_Horizontal = 0.f;
m_Vertical = 0.f;
PositionX = 0;
PositionY = 0;
Handbrake = false;
}
int PlayerID;
float PositionY;
float PositionX;
bool Handbrake;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
//virtual bool OnMouseMove(const Events::MouseMove &event);
private:
float m_Horizontal;
float m_Vertical;
};
}
+133 -120
View File
@@ -8,7 +8,7 @@ void Systems::ParticleSystem::Initialize()
{
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
tempSpawnedExplosions = false;
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Systems::ParticleSystem::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EExplosion, &ParticleSystem::CreateExplosion);
}
void Systems::ParticleSystem::Update(double dt)
@@ -22,11 +22,14 @@ void Systems::ParticleSystem::Update(double dt)
double timeLived = glfwGetTime() - spawnTime;
auto eComp = m_World->GetComponent<Components::ParticleEmitter>(explosionID);
if(timeLived > eComp->LifeTime)
if(timeLived > eComp->LifeTime && m_ParticlesToEmitter[explosionID] == NULL)
{
auto e = m_World->GetComponent<Components::ParticleEmitter>(explosionID);
m_World->RemoveEntity(e->ParticleTemplate);
m_World->RemoveEntity(explosionID);
it = m_ExplosionEmitters.erase(it);
//LOG_INFO("Deleted explosion emitter successfully");
//LOG_INFO("Deleted explosion emitter successfully. nr of emitters%i", m_ExplosionEmitters.size());
}
else
{
@@ -46,69 +49,86 @@ void Systems::ParticleSystem::UpdateEntity(double dt, EntityID entity, EntityID
{
emitterComponent->TimeSinceLastSpawn += dt;
auto emitterTransformComponent = m_World->GetComponent<Components::Transform>(entity);
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
if(emitterComponent->Emitting)
{
SpawnParticles(entity);
emitterComponent->TimeSinceLastSpawn = 0;
if(emitterComponent->TimeSinceLastSpawn > emitterComponent->SpawnFrequency)
{
SpawnParticles(entity);
emitterComponent->TimeSinceLastSpawn = 0;
}
}
}
std::list<ParticleData>::iterator it;
for(it = m_ParticleEmitter[entity].begin(); it != m_ParticleEmitter[entity].end();)
auto particleComponent = m_World->GetComponent<Components::Particle>(entity);
if(particleComponent)
{
EntityID particleID = entity;
double timeLived = glfwGetTime() - particleComponent->SpawnTime;
if(timeLived > particleComponent->LifeTime)
{
m_World->RemoveEntity(particleID);
m_ParticlesToEmitter.erase(particleID);
return;
}
else
{
EntityID particleID = (it)->ParticleID;
auto transformComponent = m_World->GetComponent<Components::Transform>(particleID);
auto particleComponent = m_World->GetComponent<Components::Particle>(particleID);
double timeLived = glfwGetTime() - it->SpawnTime;
if(timeLived > particleComponent->LifeTime)
auto eComponent = m_World->GetComponent<Components::ParticleEmitter>(m_ParticlesToEmitter[particleID]);
auto sprite = m_World->GetComponent<Components::Sprite>(entity);
// FIX: calculate once
float timeProgress = timeLived / particleComponent->LifeTime;
// ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
// Scale interpolation
if(particleComponent->ScaleSpectrum.size() > 1)
VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
// Velocity interpolation
if(particleComponent->VelocitySpectrum.size() > 1)
VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
if(particleComponent->Fade == true)
{
m_World->RemoveEntity(particleID);
it = m_ParticleEmitter[entity].erase(it);
std::vector<float> spectrum;
spectrum.push_back(1);
spectrum.push_back(0);
float alpha;
ScalarInterpolation(timeProgress, spectrum, alpha);
sprite->Color.w = alpha;
}
else
/*// Angular velocity interpolation
if (particleComponent->AngularVelocitySpectrum.size() != 0)
{
// FIX: calculate once
float timeProgress = timeLived / particleComponent->LifeTime;
// ColorInterpolation(timeProgress, particleComponent->ColorSpectrum, color);
// Scale interpolation
if(particleComponent->ScaleSpectrum.size() > 1)
VectorInterpolation(timeProgress, particleComponent->ScaleSpectrum, transformComponent->Scale);
// Velocity interpolation
if(particleComponent->VelocitySpectrum.size() > 1)
VectorInterpolation(timeProgress, particleComponent->VelocitySpectrum, transformComponent->Velocity);
// Angular velocity interpolation
if (particleComponent->AngularVelocitySpectrum.size() != 0)
if(particleComponent->AngularVelocitySpectrum.size() > 1)
{
if(particleComponent->AngularVelocitySpectrum.size() > 1)
{
ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
}
else
{
transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation);
//it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
}
ScalarInterpolation(timeProgress, particleComponent->AngularVelocitySpectrum, it->AngularVelocity);
transformComponent->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
}
//Angular velocity interpolation
if(particleComponent->OrientationSpectrum.size() > 1)
else
{
VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation);
glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]);
glm::vec3 v2 = (it->Orientation);
glm::vec3 v3 = glm::normalize(glm::cross(v1,v2));
float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2)));
transformComponent->Orientation = glm::angleAxis(angle, v3);
transformComponent->Orientation *= glm::angleAxis(it->AngularVelocity, it->Orientation);
//it->Orientation = glm::angleAxis(it->AngularVelocity, it->Orientation);
}
transformComponent->Position += transformComponent->Velocity * (float)dt;
it++;
}
//Angular velocity interpolation
if(particleComponent->OrientationSpectrum.size() > 1)
{
VectorInterpolation(timeProgress, particleComponent->OrientationSpectrum, it->Orientation);
glm::vec3 v1 = (particleComponent->OrientationSpectrum[0]);
glm::vec3 v2 = (it->Orientation);
glm::vec3 v3 = glm::normalize(glm::cross(v1,v2));
float angle = glm::acos(glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2)));
transformComponent->Orientation = glm::angleAxis(angle, v3);
}*/
transformComponent->Position += transformComponent->Velocity * (float)dt;
}
}
}
@@ -127,12 +147,11 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
glm::vec3 ePosition = m_TransformSystem->AbsolutePosition(emitterID);
glm::quat eOrientation = eTransform->Orientation;
glm::vec3 paticleSpeed = glm::vec3(eComponent->Speed);
for(int i = 0; i < eComponent->SpawnCount; i++)
{
auto particleEntity = m_World->CloneEntity(eComponent->ParticleTemplate);
auto particleTransform = m_World->GetComponent<Components::Transform>(particleEntity);
auto ent = m_World->CloneEntity(eComponent->ParticleTemplate);
m_ParticlesToEmitter.insert(std::make_pair(ent, emitterID));
auto particleTransform = m_World->GetComponent<Components::Transform>(ent);
particleTransform->Position = ePosition;
particleTransform->Orientation = eOrientation;
@@ -143,16 +162,21 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 1, 0))) *
glm::normalize(glm::angleAxis(RandomizeAngle(spreadAngle), glm::vec3(0, 0, 1)));
auto particleComponent = m_World->AddComponent<Components::Particle>(particleEntity);
particleComponent->LifeTime = eComponent->LifeTime - 0.5;
particleComponent->ScaleSpectrum = eComponent->ScaleSpectrum;
particleComponent->VelocitySpectrum.push_back(particleTransform->Velocity);
auto particle = m_World->AddComponent<Components::Particle>(ent);
particle->LifeTime = eComponent->LifeTime;
particle->ScaleSpectrum = eComponent->ScaleSpectrum;
particle->VelocitySpectrum.push_back(particleTransform->Velocity);
particle->Fade = eComponent->Fade;
auto sprite = m_World->GetComponent<Components::Sprite>(ent);
if(eComponent->Color != glm::vec4(0))
sprite->Color = eComponent->Color;
if (eComponent->ScaleSpectrum.size() > 0)
{
if (eComponent->ScaleSpectrum.size() > 1)
{
particleComponent->ScaleSpectrum = eComponent->ScaleSpectrum;
particle->ScaleSpectrum = eComponent->ScaleSpectrum;
}
else
{
@@ -165,22 +189,20 @@ void Systems::ParticleSystem::SpawnParticles(EntityID emitterID)
}
if(eComponent->UseGoalVelocity)
particleComponent->VelocitySpectrum.push_back(eComponent->GoalVelocity);
particleComponent->OrientationSpectrum = eComponent->OrientationSpectrum;
if(particleComponent->OrientationSpectrum.size() != 0)
particleTransform->Orientation = glm::angleAxis(0.f, particleComponent->OrientationSpectrum[0]);
particleComponent->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum;
particle->VelocitySpectrum.push_back(eComponent->GoalVelocity);
particle->OrientationSpectrum = eComponent->OrientationSpectrum;
if(particle->OrientationSpectrum.size() != 0)
particleTransform->Orientation = glm::angleAxis(0.f, particle->OrientationSpectrum[0]);
particle->AngularVelocitySpectrum = eComponent->AngularVelocitySpectrum;
ParticleData data;
data.ParticleID = particleEntity;
data.SpawnTime = glfwGetTime();
if (particleComponent->AngularVelocitySpectrum.size() != 0)
data.AngularVelocity = particleComponent->AngularVelocitySpectrum[0];
if (particleComponent->OrientationSpectrum.size() != 0)
data.Orientation = particleComponent->OrientationSpectrum[0];
else data.Orientation = eOrientation * glm::vec3(0,0,-1);
m_ParticleEmitter[emitterID].push_back(data);
particle->SpawnTime = glfwGetTime();
// if (particle->AngularVelocitySpectrum.size() != 0)
// data.AngularVelocity = particle->AngularVelocitySpectrum[0];
// if (particle->OrientationSpectrum.size() != 0)
// data.Orientation = particle->OrientationSpectrum[0];
// else data.Orientation = eOrientation * glm::vec3(0,0,-1);
//m_ParticleEmitter[emitterID].push_back(data);
}
}
@@ -200,23 +222,13 @@ void Systems::ParticleSystem::VectorInterpolation(double timeProgress, std::vect
dAxisValue = glm::abs(spectrum[0].y - spectrum[1].y);
if (spectrum[0].y > spectrum[1].y)
dAxisValue *= -1;
v.y = spectrum[0].y + dAxisValue * timeProgress;
v.y = spectrum[0].y + dAxisValue * timeProgress;
dAxisValue = glm::abs(spectrum[0].z - spectrum[1].z);
if(spectrum[0].z > spectrum[1].z)
dAxisValue *= -1;
v.z = spectrum[0].z + dAxisValue * timeProgress;
}
// void Systems::ParticleSystem::ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &c)
// {
// float dColor = glm::abs(spectrum[0].r - spectrum[1].r);
// c.r = spectrum[0].r + dColor * timeProgress;
// dColor = glm::abs(spectrum[0].g - spectrum[1].g);
// c.g = spectrum[0].g + dColor * timeProgress;
// dColor = glm::abs(spectrum[0].b - spectrum[1].b);
// c.b = spectrum[0].b + dColor * timeProgress;
// }
void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha)
{
float dAlpha = glm::abs(spectrum[0] - spectrum[1]);
@@ -225,53 +237,54 @@ void Systems::ParticleSystem::ScalarInterpolation(double timeProgress, std::vect
alpha = spectrum[0] + dAlpha * timeProgress;
}
void Systems::ParticleSystem::CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale)
bool Systems::ParticleSystem::CreateExplosion(const Events::CreateExplosion &e)
{
auto explosion = m_World->CreateEntity();
auto emitter = m_World->AddComponent<Components::ParticleEmitter>(explosion);
emitter->LifeTime = _lifeTime;
emitter->SpawnCount = _particlesToSpawn;
emitter->Speed = _speed;
emitter->SpreadAngle = _spreadAngle;
emitter->SpawnFrequency = _lifeTime + 20; //temp
// emitter->UseGoalVelocity = true;
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
emitter->LifeTime = e.LifeTime;
emitter->SpawnCount = e.ParticlesToSpawn;
emitter->Speed = e.Speed;
emitter->SpreadAngle = e.SpreadAngle;
emitter->Emitting = e.Emitting;
emitter->SpawnFrequency = e.SpawnFrequency;
//emitter->ScaleSpectrum.push_back(glm::vec3(e.ParticleScale));
emitter->SpawnFrequency = e.LifeTime + 20; //temp
emitter->Fade = true;
emitter->Color = e.Color;
if(e.UseGoalVector)
{
emitter->UseGoalVelocity = e.UseGoalVector;
emitter->GoalVelocity = e.GoalVelocity;
}
std::vector<glm::vec3> scale;
scale.push_back(glm::vec3(e.ParticleScale[0]));
if(e.ParticleScale.size() >= 2)
scale.push_back(glm::vec3(e.ParticleScale[1]));
emitter->ScaleSpectrum = scale;
// emitter->GoalVelocity = glm::vec3(0,-_speed, 0);
m_World->CommitEntity(explosion);
auto particleEnt = m_World->CreateEntity();
auto templateComponent = m_World->AddComponent<Components::Template>(particleEnt);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEnt);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEnt);
spriteComponent->SpriteFile = _spritePath;
if(e.usePointLight)
{
auto light = m_World->AddComponent<Components::PointLight>(particleEnt);
light->Diffuse = glm::vec3(231.f/255.f, 181.f/255.f, 48.f/255.f);
light->Specular = glm::vec3(0.5f, 0.5f, 0.5f);
light->Radius = 20.f;
}
spriteComponent->SpriteFile = e.spritePath;
m_World->CommitEntity(particleEnt);
emitter->ParticleTemplate = particleEnt;
auto transform = m_World->AddComponent<Components::Transform>(explosion);
transform->Position = _pos;
transform->Orientation = _relativeUpOri;
transform->Position = e.Position;
transform->Orientation = e.RelativeUpOrientation;
SpawnParticles(explosion);
m_ExplosionEmitters[explosion] = glfwGetTime();
}
bool Systems::ParticleSystem::OnKeyUp(const Events::KeyUp &e)
{
if(!tempSpawnedExplosions)
{
if (e.KeyCode == GLFW_KEY_B)
{
tempSpawnedExplosions = true;
CreateExplosion(
glm::vec3(0, 10, 0),
0.5,
60,
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
40,
glm::pi<float>(),
0.5f
);
}
}
return true;
}
+12 -17
View File
@@ -5,25 +5,18 @@
#include "Systems/TransformSystem.h"
#include "Components/Transform.h"
#include "Components/ParticleEmitter.h"
#include "Components/PointLight.h"
#include "Components/Particle.h"
#include "Components/Sprite.h"
#include "EventBroker.h"
#include "Events/KeyUp.h"
#include "Events/CreateExplosion.h"
#include "Color.h"
#include <GLFW/glfw3.h>
namespace Systems
{
struct ParticleData
{
EntityID ParticleID;
double SpawnTime;
float AngularVelocity;
glm::vec3 Orientation;
Color color;
};
class ParticleSystem : public System
{
public:
@@ -36,7 +29,7 @@ public:
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
void Initialize() override;
void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
//void CreateExplosion(glm::vec3 _pos, double _lifeTime, int _particlesToSpawn, std::string _spritePath, glm::quat _relativeUpOri, float _speed, float _spreadAngle, float _particleScale);
virtual bool OnCommand(const Events::KeyUp &event) { return false; }
@@ -45,19 +38,21 @@ private:
float RandomizeAngle(float spreadAngle);
//void ScaleInterpolation(double timeProgress, std::vector<float> spectrum, glm::vec3 &scale);
void VectorInterpolation(double timeProgress, std::vector<glm::vec3> spectrum, glm::vec3 &velocity);
//void ColorInterpolation(double timeProgress, std::vector<Color> spectrum, Color &color);
void ScalarInterpolation(double timeProgress, std::vector<float> spectrum, float &alpha);
void Billboard();
std::map<EntityID, std::list<ParticleData>> m_ParticleEmitter;
std::map<EntityID, double> m_TimeSinceLastSpawn;
std::map<EntityID, double> m_ExplosionEmitters;
//std::map<EntityID, std::list<ParticleData>> m_ParticleEmitter;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
bool tempSpawnedExplosions;
EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
bool OnKeyUp(const Events::KeyUp &e);
// EventRelay<ParticleSystem, Events::KeyUp> m_EKeyUp;
// bool OnKeyUp(const Events::KeyUp &e);
EventRelay<ParticleSystem, Events::CreateExplosion> m_EExplosion;
bool CreateExplosion(const Events::CreateExplosion &e);
std::map<EntityID, double> m_ExplosionEmitters;
std::map<EntityID, EntityID> m_ParticlesToEmitter;
};
}
+178 -79
View File
@@ -33,11 +33,13 @@ void Systems::PhysicsSystem::Initialize()
// Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_EJeepSteer, &Systems::PhysicsSystem::OnJeepSteer);
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
EVENT_SUBSCRIBE_MEMBER(m_EEnableCollisions, &Systems::PhysicsSystem::OnEnableCollisions);
EVENT_SUBSCRIBE_MEMBER(m_EDisableCollisions, &Systems::PhysicsSystem::OnDisableCollisions);
EVENT_SUBSCRIBE_MEMBER(m_EDead, &Systems::PhysicsSystem::OnDead);
hkMemorySystem::FrameInfo finfo(10000 * 1024); // Allocate 10MB of Physics solver buffer
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
@@ -80,7 +82,7 @@ void Systems::PhysicsSystem::Initialize()
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY;
// You must specify the size of the broad phase - objects should not be simulated outside this region
worldInfo.setBroadPhaseWorldSize(1500.0f);
worldInfo.setBroadPhaseWorldSize(1000.0f);
m_PhysicsWorld = new hkpWorld(worldInfo);
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
@@ -151,6 +153,10 @@ void Systems::PhysicsSystem::Update(double dt)
EntityID entity = pair.first;
EntityID parent = pair.second;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if(templateComponent)
continue;
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
continue;
@@ -176,6 +182,12 @@ void Systems::PhysicsSystem::Update(double dt)
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity);
}
/*auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity);*/
m_PhysicsWorld->markForWrite();
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
@@ -218,6 +230,10 @@ void Systems::PhysicsSystem::Update(double dt)
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if(templateComponent)
return;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent)
return;
@@ -229,6 +245,20 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
if(m_Vehicles.find(car) != m_Vehicles.end())
{
m_PhysicsWorld->markForWrite();
/*auto player = m_World->GetComponent<Components::Player>(car);
if(player)
{
if(player->ID == 1)
{
LOG_INFO("Speed: %f, Gear: %i, RPM: %f", m_Vehicles[car]->calcKMPH(), m_Vehicles[car]->m_currentGear, m_Vehicles[car]->m_rpm);
}
}*/
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(car);
vehicleComponent->currentRPM = m_Vehicles[car]->calcRPM();
m_Vehicles[car]->getChassis()->activate();
hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace;
@@ -250,14 +280,13 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
// TODO: No support for Scale, MIGHT be possible
// HACK: WTF IS THIS?
if (transformComponentParent)
{
transformComponent->Position -= transformComponentParent->Position;
transformComponent->Position = transformComponent->Position * transformComponentParent->Orientation;
transformComponent->Orientation = transformComponent->Orientation * glm::inverse(transformComponentParent->Orientation);
auto absoluteTransformParent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(parent);
transformComponent->Position -= absoluteTransformParent.Position;
transformComponent->Position = transformComponent->Position * absoluteTransformParent.Orientation;
transformComponent->Orientation = glm::inverse(absoluteTransformParent.Orientation) * transformComponent->Orientation;
}
}
@@ -297,14 +326,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (physicsComponent && m_Shapes[entity].size() > 0)
{
if(entityParent != 0 && !physicsComponent->Static)
if(entityParent != 0 && physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
{
LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity);
return;
}
hkpShape* shape;
if(! physicsComponent->Static) // Not static
if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
{
hkArray<hkpShape*> shapeArray;
for (auto &shapeData : m_Shapes[entity])
@@ -368,6 +397,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
if(physicsComponent->CalculateCenterOfMass)
physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass);
rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass);
rigidBodyInfo.m_mass = massProperties.m_mass;
rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity);
@@ -381,7 +411,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
rigidBodyInfo.m_enableDeactivation = false;
rigidBodyInfo.m_enableDeactivation = true;;
}
// Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
@@ -400,7 +430,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
}
}
VehicleSetup vehicleSetup;
// Create the basic vehicle.
m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]);
@@ -438,7 +467,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBody->removeReference();
}
}
else // Static
else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed || physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
{
// Create the hkpStaticCompoundShape and add the instances.
// "meshShape" should not be modified by the user in any way after adding it as an instance.
@@ -490,7 +519,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
hkpRigidBodyCinfo rigidBodyInfo;
{
rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED;
if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed)
{
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
}
else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
{
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED;
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
@@ -513,7 +550,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
rigidBodyInfo.m_enableDeactivation = false;
rigidBodyInfo.m_enableDeactivation = true;
}
// Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
@@ -621,6 +658,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
std::vector<hkReal>* vertices = new std::vector<hkReal>;
std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>;
auto meshShape = ResourceManager->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
if(!meshShape)
return;
for (auto &vertex : meshShape->Vertices)
{
@@ -705,53 +744,13 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
LOG_INFO("%s", msg);
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = steeringX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->activate();
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
transformComponent->Velocity = event.Velocity;
@@ -786,42 +785,42 @@ bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpuls
void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string type, Component* component)
{
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed Trigger of entity %i", entity);
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
}
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
{
if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed rigid body of entity %i", entity);
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
if(m_ListShapes.find(entity) != m_ListShapes.end())
{
m_ListShapes[entity]->removeReference();
m_ListShapes.erase(entity);
}
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
if(m_Vehicles.find(entity) != m_Vehicles.end())
if (m_Vehicles.find(entity) != m_Vehicles.end())
{
m_PhysicsWorld->markForWrite();
m_Vehicles[entity]->removeFromWorld();
m_PhysicsWorld->unmarkForWrite();
m_Vehicles.erase(entity);
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
}
else if (m_RigidBodies.find(entity) != m_RigidBodies.end())
{
m_PhysicsWorld->markForWrite();
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite();
}
/*
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
LOG_INFO("Removed rigid body of entity %i abogfusdkifbhdzfsgiudfhghdfhgdhfögödhfgödhfödhfödfjhödgfdgföuhudgf", entity);
m_PhysicsWorld->markForWrite();
m_PhysicsWorld->removeEntity(m_RigidBodies[entity]);
m_PhysicsWorld->unmarkForWrite();
m_RigidBodies.erase(entity);
m_RigidBodyEntities.erase(m_RigidBodies[entity]);
}*/
}
bool Systems::PhysicsSystem::OnEnableCollisions( const Events::EnableCollisions &e )
@@ -841,3 +840,103 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
m_PhysicsWorld->unmarkForWrite();
return true;
}
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
else
{
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnJeepSteer( const Events::JeepSteer &event )
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
}
deviceStatus->m_handbrakeButtonPressed = event.Handbrake;
}
return true;
}
bool Systems::PhysicsSystem::OnDead( const Events::Dead &e )
{
if(m_Vehicles.find(e.Entity) != m_Vehicles.end())
{
m_World->RemoveEntity(e.Entity);
//EntityID camera = m_World->GetProperty<EntityID>(e.Entity, "Camera");
//m_World->RemoveComponent<Components::Camera>(camera);
//auto transform = m_World->GetComponent<Components::Transform>(e.Entity);
//transform->Position = glm::vec3(0, -10000.f, 0);
////m_RigidBodies[e.Entity]->setPosition(hkVector4(0, -10000, 0));
///*m_Vehicles.erase(e.Entity);
//m_RigidBodyEntities.erase(m_RigidBodies[e.Entity]);
//m_RigidBodies.erase(e.Entity);*/
//auto jeep = m_World->GetComponent<Components::JeepSteering>(e.Entity);
//if(jeep)
//{
// m_World->RemoveComponent<Components::JeepSteering>(e.Entity);
//}
//auto tank = m_World->GetComponent<Components::TankSteering>(e.Entity);
//if(tank)
//{
// m_World->RemoveComponent<Components::TankSteering>(e.Entity);
//}
auto listener = m_World->GetComponent<Components::Listener>(e.Entity);
if (listener)
{
m_World->RemoveComponent<Components::Listener>(e.Entity);
}
}
return true;
}
+11 -2
View File
@@ -23,6 +23,7 @@
#include "Components/HingeConstraint.h"
#include "Components/WheelPair.h"
#include "Components/TowerSteering.h"
#include "Components/Player.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
@@ -85,8 +86,12 @@
#include "Events/DisableCollisions.h"
#include "Components/Trigger.h"
#include "Components/Template.h"
#include "Components/Camera.h"
#include "Components/Listener.h"
#include "Events/EnterTrigger.h"
#include "Events/JeepSteer.h"
#include "Events/Dead.h"
#include "Components/JeepSteering.h"
namespace Systems
{
@@ -109,7 +114,6 @@ public:
e.Entity1 = entity1;
e.Entity2 = entity2;
m_PhysicsSystem->EventBroker->Publish(e);
LOG_INFO("CollisionEvent!");
}
private:
@@ -177,6 +181,8 @@ private:
// Events
EventRelay<PhysicsSystem, Events::TankSteer> m_ETankSteer;
bool OnTankSteer(const Events::TankSteer &event);
EventRelay<PhysicsSystem, Events::JeepSteer> m_EJeepSteer;
bool OnJeepSteer(const Events::JeepSteer &event);
EventRelay<PhysicsSystem, Events::SetVelocity> m_ESetVelocity;
bool OnSetVelocity(const Events::SetVelocity &event);
EventRelay<PhysicsSystem, Events::ApplyForce> m_EApplyForce;
@@ -188,6 +194,9 @@ private:
bool OnEnableCollisions(const Events::EnableCollisions &e);
EventRelay<PhysicsSystem, Events::DisableCollisions> m_EDisableCollisions;
bool OnDisableCollisions(const Events::DisableCollisions &e);
EventRelay<PhysicsSystem, Events::Dead> m_EDead;
bool OnDead(const Events::Dead &e);
void SetUpPhysicsState(EntityID entity, EntityID parent);
void TearDownPhysicsState(EntityID entity, EntityID parent);
+1
View File
@@ -15,6 +15,7 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
cf->Register<Components::Viewport>([]() { return new Components::Viewport(); });
cf->Register<Components::BlendMap>([]() { return new Components::BlendMap(); });
}
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
+1
View File
@@ -20,6 +20,7 @@
#include "Renderer.h"
#include "RenderQueue.h"
#include "Events/SetViewportCamera.h"
#include "Components/BlendMap.h"
namespace Systems
{
+60 -35
View File
@@ -2,16 +2,21 @@
#include "SoundSystem.h"
#include "World.h"
Systems::SoundSystem::~SoundSystem()
{
FMOD_System_Release(m_System);
}
void Systems::SoundSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EComponentCreated, &SoundSystem::OnComponentCreated);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::PlaySFX);
EVENT_SUBSCRIBE_MEMBER(m_EPlayBGM, &SoundSystem::PlayBGM);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::StopSound);
m_isPlaying = false;
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
FMOD_System_Create(&m_System);
FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED, 0);
FMOD_RESULT result = FMOD_System_Init(m_System, 32, FMOD_INIT_3D_RIGHTHANDED | FMOD_INIT_ENABLE_PROFILE, 0);
if(result != FMOD_OK)
{
LOG_ERROR("Did initialized load FMOD correctly");
@@ -20,7 +25,7 @@ void Systems::SoundSystem::Initialize()
{
LOG_INFO("FMOD initialized successfully");
}
FMOD_System_Set3DSettings(m_System, 1.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale
FMOD_System_Set3DSettings(m_System, 0.f, 1.f, 1.f); //dopplerScale, distancefactor, rolloffscale
}
@@ -44,20 +49,33 @@ void Systems::SoundSystem::Update(double dt)
std::map<EntityID, FMOD_CHANNEL*>::iterator it;
for(it = m_DeleteChannels.begin(); it != m_DeleteChannels.end();)
{
FMOD_BOOL *isPlaying = false;
FMOD_Channel_IsPlaying(it->second, isPlaying);
if(isPlaying)
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
if(m_isPlaying)
{
it++;
}
else
{
FMOD_Sound_Release(m_DeleteSounds[it->first]);
m_DeleteSounds.erase(it->first);
// FMOD_Sound_Release(m_DeleteSounds[it->first]);
m_DeleteSounds.erase(it->first);
it = m_DeleteChannels.erase(it);
}
}
//LOG_INFO("Antal emitters i listan: %i", m_Channels.size());
for(it = m_Channels.begin(); it != m_Channels.end();)
{
FMOD_Channel_IsPlaying(it->second, &m_isPlaying);
if(!m_isPlaying)
{
it = m_Channels.erase(it);
}
else
{
it++;
}
}
}
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
@@ -119,7 +137,7 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
float maxDist = emitter->MaxDistance;
float minDist = emitter->MinDistance;
float pitch = emitter->Pitch;
//LoadSound(sound, path, maxDist, minDist);
LoadSound(sound, path, maxDist, minDist);
m_Channels.insert(std::make_pair(emitter->Entity, channel));
m_Sounds.insert(std::make_pair(emitter->Entity, sound));
}
@@ -128,47 +146,54 @@ bool Systems::SoundSystem::OnComponentCreated(const Events::ComponentCreated &ev
bool Systems::SoundSystem::PlaySFX(const Events::PlaySFX &event)
{
auto emitter = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
if(!emitter)
{
LOG_ERROR("FMOD: The Entity %i does not have a SoundEmitter-component, but is trying to play a sound", event.Emitter);FMOD_CHANNEL* channel = m_Channels[event.Emitter];
return false;
}
auto eEntity = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(eEntity);
eTransform->Position = event.Position;
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(eEntity);
eComponent->MinDistance = event.MinDistance;
eComponent->MaxDistance= event.MaxDistance;
eComponent->Loop = event.Loop;
eComponent->Gain = event.Volume;
emitter->type = Components::SoundEmitter::SoundType::SOUND_3D;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
Sound* sound = ResourceManager->Load<Sound>("Sound3D", event.Resource);
m_Sounds[event.Emitter] = *sound;
FMOD_Sound_Set3DMinMaxDistance(*sound, emitter->MinDistance, emitter->MaxDistance);
m_Sounds[eEntity] = *sound;
FMOD_Sound_Set3DMinMaxDistance(*sound, eComponent->MinDistance, eComponent->MaxDistance);
PlaySound(&m_Channels[event.Emitter], m_Sounds[event.Emitter], 1.0, event.Loop);
FMOD_System_Update(m_System);
FMOD_BOOL isPlaying = false;
FMOD_Channel_IsPlaying(m_Channels[event.Emitter], &isPlaying);
if(!isPlaying)
LOG_ERROR("FMOD: File %s is not playing", event.Resource.c_str());
else
LOG_INFO("Now playing sound %s", event.Resource.c_str());
PlaySound(&m_Channels[eEntity], *sound, 1.0, eComponent->Loop);
return true;
}
bool Systems::SoundSystem::PlayBGM(const Events::PlayBGM &event)
{
auto emitter = m_World->CreateEntity();
auto eTransform = m_World->AddComponent<Components::Transform>(emitter);
auto eComponent = m_World->AddComponent<Components::SoundEmitter>(emitter);
m_Channels[emitter] = m_BGMChannel;
eComponent->type = Components::SoundEmitter::SoundType::SOUND_3D;
FMOD_RESULT result;
result = FMOD_Channel_Stop(m_BGMChannel);
if(result != FMOD_OK)
LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
Sound* sound = ResourceManager->Load<Sound>("Sound2D", event.Resource);
m_Sounds[emitter] = *sound;
FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_Channels[emitter]);
result = FMOD_System_PlaySound(m_System, FMOD_CHANNEL_FREE, *sound, false, &m_BGMChannel);
if(result != FMOD_OK)
LOG_INFO("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
FMOD_Channel_SetMode(m_BGMChannel, FMOD_LOOP_NORMAL);
FMOD_Sound_SetLoopCount(*sound, -1);
return true;
}
bool Systems::SoundSystem::StopSound(const Events::StopSound &event)
{
FMOD_Channel_Stop(m_Channels[event.Emitter]);
auto eComp = m_World->GetComponent<Components::SoundEmitter>(event.Emitter);
if(eComp)
{
FMOD_Channel_Stop(m_Channels[event.Emitter]);
}
else
{
FMOD_Channel_Stop(m_BGMChannel);
}
return true;
}
+3 -3
View File
@@ -24,13 +24,12 @@ public:
SoundSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager)
{ }
~SoundSystem();
void RegisterComponents(ComponentFactory* cf) override;
void RegisterResourceTypes(std::shared_ptr<::ResourceManager> rm) override;
void Initialize() override;
void Update(double dt) override;
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
//void OnComponentRemoved(std::string type, Component* component);
void OnComponentRemoved(EntityID entity, std::string type, Component* component) override;
FMOD_SYSTEM* GetFMODSystem() const { return m_System; }
private:
@@ -48,12 +47,13 @@ private:
void PlaySound(FMOD_CHANNEL**, FMOD_SOUND*, float volume, bool loop);
FMOD_SYSTEM* m_System;
FMOD_BOOL m_isPlaying;
FMOD_CHANNEL* m_BGMChannel;
std::vector<EntityID> m_Listeners;
std::map<EntityID, FMOD_CHANNEL*> m_Channels;
std::map<EntityID, FMOD_CHANNEL*> m_DeleteChannels;
std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::map<EntityID, FMOD_SOUND*> m_DeleteSounds;
std::map<EntityID, FMOD_SOUND*> m_Sounds;
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
};
+278 -41
View File
@@ -30,6 +30,45 @@ void Systems::TankSteeringSystem::Update(double dt)
void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{
auto pEmitter = m_World->GetComponent<Components::ParticleEmitter>(entity);
if(pEmitter)
{auto tankTransform = m_World->GetComponent<Components::Transform>(parent);
if(!m_World->GetComponent<Components::TankSteering>(parent))
return;
glm::vec2 velXZ = glm::vec2(tankTransform->Velocity.x, tankTransform->Velocity.z);
float speedMPDT = glm::length(velXZ);
if(speedMPDT < 1)
{
pEmitter->Emitting = false;
return;
}
else
{
pEmitter->Emitting = true;
pEmitter->ScaleSpectrum.erase(pEmitter->ScaleSpectrum.begin());
float scale = speedMPDT / 20;
scale = glm::clamp(scale, 0.3f, 20.f);
pEmitter->ScaleSpectrum.push_back(glm::vec3(speedMPDT / 20));
float spawnFrequency = 1 / speedMPDT;
spawnFrequency = glm::clamp(spawnFrequency, 0.1f, 2.f);
pEmitter->SpawnFrequency = 1 / speedMPDT;
}
}
auto vehicleComp = m_World->GetComponent<Components::Vehicle>(entity);
if(vehicleComp)
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (transform->Position.y < -15 && transform->Position.y > -100)
{
Events::Dead e;
e.Entity = entity;
EventBroker->Publish(e);
}
}
auto tankSteeringComponent = m_World->GetComponent<Components::TankSteering>(entity);
if(!tankSteeringComponent)
return;
@@ -50,7 +89,6 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
eSteering.Handbrake = inputController->Handbrake;
EventBroker->Publish(eSteering);
auto towerSteeringComponent = m_World->GetComponent<Components::TowerSteering>(tankSteeringComponent->Turret);
auto barrelSteeringComponent = m_World->GetComponent<Components::BarrelSteering>(tankSteeringComponent->Barrel);
@@ -65,7 +103,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
{
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
@@ -81,7 +119,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
transformComponent->Orientation = glm::quat(angles);
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
if(inputController->Shoot && m_TimeSinceLastShot[tankSteeringComponent->Barrel] > 0.5)
{
@@ -90,20 +128,58 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Position = templateAbsoluteTransform.Position;
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(eSetVelocity);
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
{
Events::PlaySFX e;
e.Resource = "Sounds/SFX/TankShot.mp3";
e.Position = cloneTransform->Position;
e.Loop = false;
EventBroker->Publish(e);
}
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
//1,670m/s
//25kg
Events::ApplyPointImpulse ePointImpulse ;
Events::ApplyPointImpulse ePointImpulse;
ePointImpulse.Entity = entity;
ePointImpulse.Position = absoluteTransform.Position;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f;
EventBroker->Publish(ePointImpulse);
}
@@ -139,30 +215,149 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
return false;
}
if(m_World->GetComponent<Components::Template>(shellEntity))
return false;
auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>();
auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity);
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
{
Events::CreateExplosion e;
e.LifeTime = 3;
e.ParticleScale.push_back(8);
e.ParticlesToSpawn = 20;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6, 0.6, 0.6, 1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(12);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(15);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.usePointLight = true;
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
/*Events::CreateExplosion e;
e.ParticlesToSpawn = 20;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(12);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(15);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);*/
// Events::CreateExplosion e;
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180) / 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(5.f,5.f,5.f,1);
//
// EventBroker->Publish(e);
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180)/ 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(1.f,1.f,1.f,1);
// EventBroker->Publish(e);
}
{
Events::PlaySFX e;
e.MinDistance = 150.f;
e.Position = shellTransform->Position;
e.Resource = "Sounds/SFX/Explosion.wav";
EventBroker->Publish(e);
}
// Direct damage
auto health = m_World->GetComponent<Components::Health>(otherEntity);
if (health)
{
Events::Damage d;
d.Entity = otherEntity;
d.Amount = shellComponent->Damage;
EventBroker->Publish(d);
}
// Splash damage
for (auto &physComponent : *physicsComponents)
{
EntityID physicsEntity = std::dynamic_pointer_cast<Components::Physics>(physComponent)->Entity;
auto physEntityTransform = m_World->GetComponent<Components::Transform>(physicsEntity);
EntityID physicsEntity = physComponent->Entity;
// No splash damage to the direct hit target
if (physicsEntity == otherEntity)
continue;
auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(physicsEntity);
float distance = glm::distance(physEntityTransform->Position, shellTransform->Position);
float distance = glm::distance(physEntityTransform.Position, shellTransform->Position);
if (distance <= shellComponent->ExplosionRadius)
{
// DO STUFF! :D
float radius = shellComponent->ExplosionRadius;
float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength;
glm::vec3 direction = glm::normalize(physEntityTransform->Position - shellTransform->Position);
glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position);
Events::ApplyPointImpulse e;
e.Entity = physicsEntity;
e.Impulse = direction * strength;
e.Position = physEntityTransform->Position;
e.Position = physEntityTransform.Position;
EventBroker->Publish(e);
auto health = m_World->GetComponent<Components::Health>(physicsEntity);
if(health)
if (health && health->VulnerableToSplash)
{
Events::Damage d;
d.Entity = physicsEntity;
@@ -170,8 +365,6 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
EventBroker->Publish(d);
}
m_World->RemoveEntity(shellEntity);
}
}
@@ -256,14 +449,27 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
{
if (event.VehicleType != "Tank")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
for (auto &spawnPointComponent : *spawnPointComponents)
if (!spawnPointComponents)
{
auto spawnPoint = spawnPointComponent->Entity;
auto spawnPointBaseParent = m_World->GetEntityBaseParent(spawnPoint);
auto playerComponent = m_World->GetComponent<Components::Player>(spawnPointBaseParent);
if (!playerComponent || playerComponent->ID != event.PlayerID)
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &component : *spawnPointComponents)
{
auto spawnPoint = component->Entity;
auto spawnPointComponent = std::dynamic_pointer_cast<Components::SpawnPoint>(component);
auto teamComponent = m_World->GetComponent<Components::Team>(spawnPoint);
if(!teamComponent)
{
LOG_ERROR("SpawnPoint has no TeamComponent");
continue;
}
if (teamComponent->TeamID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
@@ -271,8 +477,8 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
// Create a tank
EntityID tank = CreateTank(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(tank);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(tank, "Camera");
@@ -294,18 +500,35 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000;
physics->Static = false;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
auto vehicle = m_World->AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
vehicle->MinRPM = 200.0f;
vehicle->OptimalRPM = 2500.0f,
vehicle->MaxRPM = 4000.0f;
vehicle->TopSpeed = 90.0f;
vehicle->SpringDamping = 1.f;
vehicle->UpshiftRPM = 3500.0f;
vehicle->DownshiftRPM = 1000.0f;
vehicle->gearsRatio0 = 3.0f;
vehicle->gearsRatio1 = 2.25f;
vehicle->gearsRatio2 = 1.5f;
vehicle->gearsRatio3 = 1.0f;
auto player = m_World->AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = m_World->AddComponent<Components::TankSteering>(tank);
m_World->AddComponent<Components::Input>(tank);
m_World->AddComponent<Components::Listener>(tank);
auto health = m_World->AddComponent<Components::Health>(tank);
health->Amount = 100.f;
health->Amount = 200.f;
{
auto shape = m_World->CreateEntity(tank);
auto transform = m_World->AddComponent<Components::Transform>(shape);
@@ -362,20 +585,20 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
m_World->AddComponent<Components::Template>(shot);
auto physics = m_World->AddComponent<Components::Physics>(shot);
physics->Mass = 25.f;
physics->Static = false;
physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
physics->CollisionEvent = true;
auto modelComponent = m_World->AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto tankShellComponent = m_World->AddComponent<Components::TankShell>(shot);
tankShellComponent->Damage = 20.f;
tankShellComponent->ExplosionRadius = 30.f;
tankShellComponent->ExplosionStrength = 300000.f;
tankShellComponent->ExplosionRadius = 20.f;
tankShellComponent->ExplosionStrength = 140.f;
{
auto shape = m_World->CreateEntity(shot);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto boxShape = m_World->AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Width = 0.1f;
boxShape->Height = 0.1f;
boxShape->Depth = 0.5f;
m_World->CommitEntity(shape);
}
@@ -391,6 +614,8 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = m_World->AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
/*auto follow = m_World->AddComponent<Components::Follow>(cameraTower);
follow->Entity = barrel;
follow->Distance = 15.f;
@@ -439,31 +664,43 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false);
#pragma endregion
#pragma region DustParticles
std::vector<glm::vec3> ePos;
ePos.push_back(glm::vec3(-2, -1.7, 2.0));
ePos.push_back(glm::vec3(2, -1.7, 2.0));
ePos.push_back(glm::vec3(2, -1.7, -2.0));
ePos.push_back(glm::vec3(-2, -1.7, -2.0));
for (int i = 0; i < 4; i++)
{
auto entity = m_World->CreateEntity(tank);
auto transformComponent = m_World->AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
transformComponent->Position = ePos[i];
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = m_World->AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpawnCount = 1;
emitterComponent->SpawnFrequency = 0.1;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
m_World->CommitEntity(entity);
emitterComponent->LifeTime = 0.3;
emitterComponent->Speed = 3;
emitterComponent->Emitting = true;
emitterComponent->Fade = true;
emitterComponent->ScaleSpectrum.push_back(glm::vec3(1));
//emitterComponent->Color = glm::vec4(1);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
m_World->AddComponent<Components::Template>(particleEntity);
m_World->AddComponent<Components::Transform>(particleEntity);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
spriteComponent->SpriteFile = "Textures/Sprites/Dirt.png";
m_World->CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(entity);
}
#pragma endregion
m_World->CommitEntity(tank);
+9 -1
View File
@@ -1,10 +1,10 @@
#include <array>
#include "System.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
#include "Events/ApplyForce.h"
#include "Events/ApplyPointImpulse.h"
#include "Events/CreateExplosion.h"
#include "Events/Collision.h"
#include "Components/Transform.h"
#include "Components/TankSteering.h"
@@ -14,6 +14,7 @@
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Components/Model.h"
#include "Components/Team.h"
#include "Systems/TransformSystem.h"
#include "Systems/ParticleSystem.h"
#include "InputController.h"
@@ -21,6 +22,8 @@
#include "Components/Health.h"
#include "Components/TankShell.h"
#include "Components/SphereShape.h"
#include "Components/Listener.h"
#include "Components/SoundEmitter.h"
#include "Events/EnableCollisions.h"
#include "Events/DisableCollisions.h"
@@ -28,6 +31,10 @@
#include "Components/TriggerExplosion.h"
#include "Components/FrameTimer.h"
#include "Events/PlaySFX.h"
#include "Events/PlayBGM.h"
#include "Events/Dead.h"
#include "Events/Damage.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
@@ -43,6 +50,7 @@
#include "Components/Input.h"
#include "Events/SetViewportCamera.h"
#include "Events/GameOver.h"
namespace Systems
{
+383
View File
@@ -0,0 +1,383 @@
#include "PrecompiledHeader.h"
#include "TowerSystem.h"
#include "World.h"
void Systems::TowerSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Tower>([]() { return new Components::Tower(); });
cf->Register<Components::Turret>([]() { return new Components::Turret(); });
cf->Register<Components::TurretShot>([]() {return new Components::TurretShot(); });
cf->Register<Components::TowerDebris>([]() {return new Components::TowerDebris(); });
}
void Systems::TowerSystem::Initialize()
{
//EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage);
EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TowerSystem::OnCollision);
EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::TowerSystem::Damage);
Temp_m_TimeSinceLastShot = 0;
}
void Systems::TowerSystem::Update( double dt )
{
}
bool Systems::TowerSystem::Damage( const Events::Damage &event )
{
auto debrisComponent = m_World->GetComponent<Components::TowerDebris>(event.Entity);
if(!debrisComponent)
{
return false;
}
LOG_INFO("TowerSystem::Damage");
// Change to damage model
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
return false;
}
LOG_INFO("Entity %i is dead", event.Entity);
auto entitytransform = m_World->GetComponent<Components::Transform>(event.Entity);
if(!entitytransform)
return false;
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
// Spawn debris
for(auto d : debrisComponent->TowerDebrisIDs)
{
auto debris = m_World->CloneEntity(d);
auto transform = m_World->GetComponent<Components::Transform>(debris);
Components::Transform absolutetransformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(debris);
transform->Orientation = transform->Orientation * transformComponent.Orientation;
transform->Position = transform->Orientation * transform->Position + transformComponent.Position;
//DO STUFF! :D
float distance = glm::distance(transform->Position, transformComponent.Position);
float radius = 15.f;
float strength = (1.f - pow(distance / radius, 2)) * 2000.f;
glm::vec3 direction = glm::normalize(transformComponent.Position - transform->Position);
Events::ApplyPointImpulse e;
e.Entity = debris;
e.Impulse = direction * strength;
e.Position = transformComponent.Position;
EventBroker->Publish(e);
}
entitytransform->Position = glm::vec3(0.f, -50000000.f, 0.f);
return true;
}
void Systems::TowerSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
{
auto towerComponent = m_World->GetComponent<Components::Tower>(entity);
if(!towerComponent)
return;
Components::Transform absoluteTowerGunTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(towerComponent->Gun);
auto towerGunTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->Gun);
if(!towerGunTransformComponent)
return;
auto towerGunBaseTransformComponent = m_World->GetComponent<Components::Transform>(towerComponent->GunBase);
if(!towerGunBaseTransformComponent)
return;
auto turretComponent = m_World->GetComponent<Components::Turret>(entity);
if(!turretComponent)
return;
auto players = m_World->GetComponentsOfType<Components::Player>();
if (!players)
return;
for(auto player : *players)
{
auto playerComponent = std::dynamic_pointer_cast<Components::Player>(player);
if(towerComponent->ID == playerComponent->ID) //!= betyder att den bara targetar sitt eget lag, == fienden.
continue;
auto playerTransform = m_World->GetComponent<Components::Transform>(player->Entity);
if(!playerTransform)
continue;
Components::Transform absolutePlayerTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(player->Entity);
if(glm::distance(absolutePlayerTransform.Position, absoluteTowerGunTransform.Position) > 45.f)
continue;
//Rotate the turret towards the enemy player
glm::quat baseLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absoluteTowerGunTransform.Position.y, absolutePlayerTransform.Position.z), glm::vec3(0, 1, 0))));
glm::quat gunLookAt = glm::inverse(glm::quat_cast(glm::lookAt(absoluteTowerGunTransform.Position, glm::vec3(absolutePlayerTransform.Position.x, absolutePlayerTransform.Position.y, absolutePlayerTransform.Position.z ), glm::vec3(0, 1, 0))));
towerGunTransformComponent->Orientation = glm::inverse(baseLookAt) * gunLookAt;
towerGunBaseTransformComponent->Orientation = baseLookAt;
#pragma region GetShotDirectionAndLaunchShot
Temp_m_TimeSinceLastShot += dt;
if(Temp_m_TimeSinceLastShot > 1)
{
{
//Shoot code
EntityID clone = m_World->CloneEntity(turretComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(turretComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Orientation = templateAbsoluteTransform.Orientation;
cloneTransform->Position = templateAbsoluteTransform.Position - (cloneTransform->Orientation* glm::vec3(0.97163f, 0.f, 0.f));
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = gunLookAt * glm::vec3(0.f, 0.f, -1.f) * turretComponent->ShotSpeed;
EventBroker->Publish(eSetVelocity);
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
}
{
EntityID clone = m_World->CloneEntity(turretComponent->ShotTemplate);
auto templateAbsoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(turretComponent->ShotTemplate);
auto cloneTransform = m_World->GetComponent<Components::Transform>(clone);
cloneTransform->Orientation = templateAbsoluteTransform.Orientation;
cloneTransform->Position = templateAbsoluteTransform.Position + (cloneTransform->Orientation * glm::vec3(0.97163f, 0.f, 0.f));
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = gunLookAt * glm::vec3(0.f, 0.f, -1.f) * turretComponent->ShotSpeed;
EventBroker->Publish(eSetVelocity);
{
Events::CreateExplosion e;
e.LifeTime = 1.5;
e.ParticleScale.push_back(0.6);
e.ParticleScale.push_back(1.8);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1,0,0));
e.Speed = 1.7;
e.SpreadAngle = glm::pi<float>()/100;
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Emitting = true;
e.SpawnFrequency = 0.2;
e.Color = glm::vec4(0.6,0.6,0.6,1);
EventBroker->Publish(e);
}
{
Events::CreateExplosion e;
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
//e.ParticleScale.push_back(2);
e.ParticlesToSpawn = 1;
e.Position = cloneTransform->Position;
e.Speed = 0;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/MuzzleFlash.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
}
Temp_m_TimeSinceLastShot = 0;
#pragma endregion
}
}
}
bool Systems::TowerSystem::OnCollision(const Events::Collision &e)
{
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity2))
{
auto tankShell1 = m_World->GetComponent<Components::TurretShot>(e.Entity1);
auto tankShell2 = m_World->GetComponent<Components::TurretShot>(e.Entity2);
EntityID shellEntity = 0;
Components::TurretShot* shellComponent;
EntityID otherEntity = 0;
if (tankShell1)
{
shellEntity = e.Entity1;
otherEntity = e.Entity2;
shellComponent = tankShell1;
}
else if (tankShell2)
{
shellEntity = e.Entity2;
otherEntity = e.Entity1;
shellComponent = tankShell2;
}
else
{
return false;
}
if(m_World->GetComponent<Components::Template>(shellEntity))
return false;
//auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>();
auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity);
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
{
Events::CreateExplosion e;
e.LifeTime = 2;
e.ParticleScale.push_back(3);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 3;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Smoke1.png";
e.Color = glm::vec4(0.6, 0.6, 0.6, 0.1);
EventBroker->Publish(e);
e.LifeTime = 0.7;
e.ParticleScale.push_back(5);
e.ParticlesToSpawn = 10;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 17;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Fire.png";
EventBroker->Publish(e);
e.LifeTime = 0.2;
e.ParticleScale.push_back(1);
e.ParticleScale.push_back(5);
e.ParticlesToSpawn = 5;
e.Position = shellTransform->Position;
e.RelativeUpOrientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
e.Speed = 6;
e.SpreadAngle = glm::pi<float>();
e.spritePath = "Textures/Sprites/Blast1.png";
e.Color = glm::vec4(2, 2, 2, 0.2);
EventBroker->Publish(e);
}
//{
// Events::CreateExplosion e;
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180) / 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(5.f,5.f,5.f,1);
// EventBroker->Publish(e);
// e.LifeTime = 1.5;
// e.ParticleScale.push_back(1);
// e.ParticleScale.push_back(6);
// e.ParticlesToSpawn = 20;
// e.Position = shellTransform->Position;
// e.SpreadAngle = glm::radians<float>(180)/ 4;
// e.RelativeUpOrientation = glm::angleAxis(glm::radians<float>(90), glm::vec3(1,0,0));
// e.UseGoalVector = true;
// e.GoalVelocity = glm::vec3(0,-12,0);
// e.Speed = 12;
// e.spritePath = "Textures/Sprites/Splash.png";
// e.Color = glm::vec4(1.f,1.f,1.f,1);
// EventBroker->Publish(e);
//}
//{
// Events::PlaySFX e;
// e.MinDistance = 150.f;
// e.Position = shellTransform->Position;
// e.Resource = "Sounds/SFX/Explosion.wav";
// EventBroker->Publish(e);
//}
// Direct damage
auto health = m_World->GetComponent<Components::Health>(otherEntity);
if (health)
{
Events::Damage d;
d.Entity = otherEntity;
d.Amount = shellComponent->Damage;
EventBroker->Publish(d);
}
// Splash damage
//for (auto &physComponent : *physicsComponents)
//{
// EntityID physicsEntity = physComponent->Entity;
// // No splash damage to the direct hit target
// if (physicsEntity == otherEntity)
// continue;
// auto physEntityTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(physicsEntity);
// float distance = glm::distance(physEntityTransform.Position, shellTransform->Position);
// if (distance <= shellComponent->ExplosionRadius)
// {
// // DO STUFF! :D
// float radius = shellComponent->ExplosionRadius;
// float strength = (1.f - pow(distance / radius, 2)) * shellComponent->ExplosionStrength;
// glm::vec3 direction = glm::normalize(physEntityTransform.Position - shellTransform->Position);
// Events::ApplyPointImpulse e;
// e.Entity = physicsEntity;
// e.Impulse = direction * strength;
// e.Position = physEntityTransform.Position;
// EventBroker->Publish(e);
// auto health = m_World->GetComponent<Components::Health>(physicsEntity);
// if (health && health->VulnerableToSplash)
// {
// Events::Damage d;
// d.Entity = physicsEntity;
// d.Amount = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
// EventBroker->Publish(d);
// }
//
//
// }
//}
m_World->RemoveEntity(shellEntity);
}
return true;
}
+55
View File
@@ -0,0 +1,55 @@
#ifndef TowerSystem_h__
#define TowerSystem_h__
#include "System.h"
#include "Systems/TransformSystem.h"
#include "Components/Player.h"
#include "Components/Tower.h"
#include "Components/Turret.h"
#include "Components/TurretShot.h"
#include "Components/Health.h"
#include "Components/TowerDebris.h"
#include "Components/Model.h"
#include "Events/SetVelocity.h"
#include "Events/CreateExplosion.h"
#include "Events/Collision.h"
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
namespace Systems
{
class TowerSystem : public System
{
public:
TowerSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
virtual void Update(double dt);
virtual void UpdateEntity(double dt, EntityID entity, EntityID parent);
EventRelay<TowerSystem, Events::Collision> m_ECollision;
bool OnCollision(const Events::Collision &e);
EventRelay<TowerSystem, Events::Damage> m_eDamage;
bool Damage(const Events::Damage &event);
private:
std::map<EntityID, double> m_TimeSinceLastShot;
float Temp_m_TimeSinceLastShot;
};
}
#endif // TowerSystem_h__
+2 -1
View File
@@ -24,7 +24,7 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI
if(m_MoveItems.find(entity) != m_MoveItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
glm::vec3 direction = glm::normalize(m_MoveItems[entity].GoalPosition - transform->Position);
glm::vec3 movement = direction * m_MoveItems[entity].Speed * (float)dt;
@@ -54,6 +54,7 @@ void Systems::TransformSystem::UpdateEntity( double dt, EntityID entity, EntityI
if(m_RotationItems.find(entity) != m_RotationItems.end())
{
auto transform = m_World->GetComponent<Components::Transform>(entity);
auto absolutetransform = AbsoluteTransform(entity);
float percentage = dt/m_RotationItems[entity].Time;
m_RotationItems[entity].Time -= dt;
+20 -27
View File
@@ -44,21 +44,17 @@ void Systems::TriggerSystem::OnEntityRemoved( EntityID entity )
bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
//HACK: SIMON IS DISSING AMERICA
if(flagComponent1)
{
Flag(event.Entity, event.Trigger);
}
else if (flagComponent2)
{
Flag(event.Trigger, event.Entity);
}
auto triggerMoveComponent = m_World->GetComponent<Components::TriggerMove>(event.Trigger);
if (triggerMoveComponent)
{
@@ -77,6 +73,17 @@ bool Systems::TriggerSystem::OnEnterTrigger( const Events::EnterTrigger &event )
bool Systems::TriggerSystem::OnLeaveTrigger( const Events::LeaveTrigger &event )
{
auto teamComponent = m_World->GetComponent<Components::Team>(event.Trigger);
auto playerComponent = m_World->GetComponent<Components::Player>(event.Entity);
if(!teamComponent || !playerComponent)
return false;
if (teamComponent->TeamID != playerComponent->ID)
return false;
auto flagComponent1 = m_World->GetComponent<Components::Flag>(event.Trigger);
auto flagComponent2 = m_World->GetComponent<Components::Flag>(event.Entity);
auto triggerMoveComponent = m_World->GetComponent<Components::TriggerMove>(event.Trigger);
if (triggerMoveComponent)
{
@@ -129,20 +136,6 @@ void Systems::TriggerSystem::Move(EntityID entity, bool queue, bool swap)
}
}
void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity )
{
auto tankSteering = m_World->GetComponent<Components::TankSteering>(entity);
if (!tankSteering)
return;
m_World->RemoveComponent<Components::Trigger>(phantomEntity);
m_World->SetEntityParent(phantomEntity, entity);
auto phantomTransform = m_World->GetComponent<Components::Transform>(phantomEntity);
phantomTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
}
void Systems::TriggerSystem::Explosion( EntityID entity, EntityID phantomEntity )
{
/*auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
+1 -1
View File
@@ -21,6 +21,7 @@
#include "Components/Move.h"
#include "Components/Rotate.h"
#include "Components/Player.h"
#include "Components/Team.h"
#include "Events/Move.h"
#include "Events/Rotate.h"
#include <math.h>
@@ -47,7 +48,6 @@ namespace Systems
EventRelay<TriggerSystem, Events::LeaveTrigger> m_ELeaveTrigger;
bool OnLeaveTrigger(const Events::LeaveTrigger &event);
private:
void Flag(EntityID entity, EntityID phantomEntity);
void Explosion(EntityID entity, EntityID phantomEntity);
void Move(EntityID entity, bool queue, bool swap);
void Rotate(EntityID entity, bool queue, bool swap);
+68
View File
@@ -0,0 +1,68 @@
#include "PrecompiledHeader.h"
#include "WallSystem.h"
#include "World.h"
void Systems::WallSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Wall>([]() { return new Components::Wall(); });
}
void Systems::WallSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::WallSystem::Damage);
}
bool Systems::WallSystem::Damage( const Events::Damage &event )
{
auto wallComponent = m_World->GetComponent<Components::Wall>(event.Entity);
if(!wallComponent)
{
return false;
}
LOG_INFO("WallSystem::Damage");
// Change to damage model
auto modelComponent = m_World->GetComponent<Components::Model>(event.Entity);
auto damageModel = m_World->GetComponent<Components::DamageModel>(event.Entity);
if (modelComponent)
{
modelComponent->ModelFile = damageModel->ModelFile;
modelComponent->Color = damageModel->Color;
modelComponent->ShadowCaster = damageModel->ShadowCaster;
modelComponent->Transparent = damageModel->Transparent;
}
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
return false;
}
LOG_INFO("Entity %i is dead", event.Entity);
//auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
Components::Transform transformComponent = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(event.Entity);
// Spawn debris
for(auto d : wallComponent->Walldebris)
{
auto debris = m_World->CloneEntity(d);
auto transform = m_World->GetComponent<Components::Transform>(debris);
transform->Orientation = transform->Orientation * transformComponent.Orientation;
transform->Position = transform->Orientation * transform->Position + transformComponent.Position;
//DO STUFF! :D
float distance = glm::distance(transform->Position, transformComponent.Position);
float radius = 5.f;
float strength = (1.f - pow(distance / radius, 2)) * 20.f;
glm::vec3 direction = glm::normalize(transformComponent.Position - transform->Position);
Events::ApplyPointImpulse e;
e.Entity = debris;
e.Impulse = direction * strength;
e.Position = transformComponent.Position;
EventBroker->Publish(e);
}
m_World->RemoveEntity(event.Entity);
return true;
}
+44
View File
@@ -0,0 +1,44 @@
#ifndef WallSystem_h__
#define WallSystem_h__
#include "System.h"
#include "Systems/TransformSystem.h"
#include "Events/Dead.h"
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
#include "Components/Model.h"
#include "Components/DamageModel.h"
#include "Components/Wall.h"
#include "Components/Transform.h"
#include "Components/Physics.h"
#include "Components/MeshShape.h"
#include "Components/Tankshell.h"
#include "Components/Health.h"
namespace Systems
{
class WallSystem : public System
{
public:
WallSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
EventRelay<WallSystem, Events::Damage> m_eDamage;
bool Damage(const Events::Damage &event);
private:
};
}
#endif // WallSystem_h__
+5 -3
View File
@@ -79,11 +79,13 @@ bool World::ValidEntity(EntityID entity)
void World::RemoveEntity(EntityID entity)
{
m_EntitiesToRemove.insert(entity);
for (auto pair : m_EntityParents)
auto it = m_EntityChildren.find(entity);
if (it != m_EntityChildren.end())
{
if (pair.second == entity)
for (auto entity : it->second)
{
m_EntitiesToRemove.insert(pair.first);
RemoveEntity(entity);
}
}
}
+34
View File
@@ -109,10 +109,13 @@
<ClCompile Include="..\..\src\ShaderProgram.cpp" />
<ClCompile Include="..\..\src\Skybox.cpp" />
<ClCompile Include="..\..\src\Sound.cpp" />
<ClCompile Include="..\..\src\Systems\FlagSystem.cpp" />
<ClCompile Include="..\..\src\Systems\JeepSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp" />
<ClCompile Include="..\..\src\Systems\DebugSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FreeSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp" />
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp" />
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\InputSystem.cpp" />
@@ -122,8 +125,10 @@
<ClCompile Include="..\..\src\Systems\SoundSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TimerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Texture.cpp" />
<ClCompile Include="..\..\src\World.cpp" />
@@ -133,15 +138,21 @@
<ClInclude Include="..\..\src\Color.h" />
<ClInclude Include="..\..\src\Component.h" />
<ClInclude Include="..\..\src\Components\BarrelSteering.h" />
<ClInclude Include="..\..\src\Components\BlendMap.h" />
<ClInclude Include="..\..\src\Components\BoxShape.h" />
<ClInclude Include="..\..\src\Components\Camera.h" />
<ClInclude Include="..\..\src\Components\DamageModel.h" />
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
<ClInclude Include="..\..\src\Components\Flag.h" />
<ClInclude Include="..\..\src\Components\Follow.h" />
<ClInclude Include="..\..\src\Components\FrameTimer.h" />
<ClInclude Include="..\..\src\Components\Garage.h" />
<ClInclude Include="..\..\src\Components\JeepSteering.h" />
<ClInclude Include="..\..\src\Components\Move.h" />
<ClInclude Include="..\..\src\Components\Rotate.h" />
<ClInclude Include="..\..\src\Components\Tower.h" />
<ClInclude Include="..\..\src\Components\Team.h" />
<ClInclude Include="..\..\src\Components\TowerDebris.h" />
<ClInclude Include="..\..\src\Components\TriggerMove.h" />
<ClInclude Include="..\..\src\Components\Timer.h" />
<ClInclude Include="..\..\src\Components\TriggerExplosion.h" />
@@ -169,9 +180,12 @@
<ClInclude Include="..\..\src\Components\Transform.h" />
<ClInclude Include="..\..\src\Components\Trigger.h" />
<ClInclude Include="..\..\src\Components\TriggerRotate.h" />
<ClInclude Include="..\..\src\Components\Turret.h" />
<ClInclude Include="..\..\src\Components\TurretShot.h" />
<ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\SpawnPoint.h" />
<ClInclude Include="..\..\src\Components\Viewport.h" />
<ClInclude Include="..\..\src\Components\Wall.h" />
<ClInclude Include="..\..\src\Components\Wheel.h" />
<ClInclude Include="..\..\src\Components\WheelPair.h" />
<ClInclude Include="..\..\src\CubemapTexture.h" />
@@ -184,13 +198,21 @@
<ClInclude Include="..\..\src\Events\BindKey.h" />
<ClInclude Include="..\..\src\Events\BindMouseButton.h" />
<ClInclude Include="..\..\src\Events\Collision.h" />
<ClInclude Include="..\..\src\Events\CreateExplosion.h" />
<ClInclude Include="..\..\src\Events\ComponentCreated.h" />
<ClInclude Include="..\..\src\Events\Damage.h" />
<ClInclude Include="..\..\src\Events\DisableCollisions.h" />
<ClInclude Include="..\..\src\Events\EnableCollisions.h" />
<ClInclude Include="..\..\src\Events\FlagCaptured.h" />
<ClInclude Include="..\..\src\Events\FlagDropped.h" />
<ClInclude Include="..\..\src\Events\FlagPickup.h" />
<ClInclude Include="..\..\src\Events\FlagReturned.h" />
<ClInclude Include="..\..\src\Events\GameOver.h" />
<ClInclude Include="..\..\src\Events\GamepadAxis.h" />
<ClInclude Include="..\..\src\Events\GamepadButton.h" />
<ClInclude Include="..\..\src\Events\GameStart.h" />
<ClInclude Include="..\..\src\Events\InputCommand.h" />
<ClInclude Include="..\..\src\Events\JeepSteer.h" />
<ClInclude Include="..\..\src\Events\KeyDown.h" />
<ClInclude Include="..\..\src\Events\KeyUp.h" />
<ClInclude Include="..\..\src\Events\LeaveTrigger.h" />
@@ -198,6 +220,7 @@
<ClInclude Include="..\..\src\Events\MouseMove.h" />
<ClInclude Include="..\..\src\Events\MousePress.h" />
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\Dead.h" />
<ClInclude Include="..\..\src\Events\Move.h" />
<ClInclude Include="..\..\src\Events\PlayBGM.h" />
<ClInclude Include="..\..\src\Events\PlaySFX.h" />
@@ -213,7 +236,9 @@
<ClInclude Include="..\..\src\GUI\Frame.h" />
<ClInclude Include="..\..\src\EventBroker.h" />
<ClInclude Include="..\..\src\GUI\GameFrame.h" />
<ClInclude Include="..\..\src\GUI\GameOverFrame.h" />
<ClInclude Include="..\..\src\GUI\HealthOverlay.h" />
<ClInclude Include="..\..\src\GUI\MainMenuFrame.h" />
<ClInclude Include="..\..\src\GUI\PlayerHUD.h" />
<ClInclude Include="..\..\src\GUI\VehicleSelection.h" />
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
@@ -232,10 +257,13 @@
<ClInclude Include="..\..\src\Skybox.h" />
<ClInclude Include="..\..\src\Sound.h" />
<ClInclude Include="..\..\src\System.h" />
<ClInclude Include="..\..\src\Systems\FlagSystem.h" />
<ClInclude Include="..\..\src\Systems\JeepSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\DamageSystem.h" />
<ClInclude Include="..\..\src\Systems\DebugSystem.h" />
<ClInclude Include="..\..\src\Systems\FollowSystem.h" />
<ClInclude Include="..\..\src\Systems\FreeSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\GameStateSystem.h" />
<ClInclude Include="..\..\src\Systems\GarageSystem.h" />
<ClInclude Include="..\..\src\Systems\HelicopterSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\InputSystem.h" />
@@ -245,8 +273,10 @@
<ClInclude Include="..\..\src\Systems\SoundSystem.h" />
<ClInclude Include="..\..\src\Systems\TankSteeringSystem.h" />
<ClInclude Include="..\..\src\Systems\TimerSystem.h" />
<ClInclude Include="..\..\src\Systems\TowerSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Systems\TriggerSystem.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\Systems\WheelPairSystem.h" />
<ClInclude Include="..\..\src\Texture.h" />
<ClInclude Include="..\..\src\Util\GLError.h" />
@@ -257,6 +287,10 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
<None Include="..\..\src\Shaders\BlendMap.frag.glsl" />
<None Include="..\..\src\Shaders\BlendMap.vert.glsl" />
<None Include="..\..\src\Shaders\FinalForwardPass.frag.glsl" />
<None Include="..\..\src\Shaders\FinalForwardPass.vert.glsl" />
<None Include="..\..\src\Shaders\FinalPass.frag.glsl" />
<None Include="..\..\src\Shaders\FinalPass.vert.glsl" />
<None Include="..\..\src\Shaders\ForwardRendering.frag.glsl" />
+122 -1
View File
@@ -74,7 +74,6 @@
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
@@ -84,6 +83,27 @@
<ClCompile Include="..\..\src\Sound.cpp">
<Filter>Audio</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\JeepSteeringSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\TowerSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GameStateSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp">
<Filter>Physics\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\FlagSystem.cpp">
<Filter>Game\Systems</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -182,12 +202,18 @@
<Filter Include="Game\Components">
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
</Filter>
<Filter Include="Particle System\Events">
<UniqueIdentifier>{ddd3c442-7c2f-4690-9308-fcef62deee0b}</UniqueIdentifier>
</Filter>
<Filter Include="Game\Systems">
<UniqueIdentifier>{3c2ea0e5-41a1-4b11-a891-1d59ead7223c}</UniqueIdentifier>
</Filter>
<Filter Include="Base\Events">
<UniqueIdentifier>{3cbe68d9-2446-45ee-8637-ffb805997dcd}</UniqueIdentifier>
</Filter>
<Filter Include="Rendering\Events">
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
</Filter>
<Filter Include="Game\Events">
<UniqueIdentifier>{9702064a-02a2-4b3c-a2ab-47c23a9cf49c}</UniqueIdentifier>
</Filter>
@@ -427,6 +453,9 @@
<ClInclude Include="..\..\src\Components\Player.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\CreateExplosion.h">
<Filter>Particle System\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\Collision.h">
<Filter>Physics\Events</Filter>
</ClInclude>
@@ -511,6 +540,9 @@
<ClInclude Include="..\..\src\Events\Move.h">
<Filter>Base\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LeaveTrigger.h">
<Filter>Physics\Events</Filter>
</ClInclude>
@@ -541,15 +573,92 @@
<ClInclude Include="..\..\src\Components\Rotate.h">
<Filter>Base\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Wall.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\TowerSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Tower.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Turret.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\TurretShot.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Team.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\JeepSteeringSystem.h">
<Filter>Physics\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\GUI\GameOverFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\GameStateSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagPickup.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagCaptured.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagDropped.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\FlagReturned.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\GameOver.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\GUI\MainMenuFrame.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\GameStart.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\JeepSteer.h">
<Filter>Physics\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\JeepSteering.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\DamageModel.h">
<Filter>Rendering\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\FlagSystem.h">
<Filter>Game\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\Events\Dead.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">
@@ -612,5 +721,17 @@
<None Include="..\..\src\Shaders\SunPass.vert.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\BlendMap.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\BlendMap.vert.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\FinalForwardPass.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\FinalForwardPass.vert.glsl">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
</Project>