SlideShare una empresa de Scribd logo
1 de 40
BGE: An open-source framework
for teaching component
based games development in C++
Dr Bryan Duggan
DIT School of Computing
bryan.duggan@dit.ie
@ditcomputing
http://facebook.com/ditschoolofcomputing
Questions we will answer today
•
•
•
•
•
•
•

What is BGE?
Motivation
How are 3D Graphics rendered?
Calculating the world transform
Calculating the view & projection transforms
Component based development
Examples in BGE
Motivation
•
•
•
•
•
•
•
•
•

Game Engines
DirectX/ODE
XNA/BEPU
Unity? OpenGL? Havok?
Anarchy?
BGE
Learning loads of new tech
Improve my C++
Learn best practices
How does BGE Work?
• OpenGL for rendering
– Vertex shaders & Fragment shaders (OpenGL 4)

• GLEW
– The OpenGL Extension Wrangler Library (GLEW) is a crossplatform open-source C/C++ extension loading library.
GLEW provides efficient run-time mechanisms for
determining which OpenGL extensions are supported on
the target platform. OpenGL core and extension
functionality is exposed in a single header file. GLEW has
been tested on a variety of operating systems, including
Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris.

• GLM
– OpenGL Maths Library
• SDL - Simple DirectMedia Library
– A cross-platform multimedia library designed to provide fast access to
the graphics framebuffer and audio device.
– Initialises OpenGL
– Creates the OpenGL context
– Provides an abstraction for keyboard/mouse/joystick
– SDL_TTF for TTF Font support

• FMOD – Closed source Xplatform audio library
– FMOD is a programming library and toolkit for the creation and
playback of interactive audio.
– MP3/WAV/MIDI playback
– 3D Audio
– Occlusion/doppler/effects etc
– Free for non-commercial use
• Bullet
– Bullet 3D Game Multiphysics Library provides state of the
art collision detection, soft body and rigid body dynamics.
– Rigid bodies, constraints etc
– A solver

• C++
– Smart pointers – shared pointers
– STL

• git
– Labs, lectures, solutions
– Git/github is amazing. You should use it.
– Mandated for all DT228/DT211 students now
How are 3D Graphics Rendered
in BGE?
Vertex data
in world
space
Vertex
shader
Textures

Model/World Matrix
View Matrix
Projection Matrix
Normal Matrix
MVP Matrix

Fragment
Shader

Screen
I prefer…
Vertices

The vertices
as they come out
of a 3D modelling
program.
The centre of
the model is
usually the
origin

Model
/World

Places the model
in the world
relative to all the
other objects

View

Transforms
everything
relative to the
camera (0,0,0)
looking down
the –Z Axis

Projection

Viewport
Clipping

Projects
Often does
everything
nothing special
onto a
but can be
2D plane.
a different
Far away
render target
objects are (such as a texture)
smaller
Calculating the world transform
• Combination of the position, orientation and
scale
– Position & scale & vectors
– Orientation is a quaternion

• world = glm::translate(glm::mat4(1), position)
* glm::mat4_cast(orientation) *
glm::scale(glm::mat4(1), scale);
Movement/rotation
•
•
•
•
•

Walk
Strafe
Yaw
Pitch
Roll
Calculating the View Transform
view = glm::lookAt(
position
, position + look
, basisUp
);
GLM_FUNC_QUALIFIER detail::tmat4x4<T> lookAt
(
detail::tvec3<T> const & eye,
detail::tvec3<T> const & center,
detail::tvec3<T> const & up
)
Calculating the Projection Transform
• projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 10000.0f);
GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspective
(
valType const & fovy,
valType const & aspect,
valType const & zNear,
valType const & zFar
)
The Game loop
• Initialise()
• While (true)
– Update(timeDelta)
– Draw()

• End while
• Cleanup()
What are design patterns?
• A very famous book
• Published in 1994
• Common solutions to
problems in software
developmnent
• Part 1
– The capabilities and
pitfalls of object-oriented
programming

• Part 2
– 23 classic software design
patterns
Principles
•

Program to an 'interface', not an 'implementation‘
–
–

•
•

Interfaces lead to dynamic binding and polymorphism (central features of objectoriented programming).
Inheritance is referred to as white-box reuse
–

•

