HarpSeal1 Posted October 11, 2012 Posted October 11, 2012 I have created a user class called Entity to extend the functionality of ObjectMesh. It works fine but I want use a Node file that defines physics bodies/joints and materials for the ObjectMesh. I'll try to do something like this: Entity ent = new Entity(fileName); Node node = engine.world.getNode(ent.getID()); Entity castedEnt = Entity::cast(node); castedEnt.test(); class Entity : ObjectMesh { Entity(string filename) { ObjectMesh m = node_load(filename); extern = m; } void test() { log.message("works\n"); } }; When I call castedEnt.test() Machine::do_callucf(): "int: 0" is not a user class shows in the log file. I am guessing you cannot downcast unless Entity's constructor calls ObjectMesh(fileName). But that means I cannot use engine.world.loadNode() and I'll have to setup the objectmesh with my own loadNode script. Perhaps there is a better way?
frustum Posted October 12, 2012 Posted October 12, 2012 To initialize extern member you must call base class constructor inside your Entity constructor in this way: Entity(string filename) : ObjectMesh(filename) { } // or Entity(string filename) : ObjectMesh() { extern.load(filename); } This base class construction limits inheritance flexibility because it's impossible to load base class from NodeReference. To remove this restriction a new function called set_extern() will be available in the next SDK: class Entity : ObjectMesh { Entity(string filename) { ObjectMesh m = new ObjectMesh(filename); set_extern(m); } }; This function initializes internal mapping for cast() function if the base class constructor is no called. You can also store your Entity class inside Node Variable via Node::setVariable/getVariable() functions.
HarpSeal1 Posted October 16, 2012 Author Posted October 16, 2012 Hi Frustum, setVariable works. Although once set_extern() is added to the SDK I will update my code. Thanks for you help, it is much appreciated!
Recommended Posts