Night Elf
27-08-2007 17:01:33
Night Elf
27-08-2007 17:01:33
betajaen
27-08-2007 17:06:41
Night Elf
27-08-2007 17:12:27
betajaen
27-08-2007 17:36:47
Night Elf
27-08-2007 17:43:27
betajaen
27-08-2007 17:56:22
Night Elf
27-08-2007 18:39:47
The Body class a great example of this, and you can copy and paste it into your own application (change the name of course), and use that as your physics game object.
Body* body = new Body(identifier, this, firstShapeDescription, pose, params);
mActors.lock(body->getName(), true);
return body;
betajaen
27-08-2007 18:48:42
class NxExport IActor : public Actor {
public:
// Constructors similar to. Used for creating a NxActor by hand through a blueprint,
// or the NxuStream tool
IActor(const NxString& name, Scene*);
// Constructors similar to. Normal Everyday Constructor.
// Name, Scene, ShapeBlueprint, Pose, ActorParams are required by Actor, so they
// must be part of your constructor.
IActor(const NxString& name, Scene*, ShapeBlueprint*, const Pose&, ActorParams = "");
// Destructor.
virtual ~IActor();
// Your IActor may have some visualisation.
virtual bool hasVisualisation() const {return true;}
// to call ShapeSimulate
void simulate(float);
// to call ShapeRender, and to render your visualisation.
void render(float);
// Save any custom data related to your Inherited Actor to a StringPairList
StringPairList saveCustom();
// Restore any custom data to your Inherited Actor.
void restoreCustom(StringPairList);
};
IActor::IActor(const NxString& name, Scene* scene) : Actor(name, scene) {
// Do nothing. Not even your own visualisation. RestoreCustom will kick in soon to handle that.
}
IActor::IActor(const NxString& identifier, Scene* scene, ShapeBlueprint *firstShapeDescription, const Pose& pose, ActorParams params)
: Actor(identifier, scene, firstShapeDescription, pose, params) {
// Setup visualisation stuff here.
// You can access the SceneManager from mOwner->getSceneMgr()
}
IActor::~IActor {
// Clean up your visualisation here. The destructor in Actor will clean up the NxActor stuff.
}
void IActor::simulate(float dT) {
// Required...
if (mActor) {
shapeSimulate(dT);
}
}
void IActor::render(float dT) {
// You can get the Position and Orientation of the NxActor using:
// getGlobalPosition();
// getGlobalOrientation();
//
// If you have NX_UNSTABLE_USE_SCENE_ACTIVE_TRANSFORM on, render will only be called
// if the NxActor has moved.
}
StringPairList IActor::saveCustom() {
// Required...
StringPairList l;
l.insert("ActorType", "IActor"); // IActor or the name of your class; *Not* Actor or Body.
l.insert("Key", "Value");
// You can have multiple keys with the same name.
}
void IActor::restoreCustom(StringPairList spl) {
for (StringPairList::StringPair sp = spl.begin();spl.hasNext();) {
sp = spl.next();
NxString key = sp.first;
NxString value = sp.second;
Ogre::StringUtil::toLowerCase(key);
if (key == "x") {
mY = value;
}
}
class SomeGameManagerClass {
typedef NxOgre::Container<NxString, IActor*> IActors;
IActors mActors;
};
// Create a new IActor.
IActor* iactor = new IActor("name", mScene, new CubeShape(1), Vector3::ZERO, "mass: 10");
// Store the pointer in IActors.
mIActors.insert(iactor->getName(), iactor);
// A copy of the IActor has been placed in mScene::mActors. NxOgre does not "own" the class we do. So we are responsible for deleting it.
// To own the IActor, we must "lock" it.
IActors.lock(iactor->getName(), true);
mIActors.destroyAllOwned();
mWorld->destroyScene(mScene->getName());
mIActors.destroyAllOwned();
delete mWorld;
frier
27-08-2007 18:50:29
I recommend anyone who is seriously using NxOgre to have there own "Inherited Actor" class in their game engine or application.
I'll walk you through it if you like.
betajaen
27-08-2007 18:53:08
Caphalor
27-08-2007 19:09:38
Night Elf
27-08-2007 19:11:52
frier
27-08-2007 19:22:54
betajaen
27-08-2007 19:25:45
betajaen
27-08-2007 19:26:31
So i could create.. say a iCarActor class.
i can then implement my own methods that do the following:
- Lock Y axis on the actor if its in mid air(not colliding with anything) and do a sound while your at it.
- It also will know how to create a common basic vehicle for my project using other inherited nxOgre classes(like the one i just make for AllWheelDrive) as members?
Night Elf
27-08-2007 19:54:40
No, Triggers are quite specific. The TriggerCallback system is quite extensive as it is, I'm sure you can adapt to it.
frier
27-08-2007 20:03:45
Error 1 error C2555: 'BugActor::saveCustom': overriding virtual function return type differs and is not covariant from 'NxOgre::Actor::saveCustom' c:\dev\nxogre\tutorials\compiler\source\bugactor.h 36
Warning 1 warning C4273: 'BugActor::BugActor' : inconsistent dll linkage c:\dev\nxogre\tutorials\compiler\source\bugactor.cpp 3
betajaen
27-08-2007 20:38:22
Night Elf
27-08-2007 20:57:45
@Night Elf
Ogre doesn't have anything like that, it just expects to you to get along with SceneNodes as it is. I would like it to be the same with Actor.
Can't you use the name of the Actor as some sort of, I dunno an identifier.
At least then you can use it to look up the IActor, in GameManagerObject::IActors.
frier
31-08-2007 03:08:54
NxString iActor::saveCustom()
void iActor::restoreCustom(StringPairList spl)
StringPairList iActor::saveCustom();
virtual NxString NxOgreActor::saveCustom()
betajaen
31-08-2007 10:55:29
luis
31-08-2007 11:59:26
Detailed Description
This class is designed to be subclassed by OGRE users, to allow them to associate their own application objects with MovableObject instances in the engine.
Remarks:
It's always been suggested that an OGRE application would likley comprise a number of game objects which would keep pointers to OGRE objects in order to maintain the link. However, in some cases it would be very useful to be able to navigate directly from an OGRE instance back to a custom application object. This abstract class exists for this purpose; MovableObjects hold a pointer to a UserDefinedObject instance, which application writers subclass in order to include their own attributes. Your game objects themselves may be subclasses of this class, or your subclasses may merely be a link between them.
Because OGRE never uses instances of this object itself, there is very little definition to this class; the application is expected to add all the detail it wants. However, as a hint, and for debugging purposes, this class does define a 'type id', which it is recommended you use to differentiate between your subclasses, if you have more than one type.
luis
31-08-2007 13:07:20
frier
31-08-2007 14:12:47
betajaen
31-08-2007 14:18:15
frier
31-08-2007 14:23:49
Night Elf
31-08-2007 15:39:38
Index: NxOgre/include/NxOgreActor.h
===================================================================
--- NxOgre/include/NxOgreActor.h (revision 34)
+++ NxOgre/include/NxOgreActor.h (working copy)
@@ -536,6 +536,8 @@
private:
+ public:
+ CustomData* mCustomData;
};// End of Actor Class
Index: NxOgre/include/NxOgreCharacter.h
===================================================================
--- NxOgre/include/NxOgreCharacter.h (revision 34)
+++ NxOgre/include/NxOgreCharacter.h (working copy)
@@ -148,6 +148,8 @@
private:
+ public:
+ CustomData* mCustomData;
};
Index: NxOgre/include/NxOgrePrerequisites.h
===================================================================
--- NxOgre/include/NxOgrePrerequisites.h (revision 34)
+++ NxOgre/include/NxOgrePrerequisites.h (working copy)
@@ -333,6 +333,11 @@
////////////////////////////////////////////////////////
+ // Used to store custom user data in Actors, Characters and Triggers.
+ // User can freely subclass to their own needs.
+ class CustomData
+ {
+ };
};
#endif
Index: NxOgre/include/NxOgreTrigger.h
===================================================================
--- NxOgre/include/NxOgreTrigger.h (revision 34)
+++ NxOgre/include/NxOgreTrigger.h (working copy)
@@ -257,6 +257,8 @@
TriggerCallback* mCallback;
bool mCallbackOwned;
+ public:
+ CustomData* mCustomData;
};
//////////////////////////////////////////////////////////
Index: NxOgre/source/NxOgreActor.cpp
===================================================================
--- NxOgre/source/NxOgreActor.cpp (revision 34)
+++ NxOgre/source/NxOgreActor.cpp (working copy)
@@ -167,7 +167,7 @@
//////////////////////////////////////////////////////////
-Actor::Actor(const NxString& Identifier, Scene* scene, bool isActorBased) : mName(Identifier), mOwner(scene) {
+Actor::Actor(const NxString& Identifier, Scene* scene, bool isActorBased) : mName(Identifier), mOwner(scene), mCustomData(0) {
mActor = 0;
if (isActorBased)
mOwner->_registerActor(mName, this);
@@ -175,7 +175,7 @@
//////////////////////////////////////////////////////////
-Actor::Actor(const NxString& name, Scene* scene, ShapeBlueprint *shape, const Pose& pose, ActorParams params) : mName(name), mOwner(scene) {
+Actor::Actor(const NxString& name, Scene* scene, ShapeBlueprint *shape, const Pose& pose, ActorParams params) : mName(name), mOwner(scene), mCustomData(0) {
if (scene->getActors()->has(name)) {
Index: NxOgre/source/NxOgreCharacter.cpp
===================================================================
--- NxOgre/source/NxOgreCharacter.cpp (revision 34)
+++ NxOgre/source/NxOgreCharacter.cpp (working copy)
@@ -37,7 +37,7 @@
////////////////////////////////////////////////////////////////////////////////////////////////
Character::Character(const NxString &name, Scene* scene, CharacterController* cc, Pose p , CharacterParams cp)
-: mName(name), mScene(scene), mCharacterController(cc), mNode(0), mEntity(0) {
+: mName(name), mScene(scene), mCharacterController(cc), mNode(0), mEntity(0), mCustomData(0) {
mMoveVectorController = mCharacterController;
mCharacterController->_registerCharacter(mName, this);
Index: NxOgre/source/NxOgreTrigger.cpp
===================================================================
--- NxOgre/source/NxOgreTrigger.cpp (revision 34)
+++ NxOgre/source/NxOgreTrigger.cpp (working copy)
@@ -32,7 +32,7 @@
//////////////////////////////////////////////////////////////////////
-Trigger::Trigger(const NxString& identifier, Scene* scene, ShapeBlueprint* shape, const Pose& pose, ActorParams params) : Actor(identifier, scene, false) {
+Trigger::Trigger(const NxString& identifier, Scene* scene, ShapeBlueprint* shape, const Pose& pose, ActorParams params) : Actor(identifier, scene, false), mCustomData(0) {
_createActor(shape, pose, params);
mOwner->_registerTrigger(mName, this);
}
betajaen
31-08-2007 16:11:57
betajaen
31-08-2007 16:27:43
class myCharacter : public Character {
public:
myCharacter(NxString id, Scene* scene, CharacterController* cc, NxOgre::Pose pose, CharacterParams params) : Character(id, scene,cc, pose, params) {
createNode();
attachMesh("cube.1m.mesh");
mNode->scale(toVector3(params.mDimensions));
}
~myCharacter() {
}
};
mCharacter = new myCharacter("Woo", mScene, mWorld->getCharacterController(), Vector3(0, 10,5), "type: box, dimensions: 1 2 1");
frier
31-08-2007 16:29:13
betajaen
31-08-2007 16:35:23
Night Elf
31-08-2007 16:57:12
I would still prefer you guys to use the inherited system for the Character, like with Actor. Nobody would really use it as a main class to represent a character in your game, I wouldn't.
but which class does the "delete mCustomData" or you dont need to?
betajaen
31-08-2007 17:06:39
luis
31-08-2007 18:32:26
class CustomData
{
public:
// default constructor
CustomData(void) {;}
// virtual destructor to prevent leaks
virtual ~CustomData(void){;}
// disallow direct intances of this class, also ints cast very well to enums ;)
virtual int getId(void) const = 0;
};
class myCallback : public GroupCallback::InheritedCallback {
public:
void onStartTouch(Actor* A , Actor*B) {
Body *C = static_cast<Body*>(A);
}
....
TMT
10-10-2007 19:53:34
betajaen
10-10-2007 20:11:15
kungfoomasta
10-10-2007 21:27:16