•

The internals of parent classes are often visible to subclasses

Object composition is black-box reuse
–

•

Clients are unaware of the specific types of objects they use, as long as the object adheres to the
interface
Clients remain unaware of the classes that implement these objects; clients only know about the
abstract class(es) defining the interface

No internal details of composed objects need be visible in the code using them

"Because inheritance exposes a subclass to details of its parent's implementation,
it's often said that 'inheritance breaks encapsulation'“
Using inheritance is recommended mainly when adding to the functionality of
existing components, reusing most of the old code and adding relatively small
amounts of new code
Some examples
• Creational
– Factory
– Prototype
– Singleton

• Structural
–
–
–
–

Adapter
Composite
Decorator
Proxy

• Behaviorable
–
–
–
–

Interpreter
Iterator
Observer
State
Some more!
• Lazy loading
– Loading on demand. Defer initialization of an
object until the point at which it is needed

• Instancing
– Rendering multiple copies of the same mesh in a
scene at once

• Controller
– Update a game objects state based on
circumstance
Some goals for BGE
(or any other game engine)
• Keep track of everything in the scene
• Allow game objects to be assembled from
components – increase code reuse and flexibility
• Allow easy creation of composite objects such as
physics objects
• Allow lazy loading of game assets
• Support instancing
• State management of game components
Object Oriented Game Engines
• Are terrible. I know I made one (Dalek World)
• Consider:
Problems!
• Each new piece of functionality you want to
add to a class becomes a new (more specific
class)
• Too many classes
• No flexibility
• Tight coupling
A better approach
• The aggregate design pattern
Game Component

Initialise()
Update(timeDelta)
Draw()
Cleanup()
Attach(GameComponent c)
list<GameComponent> children

0..*
Architecture?
• GameObjects, GameComponents and Transforms
– Circular dependancies
– Difficult to compile in C++

• GameComponents with own transforms
– Rules for copying transforms
– Lots of duplication

• GameComponents with shared transforms
– BGENA2
– How to store transform hierarchies?
– Duplicated calculations
Component Based Games Engines
• Everything in BGE is a component
• Most things extend GameComponent
–
–
–
–

virtual bool Initialise();
virtual void Update(float timeDelta);
virtual void Draw();
virtual void Cleanup();

• GameComponent’s keep track of a list of children
components & parent component
– std::list<std::shared_ptr<GameComponent>>
children;

• This is known as the aggregate design pattern
Each GameComponent has:
• GameComponent * parent;
• glm::vec3 velocity;
• std::list<std::shared_ptr<GameComponent>>
children;
• std::shared_ptr<Transform> transform;
• Shared!
The base class GameComponent
•
•
•
•
•

Holds a list of GameComponent children references
Use Attach() to add something to the list.
Calls Initialise, Update and Draw on all children
All subclasses do their own work first then
Must call the base class member function so that the
children get Initialised, Updated and Drawn!
– Are these depth first or breadth first?

• This means that the scene is a graph of objects each
contained by a parent object
• The parent object in BGE is the Game instance
bool GameComponent::Initialise()
{
// Initialise all the children
std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin();
while (it != children.end())
{
(*it ++)->initialised = (*it)->Initialise();
}
return true;
}
void GameComponent::Cleanup()
{
// Cleanup all the children
std::list<std::shared_ptr<GameComponent>>::iterator it =
children.begin();
while (it != children.end())
{
(*it ++)->Cleanup();
}
}
void GameComponent::Draw()
{
// Draw all the children
std::list<std::shared_ptr<GameComponent>>::iterator it =
children.begin();
while (it != children.end())
{
if ((*it)->worldMode == GameComponent::from_parent)
{
(*it)->parent = this;
(*it)->UpdateFromParent();
}
(*it ++)->Draw();
The child object is
}
}
controlled by the parent

it is attached to
An example is a model
void GameComponent::Update(float timeDelta) {
switch (worldMode)
{
case world_modes::from_self:
world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1), scale);
break;
case world_modes::from_self_with_parent:
world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1), scale);
if (parent != NULL)
{
world = (glm::translate(glm::mat4(1), parent->position) * glm::mat4_cast(parent->orientation)) *
world;
}
break;
case world_modes::to_parent:
world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) *
parent->world = glm::scale(world, parent->scale);
parent->position = this->position;
parent->up = this->up;
parent->look = this->look;
parent->right = this->right;
parent->orientation = this->orientation;

