#include "SoCollisionShape.h" #include <Inventor/fields/SoSFVec3f.h> #include <Inventor/SbString.h> class SoCollisionShapeExample : public SoCollisionShape { SO_KIT_HEADER(SoCollisionShapeExample); // set up the necessary information for the headerfile public: SoCollisionShapeExample(const SbString& nodeName = ""); virtual ~SoCollisionShapeExample(); static void initClass(); SoSFVec3f dimension; protected: virtual dGeomID cGeom(const SbMatrix& mm); virtual void updateVisualisationAndOdeProperties(); };
SoCollisionShapeExample.cpp
#include "../include/SoCollisionShapeExample.h" #include <Inventor/SbLinear.h> #include <ode/ode.h> #include <cassert> SO_KIT_SOURCE(SoCollisionShapeExample); // set up the necessary information for the implementation file // Initialises the class and it's type id variables. void SoCollisionShapeExample::initClass() { SO_KIT_INIT_CLASS(SoCollisionShapeExample, SoCollisionShape, "CollisionShape"); } // set up the class structure SoCollisionShapeExample::SoCollisionShapeExample(const SbString& nodeName = "") : SoCollisionShape(nodeName) { // define the Coin constructor SO_KIT_CONSTRUCTOR(SoCollisionShapeExample); // only write necessary member fields to files and not more isBuiltIn = TRUE; // define the field variables SO_KIT_ADD_FIELD(dimension, (2.0, 0.0, 1.0)); // change the default type of the visualisation object to SoCube SO_KIT_CHANGE_ENTRY_TYPE(visualisation, SoCube, SoCube); // the visualisation is created by default SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisation, FALSE); // set up the instance SO_KIT_INIT_INSTANCE(); // monitor property fields for changes to automatically update the visualisation shape and ODE parameters updateOdePropertiesTrigger.appendConnection(&dimension); } SoCollisionShapeExample::~SoCollisionShapeExample() { // release objects created with new } // method which creates the ODE geom (also known as collision shape) dGeomID SoCollisionShapeExample::cGeom(const SbMatrix& mm) { // check if the shape is associated with a collision space assert(NULL != this->space); // create a box geom as example const SbVec3f dim = this->dimension.getValue(); return dCreateBox(this->space, dim[0], dim[1], dim[2]); } // method which updates the ODE properties and the visualisation of the collisionshape void SoCollisionShapeExample::updateVisualisationAndOdeProperties() { // retrieve the dimension vector const SbVec3f dim = this->dimension.getValue(); // retrieve the geom ID const dGeomID boxID = this->geometry; // set the new property values on the ODE object if (NULL != boxID) dGeomBoxSetLengths(boxID, dim[0], dim[1], dim[2]); // change the property values of the visualisation if one is present SoCube* visualisationShape = dynamic_cast<SoCube*> (getPart("visualisation", TRUE)); if (NULL != visualisationShape) { visualisationShape->width.setValue(dim[0]); visualisationShape->height.setValue(dim[1]); visualisationShape->depth.setValue(dim[2]); } }
Steps to take:
SO_KIT_SOURCE(SoCollisionShapeExample);
SoCollisionShapeExample::initClass() { SO_KIT_INIT_CLASS(SoCollisionShapeExample, SoCollisionShape, "CollisionShape"); }
SO_KIT_CONSTRUCTOR(SoCollisionShapeExample);
isBuiltin = TRUE;
SO_KIT_ADD_FIELD(fieldname,(defaultvalue));
SO_KIT_CHANGE_ENTRY_TYPE(visualisation,SoCube,SoCube);
SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisation, FALSE);
SO_KIT_INIT_INSTANCE();
updateOdePropertiesTrigger.appendConnection(&odeParameterName);
#include "SoCollisionShapeExample.h"
$(IPSA_HOME)/include/ipsaclasses.h
SoCollisionShapeExample::initClass();
See the CollisionShape classes page for all collision shape classes existing in IPSA. Details on how to implement the different methods can be taken from the individual collision shape classes.
Generated on Sat Mar 10 20:00:17 2012 for IPSA by 1.5.8 |