Sign in to follow this  

Designing a 3D effect class

Recommended Posts

Farraj    152
Hi everyone, I have a question on how to manage effects in a 3D environment. What I mean by effects here is everything from a camp fire and explosions to magical spells and circles. How would you actually design the class for this? I thought about only making effects out of particle systems but that seemed a bit limiting. I’ve seen effects that use billboards and animations and I would like to include those too. I want it to be as flexible as possible. I can’t find any good documentation on this. Any help would be appreciated. Cheers :)

Share this post

Link to post
Share on other sites
Farraj    152
Thanks for the input (new info ^^) but that's not what I'm looking for.

I was thinking in the context of adding the effect as an game object or entity that handles events and gets update by time. Something like the below:

CEffect *effect = CEffectManager::GetInstance()->GetEffect("Fire");
CEntityManager::GetInstance()->AddEntity(effect); // the CEffect is inheirted from the CEntity class also

How would I design an effect manager that stores effects then make an instance of them to be used in scene manager.

I think the most confusing part for me is how can I make the CEffect class play more than one effect (like particles, billboards, etc...) and their animations? Plus what would be the methods used in it (e.g.: SetLoop(), SetTimeToDie(), etc...)?


Share this post

Link to post
Share on other sites
haegarr    7372
IMHO answering your question isn't that easy, since it depends on the overall structure of your engine.

E.g. an effect first is a specialized kind of Resource. Resources itself are (for the sake of clarity, since they are not really) to be understood as assets here. They are not any Resource but a Prototype. As such they can be instantiated, and all instances share some data stored in the Prototype, but also have some own data stored with the instance.

That said, an Effect is an Instance and hence can be integrated into the Scene(-graph), so making the Effect existing in the game world. Notice please that this is a logical view on the world.

During instantiation, a Timeline::Track is added to the timeline. Associating the Effect with the track makes the Effect affectable by time in principle. So the timeline defines the "timed view" on the scene. At any time then a Animation can be added as Timeline::Task to the said track, making the Effect actually time dependend. Since the timeline is advanced at each game loop turn-around, the Effect advances (e.g. in its look) until the Animation has ended and gets removed from the timeline's track.

In summary, the classes look roughly like this:
EffectPrototype <==(is a)== Prototype <==(is a)== Resource
Effect <==(is a)== Instance <==(is a)== SceneNode
EffectPrototype --(instantiates)--> Effect
Effect::Animation <==(is a)== Animation <==(is a)== Timeline::Task
Effect::Animation --(handles)--> Effect

The actual trigger to start an Effect is done normally by scripting or by activating a Trigger object.

Whether or not this way is practical for you is not the point here, but you see a couple of interdependencies with the system (e.g. the existance of different views on the game, from which I've mentioned the logical and the temporal one). In other words, the logic of how an effect is handled and the philosophy of the engine's implementation are accompanying.

EDIT: To come a bit closer to your last recent question, in my set-up the existance of an Animation in the Timeline is effectively the part responsible for driving the animation. Whether this is a billboard showing a transitive texture, or a linkage/skeleton influenced by forward kinematics (e.g. ipos stored with the animation) or whatever, is unimportant from the POV of the timeline. Creating other kinds of effects means to specialize EffectPrototype, Effect and Effect::Animation.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this