glm::scale(glm::mat4(1), scale);

break;

}
RecalculateVectors();
moved = false;
// Update all the children
std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin();
while (it != children.end())
{
if (!(*it)->alive)
{
it = children.erase(it);
}
else
{
(*it ++)->Update(timeDelta);
}

}
}

The parent is
controlled by a child
The child is known
as a Controller
Attaching!
• You can attach a component to another component:
child->parent = this;
// All my children share the same
transform if they dont already have one...
if (child->transform == nullptr)
{
child->transform = transform;
}
children.push_back(child);
Transform object
•
•
•
•
•
•
•
•
•
•
•

glm::vec3
glm::vec3
glm::vec3
glm::vec3
glm::vec3
glm::vec3
glm::mat4
glm::quat
glm::vec3
glm::vec3
glm::vec3

position;
look;
up;
right;
scale;
velocity;
world;
orientation;
ambient;
specular;
diffuse;
Member functions
• void Strafe(float units);
• void Fly(float units);
• void Walk(float units);

• void Pitch(float angle); // rotate on right
vector
• void Yaw(float angle); // rotate on up vector
• void Roll(float angle); // rotate on look vector
Yaw Example
• void GameComponent::Yaw(float angle)
• {
• // A yaw is a rotation around the global up
vector
• glm::quat rot = glm::angleAxis(angle,
GameComponent::basisUp);
• orientation = rot * orientation;
• }
Making game objects from
components
• You can use these rules to assemble
composite objects together. For example:
– A component with a model attached and a
steeringcontroller attached
– The steeringcontroller shares the parent world
transform
– The model gets its world from the parent
– You can attach different controllers to get different
effects.
– Examples…
Using steeringbehaviours
• SteeringController implements lots of cool
steering behaviours such as follow_path, seek,
obstacle_avoidance
• Can be attached to anything and it will update
the world transform of the thing it’s attached
to
• See 9 & 11 for examples
• 12 is just a textured model. Nothing special
• An example in code…
•
•
•
•
•
•
•
•
•
•

•
•
•
•
•
•
•
•
•

//// from_self_with_parent
station = make_shared<GameComponent>();
station->worldMode = world_modes::from_self;
station->ambient = glm::vec3(0.2f, 0.2, 0.2f);
station->specular = glm::vec3(0,0,0);
station->scale = glm::vec3(1,1,1);
std::shared_ptr<Model> cmodel = Content::LoadModel("coriolis", glm::rotate(glm::mat4(1),
90.0f, GameComponent::basisUp));
station->Attach(cmodel);
station->Attach(make_shared<VectorDrawer>(glm::vec3(5,5,5)));
Attach(station);

// Add a child to the station and update by including the parent's world transform
std::shared_ptr<GameComponent> ship1 = make_shared<GameComponent>();
ship1->worldMode = world_modes::from_self_with_parent;
ship1->ambient = glm::vec3(0.2f, 0.2, 0.2f);
ship1->specular = glm::vec3(1.2f, 1.2f, 1.2f);
std::shared_ptr<Model> ana = Content::LoadModel("anaconda", glm::rotate(glm::mat4(1),
180.0f, GameComponent::basisUp));
ship1->Attach(ana);
ship1->position = glm::vec3(0, 0, -10); // NOTE the ship is attached to the station at an offset
of 10
station->Attach(ship1);.
VR
• Render the scene twice
– Left eye and right eye

• Split the screen in two
• Combine quaternion from Xbox controller
with quaternion from rift
What I learned
•
•
•
•
•
•
•
•

OpenGL
Shaders
Game engine deisign
OO with components
Git
Circular depedancies
2 leap motion projects, 5 pull requests!
I love programming!

Más contenido relacionado

La actualidad más candente

Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemUnity Technologies
 
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Unity Technologies
 
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Building a turn-based game prototype using ECS - Unite Copenhagen 2019Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Building a turn-based game prototype using ECS - Unite Copenhagen 2019Unity Technologies
 
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019Unity Technologies
 
