00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00041 #include "../include/IPSA/SoCollisionShapePlane.h"
00042 #include <Inventor/nodes/SoCube.h>
00043 #include <Inventor/nodes/SoDrawStyle.h>
00044 #include <Inventor/SbLinear.h>
00045
00046 SO_KIT_SOURCE(SoCollisionShapePlane);
00047
00050 void SoCollisionShapePlane::initClass()
00051 {
00052 SO_KIT_INIT_CLASS(SoCollisionShapePlane, SoCollisionShape, "CollisionShape");
00053 }
00054
00055
00062 SoCollisionShapePlane::SoCollisionShapePlane(const SbString& nodeName )
00063 : SoCollisionShape(nodeName)
00064 {
00065 SO_KIT_CONSTRUCTOR(SoCollisionShapePlane);
00066 isBuiltIn = TRUE;
00067
00068 SO_KIT_ADD_FIELD(normal,(0.0f, 1.0f, 0.0f));
00069 SO_KIT_ADD_FIELD(distance,(0.0f));
00070
00071 SO_KIT_CHANGE_ENTRY_TYPE(visualisation,SoCube,SoCube);
00072 SO_KIT_CHANGE_NULL_BY_DEFAULT(visualisation, FALSE);
00073
00074 SO_KIT_INIT_INSTANCE();
00075
00076 SoDrawStyle* dstyle = dynamic_cast<SoDrawStyle*> (getPart("visDrawStyle", TRUE));
00077 dstyle->style = SoDrawStyle::FILLED;
00078
00079 updateOdePropertiesTrigger.appendConnection(&normal);
00080 updateOdePropertiesTrigger.appendConnection(&distance);
00081 }
00082
00083
00087 SoCollisionShape* SoCollisionShapePlane::copy(SbBool copyConnections) const
00088 {
00089
00090
00091 SoCollisionShapePlane* newSoCollisionShape = dynamic_cast<SoCollisionShapePlane*> (SoCollisionShape::copy(copyConnections));
00092 newSoCollisionShape->setUpConnections(TRUE, TRUE);
00093 return newSoCollisionShape;
00094 }
00095
00096
00099 void SoCollisionShapePlane::updateVisualisationAndOdeProperties()
00100 {
00101 SoCube* visualisationShape = dynamic_cast<SoCube*> (getPart("visualisation", TRUE));
00102 if (NULL != visualisationShape)
00103 {
00104 visualisationShape->width.setValue(1.0f);
00105 visualisationShape->height.setValue(0.001f);
00106 visualisationShape->depth.setValue(1.0f);
00107 }
00108 }
00109
00110
00115 void SoCollisionShapePlane::updateGeomPosition(const SbMatrix& mm)
00116 {
00117 }
00118
00119
00131 dGeomID SoCollisionShapePlane::cGeom(const SbMatrix& mm)
00132 {
00133 assert(space != NULL);
00134
00135
00136 SbPlane p = SbPlane(normal.getValue(), distance.getValue());
00137 p.transform(mm);
00138 SbVec3f n = p.getNormal();
00139
00140 SbVec3f translation = n;
00141 translation.normalize();
00142 translation *= distance.getValue();
00143
00144
00145 SbMatrix odeTransform = SbMatrix::identity();
00146 odeTransform.setTransform(SbVec3f(translation[0],translation[1],translation[2]),
00147 SbRotation(SbVec3f(0, 1, 0), normal.getValue()),
00148 SbVec3f(1,1,1));
00149 transform->matrix.setValue(odeTransform);
00150
00151 return dCreatePlane (space, n[0], n[1], n[2], p.getDistanceFromOrigin());
00152 }