Ambient Animation Entity

From C4 Engine Wiki

Jump to: navigation, search

Contents

Overview

AmbientAnimController

This article adds a new controller to the MGGame module. This code is designed so that there is minimal code changes to the MGGame Module, however a few minor changes are still required. Also included is an animated model for quick testing.


Important user Information

Version

  • The current release is v0.5 .Unreleased on main wiki.
  • Next release v1.0 Stable, Release on wiki.
  • Next release v1.2 Add in new features to expose interpolator values i.e speed, loop count, any other important values.
  • Next release v1.3 Add in file picker to select the animation rather than type in the animation.
  • Next release v1.4 Player is effected by the movement of the objects, animation, essentially a mover (Just a thought for now).


Level of Difficulty:

  • Easy


Pre requisites:

  • C4 ready to be compiled.
  • No programming experience necessary, but an advantage.
  • Some compiler knowledge is assumed -Adding in files to the project, setting up C4 with visual C++ or there of, and compiling.


Tools Required:

  • Microsoft VC++ 2005 or higher
  • WinRar
  • Internet connection
  • Build 145 and Licence of C4. Previous versions not supported, although may work.
  • Source code from Bleeding Colour Studio. Download source here.


The following files are modified for this tutorial:

  • MGGame.cpp
  • MGGame.h


Source Code Additions:

  • AnimatedObject.cpp
  • AnimatedObject.h


Files included:

  • GameCode/AnimatedObject.cpp
  • GameCode/AnimatedObject.h
  • Data/Ambient/SpaceCraft/ufo.mdl
  • Data/Ambient/SpaceCraft/ambient.anm


Where to modify:

Look for the START and FINISH comments as shown below. Any code outside these tags is existing code and is left there to help you find the correct location of the modification and does not need to be added in.

existing code here, DONT ADD......
 
//Ambient Animation START 

code to add here......

//Ambient Animation FINISH. 

existing code here, DONT ADD......


First things first

Place the files in the correct location:

  • Place the files included in the above download within your C4 directory.
  • Using your compiler add the source files AnimatedObject.cpp and AnimatedObject.h into your MGGame project.


Modifying the Source code

In MGGame.h

  • Add this include line at the top with the rest of the includes.


#include "MGWeather.h"
#include "MGPumpkinhead.h"
#include "MGSoldier.h"

//Ambient Animation START 

#include "AnimatedObject.h"

//Ambient Animation FINISH 
  • In the C4 namespace (under locator types enum for example) add the following code. NB This is specific to the supplied entity, else you would use the type name of your animated entity.
//Ambient Animation START 

enum
{
      kEntityUFO	= 'aufo'
};

//Ambient Animation FINISH 


  • In the class class Game : public Singleton<Game>, public Application add the following code with the other Controller Registrations.
//Ambient Animation START 

ControllerReg<AmbientAnimController>	ambientAnimController;

//Ambient Animation FINISH 
  • A little further below add the following code for the entity registration. NB This is specific to the supplied entity, else you would use the name of your animated entity.
//Ambient Animation START

   //NB This is specific to the supplied entity, else you would use the name of your animated entity.
   EntityRegistration                   entityUFO;
                        
//Ambient Animation FINISH


In MGGame.cpp

  • In the constructor of the Game::Game() :Singleton<Game>(TheGame), add the following code. The first line is essential, but the following line is an entity registration and should only be used for the test entity provided.
     rotationControllerReg(kControllerRotation, stringTable.GetString(StringID('CTRL', kControllerRotation))),

//Ambient Animation START

     ambientAnimController(kControllerAmbientAnim, "Ambient Animation"),

     //NB This is specific to the supplied entity, else you would use the name of your animated entity.
     entityUFO(kEntityUFO, "SpaceCraft/ufo", kEntityPrecache), 

//Ambient Animation FINISH


World editor

  • Using the World Editor, from the Entities page place the entity in the world. Hit Ctrl-i to bring up the properties dialig box.
  • Select the Controller tab.
  • Select Ambient Animation in the list of available controllers.
  • In the Ambient section type in the path and animation name of your model. Use SpaceCraft/ambient for the model provided. TODO use a dialog to select the model
  • In the list of available properties for the controller select the option\s you require i.e. loop on/off.
  • Click OK.
  • The loop and backwards flags have not been tested yet, but should work. EDIT: Tim, these don't work.--Frank Skilton 21:45, 19 January 2008 (PST)
  • Save and run the world.
  • Watch in awe as your models animaton plays!!!


Available Animation Options

  • Animation Loop - The animation will loop continously.
  • Play Animation Backwards - The animation will play backwards.
  • TODO Play Animation Ocilate - The Animation will ocilate. Animtion Loop and Play Animation Backwards will be disabled.
  • TODO loop Times - The number of times the animation will play. If this is anything other than -1, Animation Loop will be disabled.
  • TODO Animation Speed - Adjust the slider to increase/decrease the animation speed.
Personal tools