ECS: Streaming and Serialization - Unite LA
ECS: Streaming and Serialization - Unite LAECS: Streaming and Serialization - Unite LA
ECS: Streaming and Serialization - Unite LAUnity Technologies
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...gamifi.cc
 
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsNick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorNick Pruehs
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performanceCodemotion
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesNick Pruehs
 
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesWe Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesUnity Technologies
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016Simon Schmid
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsNick Pruehs
 
Getting started with Burst – Unite Copenhagen 2019
Getting started with Burst – Unite Copenhagen 2019Getting started with Burst – Unite Copenhagen 2019
Getting started with Burst – Unite Copenhagen 2019Unity Technologies
 
How we optimized our Game - Jake & Tess' Finding Monsters Adventure
How we optimized our Game - Jake & Tess' Finding Monsters AdventureHow we optimized our Game - Jake & Tess' Finding Monsters Adventure
How we optimized our Game - Jake & Tess' Finding Monsters AdventureFelipe Lira
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesJussi Pohjolainen
 
ECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAUnity Technologies
 
Practical guide to optimization in Unity
Practical guide to optimization in UnityPractical guide to optimization in Unity
Practical guide to optimization in UnityDevGAMM Conference
 

La actualidad más candente (20)

Technical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab SystemTechnical Deep Dive into the New Prefab System
Technical Deep Dive into the New Prefab System
 
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
 
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Building a turn-based game prototype using ECS - Unite Copenhagen 2019Building a turn-based game prototype using ECS - Unite Copenhagen 2019
Building a turn-based game prototype using ECS - Unite Copenhagen 2019
 
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019
Refresh what you know about AssetDatabase.Refresh()- Unite Copenhagen 2019
 
ECS: Streaming and Serialization - Unite LA
ECS: Streaming and Serialization - Unite LAECS: Streaming and Serialization - Unite LA
ECS: Streaming and Serialization - Unite LA
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Unity - Internals: memory and performance
Unity - Internals: memory and performanceUnity - Internals: memory and performance
Unity - Internals: memory and performance
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
 
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle GamesWe Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
We Love Performance! How Tic Toc Games Uses ECS in Mobile Puzzle Games
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016
 
Style & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity SystemsStyle & Design Principles 03 - Component-Based Entity Systems
Style & Design Principles 03 - Component-Based Entity Systems
 
Getting started with Burst – Unite Copenhagen 2019
Getting started with Burst – Unite Copenhagen 2019Getting started with Burst – Unite Copenhagen 2019
Getting started with Burst – Unite Copenhagen 2019
 
How we optimized our Game - Jake & Tess' Finding Monsters Adventure
How we optimized our Game - Jake & Tess' Finding Monsters AdventureHow we optimized our Game - Jake & Tess' Finding Monsters Adventure
How we optimized our Game - Jake & Tess' Finding Monsters Adventure
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
ECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LA
 
Practical guide to optimization in Unity
Practical guide to optimization in UnityPractical guide to optimization in Unity
Practical guide to optimization in Unity
 

Similar a Soc research

Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with UnityMark Billinghurst
 
Developing Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay FrameworkDeveloping Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay FrameworkCsaba Toth
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろうUnity Technologies Japan K.K.
 
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchBringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchUnity Technologies
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...Sencha
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsSarah Sexton
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 MinigamesSusan Gold
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Lviv Startup Club
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDLWingston
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the BrowserFITC
 
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016Danny Preussler
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsLuca Galli
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Thinkful
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development documentJaejun Kim
 
Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Srijib Roy
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法Unite2017Tokyo
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法Unity Technologies Japan K.K.
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.jsVerold
 

Similar a Soc research (20)

Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with Unity
 
Developing Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay FrameworkDeveloping Multi Platform Games using PlayN and TriplePlay Framework
Developing Multi Platform Games using PlayN and TriplePlay Framework
 
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
【Unite 2017 Tokyo】ScriptableObjectを使ってプログラマーもアーティストも幸せになろう
 
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo SwitchBringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
Bringing Supernatural Thriller, "Oxenfree" to Nintendo Switch
 
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOps
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the Browser
 
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
(Android) Developer Survival in Multiscreen World, MobCon Sofia 2016
 
