Download presentation
Presentation is loading. Please wait.
1
Lecture 3: G.O. architecture + Polymorphism
2
Goal GameObject (GO) class Similar to Unity
Contains transformation info As a matrix T * S * R (right-handed) “Snap-in” Components Many of which are Ogre-wrappers LightComponent EntityComponent ParticleEmitterComponent BillboardComponent … Broadcasting messages Parent / Child relationship Unity Hierarchy
3
First attempt class GameObject { protected: ??? mTransformation; ??? mComponents; public: setPosition(???); … addMeshComponent(???); addCameraComponent(???); };
4
The Transformation part
Ogre SceneNode Methods for creating Getting via SceneManager. Methods for setting position, scale, orientation Methods for modifying position, scale, rotation Parenting SceneNodes Attaching Stuff Role of MoveableObject class. Detaching objects Destroying the scene node
5
Tangent_1: C++ Inheritance
a.h a.cpp class A { protected: int mValue; public: A(int x); ~A(); void foo(); }; #include <a.h> A::A(int x) : mX(x) { cout << “A(“ << x << “)!\n”; } // Same thing, but less efficient //A::A(int x) //{ // mX = x; // or this->mX = x; //} A::~A() cout << “A(“ << mX << “)vv\n”; void A::foo() cout << “AAA” << endl;
6
Tangent_1: C++ Inheritance
b.h b.cpp class B : public A { public: B(int x); ~B(); void foo(); }; #include <b.h> // We *must* do this – see why? B::B(int x) : A(x) { cout << “B(“ << mX << “)!\n”; } B::~B() cout << “B(“ << mX << “)vv\n”; void A::foo() cout << “BBB” << endl;
7
Tangent_2: C++ Polymorphism
Ability to assign address of derived class to base-class pointer [Trace output of this snippet] A* val1 = new A(15); B* val2 = new B(16); A* val3 = val2; // !!! val1->foo(); val2->foo(); val3->foo(); // !!! // Don’t forget these! delete val1; delete val2; // delete val3; // !!!
8
Tangent_2: C++ Polymorphism
Why didn’t val3->foo() do what we thought? Static linkage (static resolution) We (here) want dynamic resolution To get it… class A { protected: int mValue; public: A(int x); virtual ~A(); virtual void foo(); };
9
Tangent_2: C++ Polymorphism
Role of virtual function table (vfptr) Reason for virtual destructor? Can put virtual in derived class When is it necessary?
10
Tangent_3: Pure virtual
Syntax: virtual void func() = 0; Similar to Java abstract method When to use it.
11
back to GO I want a Component class
And multiple derived classes (eventually) MeshComponent SoundComponent CameraComponent LightComponent … We need a place to store them DD: Multiple components vs. one-only. DD: How to store / access them (recommend map) DD: Who creates them?
12
Discuss architecture …
13
Ogre Entity An instance of a mesh
Built-in functionality for (binary) .mesh There are exporters for Blender / Maya / etc. Code to load them Code to attach them to SceneNodes
14
tangent_4: circular includes
[On board]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.