[Opal-commits] opal/src BoxShapeData.h,NONE,1.1 CapsuleShapeData.h,NONE,1.1 ShapeData.h,NONE,1.1 Sol
Status: Inactive
Brought to you by:
tylerstreeter
|
From: tylerstreeter <tyl...@us...> - 2005-02-22 01:26:06
|
Update of /cvsroot/opal/opal/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17286/src Modified Files: Blueprint.cpp Blueprint.h BlueprintManager.cpp BlueprintManager.h Defines.h Joint.cpp Joint.h Simulator.cpp Simulator.h Solid.cpp Solid.h opal.h Added Files: BoxShapeData.h CapsuleShapeData.h ShapeData.h SolidData.h SphereShapeData.h Log Message: added new Data classes --- NEW FILE: SolidData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SOLID_DATA_H #define OPAL_SOLID_DATA_H #include "Defines.h" #include "ShapeData.h" namespace opal { /// A data structure describing a Solid. class SolidData { public: SolidData() { enabled = defaults::solid::enabled; sleeping = defaults::solid::sleeping; isStatic = defaults::solid::isStatic; // Leave the transform as an identity matrix. globalLinearVel = 0; globalAngularVel = 0; linearDamping = defaults::linearDamping; angularDamping = defaults::angularDamping; // The Shape list doesn't need to be initialized. } /// Copy constructor. SolidData(const SolidData& sd) { (*this) = sd; } virtual ~SolidData() { while (!shapes.empty()) { delete shapes.back(); shapes.pop_back(); } } /// Makes a deep copy. virtual void OPAL_CALL operator=(const SolidData& sd) { enabled = sd.enabled; sleeping = sd.sleeping; isStatic = sd.isStatic; transform = sd.transform; globalLinearVel = sd.globalLinearVel; globalAngularVel = sd.globalAngularVel; linearDamping = sd.linearDamping; angularDamping = sd.angularDamping; shapes.clear(); for (unsigned int i=0; i<sd.shapes.size(); ++i) { shapes.push_back(sd.shapes[i]); } } bool enabled; bool sleeping; bool isStatic; Matrix44r transform; Vec3r globalLinearVel; Vec3r globalAngularVel; real linearDamping; real angularDamping; std::vector<ShapeData*> shapes; protected: private: }; } #endif --- NEW FILE: SphereShapeData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SPHERE_SHAPE_DATA_H #define OPAL_SPHERE_SHAPE_DATA_H #include "Defines.h" #include "ShapeData.h" namespace opal { /// A data structure describing a sphere Shape. class SphereShapeData : public ShapeData { public: SphereShapeData() : ShapeData() { type = SPHERE_SHAPE; radius = 0; } /// Copy constructor. SphereShapeData(const SphereShapeData& data) { (*this) = data; } virtual ~SphereShapeData() { } /// Makes a deep copy. virtual void OPAL_CALL operator=(const SphereShapeData& data) { type = data.type; offset = data.offset; material = data.material; radius = data.radius; } /// The sphere's radius. real radius; protected: private: }; } #endif --- NEW FILE: ShapeData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_SHAPE_DATA_H #define OPAL_SHAPE_DATA_H #include "Defines.h" namespace opal { /// The types of collision shapes currently supported. enum ShapeType { BOX_SHAPE, SPHERE_SHAPE, CAPSULE_SHAPE, PLANE_SHAPE, RAY_SHAPE, MESH_SHAPE }; /// A data structure describing a Shape. Note that there is no other /// class associated with Shapes besides this one. class ShapeData { public: ShapeData() { type = SPHERE_SHAPE; // Leave the offset as an identity matrix. material = defaults::material; } virtual ~ShapeData() { } /// The Shape type. ShapeType type; /// The offset transform from a Solid's transform. Matrix44r offset; /// The Shape's material. Material material; protected: private: }; } #endif Index: Blueprint.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Blueprint.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Blueprint.cpp 19 Feb 2005 20:54:36 -0000 1.11 --- Blueprint.cpp 22 Feb 2005 01:25:55 -0000 1.12 *************** *** 51,83 **** } ! void Blueprint::addSolid(const SolidDescription& sd) ! { ! if (solidExists(sd.name)) ! { ! std::cout << "Warning in opal::Blueprint::addSolid: Solid " << sd.name ! << " already exists in Blueprint " << mName ! << "; ignoring Solid" << std::endl; ! } ! else ! { ! mSolidMap[sd.name] = sd; ! } ! } ! ! void Blueprint::addJoint(const JointData& jd) ! { ! // TODO: fix this! ! //if (jointExists(jd.name)) ! //{ ! // std::cout << "Warning in opal::Blueprint::addJoint: Joint " << ! // jd.name << " already exists in Blueprint " << mName ! // << "; ignoring Joint" << std::endl; ! //} ! //else ! //{ ! // mJointMap[jd.name] = jd; ! //} ! } void Blueprint::addSpace(const SpaceDescription& sd) --- 51,81 ---- } ! //void Blueprint::addSolid(const SolidDescription& sd) ! //{ ! // if (solidExists(sd.name)) ! // { ! // std::cout << "Warning in opal::Blueprint::addSolid: Solid " << sd.name ! // << " already exists in Blueprint " << mName ! // << "; ignoring Solid" << std::endl; ! // } ! // else ! // { ! // mSolidMap[sd.name] = sd; ! // } ! //} ! //void Blueprint::addJoint(const JointData& jd) ! //{ ! // if (jointExists(jd.name)) ! // { ! // std::cout << "Warning in opal::Blueprint::addJoint: Joint " << ! // jd.name << " already exists in Blueprint " << mName ! // << "; ignoring Joint" << std::endl; ! // } ! // else ! // { ! // mJointMap[jd.name] = jd; ! // } ! //} void Blueprint::addSpace(const SpaceDescription& sd) *************** *** 96,100 **** } ! const std::map<std::string, SolidDescription>& Blueprint::getSolidMap()const { return mSolidMap; --- 94,98 ---- } ! const std::map<std::string, SolidData>& Blueprint::getSolidMap()const { return mSolidMap; --- NEW FILE: CapsuleShapeData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_CAPSULE_SHAPE_DATA_H #define OPAL_CAPSULE_SHAPE_DATA_H #include "Defines.h" #include "ShapeData.h" namespace opal { /// A data structure describing a capsule Shape. class CapsuleShapeData : public ShapeData { public: CapsuleShapeData() : ShapeData() { type = CAPSULE_SHAPE; radius = 0; length = 0; } /// Copy constructor. CapsuleShapeData(const CapsuleShapeData& data) { (*this) = data; } virtual ~CapsuleShapeData() { } /// Makes a deep copy. virtual void OPAL_CALL operator=(const CapsuleShapeData& data) { type = data.type; offset = data.offset; material = data.material; radius = data.radius; length = data.length; } /// The capsule's radius. real radius; /// The capsule's length. real length; protected: private: }; } #endif --- NEW FILE: BoxShapeData.h --- /************************************************************************* * * * Open Physics Abstraction Layer * * Copyright (C) 2004-2005 * * Alan Fischer ala...@gm... * * Andres Reinot an...@re... * * Tyler Streeter tyl...@gm... * * All rights reserved. * * Web: opal.sourceforge.net * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file license-LGPL.txt. * * (2) The BSD-style license that is included with this library in * * the file license-BSD.txt. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * license-LGPL.txt and license-BSD.txt for more details. * * * *************************************************************************/ #ifndef OPAL_BOX_SHAPE_DATA_H #define OPAL_BOX_SHAPE_DATA_H #include "Defines.h" #include "ShapeData.h" namespace opal { /// A data structure describing a box Shape. class BoxShapeData : public ShapeData { public: BoxShapeData() : ShapeData() { type = BOX_SHAPE; // "dimensions" is already initialized from its constructor. } /// Copy constructor. BoxShapeData(const BoxShapeData& data) { (*this) = data; } virtual ~BoxShapeData() { } /// Makes a deep copy. virtual void OPAL_CALL operator=(const BoxShapeData& data) { type = data.type; offset = data.offset; material = data.material; dimensions = data.dimensions; } /// The box's dimensions. Vec3r dimensions; protected: private: }; } #endif Index: opal.h =================================================================== RCS file: /cvsroot/opal/opal/src/opal.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** opal.h 18 Feb 2005 23:59:37 -0000 1.13 --- opal.h 22 Feb 2005 01:25:55 -0000 1.14 *************** *** 31,34 **** --- 31,38 ---- #include "Simulator.h" #include "Solid.h" + #include "SolidData.h" + #include "BoxShapeData.h" + #include "SphereShapeData.h" + #include "CapsuleShapeData.h" #include "Motor.h" #include "AttractorMotor.h" Index: Simulator.h =================================================================== RCS file: /cvsroot/opal/opal/src/Simulator.h,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** Simulator.h 21 Feb 2005 15:54:40 -0000 1.72 --- Simulator.h 22 Feb 2005 01:25:55 -0000 1.73 *************** *** 62,65 **** --- 62,107 ---- }; + /// Contains maps of string names to object pointers for Solids, Joints, + /// Motors, and Sensors. + struct BlueprintInstance + { + ~BlueprintInstance() + { + solidMap.clear(); + jointMap.clear(); + } + + /// Convenience function for finding a Solid pointer by name. + /// Returns NULL if the pointer is not found. + Solid* getSolid(const std::string& name) + { + if (solidMap.end() == solidMap.find(name)) + { + return NULL; + } + else + { + return solidMap[name]; + } + } + + /// Convenience function for finding a Joint pointer by name. + /// Returns NULL if the pointer is not found. + Joint* getJoint(const std::string& name) + { + if (jointMap.end() == jointMap.find(name)) + { + return NULL; + } + else + { + return jointMap[name]; + } + } + + std::map<std::string, Solid*> solidMap; + std::map<std::string, Joint*> jointMap; + }; + /// A Simulator is an environment that contains simulated objects. /// It performs collision detection and physical simulation. It is *************** *** 111,118 **** /// Sets the accuracy level used by the physics engine's constraint /// solver. ! virtual void OPAL_CALL setAccuracy(AccuracyLevel level); /// Returns the accuracy level. ! virtual AccuracyLevel OPAL_CALL getAccuracy()const; //virtual void OPAL_CALL setDefaultLinearDamping(real ld); --- 153,160 ---- /// Sets the accuracy level used by the physics engine's constraint /// solver. ! virtual void OPAL_CALL setSolverAccuracy(SolverAccuracyLevel level); /// Returns the accuracy level. ! virtual SolverAccuracyLevel OPAL_CALL getSolverAccuracy()const; //virtual void OPAL_CALL setDefaultLinearDamping(real ld); *************** *** 269,273 **** /// The accuracy level used internally by the physics engine's /// constraint solver. ! AccuracyLevel mAccuracyLevel; /// Pointer to user data. This is totally user-managed (i.e. OPAL --- 311,315 ---- /// The accuracy level used internally by the physics engine's /// constraint solver. ! SolverAccuracyLevel mSolverAccuracyLevel; /// Pointer to user data. This is totally user-managed (i.e. OPAL Index: Solid.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Solid.cpp 20 Feb 2005 07:12:58 -0000 1.21 --- Solid.cpp 22 Feb 2005 01:25:55 -0000 1.22 *************** *** 32,45 **** Solid::Solid() { ! mStatic = defaults::staticSolids; mEventHandler = NULL; setUserData(NULL); ! mEnabled = true; //mPrevGlobalLinearVel.set(0.0, 0.0, 0.0); //mPrevGlobalAngularVel.set(0.0, 0.0, 0.0); //mGlobalLinearAccel.set(0.0, 0.0, 0.0); //mGlobalAngularAccel.set(0.0, 0.0, 0.0); ! setLinearDamping(defaults::linearDamping); ! setAngularDamping(defaults::linearDamping); } --- 32,45 ---- Solid::Solid() { ! //mStatic = defaults::solid::isStatic; mEventHandler = NULL; setUserData(NULL); ! //mEnabled = defaults::solid::enabled; //mPrevGlobalLinearVel.set(0.0, 0.0, 0.0); //mPrevGlobalAngularVel.set(0.0, 0.0, 0.0); //mGlobalLinearAccel.set(0.0, 0.0, 0.0); //mGlobalAngularAccel.set(0.0, 0.0, 0.0); ! //setLinearDamping(defaults::linearDamping); ! //setAngularDamping(defaults::linearDamping); } *************** *** 49,60 **** } bool Solid::isEnabled()const { ! return mEnabled; } void Solid::setEnabled(bool e) { ! mEnabled = e; } --- 49,68 ---- } + const SolidData& Solid::getSolidData() + { + // The sleeping parameter needs to be updated here because it + // doesn't get updated automatically. + mData.sleeping = isSleeping(); + return mData; + } + bool Solid::isEnabled()const { ! return mData.enabled; } void Solid::setEnabled(bool e) { ! mData.enabled = e; } *************** *** 83,87 **** bool Solid::isStatic() { ! return mStatic; } --- 91,95 ---- bool Solid::isStatic() { ! return mData.isStatic; } *************** *** 89,98 **** { assert(ld >= 0.0); ! mLinearDamping = ld; } real Solid::getLinearDamping()const { ! return mLinearDamping; } --- 97,106 ---- { assert(ld >= 0.0); ! mData.linearDamping = ld; } real Solid::getLinearDamping()const { ! return mData.linearDamping; } *************** *** 100,109 **** { assert(ad >= 0.0); ! mAngularDamping = ad; } real Solid::getAngularDamping()const { ! return mAngularDamping; } --- 108,117 ---- { assert(ad >= 0.0); ! mData.angularDamping = ad; } real Solid::getAngularDamping()const { ! return mData.angularDamping; } *************** *** 120,124 **** void Solid::setTransform(const Matrix44r& transform) { ! mTransform = transform; internal_updateEngineTransform(); } --- 128,132 ---- void Solid::setTransform(const Matrix44r& transform) { ! mData.transform = transform; internal_updateEngineTransform(); } *************** *** 126,135 **** const Matrix44r& Solid::getTransform()const { ! return mTransform; } void Solid::setPosition(real x, real y, real z) { ! mTransform.setPosition(x, y, z); internal_updateEngineTransform(); } --- 134,143 ---- const Matrix44r& Solid::getTransform()const { ! return mData.transform; } void Solid::setPosition(real x, real y, real z) { ! mData.transform.setPosition(x, y, z); internal_updateEngineTransform(); } *************** *** 142,156 **** Point3r Solid::getPosition()const { ! return mTransform.getPosition(); } Vec3r Solid::getEulerXYZ()const { ! return mTransform.getEulerXYZ(); } Quaternion Solid::getQuaternion()const { ! return mTransform.getQuaternion(); } --- 150,164 ---- Point3r Solid::getPosition()const { ! return mData.transform.getPosition(); } Vec3r Solid::getEulerXYZ()const { ! return mData.transform.getEulerXYZ(); } Quaternion Solid::getQuaternion()const { ! return mData.transform.getQuaternion(); } *************** *** 177,181 **** void Solid::addForce(const Force& f) { ! if (mEnabled && !mStatic && f.vec.lengthSquared() > 0.0000001f ) { mForceList.push_back(f); --- 185,190 ---- void Solid::addForce(const Force& f) { ! if (mData.enabled && !mData.isStatic && ! f.vec.lengthSquared() > 0.0000001f ) { mForceList.push_back(f); *************** *** 279,283 **** void Solid::internal_applyForces(real stepSize) { ! if (mStatic) { return; --- 288,292 ---- void Solid::internal_applyForces(real stepSize) { ! if (mData.isStatic) { return; *************** *** 356,373 **** //} ! BodyState Solid::getState()const ! { ! BodyState s; ! s.transform = getTransform(); ! s.globalAngularVel = getGlobalAngularVel(); ! s.globalLinearVel = getGlobalLinearVel(); ! return s; ! } ! void Solid::setState(const BodyState & s) ! { ! setTransform(s.transform); ! setGlobalAngularVel(s.globalAngularVel); ! setGlobalLinearVel(s.globalLinearVel); ! } } --- 365,382 ---- //} ! //BodyState Solid::getState()const ! //{ ! // BodyState s; ! // s.transform = getTransform(); ! // s.globalAngularVel = getGlobalAngularVel(); ! // s.globalLinearVel = getGlobalLinearVel(); ! // return s; ! //} ! //void Solid::setState(const BodyState & s) ! //{ ! // setTransform(s.transform); ! // setGlobalAngularVel(s.globalAngularVel); ! // setGlobalLinearVel(s.globalLinearVel); ! //} } Index: Defines.h =================================================================== RCS file: /cvsroot/opal/opal/src/Defines.h,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Defines.h 21 Feb 2005 15:54:35 -0000 1.56 --- Defines.h 22 Feb 2005 01:25:55 -0000 1.57 *************** *** 162,174 **** }; ! /// Accuracy levels determine how the physics engine constraint solver ! /// is used (e.g. the number of iterations in an iterative solver). ! enum AccuracyLevel { ! ACCURACY_VERY_LOW, ! ACCURACY_LOW, ! ACCURACY_MEDIUM, ! ACCURACY_HIGH, ! ACCURACY_VERY_HIGH }; --- 162,175 ---- }; ! /// Solver accuracy levels determine how the physics engine constraint ! /// solver is used (e.g. the number of iterations in an iterative ! /// solver). ! enum SolverAccuracyLevel { ! SOLVER_ACCURACY_VERY_LOW, ! SOLVER_ACCURACY_LOW, ! SOLVER_ACCURACY_MEDIUM, ! SOLVER_ACCURACY_HIGH, ! SOLVER_ACCURACY_VERY_HIGH }; *************** *** 222,236 **** }; - /// The types of collision shapes currently supported. - enum ShapeType - { - BOX_SHAPE, - SPHERE_SHAPE, - CAPSULE_SHAPE, - PLANE_SHAPE, - RAY_SHAPE, - MESH_SHAPE - }; - /// A namespace containing globally useful parameters. namespace globals --- 223,226 ---- *************** *** 267,272 **** const Material iceMaterial(iceHardness, iceFriction, iceBounciness, iceDensity); - - const int numShapeDimensions=7; } --- 257,260 ---- *************** *** 276,284 **** const real stepSize = (real)0.0167; // ~60 Hz physics rate const Vec3r gravity(0, 0, 0); - const bool staticSolids = false; const real sleepiness = (real)0.5; const real bounceThreshold = (real)1.0; const Material material(opal::globals::woodMaterial); ! const AccuracyLevel accuracy = ACCURACY_MEDIUM; //const bool allowPartialFrames=true; //const int maxStepsPerFrame=10; --- 264,271 ---- const real stepSize = (real)0.0167; // ~60 Hz physics rate const Vec3r gravity(0, 0, 0); const real sleepiness = (real)0.5; const real bounceThreshold = (real)1.0; const Material material(opal::globals::woodMaterial); ! const SolverAccuracyLevel solverAccuracy = SOLVER_ACCURACY_MEDIUM; //const bool allowPartialFrames=true; //const int maxStepsPerFrame=10; *************** *** 288,291 **** --- 275,286 ---- const real maxAngularVel = (real)1000.0; + /// Default parameters used in Solid creation. + namespace solid + { + const bool enabled = true; + const bool sleeping = true; + const bool isStatic = false; + } + /// Default parameters used in Joint creation. namespace joint *************** *** 368,409 **** } - /// TODO: replace with ShapeData - struct ShapeDescription - { - ShapeDescription() - { - for (int i=0; i<globals::numShapeDimensions; ++i) - { - dimensions[i] = 0; - } - type = BOX_SHAPE; - offset.makeIdentity(); - material = defaults::material; - } - - // TODO: this needs an operator= - - // dimensions for all shape types are stored in "dimensions"; for - // boxes, elements 0, 1, 2 are dimensions; for spheres, element 0 is - // radius; for planes, elements 0, 1, 2, 3 are the plane normal and - // distance from the origin (i.e. they define the plane equation - // ax + by + cz = d); for capped cylinders, elements 0 and 1 are - // radius and length; for rays, elements 0, 1, 2 are the ray origin, - // 3, 4, 5 are direction, and 6 is length - real dimensions[globals::numShapeDimensions]; - ShapeType type; - Matrix44r offset; - Material material; - }; - // Structs used for Blueprints... /// Data structure for storing user-defined properties loaded from XML /// files. ! struct UserProperty ! { ! std::string name; ! std::string value; ! }; /// TODO: replace with SpaceData? --- 363,375 ---- } // Structs used for Blueprints... /// Data structure for storing user-defined properties loaded from XML /// files. ! //struct UserProperty ! //{ ! // std::string name; ! // std::string value; ! //}; /// TODO: replace with SpaceData? *************** *** 415,419 **** } ! // TODO: this needs an operator= bool containsSolid(const std::string& name) --- 381,385 ---- } ! // TODO: this needs an operator= and copy constructor bool containsSolid(const std::string& name) *************** *** 434,539 **** std::vector<std::string> solidNameList; }; - - /// TODO: replace with SolidData struct - struct BodyState - { - Matrix44r transform; - Vec3r globalLinearVel; - Vec3r globalAngularVel; - }; - - /// TODO: replace with SolidData - struct SolidDescription - { - ~SolidDescription() - { - shapeList.clear(); - userProperties.clear(); - } - - // TODO: this needs an operator= - - std::string name; - Matrix44r transform; - bool isStatic; - real linearDamping; - real angularDamping; - std::vector<ShapeDescription> shapeList; - std::vector<UserProperty> userProperties; - }; - - /// TODO: expand this to include all Solid data - struct SolidData - { - ~SolidData() - { - userProperties.clear(); - } - - // TODO: this needs an operator= - - std::string getUserProperty(std::string name) - { - std::map<std::string, std::string>::iterator iter = - userProperties.find(name); - if (userProperties.end() != iter) - { - return (*iter).second; - } - else - { - return ""; - } - } - - Solid* solidPtr; - std::map<std::string, std::string> userProperties; - }; - - /// For giving users lists of pointers to Solids and Joints created from - /// blueprints; pointers can be accessed by individual names. - struct NamedObjectCollection - { - ~NamedObjectCollection() - { - solidMap.clear(); - jointMap.clear(); - } - - // TODO: this needs an operator= - - SolidData getSolid(std::string name) - { - if (solidMap.end() == solidMap.find(name)) - { - //std::cout << "Error in opal::NamedObjectCollection::getSolid: Invalid solid requested: " - // << name << std::endl; - SolidData sd; - sd.solidPtr = NULL; - return sd; - } - else - { - return solidMap[name]; - } - } - - Joint* getJoint(std::string name) - { - if (jointMap.end() == jointMap.find(name)) - { - //std::cout << "Error in opal::NamedObjectCollection::getJoint: Invalid joint requested: " - // << name << std::endl; - return NULL; - } - else - { - return jointMap[name]; - } - } - - std::map<std::string, SolidData> solidMap; - std::map<std::string, Joint*> jointMap; - }; } --- 400,403 ---- Index: Solid.h =================================================================== RCS file: /cvsroot/opal/opal/src/Solid.h,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** Solid.h 19 Feb 2005 20:54:36 -0000 1.73 --- Solid.h 22 Feb 2005 01:25:55 -0000 1.74 *************** *** 31,34 **** --- 31,35 ---- #include "Defines.h" #include "EventHandler.h" + #include "SolidData.h" namespace opal *************** *** 36,39 **** --- 37,218 ---- class Simulator; class Space; + class ShapeData; + + /// TODO: replace with SolidData struct + //struct BodyState + //{ + // Matrix44r transform; + // Vec3r globalLinearVel; + // Vec3r globalAngularVel; + //}; + + ///// TODO: replace with SolidData + //struct SolidDescription + //{ + // ~SolidDescription() + // { + // shapeList.clear(); + // userProperties.clear(); + // } + + // std::string name; + // Matrix44r transform; + // bool isStatic; + // real linearDamping; + // real angularDamping; + // std::vector<ShapeDescription> shapeList; + // std::vector<UserProperty> userProperties; + //}; + + // Old data structure... + //struct SolidData + //{ + // ~SolidData() + // { + // userProperties.clear(); + // } + + // std::string getUserProperty(std::string name) + // { + // std::map<std::string, std::string>::iterator iter = + // userProperties.find(name); + // if (userProperties.end() != iter) + // { + // return (*iter).second; + // } + // else + // { + // return ""; + // } + // } + + // Solid* solidPtr; + // std::map<std::string, std::string> userProperties; + //} + + //namespace globals + //{ + // /// The number of floats needed to describe the dimensions of + // /// any Shape. + // const int numShapeDimensions=7; + //} + + ///// A data structure containing all essential parameters that describe + ///// a Shape. Note that there is no class associated with Shapes, just + ///// this data structure. + //struct ShapeData + //{ + // ShapeData() + // { + // type = SPHERE_SHAPE; + // // Leave the offset as an identity matrix. + // material = defaults::material; + + // for (int i=0; i<globals::numShapeDimensions; ++i) + // { + // dimensions[i] = 0; + // } + // } + + // /// Copy constructor. + // ShapeData(const ShapeData& sd) + // { + // (*this) = sd; + // } + + // /// Makes a deep copy. + // void operator=(const ShapeData& sd) + // { + // type = sd.type; + // offset = sd.offset; + // material = sd.material; + + // for (int i=0; i<globals::numShapeDimensions; ++i) + // { + // dimensions[i] = sd.dimensions[i]; + // } + // } + + // /// The Shape type. + // ShapeType type; + + // /// The offset transform from a Solid's transform. + // Matrix44r offset; + + // /// The Shape's material. + // Material material; + + // /// Dimensions for all Shape types are stored in the "dimensions" + // /// array. + // /// Boxes: elements 0, 1, 2 are the box dimensions. + // /// Spheres: element 0 is radius. + // /// Planes: elements 0, 1, 2, 3 are the plane normal and + // /// distance from the origin (i.e. they define the plane equation + // /// ax + by + cz = d). + // /// Capped cylinders: elements 0 and 1 are radius and length. + // /// Rays: elements 0, 1, 2 are the origin, 3, 4, 5 are direction, + // /// and 6 is length. + // real dimensions[globals::numShapeDimensions]; + //}; + + ///// A data structure containing all essential parameters that describe + ///// a Solid. + //struct SolidData + //{ + // SolidData() + // { + // enabled = defaults::solid::enabled; + // sleeping = defaults::solid::sleeping; + // isStatic = defaults::solid::isStatic; + // // Leave the transform as an identity matrix. + // globalLinearVel = 0; + // globalAngularVel = 0; + // linearDamping = defaults::linearDamping; + // angularDamping = defaults::angularDamping; + // // The Shape list doesn't need to be initialized. + // } + + // /// Copy constructor. + // SolidData(const SolidData& sd) + // { + // (*this) = sd; + // } + + // /// This is necessary because SolidData uses a dynamically-allocated + // /// list of Shapes. + // ~SolidData() + // { + // shapes.clear(); + // } + + // /// Makes a deep copy. + // void operator=(const SolidData& sd) + // { + // enabled = sd.enabled; + // sleeping = sd.sleeping; + // isStatic = sd.isStatic; + // transform = sd.transform; + // globalLinearVel = sd.globalLinearVel; + // globalAngularVel = sd.globalAngularVel; + // linearDamping = sd.linearDamping; + // angularDamping = sd.angularDamping; + + // shapes.clear(); + // for (unsigned int i=0; i<sd.shapes.size(); ++i) + // { + // shapes.push_back(sd.shapes[i]); + // } + // } + + // bool enabled; + // bool sleeping; + // bool isStatic; + // Matrix44r transform; + // Vec3r globalLinearVel; + // Vec3r globalAngularVel; + // real linearDamping; + // real angularDamping; + // std::vector<ShapeData> shapes; + //}; /// Solids are the physical objects in the simulation. Solids can be *************** *** 50,53 **** --- 229,235 ---- virtual ~Solid(); + /// Returns all data describing the Solid. + virtual const SolidData& OPAL_CALL getSolidData(); + /// Returns true if the Solid is enabled. virtual bool OPAL_CALL isEnabled()const; *************** *** 121,170 **** virtual Quaternion OPAL_CALL getQuaternion()const; ! /// Adds a box Shape to this Solid. ! virtual void OPAL_CALL addBox(const Vec3r& dimensions, ! const Matrix44r& offset = Matrix44r(), ! const Material& m = defaults::material) = 0; ! /// Adds a sphere Shape to this Solid. ! virtual void OPAL_CALL addSphere(real radius, ! const Matrix44r& offset = Matrix44r(), ! const Material& m = defaults::material) = 0; ! /// Adds a plane Shape to this Solid. abcd are used to define ! /// the plane equation a*x + b*y + c*z = d. ! virtual void OPAL_CALL addPlane(real abcd[4], ! const Material& m = defaults::material) = 0; ! // alternate plane definition method; uses a point on the plane and ! // the plane normal ! //void addPlane(const Point3r& point, const Vec3r& normal, ! // const Material& m = defaults::material); ! //note: normal cylinders are not yet part of standard ODE ! //virtual void addCylinder(real radius, real length, // const Matrix44r& offset = Matrix44r(), // const Material& m = defaults::material) = 0; ! /// Adds a capsule Shape to this Solid. ! virtual void OPAL_CALL addCapsule(real radius, real length, ! const Matrix44r& offset = Matrix44r(), ! const Material& m = defaults::material) = 0; ! ! /// Adds a ray Shape to this Solid. ! virtual void OPAL_CALL addRay(const Point3r& origin, ! const Vec3r& dir, real length, ! const Matrix44r& offset = Matrix44r(), ! const Material& m = defaults::material) = 0; ! /// The data pointers passed in here must remain valid because no data ! /// is stored within the Solid. It is critical that the size of the ! /// data type used in these arrays (i.e. OPAL real) matches the size ! /// of the data type expected by the underlying physics engine. ! virtual void OPAL_CALL addMesh(const real* vertexArray[3], ! int numVertices, const int* faceArray, int numFaces, ! const Matrix44r& offset = Matrix44r(), ! const Material& m = defaults::material) = 0; ! //virtual void addCHull(); /// Applies a force/torque to this Solid. If the Solid is disabled, --- 303,355 ---- virtual Quaternion OPAL_CALL getQuaternion()const; ! /// Adds a Shape to this Solid. ! virtual void OPAL_CALL addShape(const ShapeData& sd) = 0; ! ///// Adds a box Shape to this Solid. ! //virtual void OPAL_CALL addBox(const Vec3r& dimensions, ! // const Matrix44r& offset = Matrix44r(), ! // const Material& m = defaults::material) = 0; ! ///// Adds a sphere Shape to this Solid. ! //virtual void OPAL_CALL addSphere(real radius, ! // const Matrix44r& offset = Matrix44r(), ! // const Material& m = defaults::material) = 0; ! ///// Adds a plane Shape to this Solid. abcd are used to define ! ///// the plane equation a*x + b*y + c*z = d. ! //virtual void OPAL_CALL addPlane(real abcd[4], ! // const Material& m = defaults::material) = 0; ! //// alternate plane definition method; uses a point on the plane and ! //// the plane normal ! ////void addPlane(const Point3r& point, const Vec3r& normal, ! //// const Material& m = defaults::material); ! ! ////note: normal cylinders are not yet part of standard ODE ! ////virtual void addCylinder(real radius, real length, ! //// const Matrix44r& offset = Matrix44r(), ! //// const Material& m = defaults::material) = 0; ! ! ///// Adds a capsule Shape to this Solid. ! //virtual void OPAL_CALL addCapsule(real radius, real length, // const Matrix44r& offset = Matrix44r(), // const Material& m = defaults::material) = 0; ! ///// Adds a ray Shape to this Solid. ! //virtual void OPAL_CALL addRay(const Point3r& origin, ! // const Vec3r& dir, real length, ! // const Matrix44r& offset = Matrix44r(), ! // const Material& m = defaults::material) = 0; ! ///// The data pointers passed in here must remain valid because no data ! ///// is stored within the Solid. It is critical that the size of the ! ///// data type used in these arrays (i.e. OPAL real) matches the size ! ///// of the data type expected by the underlying physics engine. ! //virtual void OPAL_CALL addMesh(const real* vertexArray[3], ! // int numVertices, const int* faceArray, int numFaces, ! // const Matrix44r& offset = Matrix44r(), ! // const Material& m = defaults::material) = 0; ! ////virtual void addCHull(); /// Applies a force/torque to this Solid. If the Solid is disabled, *************** *** 250,257 **** // TODO: replace with SolidData functions? ! virtual BodyState OPAL_CALL getState()const; // TODO: replace with SolidData functions? ! virtual void OPAL_CALL setState(const BodyState & s); /// Update the OPAL transform using the physics engine transform. --- 435,442 ---- // TODO: replace with SolidData functions? ! //virtual BodyState OPAL_CALL getState()const; // TODO: replace with SolidData functions? ! //virtual void OPAL_CALL setState(const BodyState & s); /// Update the OPAL transform using the physics engine transform. *************** *** 274,285 **** std::vector<Force> mForceList; /// This Solids's transform corresponding to its center of mass. ! Matrix44r mTransform; /// True if this Solid is enabled. ! bool mEnabled; /// True if this Solid is static. ! bool mStatic; /// Pointer to this Solid's event handler. --- 459,473 ---- std::vector<Force> mForceList; + /// Stores data describing the Solid. + SolidData mData; + /// This Solids's transform corresponding to its center of mass. ! //Matrix44r mTransform; /// True if this Solid is enabled. ! //bool mEnabled; /// True if this Solid is static. ! //bool mStatic; /// Pointer to this Solid's event handler. *************** *** 296,303 **** /// The amount of linear damping used by this Solid. ! real mLinearDamping; /// The amount of angular damping used by this Solid. ! real mAngularDamping; private: --- 484,491 ---- /// The amount of linear damping used by this Solid. ! //real mLinearDamping; /// The amount of angular damping used by this Solid. ! //real mAngularDamping; private: Index: BlueprintManager.h =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** BlueprintManager.h 19 Feb 2005 20:54:36 -0000 1.13 --- BlueprintManager.h 22 Feb 2005 01:25:55 -0000 1.14 *************** *** 46,50 **** virtual ~BlueprintManager(); ! virtual void OPAL_CALL loadFile(const std::string& filename); virtual void OPAL_CALL addBlueprint(Blueprint* bp); --- 46,50 ---- virtual ~BlueprintManager(); ! //virtual void OPAL_CALL loadFile(const std::string& filename); virtual void OPAL_CALL addBlueprint(Blueprint* bp); *************** *** 56,61 **** private: ! SolidDescription loadSolid(const TiXmlNode* nodePtr, ! const std::string& filename); JointData loadJoint(const TiXmlNode* nodePtr, --- 56,61 ---- private: ! //SolidData loadSolid(const TiXmlNode* nodePtr, ! // const std::string& filename); JointData loadJoint(const TiXmlNode* nodePtr, *************** *** 65,70 **** const std::string& filename); ! ShapeDescription loadShape(const TiXmlNode* nodePtr, ! const std::string& filename); // helper function; returns false if the attribute doesn't exist --- 65,70 ---- const std::string& filename); ! //ShapeData loadShape(const TiXmlNode* nodePtr, ! // const std::string& filename); // helper function; returns false if the attribute doesn't exist Index: Joint.h =================================================================== RCS file: /cvsroot/opal/opal/src/Joint.h,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** Joint.h 21 Feb 2005 15:54:38 -0000 1.52 --- Joint.h 22 Feb 2005 01:25:55 -0000 1.53 *************** *** 105,127 **** JointData(const JointData& jd) { ! type = jd.type; ! enabled = jd.enabled; ! //name = jd.name; ! solid0 = jd.solid0; ! solid1 = jd.solid1; ! anchor = jd.anchor; ! ! for (int i=0; i<3; ++i) ! { ! axis[i] = jd.axis[i]; ! } ! ! breakMode = jd.breakMode; ! breakThresh = jd.breakThresh; ! accumThresh = jd.accumThresh; ! accumDamage = jd.accumDamage; } ! /// This is necessary because JointDatas contain an array. void operator=(const JointData& jd) { --- 105,112 ---- JointData(const JointData& jd) { ! (*this) = jd; } ! /// Makes a deep copy. void operator=(const JointData& jd) { *************** *** 221,225 **** /// Returns all data describing the Joint. ! virtual const JointData& getJointData(); /// Returns the Joint type. --- 206,210 ---- /// Returns all data describing the Joint. ! virtual const JointData& OPAL_CALL getJointData(); /// Returns the Joint type. *************** *** 377,388 **** void updateDamage(real currentStress); ! /// Stores most data describing the Joint. JointData mData; ! /// A pointer to Solid0. ! Solid* mSolid0; ! /// A pointer to Solid1. ! Solid* mSolid1; /// A pointer to the Joint's event handler. --- 362,373 ---- void updateDamage(real currentStress); ! /// Stores data describing the Joint. JointData mData; ! ///// A pointer to Solid0. ! //Solid* mSolid0; ! ///// A pointer to Solid1. ! //Solid* mSolid1; /// A pointer to the Joint's event handler. Index: BlueprintManager.cpp =================================================================== RCS file: /cvsroot/opal/opal/src/BlueprintManager.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** BlueprintManager.cpp 19 Feb 2005 20:54:36 -0000 1.23 --- BlueprintManager.cpp 22 Feb 2005 01:25:55 -0000 1.24 *************** *** 82,264 **** } ! void BlueprintManager::loadFile(const std::string& filename) ! { ! #ifdef OPAL_USE_XML ! ! // the XML file will contain one or more OpalBlueprint elements; ! // each OpalBlueprint element contains one or more Solid elements ! // and zero or more Joint elements; an OpalBlueprint can contain ! // zero or more Space elements containing Solid elements; note ! // that in many case (e.g. offsets, materials) the default values ! // will automatically be used if no elements are specified ! ! TiXmlDocument file; ! if (false == file.LoadFile(filename.c_str())) ! { ! std::cout << "Error in opal::BlueprintManager::loadFile: \ ! Failed to load XML file: " ! << filename << std::endl; ! return; ! } ! ! TiXmlElement* rootElement = file.RootElement(); ! if (NULL == rootElement) ! { ! std::cout << "Error in opal::BlueprintManager::loadFile: \ ! Missing root element in XML file: " ! << filename << std::endl; ! return; ! } ! ! // loop over blueprints ! TiXmlNode* blueprintNodePtr = NULL; ! while (blueprintNodePtr = rootElement->IterateChildren( ! "OpalBlueprint", blueprintNodePtr)) ! { ! Blueprint* bp = new Blueprint(); ! ! bp->setName(getAttributeString(blueprintNodePtr, "name")); ! ! // loop over spaces; TODO: should we support hierarchical ! // spaces in XML files? ! TiXmlNode* spaceNodePtr = NULL; ! while (spaceNodePtr = blueprintNodePtr->IterateChildren( ! "Space", spaceNodePtr)) ! { ! SpaceDescription newSpace; ! ! // loop over solids within this space ! TiXmlNode* solidNodePtr = NULL; ! while (solidNodePtr = spaceNodePtr->IterateChildren( ! "Solid", solidNodePtr)) ! { ! SolidDescription newSolid = loadSolid(solidNodePtr, ! filename); ! bp->addSolid(newSolid); ! newSpace.solidNameList.push_back(newSolid.name); ! } ! ! if (0 == newSpace.solidNameList.size()) ! { ! std::cout << "Warning in opal::BlueprintManager::\ ! loadFile: Empty space will be ignored" ! << " in " << filename << std::endl; ! } ! else ! { ! bp->addSpace(newSpace); ! } ! } ! ! // loop over solids (those not in spaces) ! TiXmlNode* solidNodePtr = NULL; ! while (solidNodePtr = blueprintNodePtr->IterateChildren( ! "Solid", solidNodePtr)) ! { ! SolidDescription newSolid = loadSolid(solidNodePtr, ! filename); ! bp->addSolid(newSolid); ! } ! ! // loop over joints ! TiXmlNode* jointNodePtr = NULL; ! while (jointNodePtr = blueprintNodePtr->IterateChildren( ! "Joint", jointNodePtr)) ! { ! JointData newJoint = loadJoint(jointNodePtr, ! filename); ! bp->addJoint(newJoint); ! } ! ! addBlueprint(bp); ! } ! #endif ! } ! ! SolidDescription BlueprintManager::loadSolid(const TiXmlNode* nodePtr, ! const std::string& filename) ! { ! SolidDescription sd; ! ! #ifdef OPAL_USE_XML ! ! sd.name = getAttributeString(nodePtr, "name"); ! ! // specify default parameters in case they aren't given in the file ! sd.isStatic = defaults::staticSolids; ! sd.linearDamping = defaults::linearDamping; ! sd.angularDamping = defaults::angularDamping; ! ! // load Params elements ! TiXmlNode* paramsNodePtr = ! const_cast<TiXmlNode*>(nodePtr)->FirstChild("Params"); ! if (NULL != paramsNodePtr) ! { ! // loop over Params ! TiXmlNode* paramNodePtr = NULL; ! ! while (paramNodePtr = paramsNodePtr->IterateChildren("Param", ! paramNodePtr)) ! { ! TiXmlAttribute* a = ! paramNodePtr->ToElement()->FirstAttribute(); ! std::string name = a->Name(); ! std::string value = a->Value(); ! ! if (name == "static") ! { ! if (value == "true") ! { ! sd.isStatic = true; ! } ! // default static value is specified above ! } ! else if (name == "lineardamping") ! { ! sd.linearDamping = getAttributeReal(paramNodePtr, ! "lineardamping"); ! } ! else if (name == "angulardamping") ! { ! sd.angularDamping = getAttributeReal(paramNodePtr, ! "value"); ! } ! else ! { ! // this is a user-defined property ! UserProperty prop; ! prop.name = name; ! prop.value = value; ! sd.userProperties.push_back(prop); ! } ! } ! } ! ! // load Offset element ! TiXmlNode* offsetNodePtr = ! const_cast<TiXmlNode*>(nodePtr)->FirstChild("Offset"); ! if (NULL != offsetNodePtr) ! { ! sd.transform = loadOffset(offsetNodePtr, filename); ! } ! else ! { ! // offset will remain as an identity matrix ! sd.transform.makeIdentity(); ! } ! ! // loop over shapes ! TiXmlNode* shapeNodePtr = NULL; ! while (shapeNodePtr = const_cast<TiXmlNode*> ! (nodePtr)->IterateChildren("Shape", shapeNodePtr)) ! { ! ShapeDescription shape = loadShape(shapeNodePtr, filename); ! sd.shapeList.push_back(shape); ! } ! ! #endif ! ! return sd; ! } Matrix44r BlueprintManager::loadOffset(const TiXmlNode* nodePtr, --- 82,264 ---- } ! // void BlueprintManager::loadFile(const std::string& filename) ! // { ! //#ifdef OPAL_USE_XML ! // ! // // the XML file will contain one or more OpalBlueprint elements; ! // // each OpalBlueprint element contains one or more Solid elements ! // // and zero or more Joint elements; an OpalBlueprint can contain ! // // zero or more Space elements containing Solid elements; note ! // // that in many case (e.g. offsets, materials) the default values ! // // will automatically be used if no elements are specified ! // ! // TiXmlDocument file; ! // if (false == file.LoadFile(filename.c_str())) ! // { ! // std::cout << "Error in opal::BlueprintManager::loadFile: \ ! // Failed to load XML file: " ! // << filename << std::endl; ! // return; ! // } ! // ! // TiXmlElement* rootElement = file.RootElement(); ! // if (NULL == rootElement) ! // { ! // std::cout << "Error in opal::BlueprintManager::loadFile: \ ! // Missing root element in XML file: " ! // << filename << std::endl; ! // return; ! // } ! // ! // // loop over blueprints ! // TiXmlNode* blueprintNodePtr = NULL; ! // while (blueprintNodePtr = rootElement->IterateChildren( ! // "OpalBlueprint", blueprintNodePtr)) ! // { ! // Blueprint* bp = new Blueprint(); ! // ! // bp->setName(getAttributeString(blueprintNodePtr, "name")); ! // ! // // loop over spaces; TODO: should we support hierarchical ! // // spaces in XML files? ! // TiXmlNode* spaceNodePtr = NULL; ! // while (spaceNodePtr = blueprintNodePtr->IterateChildren( ! // "Space", spaceNodePtr)) ! // { ! // SpaceDescription newSpace; ! // ! // // loop over solids within this space ! // TiXmlNode* solidNodePtr = NULL; ! // while (solidNodePtr = spaceNodePtr->IterateChildren( ! // "Solid", solidNodePtr)) ! // { ! // SolidData newSolid = loadSolid(solidNodePtr, ! // filename); ! // bp->addSolid(newSolid); ! // newSpace.solidNameList.push_back(newSolid.name); ! // } ! // ! // if (0 == newSpace.solidNameList.size()) ! // { ! // std::cout << "Warning in opal::BlueprintManager::\ ! // loadFile: Empty space will be ignored" ! // << " in " << filename << std::endl; ! // } ! // else ! // { ! // bp->addSpace(newSpace); ! // } ! // } ! // ! // // loop over solids (those not in spaces) ! // TiXmlNode* solidNodePtr = NULL; ! // while (solidNodePtr = blueprintNodePtr->IterateChildren( ! // "Solid", solidNodePtr)) ! // { ! // SolidData newSolid = loadSolid(solidNodePtr, ! // filename); ! // bp->addSolid(newSolid); ! // } ! // ! // // loop over joints ! // TiXmlNode* jointNodePtr = NULL; ! // while (jointNodePtr = blueprintNodePtr->IterateChildren( ! // "Joint", jointNodePtr)) ! // { ! // JointData newJoint = loadJoint(jointNodePtr, ! // filename); ! // bp->addJoint(newJoint); ! // } ! // ! // addBlueprint(bp); ! // } ! //#endif ! // } ! // ! // SolidData BlueprintManager::loadSolid(const TiXmlNode* nodePtr, ! // const std::string& filename) ! // { ! // SolidData sd; ! // ! //#ifdef OPAL_USE_XML ! // ! // sd.name = getAttributeString(nodePtr, "name"); ! // ! // // specify default parameters in case they aren't given in the file ! // sd.isStatic = defaults::staticSolids; ! // sd.linearDamping = defaults::linearDamping; ! // sd.angularDamping = defaults::angularDamping; ! // ! // // load Params elements ! // TiXmlNode* paramsNodePtr = ! // const_cast<TiXmlNode*>(nodePtr)->FirstChild("Params"); ! // if (NULL != paramsNodePtr) ! // { ! // // loop over Params ! // TiXmlNode* paramNodePtr = NULL; ! // ! // while (paramNodePtr = paramsNodePtr->IterateChildren("Param", ! // paramNodePtr)) ! // { ! // TiXmlAttribute* a = ! // paramNodePtr->ToElement()->FirstAttribute(); ! // std::string name = a->Name(); ! // std::string value = a->Value(); ! // ! // if (name == "static") ! // { ! // if (value == "true") ! // { ! // sd.isStatic = true; ! // } ! // // default static value is specified above ! // } ! // else if (name == "lineardamping") ! // { ! // sd.linearDamping = getAttributeReal(paramNodePtr, ! // "lineardamping"); ! // } ! // else if (name == "angulardamping") ! // { ! // sd.angularDamping = getAttributeReal(paramNodePtr, ! // "value"); ! // } ! // else ! // { ! // // this is a user-defined property ! // UserProperty prop; ! // prop.name = name; ! // prop.value = value; ! // sd.userProperties.push_back(prop); ! // } ! // } ! // } ! // ! // // load Offset element ! // TiXmlNode* offsetNodePtr = ! // const_cast<TiXmlNode*>(nodePtr)->FirstChild("Offset"); ! // if (NULL != offsetNodePtr) ! // { ! // sd.transform = loadOffset(offsetNodePtr, filename); ! // } ! // else ! // { ! // // offset will remain as an identity matrix ! // sd.transform.makeIdentity(); ! // } ! // ! // // loop over shapes ! // TiXmlNode* shapeNodePtr = NULL; ! // while (shapeNodePtr = const_cast<TiXmlNode*> ! // (nodePtr)->IterateChildren("Shape", shapeNodePtr)) ! // { ! // ShapeDescription shape = loadShape(shapeNodePtr, filename); ! // sd.shapeList.push_back(shape); ! // } ! // ! //#endif ! // ! // return sd; ! // } Matrix44r BlueprintManager::loadOffset(const TiXmlNode* nodePtr, *************** *** 337,470 **** } ! ShapeDescription BlueprintManager::loadShape(const TiXmlNode* nodePtr, ! const std::string& filename) ! { ! ShapeDescription shape; ! ! #ifdef OPAL_USE_XML ! ! std::string type = getAttributeString(nodePtr, "type"); ! ! // load dimensions; note that dimension attributes are different ! // for each shape type ! TiXmlNode* dimensionsNodePtr = const_cast<TiXmlNode*> ! (nodePtr)->FirstChild("Dimensions"); ! ! if ("box" == type) ! { ! shape.type = BOX_SHAPE; ! shape.dimensions[0] = getAttributeReal(dimensionsNodePtr, "x"); ! shape.dimensions[1] = getAttributeReal(dimensionsNodePtr, "y"); ! shape.dimensions[2] = getAttributeReal(dimensionsNodePtr, "z"); ! shape.dimensions[3] = 0; ! shape.dimensions[4] = 0; ! shape.dimensions[5] = 0; ! shape.dimensions[6] = 0; ! } ! else if ("sphere" == type) ! { ! shape.type = SPHERE_SHAPE; ! shape.dimensions[0] = getAttributeReal(dimensionsNodePtr, ! "radius"); ! shape.dimensions[1] = 0; ! shape.dimensions[2] = 0; ! shape.dimensions[3] = 0; ! shape.dimensions[4] = 0; ! shape.dimensions[5] = 0; ! shape.dimensions[6] = 0; ! } ! else if ("capsule" == type) ! { ! shape.type = CAPSULE_SHAPE; ! shape.dimensions[0] = getAttributeReal(dimensionsNodePtr, ! "radius"); ! shape.dimensions[1] = getAttributeReal(dimensionsNodePtr, ! "length"); ! shape.dimensions[2] = 0; ! shape.dimensions[3] = 0; ! shape.dimensions[4] = 0; ! shape.dimensions[5] = 0; ! shape.dimensions[6] = 0; ! } ! else if ("plane" == type) ! { ! shape.type = PLANE_SHAPE; ! //shape.dimensions[0] = ge... [truncated message content] |