Unity workshop
Unity workshopUnity workshop
Unity workshop
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)Build a game with javascript (may 21 atlanta)
Build a game with javascript (may 21 atlanta)
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development document
 
Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
Getting started with Verold and Three.js
Getting started with Verold and Three.jsGetting started with Verold and Three.js
Getting started with Verold and Three.js
 

Más de Bryan Duggan

10 Years of Tunepal: Reflections & Future Directions
10 Years of Tunepal: Reflections & Future Directions10 Years of Tunepal: Reflections & Future Directions
10 Years of Tunepal: Reflections & Future DirectionsBryan Duggan
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingBryan Duggan
 
Introduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsIntroduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsBryan Duggan
 
Tunepal: A cloud powered traditional music search engine
Tunepal: A cloud powered traditional music search engineTunepal: A cloud powered traditional music search engine
Tunepal: A cloud powered traditional music search engineBryan Duggan
 

Más de Bryan Duggan (6)

10 Years of Tunepal: Reflections & Future Directions
10 Years of Tunepal: Reflections & Future Directions10 Years of Tunepal: Reflections & Future Directions
10 Years of Tunepal: Reflections & Future Directions
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Introduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous AgentsIntroduction to Steering behaviours for Autonomous Agents
Introduction to Steering behaviours for Autonomous Agents
 
Gw01 introduction
Gw01   introductionGw01   introduction
Gw01 introduction
 
Tunepal: A cloud powered traditional music search engine
Tunepal: A cloud powered traditional music search engineTunepal: A cloud powered traditional music search engine
Tunepal: A cloud powered traditional music search engine
 
Competitions
CompetitionsCompetitions
Competitions
 

