Click here to Skip to main content
13,554,611 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 19 Oct 2012
Licenced CPOL

A 3D RPG Based on Ogre and ODE

, 18 Apr 2013
Rate this:
Please Sign up or sign in to vote.
A 3D Game Based on Ogre, ODE, 3D Max, CEGUI and so on.


In this article, I introduce a solution of 3D RPG based on Ogre Graphics Engine, ODE Physics Engine, CEGUI, and other tools. The framework is described and the full resource and source code is on


Space Knight is a cartoon I  watched when I was a child and I 'm also a game fan. So I use what I learned before to develop the cartoon to an RPG. Here displaying what lib I used in my game: 

  • Ogre: I use Ogre as the Graphics Engine. It can choose DirectX or OpenGL to render the scene.
  • OED: I use OgreOde which combines the Ogre with the ODE to build the physical world in my game.
  • CEGUI: It is used to construct the UI in the game such as main menu, trade menu, function menu etc.
  • 3D Max: The models in our game is built by 3D Max and is exported by a  plugin. 
  • DirectShow and Fmod: They are used to play the video and the audio. 

Using the code

As told before, the application  bases on several libs. Here are the UML figure of my game framework. 

There are several module in the application, There are Mission Module, Role Module, AI Module, UI Module,  Tool Module and Media Module.

The Mission Module controls the mission of the game and it contains the BaseMission class, FirstMission class and etc. Each class represents a mission in the game. The base class also control the most modules.

The Role Module controls the players in the game such as the main player, space knight, the monster Lada, the NPC, and etc. These entities are managed by the entity manager and are checked if they have collision in each frame. The part of Role Module is also controlled by the AI Module. 

The AI Module uses state machine to simulate the role's AI. Each role having the AI has its own state class and the class defines its behaviors. It can be easily changed and extended. 

The UI Module using CEGUI to display the UI of the game. It receive the input from the user and post the message to other modules. It uses OIS to receive the keyboard message and the mouse message.  Each menu on the screen is a script file rendered by CEGUI. 

The Tool Module controls the tools, medicines and other objects in the game such as the chest on the road or the  opening door.  Most tools are built by the status from the XML file.  

The Media Module is a simple adapter of Fmod and DirectShow. It play the sound of the battle or the background and the video of the opening play.

The base class of the mission contains a lot of members and functions. It uses the UI module to display the menu, the Media module to play the sound, the Role module to update the entities. It also builds the graphic world and the physical world. It has the function to move to the next mission, load the saved mission or game over. 

The state machine shows it contains three main state the previous state, the current state and the global state. The state has four behavior Enter, Exit, Execute, and OnMessage. If a role receive a message and it give to the state machine it let the current state execute and transfer to the next state. 

//Here is the Base Mission class

class BaseMission:         
    public OgreOde::CollisionListener, 
    public OgreOde::StepListener, 
    public OgreOde::TriangleMeshRayListener

    OgreOde::World                       *mWorld;
    OgreOde::Space                       *mSpace;
    OgreOde::StepHandler                 *mStepper;
    OgreOde::TriangleMeshGeometry* terrainTriMeshGeom;

    OgreOde::InfinitePlaneGeometry *mGround; 

    GameFrame *gameFrame;

    Ogre::Root*              mRoot;
    Ogre::Camera*          mCamera;
    Ogre::SceneManager*      mSceneMgr;
    Ogre::RenderWindow*      mWindow;
    CEGUI::System*   mGUISystem;

    FrameListener* mFrameListener;
    BaseMissionListener* mMissionListener;
    GuiListener *mGuiListener;

    Overlay *talkOverlay,*gameOverlay,*blackOverlay,*loadingOverlay,*missionIntruOverlay;

    CEGUI::Window* gameSheet,* opSheet,* quitSheet,
        * gameOverSheet,* loadSheet,* intruduceSheet,
        * useButton,*noUseButton,* currentPackage;

    std::vector<AnimationState *> animationStates;
    std::vector<Model *> mModels;
    std::vector<OgreOde::Geometry*> mGeoms;
    std::vector<SceneNode*> nodes;
    std::vector<StaticThing*> staticThings;
    std::vector<Role*> monsters;

    Role *mainModel;
    BaseSound *mSound;
    SceneNode * _rocket_node_explosion;
    ParticleSystem * _rocketParticles_explosion;
public :
    BaseMission(Ogre::RenderWindow* mW, Ogre::Root* mR, Ogre::Camera* mC, 
                 Ogre::SceneManager* mS,CEGUI::System*   mG,GameFrame *);
    virtual void Render();
    virtual void Clean();
    virtual void InitObjects();
    virtual void createFrameListener();

    virtual void NextMission();
    virtual void upDate();
    virtual void createScene();
    virtual void UpdateGUI(void);
    virtual void initDemoEventWiring(void);


    Ogre::SceneManager* getSceneManager(void) const { return mSceneMgr; }
    Ogre::RenderWindow* getRenderWindow(void) const { return mWindow; }
    void resetParticleSystem(Ogre::ParticleSystem *ps, bool enable, const Ogre::Real delay);

    virtual void GameOver();
    void LoadGame(int i);

// Here is part of the state machine of the AI in the game.
template <class entity_type>
class StateMachine
    entity_type *m_pOwner;
    State<entity_type> *m_pCurrentState;
    State<entity_type> *m_pPreviousState;
    State<entity_type> *m_pGlobalState;
    StateMachine(entity_type *owner):m_pOwner(owner),

    void SetCurrentState(State<entity_type> *s){m_pCurrentState = s;}
    void SetPreviousState(State<entity_type> *s){m_pPreviousState = s;}
    void SetGlobalState(State<entity_type> *s){m_pGlobalState = s;}

template <class entity_type>
class State
    virtual bool OnMessage(entity_type *,Telegram &msg) = 0;
    virtual void Enter(entity_type *) = 0;
    virtual void Exit(entity_type *) = 0;
    virtual void Execute(entity_type *) = 0;
    virtual ~State(){}

Operation and Result

The operation of the game:

  • Move: W, A, S, D
  • Fire: mouse, Z, C, V
  • Mission Pass: Y
  • Menu: F1 

Our game has seven missions which include two boss mission and one transfer mission. Here shows some picture of my game. 

The main menu of the game.

The player beat a monster.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Student Institute of Software, Chinese Academy of Sciences
China China
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionMissing files? Pin
mz850406431-Jan-14 17:08
membermz850406431-Jan-14 17:08 
BugGithub repository spoiled! Pin
Innos_mage20-Apr-13 9:15
memberInnos_mage20-Apr-13 9:15 
GeneralRe: Github repository spoiled! Pin
Sasa Kajic22-Apr-13 1:21
memberSasa Kajic22-Apr-13 1:21 
QuestionCan you add downloads to the executables? Pin
Paulo Zemek18-Apr-13 12:54
memberPaulo Zemek18-Apr-13 12:54 
GeneralNice project Pin
Espen Harlinn18-Apr-13 10:58
mvpEspen Harlinn18-Apr-13 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 18 Apr 2013
Article Copyright 2012 by lxdfigo
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid