Archived

This topic is now archived and is closed to further replies.

GekkoCube

Simple derived classes and their design.

Recommended Posts

Im not sure how to design my engine. I have 3d models display in my world, and would like them to do different things based on some criteria (AI). So i create an AI class, and quickly realized that I should create a sub class that derives from AI, AI_MD2. Class AI has several methods. And im trying to use those methods thru an instance of AI_MD2. I get errors, compiler complains about not being able to access public members from the method. Why? Finally, am I appreaching this whole AI thing correctly? I created the sub class, AI_MD2, because all my model specific stuff, such as animations/frames, states,...etc should be kept in a nice data structure - the class! Even better...is there a sample/demo/tutorial on game AI with some sourcecode? that would help a thousand times more. Thanks. ~ I am a DirectX to OpenGL convert! ~

Share this post


Link to post
Share on other sites
quote:
Original post by GekkoCube
I have 3d models display in my world, and would like them to do different things based on some criteria (AI).



Either use templates as a Policy class
template <class AI_Type> class Model {...}
or give the Model class a member pointer to the base AI class, with derived AI classes implementing different behaviours.

quote:

So i create an AI class, and quickly realized that I should create a sub class that derives from AI, AI_MD2.
...
I created the sub class, AI_MD2, because all my model specific stuff, such as animations/frames, states,...etc should be kept in a nice data structure - the class!



What does animation and such "model specific stuff" has to do with AI ? It should be held in the "Model" class, which has an AI, not is an AI.

Inheritance = is a, Aggregation = has a.

quote:

Class AI has several methods. And im trying to use those methods thru an instance of AI_MD2. I get errors, compiler complains about not being able to access public members from the method. Why?


Without seeing the code/declarations... who knows.

quote:

Finally, am I appreaching this whole AI thing correctly?


The model should ask the AI what to do, based on it current situation; then the model does it.

quote:

~ I am a DirectX to OpenGL convert! ~



Good !

Share this post


Link to post
Share on other sites