Soc research

  • 1. BGE: An open-source framework for teaching component based games development in C++ Dr Bryan Duggan DIT School of Computing bryan.duggan@dit.ie @ditcomputing http://facebook.com/ditschoolofcomputing
  • 2. Questions we will answer today • • • • • • • What is BGE? Motivation How are 3D Graphics rendered? Calculating the world transform Calculating the view & projection transforms Component based development Examples in BGE
  • 3. Motivation • • • • • • • • • Game Engines DirectX/ODE XNA/BEPU Unity? OpenGL? Havok? Anarchy? BGE Learning loads of new tech Improve my C++ Learn best practices
  • 4. How does BGE Work? • OpenGL for rendering – Vertex shaders & Fragment shaders (OpenGL 4) • GLEW – The OpenGL Extension Wrangler Library (GLEW) is a crossplatform open-source C/C++ extension loading library. GLEW provides efficient run-time mechanisms for determining which OpenGL extensions are supported on the target platform. OpenGL core and extension functionality is exposed in a single header file. GLEW has been tested on a variety of operating systems, including Windows, Linux, Mac OS X, FreeBSD, Irix, and Solaris. • GLM – OpenGL Maths Library
  • 5. • SDL - Simple DirectMedia Library – A cross-platform multimedia library designed to provide fast access to the graphics framebuffer and audio device. – Initialises OpenGL – Creates the OpenGL context – Provides an abstraction for keyboard/mouse/joystick – SDL_TTF for TTF Font support • FMOD – Closed source Xplatform audio library – FMOD is a programming library and toolkit for the creation and playback of interactive audio. – MP3/WAV/MIDI playback – 3D Audio – Occlusion/doppler/effects etc – Free for non-commercial use
  • 6. • Bullet – Bullet 3D Game Multiphysics Library provides state of the art collision detection, soft body and rigid body dynamics. – Rigid bodies, constraints etc – A solver • C++ – Smart pointers – shared pointers – STL • git – Labs, lectures, solutions – Git/github is amazing. You should use it. – Mandated for all DT228/DT211 students now
  • 7. How are 3D Graphics Rendered in BGE? Vertex data in world space Vertex shader Textures Model/World Matrix View Matrix Projection Matrix Normal Matrix MVP Matrix Fragment Shader Screen
  • 8. I prefer… Vertices The vertices as they come out of a 3D modelling program. The centre of the model is usually the origin Model /World Places the model in the world relative to all the other objects View Transforms everything relative to the camera (0,0,0) looking down the –Z Axis Projection Viewport Clipping Projects Often does everything nothing special onto a but can be 2D plane. a different Far away render target objects are (such as a texture) smaller
  • 9. Calculating the world transform • Combination of the position, orientation and scale – Position & scale & vectors – Orientation is a quaternion • world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1), scale);
  • 11. Calculating the View Transform view = glm::lookAt( position , position + look , basisUp ); GLM_FUNC_QUALIFIER detail::tmat4x4<T> lookAt ( detail::tvec3<T> const & eye, detail::tvec3<T> const & center, detail::tvec3<T> const & up )
  • 12. Calculating the Projection Transform • projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 10000.0f); GLM_FUNC_QUALIFIER detail::tmat4x4<valType> perspective ( valType const & fovy, valType const & aspect, valType const & zNear, valType const & zFar )
  • 13. The Game loop • Initialise() • While (true) – Update(timeDelta) – Draw() • End while • Cleanup()
  • 14. What are design patterns? • A very famous book • Published in 1994 • Common solutions to problems in software developmnent • Part 1 – The capabilities and pitfalls of object-oriented programming • Part 2 – 23 classic software design patterns
  • 15. Principles • Program to an 'interface', not an 'implementation‘ – – • • Interfaces lead to dynamic binding and polymorphism (central features of objectoriented programming). Inheritance is referred to as white-box reuse – • • The internals of parent classes are often visible to subclasses Object composition is black-box reuse – • Clients are unaware of the specific types of objects they use, as long as the object adheres to the interface Clients remain unaware of the classes that implement these objects; clients only know about the abstract class(es) defining the interface No internal details of composed objects need be visible in the code using them "Because inheritance exposes a subclass to details of its parent's implementation, it's often said that 'inheritance breaks encapsulation'“ Using inheritance is recommended mainly when adding to the functionality of existing components, reusing most of the old code and adding relatively small amounts of new code
  • 16. Some examples • Creational – Factory – Prototype – Singleton • Structural – – – – Adapter Composite Decorator Proxy • Behaviorable – – – – Interpreter Iterator Observer State
  • 17. Some more! • Lazy loading – Loading on demand. Defer initialization of an object until the point at which it is needed • Instancing – Rendering multiple copies of the same mesh in a scene at once • Controller – Update a game objects state based on circumstance
  • 18. Some goals for BGE (or any other game engine) • Keep track of everything in the scene • Allow game objects to be assembled from components – increase code reuse and flexibility • Allow easy creation of composite objects such as physics objects • Allow lazy loading of game assets • Support instancing • State management of game components
  • 19. Object Oriented Game Engines • Are terrible. I know I made one (Dalek World) • Consider:
  • 20. Problems! • Each new piece of functionality you want to add to a class becomes a new (more specific class) • Too many classes • No flexibility • Tight coupling
  • 21. A better approach • The aggregate design pattern Game Component Initialise() Update(timeDelta) Draw() Cleanup() Attach(GameComponent c) list<GameComponent> children 0..*
  • 22. Architecture? • GameObjects, GameComponents and Transforms – Circular dependancies – Difficult to compile in C++ • GameComponents with own transforms – Rules for copying transforms – Lots of duplication • GameComponents with shared transforms – BGENA2 – How to store transform hierarchies? – Duplicated calculations
  • 23. Component Based Games Engines • Everything in BGE is a component • Most things extend GameComponent – – – – virtual bool Initialise(); virtual void Update(float timeDelta); virtual void Draw(); virtual void Cleanup(); • GameComponent’s keep track of a list of children components & parent component – std::list<std::shared_ptr<GameComponent>> children; • This is known as the aggregate design pattern
  • 24. Each GameComponent has: • GameComponent * parent; • glm::vec3 velocity; • std::list<std::shared_ptr<GameComponent>> children; • std::shared_ptr<Transform> transform; • Shared!
  • 25. The base class GameComponent • • • • • Holds a list of GameComponent children references Use Attach() to add something to the list. Calls Initialise, Update and Draw on all children All subclasses do their own work first then Must call the base class member function so that the children get Initialised, Updated and Drawn! – Are these depth first or breadth first? • This means that the scene is a graph of objects each contained by a parent object • The parent object in BGE is the Game instance
  • 26. bool GameComponent::Initialise() { // Initialise all the children std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin(); while (it != children.end()) { (*it ++)->initialised = (*it)->Initialise(); } return true; }
  • 27. void GameComponent::Cleanup() { // Cleanup all the children std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin(); while (it != children.end()) { (*it ++)->Cleanup(); } } void GameComponent::Draw() { // Draw all the children std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin(); while (it != children.end()) { if ((*it)->worldMode == GameComponent::from_parent) { (*it)->parent = this; (*it)->UpdateFromParent(); } (*it ++)->Draw(); The child object is } } controlled by the parent it is attached to An example is a model
  • 28. void GameComponent::Update(float timeDelta) { switch (worldMode) { case world_modes::from_self: world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1), scale); break; case world_modes::from_self_with_parent: world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * glm::scale(glm::mat4(1), scale); if (parent != NULL) { world = (glm::translate(glm::mat4(1), parent->position) * glm::mat4_cast(parent->orientation)) * world; } break; case world_modes::to_parent: world = glm::translate(glm::mat4(1), position) * glm::mat4_cast(orientation) * parent->world = glm::scale(world, parent->scale); parent->position = this->position; parent->up = this->up; parent->look = this->look; parent->right = this->right; parent->orientation = this->orientation; glm::scale(glm::mat4(1), scale); break; } RecalculateVectors(); moved = false; // Update all the children std::list<std::shared_ptr<GameComponent>>::iterator it = children.begin(); while (it != children.end()) { if (!(*it)->alive) { it = children.erase(it); } else { (*it ++)->Update(timeDelta); } } } The parent is controlled by a child The child is known as a Controller
  • 29.
  • 30. Attaching! • You can attach a component to another component: child->parent = this; // All my children share the same transform if they dont already have one... if (child->transform == nullptr) { child->transform = transform; } children.push_back(child);
  • 32. Member functions • void Strafe(float units); • void Fly(float units); • void Walk(float units); • void Pitch(float angle); // rotate on right vector • void Yaw(float angle); // rotate on up vector • void Roll(float angle); // rotate on look vector
  • 33. Yaw Example • void GameComponent::Yaw(float angle) • { • // A yaw is a rotation around the global up vector • glm::quat rot = glm::angleAxis(angle, GameComponent::basisUp); • orientation = rot * orientation; • }
  • 34.
  • 35. Making game objects from components • You can use these rules to assemble composite objects together. For example: – A component with a model attached and a steeringcontroller attached – The steeringcontroller shares the parent world transform – The model gets its world from the parent – You can attach different controllers to get different effects. – Examples…
  • 36.
  • 37. Using steeringbehaviours • SteeringController implements lots of cool steering behaviours such as follow_path, seek, obstacle_avoidance • Can be attached to anything and it will update the world transform of the thing it’s attached to • See 9 & 11 for examples • 12 is just a textured model. Nothing special • An example in code…
  • 38. • • • • • • • • • • • • • • • • • • • //// from_self_with_parent station = make_shared<GameComponent>(); station->worldMode = world_modes::from_self; station->ambient = glm::vec3(0.2f, 0.2, 0.2f); station->specular = glm::vec3(0,0,0); station->scale = glm::vec3(1,1,1); std::shared_ptr<Model> cmodel = Content::LoadModel("coriolis", glm::rotate(glm::mat4(1), 90.0f, GameComponent::basisUp)); station->Attach(cmodel); station->Attach(make_shared<VectorDrawer>(glm::vec3(5,5,5))); Attach(station); // Add a child to the station and update by including the parent's world transform std::shared_ptr<GameComponent> ship1 = make_shared<GameComponent>(); ship1->worldMode = world_modes::from_self_with_parent; ship1->ambient = glm::vec3(0.2f, 0.2, 0.2f); ship1->specular = glm::vec3(1.2f, 1.2f, 1.2f); std::shared_ptr<Model> ana = Content::LoadModel("anaconda", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp)); ship1->Attach(ana); ship1->position = glm::vec3(0, 0, -10); // NOTE the ship is attached to the station at an offset of 10 station->Attach(ship1);.
  • 39. VR • Render the scene twice – Left eye and right eye • Split the screen in two • Combine quaternion from Xbox controller with quaternion from rift
  • 40. What I learned • • • • • • • • OpenGL Shaders Game engine deisign OO with components Git Circular depedancies 2 leap motion projects, 5 pull requests! I love programming!