diff --git a/Bullet/BroadphaseCollision/OverlappingPairCache.h b/Bullet/BroadphaseCollision/OverlappingPairCache.h index e0fd5a4c5..05b2025f8 100644 --- a/Bullet/BroadphaseCollision/OverlappingPairCache.h +++ b/Bullet/BroadphaseCollision/OverlappingPairCache.h @@ -77,4 +77,5 @@ class OverlappingPairCache : public BroadphaseInterface }; -#endif //OVERLAPPING_PAIR_CACHE_H \ No newline at end of file +#endif //OVERLAPPING_PAIR_CACHE_H + diff --git a/Bullet/BroadphaseCollision/SimpleBroadphase.cpp b/Bullet/BroadphaseCollision/SimpleBroadphase.cpp index fd2fbaec8..5733f0418 100644 --- a/Bullet/BroadphaseCollision/SimpleBroadphase.cpp +++ b/Bullet/BroadphaseCollision/SimpleBroadphase.cpp @@ -97,6 +97,7 @@ BroadphaseProxy* SimpleBroadphase::CreateProxy( const SimdVector3& min, const class RemovingOverlapCallback : public OverlapCallback { +protected: virtual bool ProcessOverlap(BroadphasePair& pair) { assert(0); @@ -107,7 +108,7 @@ class RemovePairContainingProxy { BroadphaseProxy* m_targetProxy; - +protected: virtual bool ProcessOverlap(BroadphasePair& pair) { SimpleBroadphaseProxy* proxy0 = static_cast(pair.m_pProxy0); diff --git a/Bullet/CollisionDispatch/CollisionCreateFunc.h b/Bullet/CollisionDispatch/CollisionCreateFunc.h index 6f12b7af5..d86948bec 100644 --- a/Bullet/CollisionDispatch/CollisionCreateFunc.h +++ b/Bullet/CollisionDispatch/CollisionCreateFunc.h @@ -39,4 +39,5 @@ struct CollisionAlgorithmCreateFunc return 0; } }; -#endif //COLLISION_CREATE_FUNC \ No newline at end of file +#endif //COLLISION_CREATE_FUNC + diff --git a/Bullet/CollisionDispatch/CollisionDispatcher.cpp b/Bullet/CollisionDispatch/CollisionDispatcher.cpp index 93d590c1b..b49ff49ad 100644 --- a/Bullet/CollisionDispatch/CollisionDispatcher.cpp +++ b/Bullet/CollisionDispatch/CollisionDispatcher.cpp @@ -334,8 +334,6 @@ void CollisionDispatcher::DispatchAllCollisionPairs(OverlappingPairCache* pairCa { //m_blockedForChanges = true; - int i; - int dispatcherId = GetUniqueId(); CollisionPairCallback collisionCallback(dispatchInfo,this,dispatcherId); @@ -344,4 +342,6 @@ void CollisionDispatcher::DispatchAllCollisionPairs(OverlappingPairCache* pairCa //m_blockedForChanges = false; -} \ No newline at end of file +} + + diff --git a/Bullet/CollisionDispatch/CollisionWorld.cpp b/Bullet/CollisionDispatch/CollisionWorld.cpp index e750e29b5..a4aa7bcde 100644 --- a/Bullet/CollisionDispatch/CollisionWorld.cpp +++ b/Bullet/CollisionDispatch/CollisionWorld.cpp @@ -33,7 +33,6 @@ CollisionWorld::~CollisionWorld() //clean up remaining objects std::vector::iterator i; - int index = 0; for (i=m_collisionObjects.begin(); !(i==m_collisionObjects.end()); i++) diff --git a/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.cpp b/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.cpp index 0a79d2b7b..a29f0d492 100644 --- a/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.cpp +++ b/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.cpp @@ -141,4 +141,6 @@ float CompoundCollisionAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0, } return hitFraction; -} \ No newline at end of file +} + + diff --git a/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.h b/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.h index 3c080ca5f..9d9ef90c1 100644 --- a/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.h +++ b/Bullet/CollisionDispatch/CompoundCollisionAlgorithm.h @@ -30,12 +30,12 @@ class Dispatcher; /// Place holder, not fully implemented yet class CompoundCollisionAlgorithm : public CollisionAlgorithm { + Dispatcher* m_dispatcher; BroadphaseProxy m_compoundProxy; BroadphaseProxy m_otherProxy; std::vector m_childProxies; std::vector m_childCollisionAlgorithms; - Dispatcher* m_dispatcher; BroadphaseProxy m_compound; BroadphaseProxy m_other; diff --git a/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp b/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp index 765ae8625..2e896989a 100644 --- a/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp +++ b/Bullet/CollisionDispatch/ConvexConvexAlgorithm.cpp @@ -340,7 +340,6 @@ float ConvexConvexAlgorithm::CalculateTimeOfImpact(BroadphaseProxy* proxy0,Broad CollisionObject* col0 = static_cast(m_box0.m_clientObject); float squareMot0 = (col0->m_interpolationWorldTransform.getOrigin() - col0->m_worldTransform.getOrigin()).length2(); - float squareMot1 = (col1->m_interpolationWorldTransform.getOrigin() - col1->m_worldTransform.getOrigin()).length2(); if (squareMot0 < col0->m_ccdSquareMotionTreshold && squareMot0 < col0->m_ccdSquareMotionTreshold) diff --git a/Bullet/CollisionDispatch/SimulationIslandManager.cpp b/Bullet/CollisionDispatch/SimulationIslandManager.cpp index 06db9acef..d9b7d4b21 100644 --- a/Bullet/CollisionDispatch/SimulationIslandManager.cpp +++ b/Bullet/CollisionDispatch/SimulationIslandManager.cpp @@ -13,6 +13,11 @@ SimulationIslandManager::SimulationIslandManager() { } +SimulationIslandManager::~SimulationIslandManager() +{ +} + + void SimulationIslandManager::InitUnionFind(int n) { m_unionFind.reset(n); @@ -131,17 +136,13 @@ bool PersistentManifoldSortPredicate(const PersistentManifold* lhs, const Persis // void SimulationIslandManager::BuildAndProcessIslands(Dispatcher* dispatcher,CollisionObjectArray& collisionObjects, IslandCallback* callback) { - - - int numBodies = collisionObjects.size(); - //we are going to sort the unionfind array, and store the element id in the size //afterwards, we clean unionfind, to make sure no-one uses it anymore GetUnionFind().sortIslands(); int numElem = GetUnionFind().getNumElements(); - int startIslandIndex=0,endIslandIndex=1; + int endIslandIndex=1; //update the sleeping state for bodies, if all are sleeping for (int startIslandIndex=0;startIslandIndex& planeEquations , std::vector& verticesOut ) { - float minimumDotProduct = 1e30f; - const int numbrushes = planeEquations.size(); // brute force: for (int i=0;i& planeEquations, cons } return true; -} \ No newline at end of file +} diff --git a/Demos/BspDemo/BspConverter.h b/Demos/BspDemo/BspConverter.h index 01e9c9c5b..bb7cae470 100644 --- a/Demos/BspDemo/BspConverter.h +++ b/Demos/BspDemo/BspConverter.h @@ -37,4 +37,5 @@ class BspConverter }; -#endif //BSP_CONVERTER_H \ No newline at end of file +#endif //BSP_CONVERTER_H + diff --git a/Demos/BspDemo/BspDemo.cpp b/Demos/BspDemo/BspDemo.cpp index 6e5ca8ac4..caec6c2be 100644 --- a/Demos/BspDemo/BspDemo.cpp +++ b/Demos/BspDemo/BspDemo.cpp @@ -261,7 +261,7 @@ char* makeExeToBspFilename(const char* lpCmdLine) // displays the first filename const char *in = lpCmdLine; char* out = cleaned_filename; - *out = NULL; + *out = '\0'; // If the first character is a ", skip it (filenames with spaces in them are quoted) if(*in == '\"') { @@ -276,7 +276,7 @@ char* makeExeToBspFilename(const char* lpCmdLine) break; // If we hit a null or a quote, stop copying. This will get just the first filename. - if(*in == NULL || *in == '\"') + if(*in == '\0' || *in == '\"') break; // Copy while swapping backslashes for forward ones if(*in == '\\') diff --git a/Demos/BspDemo/BspDemo.h b/Demos/BspDemo/BspDemo.h index 1a63af889..d3326a707 100644 --- a/Demos/BspDemo/BspDemo.h +++ b/Demos/BspDemo/BspDemo.h @@ -34,4 +34,6 @@ class BspDemo : public DemoApplication }; -#endif //BSP_DEMO_H \ No newline at end of file +#endif //BSP_DEMO_H + + diff --git a/Demos/BspDemo/BspLoader.cpp b/Demos/BspDemo/BspLoader.cpp index d4aa38de2..f4f36badd 100644 --- a/Demos/BspDemo/BspLoader.cpp +++ b/Demos/BspDemo/BspLoader.cpp @@ -710,4 +710,5 @@ const BSPEntity * BspLoader::getEntityByValue( const char* name, const char* val } } return entity; -} \ No newline at end of file +} + diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 273e3146a..507867ab7 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -269,8 +269,7 @@ void CcdPhysicsDemo::initPhysics() { CollisionDispatcher* dispatcher = new CollisionDispatcher(); - ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher(); - + SimdVector3 worldAabbMin(-10000,-10000,-10000); SimdVector3 worldAabbMax(10000,10000,10000); diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.h b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.h index e3cb05546..da007c376 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.h +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.h @@ -32,4 +32,5 @@ class CcdPhysicsDemo : public DemoApplication }; -#endif //CCD_PHYSICS_DEMO_H \ No newline at end of file +#endif //CCD_PHYSICS_DEMO_H + diff --git a/Demos/ColladaDemo/ColladaConverter.cpp b/Demos/ColladaDemo/ColladaConverter.cpp index 4f48cc8f0..95a68785a 100644 --- a/Demos/ColladaDemo/ColladaConverter.cpp +++ b/Demos/ColladaDemo/ColladaConverter.cpp @@ -1,145 +1,145 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#include "ColladaConverter.h" - -#include "dae.h" -#include "dom/domCOLLADA.h" - -#include "CollisionShapes/BoxShape.h" -#include "CollisionShapes/SphereShape.h" -#include "CollisionShapes/CylinderShape.h" -#include "CollisionShapes/ConeShape.h" -#include "CollisionShapes/StaticPlaneShape.h" -#include "CollisionShapes/ConvexHullShape.h" -#include "CollisionShapes/TriangleMesh.h" -#include "CollisionShapes/ConvexTriangleMeshShape.h" -#include "CollisionShapes/TriangleMeshShape.h" -#include "CollisionShapes/TriangleIndexVertexArray.h" -#include "CollisionShapes/CompoundShape.h" - -#include "CcdPhysicsController.h" - - -char* getLastFileName(); -char* fixFileName(const char* lpCmdLine); -//todo: sort out this domInstance_rigid_bodyRef forward definition, put it in the headerfile and make it virtual (make code more re-usable) - -struct RigidBodyInput -{ - domInstance_rigid_bodyRef m_instanceRigidBodyRef; - domRigid_bodyRef m_rigidBodyRef2; - - char* m_bodyName; -}; - -struct ConstraintInput -{ - domInstance_physics_modelRef m_instance_physicsModelRef; - domPhysics_modelRef m_model; -}; - - -struct RigidBodyOutput -{ - float m_mass; - bool m_isDynamics; - CollisionShape* m_colShape; - CompoundShape* m_compoundShape; -}; - - - -domMatrix_Array emptyMatrixArray; -domNodeRef m_colladadomNodes[COLLADA_CONVERTER_MAX_NUM_OBJECTS]; - - -SimdTransform GetSimdTransformFromCOLLADA_DOM(domMatrix_Array& matrixArray, - domRotate_Array& rotateArray, - domTranslate_Array& translateArray - ) - -{ - SimdTransform startTransform; - startTransform.setIdentity(); - - int i; - //either load the matrix (worldspace) or incrementally build the transform from 'translate'/'rotate' - for (i=0;igetValue(); - SimdVector3 origin(fl16.get(3),fl16.get(7),fl16.get(11)); - startTransform.setOrigin(origin); - SimdMatrix3x3 basis(fl16.get(0),fl16.get(1),fl16.get(2), - fl16.get(4),fl16.get(5),fl16.get(6), - fl16.get(8),fl16.get(9),fl16.get(10)); - startTransform.setBasis(basis); - } - - for (i=0;igetValue(); - float angleRad = SIMD_RADS_PER_DEG*fl4.get(3); - SimdQuaternion rotQuat(SimdVector3(fl4.get(0),fl4.get(1),fl4.get(2)),angleRad); - startTransform.getBasis() = startTransform.getBasis() * SimdMatrix3x3(rotQuat); - } - - for (i=0;igetValue(); - startTransform.getOrigin() += SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2)); - } - return startTransform; -} - - - - - -ColladaConverter::ColladaConverter() -:m_collada(0), -m_dom(0), -m_filename(0), -m_numObjects(0) -{ - //Collada-m_dom - m_collada = new DAE; - - //clear - { - - for (int i=0;iload(filename);//,docBuffer); - - if (res != DAE_OK) - { +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "ColladaConverter.h" + +#include "dae.h" +#include "dom/domCOLLADA.h" + +#include "CollisionShapes/BoxShape.h" +#include "CollisionShapes/SphereShape.h" +#include "CollisionShapes/CylinderShape.h" +#include "CollisionShapes/ConeShape.h" +#include "CollisionShapes/StaticPlaneShape.h" +#include "CollisionShapes/ConvexHullShape.h" +#include "CollisionShapes/TriangleMesh.h" +#include "CollisionShapes/ConvexTriangleMeshShape.h" +#include "CollisionShapes/TriangleMeshShape.h" +#include "CollisionShapes/TriangleIndexVertexArray.h" +#include "CollisionShapes/CompoundShape.h" + +#include "CcdPhysicsController.h" + + +char* getLastFileName(); +char* fixFileName(const char* lpCmdLine); +//todo: sort out this domInstance_rigid_bodyRef forward definition, put it in the headerfile and make it virtual (make code more re-usable) + +struct RigidBodyInput +{ + domInstance_rigid_bodyRef m_instanceRigidBodyRef; + domRigid_bodyRef m_rigidBodyRef2; + + char* m_bodyName; +}; + +struct ConstraintInput +{ + domInstance_physics_modelRef m_instance_physicsModelRef; + domPhysics_modelRef m_model; +}; + + +struct RigidBodyOutput +{ + float m_mass; + bool m_isDynamics; + CollisionShape* m_colShape; + CompoundShape* m_compoundShape; +}; + + + +domMatrix_Array emptyMatrixArray; +domNodeRef m_colladadomNodes[COLLADA_CONVERTER_MAX_NUM_OBJECTS]; + + +SimdTransform GetSimdTransformFromCOLLADA_DOM(domMatrix_Array& matrixArray, + domRotate_Array& rotateArray, + domTranslate_Array& translateArray + ) + +{ + SimdTransform startTransform; + startTransform.setIdentity(); + + unsigned int i; + //either load the matrix (worldspace) or incrementally build the transform from 'translate'/'rotate' + for (i=0;igetValue(); + SimdVector3 origin(fl16.get(3),fl16.get(7),fl16.get(11)); + startTransform.setOrigin(origin); + SimdMatrix3x3 basis(fl16.get(0),fl16.get(1),fl16.get(2), + fl16.get(4),fl16.get(5),fl16.get(6), + fl16.get(8),fl16.get(9),fl16.get(10)); + startTransform.setBasis(basis); + } + + for (i=0;igetValue(); + float angleRad = SIMD_RADS_PER_DEG*fl4.get(3); + SimdQuaternion rotQuat(SimdVector3(fl4.get(0),fl4.get(1),fl4.get(2)),angleRad); + startTransform.getBasis() = startTransform.getBasis() * SimdMatrix3x3(rotQuat); + } + + for (i=0;igetValue(); + startTransform.getOrigin() += SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2)); + } + return startTransform; +} + + + + + +ColladaConverter::ColladaConverter() +:m_collada(0), +m_dom(0), +m_filename(0), +m_numObjects(0) +{ + //Collada-m_dom + m_collada = new DAE; + + //clear + { + + for (int i=0;iload(filename);//,docBuffer); + + if (res != DAE_OK) + { //some platforms might require different path, try two additional locations char newname[256]; sprintf(newname,"../../%s",orgfilename); @@ -147,1128 +147,1118 @@ bool ColladaConverter::load(const char* orgfilename) res = m_collada->load(filename); if (res != DAE_OK) { - printf("DAE/Collada-m_dom: Couldn't load %s\n",filename); - return false; - } - } - - if (res == DAE_OK) - { - - m_dom = m_collada->getDom(filename); - if ( !m_dom ) - { - printf("COLLADA File loaded to the m_dom, but query for the m_dom assets failed \n" ); - printf("COLLADA Load Aborted! \n" ); - delete m_collada; - return false; - } - } - return true; -} - - - - - -bool ColladaConverter::convert() -{ - -//succesfully loaded file, now convert data - - if ( m_dom->getAsset()->getUp_axis() ) - { - domAsset::domUp_axis * up = m_dom->getAsset()->getUp_axis(); - switch( up->getValue() ) - { - case UPAXISTYPE_X_UP: - printf(" X is Up Data and Hiearchies must be converted!\n" ); - printf(" Conversion to X axis Up isn't currently supported!\n" ); - printf(" COLLADA_RT defaulting to Y Up \n" ); - SetGravity(SimdVector3(-10,0,0)); - SetCameraInfo(SimdVector3(1,0,0),1); - break; - case UPAXISTYPE_Y_UP: - printf(" Y Axis is Up for this file \n" ); - printf(" COLLADA_RT set to Y Up \n" ); - SetGravity(SimdVector3(0,-10,0)); - SetCameraInfo(SimdVector3(0,1,0),0); - - break; - case UPAXISTYPE_Z_UP: - printf(" Z Axis is Up for this file \n" ); - printf(" All Geometry and Hiearchies must be converted!\n" ); - SetGravity(SimdVector3(0,0,-10)); - break; - default: - - break; - } - } - - - //we don't handle visual objects, physics objects are rendered as such - for (int s=0;sgetLibrary_visual_scenes_array().getCount();s++) - { - domLibrary_visual_scenesRef scenesRef = m_dom->getLibrary_visual_scenes_array()[s]; - for (int i=0;igetVisual_scene_array().getCount();i++) - { - domVisual_sceneRef sceneRef = scenesRef->getVisual_scene_array()[i]; - for (int n=0;ngetNode_array().getCount();n++) - { - domNodeRef nodeRef = sceneRef->getNode_array()[n]; - nodeRef->getRotate_array(); - nodeRef->getTranslate_array(); - nodeRef->getScale_array(); - - } - } - } - - - - - // Load all the geometry libraries - for ( int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++) - { - domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i]; - - printf(" CrtScene::Reading Geometry Library \n" ); - for ( int i = 0; i < libgeom->getGeometry_array().getCount(); i++) - { - //ReadGeometry( ); - domGeometryRef lib = libgeom->getGeometry_array()[i]; - - domMesh *meshElement = lib->getMesh(); - if (meshElement) - { - // Find out how many groups we need to allocate space for - int numTriangleGroups = (int)meshElement->getTriangles_array().getCount(); - int numPolygonGroups = (int)meshElement->getPolygons_array().getCount(); - int totalGroups = numTriangleGroups + numPolygonGroups; - if (totalGroups == 0) - { - printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() ); - } else - { - printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups:%i\n",lib->getId(),numTriangleGroups,numPolygonGroups); - } - - - } - domConvex_mesh *convexMeshElement = lib->getConvex_mesh(); - if (convexMeshElement) - { - printf("found convexmesh element\n"); - // Find out how many groups we need to allocate space for - int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount(); - int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount(); - - int totalGroups = numTriangleGroups + numPolygonGroups; - if (totalGroups == 0) - { - printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() ); - }else - { - printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups); - } - }//fi - }//for each geometry - - }//for all geometry libraries - - - //m_dom->getLibrary_physics_models_array() - - for ( int i = 0; i < m_dom->getLibrary_physics_scenes_array().getCount(); i++) - { - domLibrary_physics_scenesRef physicsScenesRef = m_dom->getLibrary_physics_scenes_array()[i]; - for (int s=0;sgetPhysics_scene_array().getCount();s++) - { - domPhysics_sceneRef physicsSceneRef = physicsScenesRef->getPhysics_scene_array()[s]; - - if (physicsSceneRef->getTechnique_common()) - { - if (physicsSceneRef->getTechnique_common()->getGravity()) - { - const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue(); - printf("gravity set to %f,%f,%f\n",grav.get(0),grav.get(1),grav.get(2)); - - SetGravity(SimdVector3(grav.get(0),grav.get(1),grav.get(2))); - } - - } - - for (int m=0;mgetInstance_physics_model_array().getCount();m++) - { - domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[m]; - - daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); - - domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; - - - int p,r; - for ( p=0;pgetInstance_physics_model_array().getCount();p++) - { - domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; - - daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); - - domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; - - //todo: group some shared functionality in following 2 'blocks'. - for (r=0;rgetInstance_rigid_body_array().getCount();r++) - { - domInstance_rigid_bodyRef instRigidbodyRef = instancePhysicsModelRef->getInstance_rigid_body_array()[r]; - - float mass = 1.f; - bool isDynamics = true; - CollisionShape* colShape = 0; - CompoundShape* compoundShape = 0; - - xsNCName bodyName = instRigidbodyRef->getBody(); - - domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); - if (techniqueRef) - { - if (techniqueRef->getMass()) - { - mass = techniqueRef->getMass()->getValue(); - } - if (techniqueRef->getDynamic()) - { - isDynamics = techniqueRef->getDynamic()->getValue(); - } - } - - printf("mass = %f, isDynamics %i\n",mass,isDynamics); - - if (bodyName && model) - { - //try to find the rigid body - int numBody = model->getRigid_body_array().getCount(); - - for (int r=0;rgetRigid_body_array().getCount();r++) - { - domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; - if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) - { - - - RigidBodyOutput output; - output.m_colShape = colShape; - output.m_compoundShape = compoundShape; - - RigidBodyInput rbInput; - rbInput.m_rigidBodyRef2 = rigidBodyRef; - rbInput.m_instanceRigidBodyRef = instRigidbodyRef; - ConvertRigidBodyRef( rbInput , output ); - - mass = output.m_mass; - isDynamics = output.m_isDynamics; - colShape = output.m_colShape; - compoundShape = output.m_compoundShape; - - } - } - - ////////////////////// - } - - if (compoundShape) - colShape = compoundShape; - - if (colShape) - { - RigidBodyInput input; - input.m_instanceRigidBodyRef = instRigidbodyRef; - input.m_rigidBodyRef2 = 0; - input.m_bodyName = (char*)bodyName; - PreparePhysicsObject(input, isDynamics,mass,colShape); - } - } - } - - - for (r=0;rgetInstance_rigid_body_array().getCount();r++) - { - - domInstance_rigid_bodyRef instRigidbodyRef = instance_physicsModelRef->getInstance_rigid_body_array()[r]; - - - - float mass = 1.f; - bool isDynamics = true; - CollisionShape* colShape = 0; - CompoundShape* compoundShape = 0; - - xsNCName bodyName = instRigidbodyRef->getBody(); - - domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); - if (techniqueRef) - { - if (techniqueRef->getMass()) - { - mass = techniqueRef->getMass()->getValue(); - } - if (techniqueRef->getDynamic()) - { - isDynamics = techniqueRef->getDynamic()->getValue(); - } - } - - printf("mass = %f, isDynamics %i\n",mass,isDynamics); - - if (bodyName && model) - { - //try to find the rigid body - int numBody = model->getRigid_body_array().getCount(); - - for (int r=0;rgetRigid_body_array().getCount();r++) - { - domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; - if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) - { - - - RigidBodyOutput output; - output.m_colShape = colShape; - output.m_compoundShape = compoundShape; - - RigidBodyInput rbInput; - rbInput.m_rigidBodyRef2 = rigidBodyRef; - rbInput.m_instanceRigidBodyRef = instRigidbodyRef; - ConvertRigidBodyRef( rbInput , output ); - - mass = output.m_mass; - isDynamics = output.m_isDynamics; - colShape = output.m_colShape; - compoundShape = output.m_compoundShape; - - } - } - - ////////////////////// - } - - if (compoundShape) - colShape = compoundShape; - - if (colShape) - { - RigidBodyInput input; - input.m_instanceRigidBodyRef = instRigidbodyRef; - input.m_rigidBodyRef2 = 0; - input.m_bodyName = (char*)bodyName; - PreparePhysicsObject(input, isDynamics,mass,colShape); - } - - } //for each instance_rigid_body - - - } //for each physics model - - - //handle constraints - for (int m=0;mgetInstance_physics_model_array().getCount();m++) - { - domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[m]; - - daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); - - domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; - - { - ConstraintInput cInput; - cInput.m_instance_physicsModelRef = instance_physicsModelRef; - cInput.m_model = model; - PrepareConstraints(cInput); - } - - //also don't forget the model's 'instance_physics_models! - for ( int p=0;pgetInstance_physics_model_array().getCount();p++) - { - domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; - - daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); - - domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; - - ConstraintInput cInput; - cInput.m_instance_physicsModelRef = instancePhysicsModelRef; - cInput.m_model = model; - PrepareConstraints(cInput); - } - - - } //2nd time, for each physics model - - } - } - - return true; -} - - -void ColladaConverter::PrepareConstraints(ConstraintInput& input) -{ - domInstance_physics_modelRef instance_physicsModelRef = input.m_instance_physicsModelRef; - domPhysics_modelRef model = input.m_model; - - for (int c=0;cgetInstance_rigid_constraint_array().getCount();c++) - { - domInstance_rigid_constraintRef constraintRef = instance_physicsModelRef->getInstance_rigid_constraint_array().get(c); - xsNCName constraintName = constraintRef->getConstraint(); - - if (constraintName && model) - { - //try to find the rigid body - int numConstraints= model->getRigid_constraint_array().getCount(); - - for (int r=0;rgetRigid_constraint_array()[r]; - - if (rigidConstraintRef->getSid() && !strcmp(rigidConstraintRef->getSid(),constraintName)) - { - - //two bodies - const domRigid_constraint::domRef_attachmentRef attachRefBody = rigidConstraintRef->getRef_attachment(); - const domRigid_constraint::domAttachmentRef attachBody1 = rigidConstraintRef->getAttachment(); - - daeString uri = attachRefBody->getRigid_body().getURI(); - daeString orgUri0 = attachRefBody->getRigid_body().getOriginalURI(); - daeString orgUri1 = attachBody1->getRigid_body().getOriginalURI(); - CcdPhysicsController* ctrl0=0,*ctrl1=0; - - for (int i=0;igetNewClientInfo(); - if (!strcmp(bodyName,orgUri0)) - { - ctrl0=m_physObjects[i]; - } - if (!strcmp(bodyName,orgUri1)) - { - ctrl1=m_physObjects[i]; - } - } - - - - const domRigid_constraint::domAttachmentRef attachOtherBody = rigidConstraintRef->getAttachment(); - - - const domRigid_constraint::domTechnique_commonRef commonRef = rigidConstraintRef->getTechnique_common(); - - domFloat3 flMin = commonRef->getLimits()->getLinear()->getMin()->getValue(); - SimdVector3 minLinearLimit(flMin.get(0),flMin.get(1),flMin.get(2)); - - domFloat3 flMax = commonRef->getLimits()->getLinear()->getMax()->getValue(); - SimdVector3 maxLinearLimit(flMax.get(0),flMax.get(1),flMax.get(2)); - - domFloat3 coneMinLimit = commonRef->getLimits()->getSwing_cone_and_twist()->getMin()->getValue(); - SimdVector3 angularMin(coneMinLimit.get(0),coneMinLimit.get(1),coneMinLimit.get(2)); - - domFloat3 coneMaxLimit = commonRef->getLimits()->getSwing_cone_and_twist()->getMax()->getValue(); - SimdVector3 angularMax(coneMaxLimit.get(0),coneMaxLimit.get(1),coneMaxLimit.get(2)); - - { - int constraintId; - - SimdTransform attachFrameRef0; - attachFrameRef0 = - GetSimdTransformFromCOLLADA_DOM - ( - emptyMatrixArray, - attachRefBody->getRotate_array(), - attachRefBody->getTranslate_array()); - - SimdTransform attachFrameOther; - attachFrameOther = - GetSimdTransformFromCOLLADA_DOM - ( - emptyMatrixArray, - attachBody1->getRotate_array(), - attachBody1->getTranslate_array() - ); - - - //convert INF / -INF into lower > upper - - //currently there is a hack in the DOM to detect INF / -INF - //see daeMetaAttribute.cpp - //INF -> 999999.9 - //-INF -> -999999.9 - float linearCheckTreshold = 999999.0; - float angularCheckTreshold = 180.0;//check this - - - - - //free means upper < lower, - //locked means upper == lower - //limited means upper > lower - //limitIndex: first 3 are linear, next 3 are angular - - SimdVector3 linearLowerLimits = minLinearLimit; - SimdVector3 linearUpperLimits = maxLinearLimit; - SimdVector3 angularLowerLimits = angularMin; - SimdVector3 angularUpperLimits = angularMax; - { - for (int i=0;i<3;i++) - { - if ((linearLowerLimits[i] < -linearCheckTreshold) || - (linearUpperLimits[i] > linearCheckTreshold)) - { - //disable limits - linearLowerLimits[i] = 1; - linearUpperLimits[i] = 0; - } - - if ((angularLowerLimits[i] < -angularCheckTreshold) || - (angularUpperLimits[i] > angularCheckTreshold)) - { - //disable limits - angularLowerLimits[i] = 1; - angularUpperLimits[i] = 0; - } - } - } - - - if (ctrl0 && ctrl1) - { - constraintId = createUniversalD6Constraint( - ctrl0, - ctrl1, - attachFrameRef0, - attachFrameOther, - linearLowerLimits, - linearUpperLimits, - angularLowerLimits, - angularUpperLimits - ); - } else - { - printf("Error: Cannot find Rigidbodies(%s,%s) for constraint %s\n",orgUri0,orgUri1,constraintName); - } - - - } - - - - } - } - } - - } - -} - -void ColladaConverter::PreparePhysicsObject(struct RigidBodyInput& input, bool isDynamics, float mass,CollisionShape* colShape) -{ - SimdTransform startTransform; - startTransform.setIdentity(); - SimdVector3 startScale(1.f,1.f,1.f); - - //The 'target' points to a graphics element/node, which contains the start (world) transform - daeElementRef elem = input.m_instanceRigidBodyRef->getTarget().getElement(); - if (elem) - { - domNodeRef node = *(domNodeRef*)&elem; - m_colladadomNodes[m_numObjects] = node; - - //find transform of the node that this rigidbody maps to - - - startTransform = GetSimdTransformFromCOLLADA_DOM( - node->getMatrix_array(), - node->getRotate_array(), - node->getTranslate_array() - ); - - int i; - for (i=0;igetScale_array().getCount();i++) - { - domScaleRef scaleRef = node->getScale_array()[i]; - domFloat3 fl3 = scaleRef->getValue(); - startScale = SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2)); - } - - } - - - - CcdPhysicsController* ctrl = CreatePhysicsObject(isDynamics,mass,startTransform,colShape); - if (ctrl) - { - //for bodyName lookup in constraints - ctrl->setNewClientInfo((void*)input.m_bodyName); - m_physObjects[m_numObjects] = ctrl; - m_numObjects++; - } - -} - -bool ColladaConverter::saveAs(const char* filename) -{ - if (m_collada) - { - for (int i=0;igetTranslate_array().getCount()) - { - domTranslate* transl = (domTranslate*) m_colladadomNodes[i]->createAndPlace("translate"); - transl->getValue().append(0.); - transl->getValue().append(0.); - transl->getValue().append(0.); - } - - while (m_colladadomNodes[i]->getTranslate_array().getCount() > 1) - { - m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getTranslate_array().get(1)); - //m_colladadomNodes[i]->getTranslate_array().removeIndex(1); - } - - { - - float np[3]; - domFloat3 newPos = m_colladadomNodes[i]->getTranslate_array().get(0)->getValue(); - m_physObjects[i]->GetMotionState()->getWorldPosition( - np[0], - np[1], - np[2]); - newPos.set(0,np[0]); - newPos.set(1,np[1]); - newPos.set(2,np[2]); - m_colladadomNodes[i]->getTranslate_array().get(0)->setValue(newPos); - - } - - - if (!m_colladadomNodes[i]->getRotate_array().getCount()) - { - domRotate* rot = (domRotate*)m_colladadomNodes[i]->createAndPlace("rotate"); - rot->getValue().append(1.0); - rot->getValue().append(0.0); - rot->getValue().append(0.0); - rot->getValue().append(0.0); - } - - while (m_colladadomNodes[i]->getRotate_array().getCount()>1) - { - m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getRotate_array().get(1)); - //m_colladadomNodes[i]->getRotate_array().removeIndex(1); - - } - - { - float quatIma0,quatIma1,quatIma2,quatReal; - - SimdQuaternion quat = m_physObjects[i]->GetRigidBody()->getCenterOfMassTransform().getRotation(); - SimdVector3 axis(quat.getX(),quat.getY(),quat.getZ()); - axis[3] = 0.f; - //check for axis length - SimdScalar len = axis.length2(); - if (len < SIMD_EPSILON*SIMD_EPSILON) - axis = SimdVector3(1.f,0.f,0.f); - else - axis /= SimdSqrt(len); - m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(0,axis[0]); - m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(1,axis[1]); - m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(2,axis[2]); - m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(3,quat.getAngle()*SIMD_DEGS_PER_RAD); - } - - while (m_colladadomNodes[i]->getMatrix_array().getCount()) - { - m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getMatrix_array().get(0)); - //m_colladadomNodes[i]->getMatrix_array().removeIndex(0); - } - } - char saveName[550]; - static int saveCount=1; - sprintf(saveName,"%s%i",getLastFileName(),saveCount++); - char* name = &saveName[0]; - if (name[0] == '/') - { - name = &saveName[1]; - } - - if (m_dom->getAsset()->getContributor_array().getCount()) - { - if (!m_dom->getAsset()->getContributor_array().get(0)->getAuthor()) - { - m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("author"); - } - - m_dom->getAsset()->getContributor_array().get(0)->getAuthor()->setValue - ("http://bullet.sf.net Erwin Coumans"); - - if (!m_dom->getAsset()->getContributor_array().get(0)->getAuthoring_tool()) - { - m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("authoring_tool"); - } - - m_dom->getAsset()->getContributor_array().get(0)->getAuthoring_tool()->setValue -#ifdef WIN32 - ("Bullet ColladaPhysicsViewer-Win32-0.8"); -#else -#ifdef __APPLE__ - ("Bullet ColladaPhysicsViewer-MacOSX-0.8"); -#else - ("Bullet ColladaPhysicsViewer-UnknownPlatform-0.8"); -#endif -#endif - if (!m_dom->getAsset()->getContributor_array().get(0)->getComments()) - { - m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("comments"); - } - m_dom->getAsset()->getContributor_array().get(0)->getComments()->setValue - ("Comments to Physics Forum at http://www.continuousphysics.com/Bullet/phpBB2/index.php"); - } - - m_collada->saveAs(name); - return true; - - } - return false; -} - -//some code that de-mangles the windows filename passed in as argument -char cleaned_filename[512]; -char* getLastFileName() -{ - return cleaned_filename; -} - - -char* fixFileName(const char* lpCmdLine) -{ - - - // We might get a windows-style path on the command line, this can mess up the DOM which expects - // all paths to be URI's. This block of code does some conversion to try and make the input - // compliant without breaking the ability to accept a properly formatted URI. Right now this only - // displays the first filename - const char *in = lpCmdLine; - char* out = cleaned_filename; - *out = NULL; - // If the first character is a ", skip it (filenames with spaces in them are quoted) - if(*in == '\"') - { - in++; - } - if(*(in+1) == ':') - { - // Second character is a :, assume we have a path with a drive letter and add a slash at the beginning - *(out++) = '/'; - } - int i; - for(i =0; i<512; i++) - { - // If we hit a null or a quote, stop copying. This will get just the first filename. - if(*in == NULL || *in == '\"') - break; - // Copy while swapping backslashes for forward ones - if(*in == '\\') - { - *out = '/'; - } - else - { - *out = *in; - } - in++; - out++; - } - - return cleaned_filename; -} - - -void ColladaConverter::ConvertRigidBodyRef( RigidBodyInput& rbInput,RigidBodyOutput& rbOutput) -{ - - const domRigid_body::domTechnique_commonRef techniqueRef = rbInput.m_rigidBodyRef2->getTechnique_common(); - if (techniqueRef) - { - - if (techniqueRef->getMass()) - { - rbOutput.m_mass = techniqueRef->getMass()->getValue(); - } - if (techniqueRef->getDynamic()) - { - rbOutput.m_isDynamics = techniqueRef->getDynamic()->getValue(); - } - - //shapes - for (int s=0;sgetShape_array().getCount();s++) - { - domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s]; - - if (shapeRef->getPlane()) - { - domPlaneRef planeRef = shapeRef->getPlane(); - if (planeRef->getEquation()) - { - const domFloat4 planeEq = planeRef->getEquation()->getValue(); - SimdVector3 planeNormal(planeEq.get(0),planeEq.get(1),planeEq.get(2)); - SimdScalar planeConstant = planeEq.get(3); - rbOutput.m_colShape = new StaticPlaneShape(planeNormal,planeConstant); - } - - } - - if (shapeRef->getBox()) - { - domBoxRef boxRef = shapeRef->getBox(); - domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents(); - domFloat3& halfExtents = domHalfExtentsRef->getValue(); - float x = halfExtents.get(0); - float y = halfExtents.get(1); - float z = halfExtents.get(2); - rbOutput.m_colShape = new BoxShape(SimdVector3(x,y,z)); - } - if (shapeRef->getSphere()) - { - domSphereRef sphereRef = shapeRef->getSphere(); - domSphere::domRadiusRef radiusRef = sphereRef->getRadius(); - domFloat radius = radiusRef->getValue(); - rbOutput.m_colShape = new SphereShape(radius); - } - - if (shapeRef->getCylinder()) - { - domCylinderRef cylinderRef = shapeRef->getCylinder(); - domFloat height = cylinderRef->getHeight()->getValue(); - domFloat2 radius2 = cylinderRef->getRadius()->getValue(); - domFloat radius0 = radius2.get(0); - - //Cylinder around the local Y axis - rbOutput.m_colShape = new CylinderShape(SimdVector3(radius0,height,radius0)); - - } - - if (shapeRef->getInstance_geometry()) - { - const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry(); - daeElement* geomElem = geomInstRef->getUrl().getElement(); - //elemRef->getTypeName(); - domGeometry* geom = (domGeometry*) geomElem; - if (geom && geom->getMesh()) - { - const domMeshRef meshRef = geom->getMesh(); - TriangleIndexVertexArray* tindexArray = new TriangleIndexVertexArray(); - - TriangleMesh* trimesh = new TriangleMesh(); - - - for (int tg = 0;tggetTriangles_array().getCount();tg++) - { - - - domTrianglesRef triRef = meshRef->getTriangles_array()[tg]; - const domPRef pRef = triRef->getP(); - daeMemoryRef memRef = pRef->getValue().getRawData(); - IndexedMesh meshPart; - meshPart.m_triangleIndexStride=0; - - - - int vertexoffset = -1; - domInputLocalOffsetRef indexOffsetRef; - - - for (int w=0;wgetInput_array().getCount();w++) - { - int offset = triRef->getInput_array()[w]->getOffset(); - daeString str = triRef->getInput_array()[w]->getSemantic(); - if (!strcmp(str,"VERTEX")) - { - indexOffsetRef = triRef->getInput_array()[w]; - vertexoffset = offset; - } - if (offset > meshPart.m_triangleIndexStride) - { - meshPart.m_triangleIndexStride = offset; - } - } - meshPart.m_triangleIndexStride++; - domListOfUInts indexArray =triRef->getP()->getValue(); - int count = indexArray.getCount(); - - //int* m_triangleIndexBase; - - - - meshPart.m_numTriangles = triRef->getCount(); - - const domVerticesRef vertsRef = meshRef->getVertices(); - int numInputs = vertsRef->getInput_array().getCount(); - for (int i=0;igetInput_array()[i]; - daeString str = localRef->getSemantic(); - if ( !strcmp(str,"POSITION")) - { - const domURIFragmentType& frag = localRef->getSource(); - - daeElementConstRef constElem = frag.getElement(); - - const domSourceRef node = *(const domSourceRef*)&constElem; - const domFloat_arrayRef flArray = node->getFloat_array(); - if (flArray) - { - int numElem = flArray->getCount(); - const domListOfFloats& listFloats = flArray->getValue(); - - int numVerts = listFloats.getCount()/3; - int k=vertexoffset; - int t=0; - int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor' - for (;tAddTriangle(verts[0],verts[1],verts[2]); - } - } - } - } - - - - - - //int m_triangleIndexStride;//calculate max offset - //int m_numVertices; - //float* m_vertexBase;//getRawData on floatArray - //int m_vertexStride;//use the accessor for this - - //}; - //tindexArray->AddIndexedMesh(meshPart); - if (rbOutput.m_isDynamics) - { - printf("moving concave not supported, transformed into convex\n"); - rbOutput.m_colShape = new ConvexTriangleMeshShape(trimesh); - } else - { - printf("static concave triangle added\n"); - rbOutput.m_colShape = new TriangleMeshShape(trimesh); - } - - } - - } - - if (geom && geom->getConvex_mesh()) - { - - { - const domConvex_meshRef convexRef = geom->getConvex_mesh(); - daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement(); - if ( otherElemRef != NULL ) - { - domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; - printf( "otherLinked\n"); - } else - { - printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount()); - printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount()); - - } - } - - - - ConvexHullShape* convexHullShape = new ConvexHullShape(0,0); - - //it is quite a trick to get to the vertices, using Collada. - //we are not there yet... - - const domConvex_meshRef convexRef = geom->getConvex_mesh(); - //daeString urlref = convexRef->getConvex_hull_of().getURI(); - daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI(); - if (urlref2) - { - daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement(); - // if ( otherElemRef != NULL ) - // { - // domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; - - // Load all the geometry libraries - for ( int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++) - { - domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i]; - //int index = libgeom->findLastIndexOf(urlref2); - //can't find it - - for ( int i = 0; i < libgeom->getGeometry_array().getCount(); i++) - { - //ReadGeometry( ); - domGeometryRef lib = libgeom->getGeometry_array()[i]; - if (!strcmp(lib->getName(),urlref2)) - { - //found convex_hull geometry - domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh(); - if (meshElement) - { - const domVerticesRef vertsRef = meshElement->getVertices(); - int numInputs = vertsRef->getInput_array().getCount(); - for (int i=0;igetInput_array()[i]; - daeString str = localRef->getSemantic(); - if ( !strcmp(str,"POSITION")) - { - const domURIFragmentType& frag = localRef->getSource(); - - daeElementConstRef constElem = frag.getElement(); - - const domSourceRef node = *(const domSourceRef*)&constElem; - const domFloat_arrayRef flArray = node->getFloat_array(); - if (flArray) - { - int numElem = flArray->getCount(); - const domListOfFloats& listFloats = flArray->getValue(); - - for (int k=0;k+2AddPoint(SimdPoint3(fl0,fl1,fl2)); - } - - } - - } - - - } - - } - } - - - - } - } - - - } else - { - //no getConvex_hull_of but direct vertices - const domVerticesRef vertsRef = convexRef->getVertices(); - int numInputs = vertsRef->getInput_array().getCount(); - for (int i=0;igetInput_array()[i]; - daeString str = localRef->getSemantic(); - if ( !strcmp(str,"POSITION")) - { - const domURIFragmentType& frag = localRef->getSource(); - - daeElementConstRef constElem = frag.getElement(); - - const domSourceRef node = *(const domSourceRef*)&constElem; - const domFloat_arrayRef flArray = node->getFloat_array(); - if (flArray) - { - int numElem = flArray->getCount(); - const domListOfFloats& listFloats = flArray->getValue(); - - for (int k=0;k+2AddPoint(SimdPoint3(fl0,fl1,fl2)); - } - - } - - } - - - } - - - } - - if (convexHullShape->GetNumVertices()) - { - rbOutput.m_colShape = convexHullShape; - printf("created convexHullShape with %i points\n",convexHullShape->GetNumVertices()); - } else - { - delete convexHullShape; - printf("failed to create convexHullShape\n"); - } - - - //domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; - - printf("convexmesh\n"); - - } - } - - //if more then 1 shape, or a non-identity local shapetransform - //use a compound - - bool hasShapeLocalTransform = ((shapeRef->getRotate_array().getCount() > 0) || - (shapeRef->getTranslate_array().getCount() > 0)); - - if (rbOutput.m_colShape) - { - if ((techniqueRef->getShape_array().getCount()>1) || - (hasShapeLocalTransform)) - { - - if (!rbOutput.m_compoundShape) - { - rbOutput.m_compoundShape = new CompoundShape(); - } - - SimdTransform localTransform; - localTransform.setIdentity(); - if (hasShapeLocalTransform) - { - localTransform = GetSimdTransformFromCOLLADA_DOM( - emptyMatrixArray, - shapeRef->getRotate_array(), - shapeRef->getTranslate_array() - ); - } - - rbOutput.m_compoundShape->AddChildShape(localTransform,rbOutput.m_colShape); - rbOutput.m_colShape = 0; - } - } - - - }//for each shape - } - - -} \ No newline at end of file + printf("DAE/Collada-m_dom: Couldn't load %s\n",filename); + return false; + } + } + + if (res == DAE_OK) + { + + m_dom = m_collada->getDom(filename); + if ( !m_dom ) + { + printf("COLLADA File loaded to the m_dom, but query for the m_dom assets failed \n" ); + printf("COLLADA Load Aborted! \n" ); + delete m_collada; + return false; + } + } + return true; +} + + + + + +bool ColladaConverter::convert() +{ + +//succesfully loaded file, now convert data + + if ( m_dom->getAsset()->getUp_axis() ) + { + domAsset::domUp_axis * up = m_dom->getAsset()->getUp_axis(); + switch( up->getValue() ) + { + case UPAXISTYPE_X_UP: + printf(" X is Up Data and Hiearchies must be converted!\n" ); + printf(" Conversion to X axis Up isn't currently supported!\n" ); + printf(" COLLADA_RT defaulting to Y Up \n" ); + SetGravity(SimdVector3(-10,0,0)); + SetCameraInfo(SimdVector3(1,0,0),1); + break; + case UPAXISTYPE_Y_UP: + printf(" Y Axis is Up for this file \n" ); + printf(" COLLADA_RT set to Y Up \n" ); + SetGravity(SimdVector3(0,-10,0)); + SetCameraInfo(SimdVector3(0,1,0),0); + + break; + case UPAXISTYPE_Z_UP: + printf(" Z Axis is Up for this file \n" ); + printf(" All Geometry and Hiearchies must be converted!\n" ); + SetGravity(SimdVector3(0,0,-10)); + break; + default: + + break; + } + } + + + //we don't handle visual objects, physics objects are rered as such + for (unsigned int s=0;sgetLibrary_visual_scenes_array().getCount();s++) + { + domLibrary_visual_scenesRef scenesRef = m_dom->getLibrary_visual_scenes_array()[s]; + for (unsigned int i=0;igetVisual_scene_array().getCount();i++) + { + domVisual_sceneRef sceneRef = scenesRef->getVisual_scene_array()[i]; + for (unsigned int n=0;ngetNode_array().getCount();n++) + { + domNodeRef nodeRef = sceneRef->getNode_array()[n]; + nodeRef->getRotate_array(); + nodeRef->getTranslate_array(); + nodeRef->getScale_array(); + + } + } + } + + + + + // Load all the geometry libraries + for ( unsigned int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++) + { + domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i]; + + printf(" CrtScene::Reading Geometry Library \n" ); + for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++) + { + //ReadGeometry( ); + domGeometryRef lib = libgeom->getGeometry_array()[i]; + + domMesh *meshElement = lib->getMesh(); + if (meshElement) + { + // Find out how many groups we need to allocate space for + int numTriangleGroups = (int)meshElement->getTriangles_array().getCount(); + int numPolygonGroups = (int)meshElement->getPolygons_array().getCount(); + int totalGroups = numTriangleGroups + numPolygonGroups; + if (totalGroups == 0) + { + printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() ); + } else + { + printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups:%i\n",lib->getId(),numTriangleGroups,numPolygonGroups); + } + + + } + domConvex_mesh *convexMeshElement = lib->getConvex_mesh(); + if (convexMeshElement) + { + printf("found convexmesh element\n"); + // Find out how many groups we need to allocate space for + int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount(); + int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount(); + + int totalGroups = numTriangleGroups + numPolygonGroups; + if (totalGroups == 0) + { + printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() ); + }else + { + printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups); + } + }//fi + }//for each geometry + + }//for all geometry libraries + + + //m_dom->getLibrary_physics_models_array() + + for ( unsigned int i = 0; i < m_dom->getLibrary_physics_scenes_array().getCount(); i++) + { + domLibrary_physics_scenesRef physicsScenesRef = m_dom->getLibrary_physics_scenes_array()[i]; + for (unsigned int s=0;sgetPhysics_scene_array().getCount();s++) + { + domPhysics_sceneRef physicsSceneRef = physicsScenesRef->getPhysics_scene_array()[s]; + + if (physicsSceneRef->getTechnique_common()) + { + if (physicsSceneRef->getTechnique_common()->getGravity()) + { + const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue(); + printf("gravity set to %f,%f,%f\n",grav.get(0),grav.get(1),grav.get(2)); + + SetGravity(SimdVector3(grav.get(0),grav.get(1),grav.get(2))); + } + + } + + for (unsigned int m=0;mgetInstance_physics_model_array().getCount();m++) + { + domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[m]; + + daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); + + domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; + + + unsigned int p,r; + for ( p=0;pgetInstance_physics_model_array().getCount();p++) + { + domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; + + daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); + + domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; + + //todo: group some shared functionality in following 2 'blocks'. + for (r=0;rgetInstance_rigid_body_array().getCount();r++) + { + domInstance_rigid_bodyRef instRigidbodyRef = instancePhysicsModelRef->getInstance_rigid_body_array()[r]; + + float mass = 1.f; + bool isDynamics = true; + CollisionShape* colShape = 0; + CompoundShape* compoundShape = 0; + + xsNCName bodyName = instRigidbodyRef->getBody(); + + domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); + if (techniqueRef) + { + if (techniqueRef->getMass()) + { + mass = techniqueRef->getMass()->getValue(); + } + if (techniqueRef->getDynamic()) + { + isDynamics = techniqueRef->getDynamic()->getValue(); + } + } + + printf("mass = %f, isDynamics %i\n",mass,isDynamics); + + if (bodyName && model) + { + //try to find the rigid body + + for (unsigned int r=0;rgetRigid_body_array().getCount();r++) + { + domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; + if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) + { + + + RigidBodyOutput output; + output.m_colShape = colShape; + output.m_compoundShape = compoundShape; + + RigidBodyInput rbInput; + rbInput.m_rigidBodyRef2 = rigidBodyRef; + rbInput.m_instanceRigidBodyRef = instRigidbodyRef; + ConvertRigidBodyRef( rbInput , output ); + + mass = output.m_mass; + isDynamics = output.m_isDynamics; + colShape = output.m_colShape; + compoundShape = output.m_compoundShape; + + } + } + + ////////////////////// + } + + if (compoundShape) + colShape = compoundShape; + + if (colShape) + { + RigidBodyInput input; + input.m_instanceRigidBodyRef = instRigidbodyRef; + input.m_rigidBodyRef2 = 0; + input.m_bodyName = (char*)bodyName; + PreparePhysicsObject(input, isDynamics,mass,colShape); + } + } + } + + + for (r=0;rgetInstance_rigid_body_array().getCount();r++) + { + + domInstance_rigid_bodyRef instRigidbodyRef = instance_physicsModelRef->getInstance_rigid_body_array()[r]; + + + + float mass = 1.f; + bool isDynamics = true; + CollisionShape* colShape = 0; + CompoundShape* compoundShape = 0; + + xsNCName bodyName = instRigidbodyRef->getBody(); + + domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); + if (techniqueRef) + { + if (techniqueRef->getMass()) + { + mass = techniqueRef->getMass()->getValue(); + } + if (techniqueRef->getDynamic()) + { + isDynamics = techniqueRef->getDynamic()->getValue(); + } + } + + printf("mass = %f, isDynamics %i\n",mass,isDynamics); + + if (bodyName && model) + { + //try to find the rigid body + + for (unsigned int r=0;rgetRigid_body_array().getCount();r++) + { + domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; + if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) + { + + + RigidBodyOutput output; + output.m_colShape = colShape; + output.m_compoundShape = compoundShape; + + RigidBodyInput rbInput; + rbInput.m_rigidBodyRef2 = rigidBodyRef; + rbInput.m_instanceRigidBodyRef = instRigidbodyRef; + ConvertRigidBodyRef( rbInput , output ); + + mass = output.m_mass; + isDynamics = output.m_isDynamics; + colShape = output.m_colShape; + compoundShape = output.m_compoundShape; + + } + } + + ////////////////////// + } + + if (compoundShape) + colShape = compoundShape; + + if (colShape) + { + RigidBodyInput input; + input.m_instanceRigidBodyRef = instRigidbodyRef; + input.m_rigidBodyRef2 = 0; + input.m_bodyName = (char*)bodyName; + PreparePhysicsObject(input, isDynamics,mass,colShape); + } + + } //for each instance_rigid_body + + + } //for each physics model + + + //handle constraints + for (unsigned int m=0;mgetInstance_physics_model_array().getCount();m++) + { + domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[m]; + + daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); + + domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; + + { + ConstraintInput cInput; + cInput.m_instance_physicsModelRef = instance_physicsModelRef; + cInput.m_model = model; + PrepareConstraints(cInput); + } + + //also don't forget the model's 'instance_physics_models! + for ( unsigned int p=0;pgetInstance_physics_model_array().getCount();p++) + { + domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; + + daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); + + domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; + + ConstraintInput cInput; + cInput.m_instance_physicsModelRef = instancePhysicsModelRef; + cInput.m_model = model; + PrepareConstraints(cInput); + } + + + } //2nd time, for each physics model + + } + } + + return true; +} + + +void ColladaConverter::PrepareConstraints(ConstraintInput& input) +{ + domInstance_physics_modelRef instance_physicsModelRef = input.m_instance_physicsModelRef; + domPhysics_modelRef model = input.m_model; + + for (unsigned int c=0;cgetInstance_rigid_constraint_array().getCount();c++) + { + domInstance_rigid_constraintRef constraintRef = instance_physicsModelRef->getInstance_rigid_constraint_array().get(c); + xsNCName constraintName = constraintRef->getConstraint(); + + if (constraintName && model) + { + //try to find the rigid body + int numConstraints= model->getRigid_constraint_array().getCount(); + + for (int r=0;rgetRigid_constraint_array()[r]; + + if (rigidConstraintRef->getSid() && !strcmp(rigidConstraintRef->getSid(),constraintName)) + { + + //two bodies + const domRigid_constraint::domRef_attachmentRef attachRefBody = rigidConstraintRef->getRef_attachment(); + const domRigid_constraint::domAttachmentRef attachBody1 = rigidConstraintRef->getAttachment(); + + daeString orgUri0 = attachRefBody->getRigid_body().getOriginalURI(); + daeString orgUri1 = attachBody1->getRigid_body().getOriginalURI(); + CcdPhysicsController* ctrl0=0,*ctrl1=0; + + for (int i=0;igetNewClientInfo(); + if (!strcmp(bodyName,orgUri0)) + { + ctrl0=m_physObjects[i]; + } + if (!strcmp(bodyName,orgUri1)) + { + ctrl1=m_physObjects[i]; + } + } + + + + const domRigid_constraint::domAttachmentRef attachOtherBody = rigidConstraintRef->getAttachment(); + + + const domRigid_constraint::domTechnique_commonRef commonRef = rigidConstraintRef->getTechnique_common(); + + domFloat3 flMin = commonRef->getLimits()->getLinear()->getMin()->getValue(); + SimdVector3 minLinearLimit(flMin.get(0),flMin.get(1),flMin.get(2)); + + domFloat3 flMax = commonRef->getLimits()->getLinear()->getMax()->getValue(); + SimdVector3 maxLinearLimit(flMax.get(0),flMax.get(1),flMax.get(2)); + + domFloat3 coneMinLimit = commonRef->getLimits()->getSwing_cone_and_twist()->getMin()->getValue(); + SimdVector3 angularMin(coneMinLimit.get(0),coneMinLimit.get(1),coneMinLimit.get(2)); + + domFloat3 coneMaxLimit = commonRef->getLimits()->getSwing_cone_and_twist()->getMax()->getValue(); + SimdVector3 angularMax(coneMaxLimit.get(0),coneMaxLimit.get(1),coneMaxLimit.get(2)); + + { + int constraintId; + + SimdTransform attachFrameRef0; + attachFrameRef0 = + GetSimdTransformFromCOLLADA_DOM + ( + emptyMatrixArray, + attachRefBody->getRotate_array(), + attachRefBody->getTranslate_array()); + + SimdTransform attachFrameOther; + attachFrameOther = + GetSimdTransformFromCOLLADA_DOM + ( + emptyMatrixArray, + attachBody1->getRotate_array(), + attachBody1->getTranslate_array() + ); + + + //convert INF / -INF into lower > upper + + //currently there is a hack in the DOM to detect INF / -INF + //see daeMetaAttribute.cpp + //INF -> 999999.9 + //-INF -> -999999.9 + float linearCheckTreshold = 999999.0; + float angularCheckTreshold = 180.0;//check this + + + + + //free means upper < lower, + //locked means upper == lower + //limited means upper > lower + //limitIndex: first 3 are linear, next 3 are angular + + SimdVector3 linearLowerLimits = minLinearLimit; + SimdVector3 linearUpperLimits = maxLinearLimit; + SimdVector3 angularLowerLimits = angularMin; + SimdVector3 angularUpperLimits = angularMax; + { + for (int i=0;i<3;i++) + { + if ((linearLowerLimits[i] < -linearCheckTreshold) || + (linearUpperLimits[i] > linearCheckTreshold)) + { + //disable limits + linearLowerLimits[i] = 1; + linearUpperLimits[i] = 0; + } + + if ((angularLowerLimits[i] < -angularCheckTreshold) || + (angularUpperLimits[i] > angularCheckTreshold)) + { + //disable limits + angularLowerLimits[i] = 1; + angularUpperLimits[i] = 0; + } + } + } + + + if (ctrl0 && ctrl1) + { + constraintId = createUniversalD6Constraint( + ctrl0, + ctrl1, + attachFrameRef0, + attachFrameOther, + linearLowerLimits, + linearUpperLimits, + angularLowerLimits, + angularUpperLimits + ); + } else + { + printf("Error: Cannot find Rigidbodies(%s,%s) for constraint %s\n",orgUri0,orgUri1,constraintName); + } + + + } + + + + } + } + } + + } + +} + +void ColladaConverter::PreparePhysicsObject(struct RigidBodyInput& input, bool isDynamics, float mass,CollisionShape* colShape) +{ + SimdTransform startTransform; + startTransform.setIdentity(); + SimdVector3 startScale(1.f,1.f,1.f); + + //The 'target' points to a graphics element/node, which contains the start (world) transform + daeElementRef elem = input.m_instanceRigidBodyRef->getTarget().getElement(); + if (elem) + { + domNodeRef node = *(domNodeRef*)&elem; + m_colladadomNodes[m_numObjects] = node; + + //find transform of the node that this rigidbody maps to + + + startTransform = GetSimdTransformFromCOLLADA_DOM( + node->getMatrix_array(), + node->getRotate_array(), + node->getTranslate_array() + ); + + unsigned int i; + for (i=0;igetScale_array().getCount();i++) + { + domScaleRef scaleRef = node->getScale_array()[i]; + domFloat3 fl3 = scaleRef->getValue(); + startScale = SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2)); + } + + } + + + + CcdPhysicsController* ctrl = CreatePhysicsObject(isDynamics,mass,startTransform,colShape); + if (ctrl) + { + //for bodyName lookup in constraints + ctrl->setNewClientInfo((void*)input.m_bodyName); + m_physObjects[m_numObjects] = ctrl; + m_numObjects++; + } + +} + +bool ColladaConverter::saveAs(const char* filename) +{ + if (m_collada) + { + for (int i=0;igetTranslate_array().getCount()) + { + domTranslate* transl = (domTranslate*) m_colladadomNodes[i]->createAndPlace("translate"); + transl->getValue().append(0.); + transl->getValue().append(0.); + transl->getValue().append(0.); + } + + while (m_colladadomNodes[i]->getTranslate_array().getCount() > 1) + { + m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getTranslate_array().get(1)); + //m_colladadomNodes[i]->getTranslate_array().removeIndex(1); + } + + { + + float np[3]; + domFloat3 newPos = m_colladadomNodes[i]->getTranslate_array().get(0)->getValue(); + m_physObjects[i]->GetMotionState()->getWorldPosition( + np[0], + np[1], + np[2]); + newPos.set(0,np[0]); + newPos.set(1,np[1]); + newPos.set(2,np[2]); + m_colladadomNodes[i]->getTranslate_array().get(0)->setValue(newPos); + + } + + + if (!m_colladadomNodes[i]->getRotate_array().getCount()) + { + domRotate* rot = (domRotate*)m_colladadomNodes[i]->createAndPlace("rotate"); + rot->getValue().append(1.0); + rot->getValue().append(0.0); + rot->getValue().append(0.0); + rot->getValue().append(0.0); + } + + while (m_colladadomNodes[i]->getRotate_array().getCount()>1) + { + m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getRotate_array().get(1)); + //m_colladadomNodes[i]->getRotate_array().removeIndex(1); + + } + + { + SimdQuaternion quat = m_physObjects[i]->GetRigidBody()->getCenterOfMassTransform().getRotation(); + SimdVector3 axis(quat.getX(),quat.getY(),quat.getZ()); + axis[3] = 0.f; + //check for axis length + SimdScalar len = axis.length2(); + if (len < SIMD_EPSILON*SIMD_EPSILON) + axis = SimdVector3(1.f,0.f,0.f); + else + axis /= SimdSqrt(len); + m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(0,axis[0]); + m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(1,axis[1]); + m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(2,axis[2]); + m_colladadomNodes[i]->getRotate_array().get(0)->getValue().set(3,quat.getAngle()*SIMD_DEGS_PER_RAD); + } + + while (m_colladadomNodes[i]->getMatrix_array().getCount()) + { + m_colladadomNodes[i]->removeFromParent(m_colladadomNodes[i]->getMatrix_array().get(0)); + //m_colladadomNodes[i]->getMatrix_array().removeIndex(0); + } + } + char saveName[550]; + static int saveCount=1; + sprintf(saveName,"%s%i",getLastFileName(),saveCount++); + char* name = &saveName[0]; + if (name[0] == '/') + { + name = &saveName[1]; + } + + if (m_dom->getAsset()->getContributor_array().getCount()) + { + if (!m_dom->getAsset()->getContributor_array().get(0)->getAuthor()) + { + m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("author"); + } + + m_dom->getAsset()->getContributor_array().get(0)->getAuthor()->setValue + ("http://bullet.sf.net Erwin Coumans"); + + if (!m_dom->getAsset()->getContributor_array().get(0)->getAuthoring_tool()) + { + m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("authoring_tool"); + } + + m_dom->getAsset()->getContributor_array().get(0)->getAuthoring_tool()->setValue +#ifdef WIN32 + ("Bullet ColladaPhysicsViewer-Win32-0.8"); +#else +#ifdef __APPLE__ + ("Bullet ColladaPhysicsViewer-MacOSX-0.8"); +#else + ("Bullet ColladaPhysicsViewer-UnknownPlatform-0.8"); +#endif +#endif + if (!m_dom->getAsset()->getContributor_array().get(0)->getComments()) + { + m_dom->getAsset()->getContributor_array().get(0)->createAndPlace("comments"); + } + m_dom->getAsset()->getContributor_array().get(0)->getComments()->setValue + ("Comments to Physics Forum at http://www.continuousphysics.com/Bullet/phpBB2/index.php"); + } + + m_collada->saveAs(name); + return true; + + } + return false; +} + +//some code that de-mangles the windows filename passed in as argument +char cleaned_filename[512]; +char* getLastFileName() +{ + return cleaned_filename; +} + + +char* fixFileName(const char* lpCmdLine) +{ + + + // We might get a windows-style path on the command line, this can mess up the DOM which expects + // all paths to be URI's. This block of code does some conversion to try and make the input + // compliant without breaking the ability to accept a properly formatted URI. Right now this only + // displays the first filename + const char *in = lpCmdLine; + char* out = cleaned_filename; + *out = '\0'; + // If the first character is a ", skip it (filenames with spaces in them are quoted) + if(*in == '\"') + { + in++; + } + if(*(in+1) == ':') + { + // Second character is a :, assume we have a path with a drive letter and add a slash at the beginning + *(out++) = '/'; + } + int i; + for(i =0; i<512; i++) + { + // If we hit a null or a quote, stop copying. This will get just the first filename. + if(*in == '\0' || *in == '\"') + break; + // Copy while swapping backslashes for forward ones + if(*in == '\\') + { + *out = '/'; + } + else + { + *out = *in; + } + in++; + out++; + } + + return cleaned_filename; +} + + +void ColladaConverter::ConvertRigidBodyRef( RigidBodyInput& rbInput,RigidBodyOutput& rbOutput) +{ + + const domRigid_body::domTechnique_commonRef techniqueRef = rbInput.m_rigidBodyRef2->getTechnique_common(); + if (techniqueRef) + { + + if (techniqueRef->getMass()) + { + rbOutput.m_mass = techniqueRef->getMass()->getValue(); + } + if (techniqueRef->getDynamic()) + { + rbOutput.m_isDynamics = techniqueRef->getDynamic()->getValue(); + } + + //shapes + for (unsigned int s=0;sgetShape_array().getCount();s++) + { + domRigid_body::domTechnique_common::domShapeRef shapeRef = techniqueRef->getShape_array()[s]; + + if (shapeRef->getPlane()) + { + domPlaneRef planeRef = shapeRef->getPlane(); + if (planeRef->getEquation()) + { + const domFloat4 planeEq = planeRef->getEquation()->getValue(); + SimdVector3 planeNormal(planeEq.get(0),planeEq.get(1),planeEq.get(2)); + SimdScalar planeConstant = planeEq.get(3); + rbOutput.m_colShape = new StaticPlaneShape(planeNormal,planeConstant); + } + + } + + if (shapeRef->getBox()) + { + domBoxRef boxRef = shapeRef->getBox(); + domBox::domHalf_extentsRef domHalfExtentsRef = boxRef->getHalf_extents(); + domFloat3& halfExtents = domHalfExtentsRef->getValue(); + float x = halfExtents.get(0); + float y = halfExtents.get(1); + float z = halfExtents.get(2); + rbOutput.m_colShape = new BoxShape(SimdVector3(x,y,z)); + } + if (shapeRef->getSphere()) + { + domSphereRef sphereRef = shapeRef->getSphere(); + domSphere::domRadiusRef radiusRef = sphereRef->getRadius(); + domFloat radius = radiusRef->getValue(); + rbOutput.m_colShape = new SphereShape(radius); + } + + if (shapeRef->getCylinder()) + { + domCylinderRef cylinderRef = shapeRef->getCylinder(); + domFloat height = cylinderRef->getHeight()->getValue(); + domFloat2 radius2 = cylinderRef->getRadius()->getValue(); + domFloat radius0 = radius2.get(0); + + //Cylinder around the local Y axis + rbOutput.m_colShape = new CylinderShape(SimdVector3(radius0,height,radius0)); + + } + + if (shapeRef->getInstance_geometry()) + { + const domInstance_geometryRef geomInstRef = shapeRef->getInstance_geometry(); + daeElement* geomElem = geomInstRef->getUrl().getElement(); + //elemRef->getTypeName(); + domGeometry* geom = (domGeometry*) geomElem; + if (geom && geom->getMesh()) + { + const domMeshRef meshRef = geom->getMesh(); + + TriangleMesh* trimesh = new TriangleMesh(); + + + for (unsigned int tg = 0;tggetTriangles_array().getCount();tg++) + { + + + domTrianglesRef triRef = meshRef->getTriangles_array()[tg]; + const domPRef pRef = triRef->getP(); + IndexedMesh meshPart; + meshPart.m_triangleIndexStride=0; + + + + int vertexoffset = -1; + domInputLocalOffsetRef indexOffsetRef; + + + for (unsigned int w=0;wgetInput_array().getCount();w++) + { + int offset = triRef->getInput_array()[w]->getOffset(); + daeString str = triRef->getInput_array()[w]->getSemantic(); + if (!strcmp(str,"VERTEX")) + { + indexOffsetRef = triRef->getInput_array()[w]; + vertexoffset = offset; + } + if (offset > meshPart.m_triangleIndexStride) + { + meshPart.m_triangleIndexStride = offset; + } + } + meshPart.m_triangleIndexStride++; + domListOfUInts indexArray =triRef->getP()->getValue(); + + //int* m_triangleIndexBase; + + + + meshPart.m_numTriangles = triRef->getCount(); + + const domVerticesRef vertsRef = meshRef->getVertices(); + int numInputs = vertsRef->getInput_array().getCount(); + for (int i=0;igetInput_array()[i]; + daeString str = localRef->getSemantic(); + if ( !strcmp(str,"POSITION")) + { + const domURIFragmentType& frag = localRef->getSource(); + + daeElementConstRef constElem = frag.getElement(); + + const domSourceRef node = *(const domSourceRef*)&constElem; + const domFloat_arrayRef flArray = node->getFloat_array(); + if (flArray) + { + const domListOfFloats& listFloats = flArray->getValue(); + + int k=vertexoffset; + int t=0; + int vertexStride = 3;//instead of hardcoded stride, should use the 'accessor' + for (;tAddTriangle(verts[0],verts[1],verts[2]); + } + } + } + } + + + + + + //int m_triangleIndexStride;//calculate max offset + //int m_numVertices; + //float* m_vertexBase;//getRawData on floatArray + //int m_vertexStride;//use the accessor for this + + //}; + //tindexArray->AddIndexedMesh(meshPart); + if (rbOutput.m_isDynamics) + { + printf("moving concave not supported, transformed into convex\n"); + rbOutput.m_colShape = new ConvexTriangleMeshShape(trimesh); + } else + { + printf("static concave triangle added\n"); + rbOutput.m_colShape = new TriangleMeshShape(trimesh); + } + + } + + } + + if (geom && geom->getConvex_mesh()) + { + + { + const domConvex_meshRef convexRef = geom->getConvex_mesh(); + daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement(); + if ( otherElemRef != NULL ) + { + domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; + printf( "otherLinked\n"); + } else + { + printf("convexMesh polyCount = %i\n",convexRef->getPolygons_array().getCount()); + printf("convexMesh triCount = %i\n",convexRef->getTriangles_array().getCount()); + + } + } + + + + ConvexHullShape* convexHullShape = new ConvexHullShape(0,0); + + //it is quite a trick to get to the vertices, using Collada. + //we are not there yet... + + const domConvex_meshRef convexRef = geom->getConvex_mesh(); + //daeString urlref = convexRef->getConvex_hull_of().getURI(); + daeString urlref2 = convexRef->getConvex_hull_of().getOriginalURI(); + if (urlref2) + { + daeElementRef otherElemRef = convexRef->getConvex_hull_of().getElement(); + // if ( otherElemRef != NULL ) + // { + // domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; + + // Load all the geometry libraries + for ( unsigned int i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++) + { + domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i]; + //int index = libgeom->findLastIndexOf(urlref2); + //can't find it + + for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++) + { + //ReadGeometry( ); + domGeometryRef lib = libgeom->getGeometry_array()[i]; + if (!strcmp(lib->getName(),urlref2)) + { + //found convex_hull geometry + domMesh *meshElement = lib->getMesh();//linkedGeom->getMesh(); + if (meshElement) + { + const domVerticesRef vertsRef = meshElement->getVertices(); + int numInputs = vertsRef->getInput_array().getCount(); + for (int i=0;igetInput_array()[i]; + daeString str = localRef->getSemantic(); + if ( !strcmp(str,"POSITION")) + { + const domURIFragmentType& frag = localRef->getSource(); + + daeElementConstRef constElem = frag.getElement(); + + const domSourceRef node = *(const domSourceRef*)&constElem; + const domFloat_arrayRef flArray = node->getFloat_array(); + if (flArray) + { + int numElem = flArray->getCount(); + const domListOfFloats& listFloats = flArray->getValue(); + + for (int k=0;k+2AddPoint(SimdPoint3(fl0,fl1,fl2)); + } + + } + + } + + + } + + } + } + + + + } + } + + + } else + { + //no getConvex_hull_of but direct vertices + const domVerticesRef vertsRef = convexRef->getVertices(); + int numInputs = vertsRef->getInput_array().getCount(); + for (int i=0;igetInput_array()[i]; + daeString str = localRef->getSemantic(); + if ( !strcmp(str,"POSITION")) + { + const domURIFragmentType& frag = localRef->getSource(); + + daeElementConstRef constElem = frag.getElement(); + + const domSourceRef node = *(const domSourceRef*)&constElem; + const domFloat_arrayRef flArray = node->getFloat_array(); + if (flArray) + { + int numElem = flArray->getCount(); + const domListOfFloats& listFloats = flArray->getValue(); + + for (int k=0;k+2AddPoint(SimdPoint3(fl0,fl1,fl2)); + } + + } + + } + + + } + + + } + + if (convexHullShape->GetNumVertices()) + { + rbOutput.m_colShape = convexHullShape; + printf("created convexHullShape with %i points\n",convexHullShape->GetNumVertices()); + } else + { + delete convexHullShape; + printf("failed to create convexHullShape\n"); + } + + + //domGeometryRef linkedGeom = *(domGeometryRef*)&otherElemRef; + + printf("convexmesh\n"); + + } + } + + //if more then 1 shape, or a non-identity local shapetransform + //use a compound + + bool hasShapeLocalTransform = ((shapeRef->getRotate_array().getCount() > 0) || + (shapeRef->getTranslate_array().getCount() > 0)); + + if (rbOutput.m_colShape) + { + if ((techniqueRef->getShape_array().getCount()>1) || + (hasShapeLocalTransform)) + { + + if (!rbOutput.m_compoundShape) + { + rbOutput.m_compoundShape = new CompoundShape(); + } + + SimdTransform localTransform; + localTransform.setIdentity(); + if (hasShapeLocalTransform) + { + localTransform = GetSimdTransformFromCOLLADA_DOM( + emptyMatrixArray, + shapeRef->getRotate_array(), + shapeRef->getTranslate_array() + ); + } + + rbOutput.m_compoundShape->AddChildShape(localTransform,rbOutput.m_colShape); + rbOutput.m_colShape = 0; + } + } + + + }//for each shape + } + + +} diff --git a/Demos/ColladaDemo/ColladaConverter.h b/Demos/ColladaDemo/ColladaConverter.h index 1bc84faad..272b65e58 100644 --- a/Demos/ColladaDemo/ColladaConverter.h +++ b/Demos/ColladaDemo/ColladaConverter.h @@ -87,4 +87,6 @@ public: }; -#endif //COLLADA_CONVERTER_H \ No newline at end of file +#endif //COLLADA_CONVERTER_H + + diff --git a/Demos/ColladaDemo/ColladaDemo.h b/Demos/ColladaDemo/ColladaDemo.h index 047aeb6b0..491f0c49c 100644 --- a/Demos/ColladaDemo/ColladaDemo.h +++ b/Demos/ColladaDemo/ColladaDemo.h @@ -37,4 +37,5 @@ class ColladaDemo : public DemoApplication }; -#endif //COLLADA_PHYSICS_DEMO_H \ No newline at end of file +#endif //COLLADA_PHYSICS_DEMO_H + diff --git a/Demos/CollisionDemo/CollisionDemo.cpp b/Demos/CollisionDemo/CollisionDemo.cpp index d146d7661..51a8f6f3b 100644 --- a/Demos/CollisionDemo/CollisionDemo.cpp +++ b/Demos/CollisionDemo/CollisionDemo.cpp @@ -45,8 +45,8 @@ GL_Simplex1to4 simplex; PolyhedralConvexShape* shapePtr[maxNumObjects]; SimdTransform tr[numObjects]; -int screenWidth = 640.f; -int screenHeight = 480.f; +int screenWidth = 640; +int screenHeight = 480; void DrawRasterizerLine(float const* , float const*, int) { diff --git a/Demos/CollisionDemo/CollisionDemo.h b/Demos/CollisionDemo/CollisionDemo.h index a69eaae17..4926e3c0d 100644 --- a/Demos/CollisionDemo/CollisionDemo.h +++ b/Demos/CollisionDemo/CollisionDemo.h @@ -33,4 +33,5 @@ class CollisionDemo : public DemoApplication } }; -#endif //COLLISION_DEMO_H \ No newline at end of file +#endif //COLLISION_DEMO_H + diff --git a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp index a59a86cb3..b3ac3fa94 100644 --- a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp +++ b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp @@ -45,8 +45,8 @@ GL_Simplex1to4 simplex; CollisionObject objects[maxNumObjects]; CollisionWorld* collisionWorld = 0; -int screenWidth = 640.f; -int screenHeight = 480.f; +int screenWidth = 640; +int screenHeight = 480; int main(int argc,char** argv) @@ -74,8 +74,8 @@ void CollisionInterfaceDemo::initPhysics() objects[0].m_worldTransform.setBasis(basisA); objects[1].m_worldTransform.setBasis(basisB); - SimdPoint3 points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)}; - SimdPoint3 points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)}; + //SimdPoint3 points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)}; + //SimdPoint3 points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)}; BoxShape* boxA = new BoxShape(SimdVector3(1,1,1)); BoxShape* boxB = new BoxShape(SimdVector3(0.5,0.5,0.5)); diff --git a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.h b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.h index 35c2ec99a..28b0cd414 100644 --- a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.h +++ b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.h @@ -32,4 +32,5 @@ class CollisionInterfaceDemo : public DemoApplication }; -#endif //COLLISION_INTERFACE_DEMO_H \ No newline at end of file +#endif //COLLISION_INTERFACE_DEMO_H + diff --git a/Demos/ConcaveDemo/ConcaveDemo.h b/Demos/ConcaveDemo/ConcaveDemo.h index f162c7d69..4e0b8dd80 100644 --- a/Demos/ConcaveDemo/ConcaveDemo.h +++ b/Demos/ConcaveDemo/ConcaveDemo.h @@ -33,4 +33,5 @@ class ConcaveDemo : public DemoApplication }; -#endif //CONCAVE_DEMO_H \ No newline at end of file +#endif //CONCAVE_DEMO_H + diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp index f19373368..2d192d412 100644 --- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp +++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp @@ -164,7 +164,7 @@ void ConcaveDemo::initPhysics() - ConstraintSolver* solver = new SequentialImpulseConstraintSolver; + // ConstraintSolver* solver = new SequentialImpulseConstraintSolver; CollisionDispatcher* dispatcher = new CollisionDispatcher(); @@ -188,7 +188,7 @@ void ConcaveDemo::initPhysics() { CollisionShape* boxShape = new BoxShape(SimdVector3(1,1,1)); startTransform.setOrigin(SimdVector3(2*i,1,1)); - CcdPhysicsController* boxRigidBody = LocalCreatePhysicsObject(true, 1, startTransform,boxShape); + LocalCreatePhysicsObject(true, 1, startTransform,boxShape); } } m_physicsEnvironmentPtr->setGravity(-1,-10,1); diff --git a/Demos/ConstraintDemo/ConstraintDemo.cpp b/Demos/ConstraintDemo/ConstraintDemo.cpp index 9cc4aff74..706f7a59f 100644 --- a/Demos/ConstraintDemo/ConstraintDemo.cpp +++ b/Demos/ConstraintDemo/ConstraintDemo.cpp @@ -60,9 +60,7 @@ int main(int argc,char** argv) void ConstraintDemo::initPhysics() { - - - ConstraintSolver* solver = new SequentialImpulseConstraintSolver; + //ConstraintSolver* solver = new SequentialImpulseConstraintSolver; //ConstraintSolver* solver = new OdeConstraintSolver; CollisionDispatcher* dispatcher = new CollisionDispatcher(); diff --git a/Demos/ConstraintDemo/ConstraintDemo.h b/Demos/ConstraintDemo/ConstraintDemo.h index 66f2f9693..229fa4382 100644 --- a/Demos/ConstraintDemo/ConstraintDemo.h +++ b/Demos/ConstraintDemo/ConstraintDemo.h @@ -33,4 +33,5 @@ class ConstraintDemo : public DemoApplication } }; -#endif //CONSTRAINT_DEMO_H \ No newline at end of file +#endif //CONSTRAINT_DEMO_H + diff --git a/Demos/ContinuousConvexCollision/ContinuousConvexCollision.h b/Demos/ContinuousConvexCollision/ContinuousConvexCollision.h index dcc2ae7f7..da3316c66 100644 --- a/Demos/ContinuousConvexCollision/ContinuousConvexCollision.h +++ b/Demos/ContinuousConvexCollision/ContinuousConvexCollision.h @@ -33,4 +33,5 @@ class ContinuousConvexCollisionDemo : public DemoApplication } }; -#endif //CONTINUOUS_CONVEX_COLLISION_DEMO_H \ No newline at end of file +#endif //CONTINUOUS_CONVEX_COLLISION_DEMO_H + diff --git a/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp b/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp index a433efbff..5d00710e7 100644 --- a/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp +++ b/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp @@ -58,8 +58,8 @@ SimdTransform fromTrans[maxNumObjects]; SimdTransform toTrans[maxNumObjects]; -int screenWidth = 640.f; -int screenHeight = 480.f; +int screenWidth = 640; +int screenHeight = 480; int main(int argc,char** argv) @@ -158,16 +158,9 @@ void ContinuousConvexCollisionDemo::displayCallback(void) { { i=0;//for (i=1;iGetAngularMotionDisc(); - SimdScalar angspeed = angVels[i].length() * boundingRadius * dt; - SimdScalar linspeed = linVels[i].length() * dt; - - SimdScalar totalspeed = angspeed + linspeed; - //for each object, subdivide the from/to transform in 10 equal steps - int numSubSteps = 10.f; + int numSubSteps = 10; for (int s=0;s<10;s++) { SimdScalar subStep = s * 1.f/(float)numSubSteps; @@ -188,8 +181,6 @@ void ContinuousConvexCollisionDemo::displayCallback(void) { } - int shapeIndex = 1; - SimdMatrix3x3 mat; mat.setEulerZYX(yaw,pitch,roll); SimdQuaternion orn; diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp index 850598331..797e51ea9 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp @@ -76,10 +76,6 @@ GLDebugDrawer debugDrawer; int main(int argc,char** argv) { - - - int i; - char* filename = "file.obj"; @@ -308,7 +304,7 @@ void ConvexDecompositionDemo::initPhysics(const char* filename) //convexDecomposition.performConvexDecomposition(desc); ConvexBuilder cb(desc.mCallback); - int ret = cb.process(desc); + cb.process(desc); if (outputFile) fclose(outputFile); diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h index 34bf095f4..078535485 100644 --- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h +++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.h @@ -35,4 +35,6 @@ class ConvexDecompositionDemo : public DemoApplication }; -#endif //CONVEX_DECOMPOSITION_DEMO_H \ No newline at end of file +#endif //CONVEX_DECOMPOSITION_DEMO_H + + diff --git a/Demos/ForkLiftDemo/ForkLiftDemo.cpp b/Demos/ForkLiftDemo/ForkLiftDemo.cpp index db9f3a7b1..fff93d697 100644 --- a/Demos/ForkLiftDemo/ForkLiftDemo.cpp +++ b/Demos/ForkLiftDemo/ForkLiftDemo.cpp @@ -128,7 +128,7 @@ void ForkLiftDemo::setupPhysics() { CollisionDispatcher* dispatcher = new CollisionDispatcher(); - ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher(); + //ParallelIslandDispatcher* dispatcher2 = new ParallelIslandDispatcher(); SimdVector3 worldAabbMin(-30000,-30000,-30000); SimdVector3 worldAabbMax(30000,30000,30000); diff --git a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp index 674e6b638..a3dd3417e 100644 --- a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp +++ b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp @@ -50,8 +50,8 @@ const int numObjects = 2; PolyhedralConvexShape* shapePtr[maxNumObjects]; SimdTransform tr[numObjects]; -int screenWidth = 640.f; -int screenHeight = 480.f; +int screenWidth = 640; +int screenHeight = 480; void DrawRasterizerLine(float const* , float const*, int) { diff --git a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.h b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.h index 3f5093d4f..09082c13f 100644 --- a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.h +++ b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.h @@ -33,4 +33,5 @@ class LinearConvexCastDemo : public DemoApplication } }; -#endif //LINEAR_CONVEX_CAST_DEMO_H \ No newline at end of file +#endif //LINEAR_CONVEX_CAST_DEMO_H + diff --git a/Demos/OpenGL/BMF_BitmapFont.cpp b/Demos/OpenGL/BMF_BitmapFont.cpp index c42a371e1..0c1035a01 100644 --- a/Demos/OpenGL/BMF_BitmapFont.cpp +++ b/Demos/OpenGL/BMF_BitmapFont.cpp @@ -75,7 +75,7 @@ void BMF_BitmapFont::DrawString(const char* str) glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - while (c = (unsigned char) *str++) { + while ((c = (unsigned char) *str++)) { BMF_CharData & cd = m_fontData->chars[c]; if (cd.data_offset==-1) { @@ -98,7 +98,7 @@ int BMF_BitmapFont::GetStringWidth(char* str) unsigned char c; int length = 0; - while (c = (unsigned char) *str++) { + while ((c = (unsigned char) *str++)) { length += m_fontData->chars[c].advance; } @@ -182,7 +182,7 @@ void BMF_BitmapFont::DrawStringTexture(char *str, float x, float y, float z) int baseLine = -(m_fontData->ymin); glBegin(GL_QUADS); - while (c = (unsigned char) *str++) { + while ((c = (unsigned char) *str++)) { BMF_CharData & cd = m_fontData->chars[c]; if (cd.data_offset != -1) { diff --git a/Demos/OpenGL/DemoApplication.h b/Demos/OpenGL/DemoApplication.h index f49d2a1ec..72653d0c5 100644 --- a/Demos/OpenGL/DemoApplication.h +++ b/Demos/OpenGL/DemoApplication.h @@ -167,4 +167,5 @@ class DemoApplication }; -#endif //DEMO_APPLICATION_H \ No newline at end of file +#endif //DEMO_APPLICATION_H + diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp index 86d6cdf13..5b6e9ae09 100644 --- a/Demos/OpenGL/GL_ShapeDrawer.cpp +++ b/Demos/OpenGL/GL_ShapeDrawer.cpp @@ -151,7 +151,6 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim case TRIANGLE_SHAPE_PROXYTYPE: case TETRAHEDRAL_SHAPE_PROXYTYPE: { - const BU_Simplex1to4* tetra = static_cast(shape); //todo: // useWireframeFallback = false; break; diff --git a/Demos/OpenGL/GL_Simplex1to4.cpp b/Demos/OpenGL/GL_Simplex1to4.cpp index a67ea8b1b..5d0f3f175 100644 --- a/Demos/OpenGL/GL_Simplex1to4.cpp +++ b/Demos/OpenGL/GL_Simplex1to4.cpp @@ -51,21 +51,14 @@ void GL_Simplex1to4::CalcClosest(float* m) bool res; SimdVector3 v; - SimdPoint3 pBuf[4]; - SimdPoint3 qBuf[4]; - SimdPoint3 yBuf[4]; - for (int i=0;iaddVertex(v,v,SimdPoint3(0.f,0.f,0.f)); res = m_simplexSolver->closest(v); - int res = m_simplexSolver->getSimplex(pBuf, qBuf, yBuf); - } - //draw v? glDisable(GL_LIGHTING); glBegin(GL_LINES); diff --git a/Demos/OpenGL/RenderTexture.cpp b/Demos/OpenGL/RenderTexture.cpp index 9af21d29f..a0ea8ed30 100644 --- a/Demos/OpenGL/RenderTexture.cpp +++ b/Demos/OpenGL/RenderTexture.cpp @@ -42,7 +42,7 @@ void RenderTexture::Printf(char* str, BMF_FontData* fontData, int startx,int sta unsigned char c; int rasterposx = startx; int rasterposy = starty; - while (c = (unsigned char) *str++) { + while ((c = (unsigned char) *str++)) { BMF_CharData & cd = fontData->chars[c]; if (cd.data_offset!=-1) { diff --git a/Demos/Raytracer/Raytracer.cpp b/Demos/Raytracer/Raytracer.cpp index 47a81a344..d34318756 100644 --- a/Demos/Raytracer/Raytracer.cpp +++ b/Demos/Raytracer/Raytracer.cpp @@ -110,9 +110,8 @@ void Raytracer::initPhysics() SimdVector3(-0.5f, 0.6f, 0.f), SimdVector3(0.f, 0.f, 0.f) }; - SimdScalar radi[NUM_SPHERES] = { 0.35f,0.35f,0.45f,0.40f,0.40f }; - MultiSphereShape* multiSphereShape = new MultiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES); + // MultiSphereShape* multiSphereShape = new MultiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES); ConvexHullShape* convexHullShape = new ConvexHullShape(positions,3); diff --git a/Demos/Raytracer/Raytracer.h b/Demos/Raytracer/Raytracer.h index 172656311..988157031 100644 --- a/Demos/Raytracer/Raytracer.h +++ b/Demos/Raytracer/Raytracer.h @@ -33,4 +33,6 @@ class Raytracer : public DemoApplication } }; -#endif //RAYTRACER_H \ No newline at end of file +#endif //RAYTRACER_H + + diff --git a/Demos/SimplexDemo/SimplexDemo.cpp b/Demos/SimplexDemo/SimplexDemo.cpp index d86ed3b99..94abe4636 100644 --- a/Demos/SimplexDemo/SimplexDemo.cpp +++ b/Demos/SimplexDemo/SimplexDemo.cpp @@ -34,8 +34,8 @@ VoronoiSimplexSolver simplexSolver; float yaw=0.f,pitch=0.f,roll=0.f; const int maxNumObjects = 4; const int numObjects = 1; -int screenWidth = 640.f; -int screenHeight = 480.f; +int screenWidth = 640; +int screenHeight = 480; /// simplex contains the vertices, and some extra code to draw and debug GL_Simplex1to4 simplex; @@ -115,4 +115,6 @@ void SimplexDemo::initPhysics() SimdTransform tr; tr.setIdentity(); -} \ No newline at end of file +} + + diff --git a/Demos/SimplexDemo/SimplexDemo.h b/Demos/SimplexDemo/SimplexDemo.h index 26ee00683..532c14fdf 100644 --- a/Demos/SimplexDemo/SimplexDemo.h +++ b/Demos/SimplexDemo/SimplexDemo.h @@ -33,4 +33,6 @@ class SimplexDemo : public DemoApplication } }; -#endif //SIMPLEX_DEMO_H \ No newline at end of file +#endif //SIMPLEX_DEMO_H + + diff --git a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp index b9460fddc..a37e99875 100644 --- a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp +++ b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.cpp @@ -137,7 +137,7 @@ void UserCollisionAlgorithm::initPhysics() - ConstraintSolver* solver = new SequentialImpulseConstraintSolver; + //ConstraintSolver* solver = new SequentialImpulseConstraintSolver; CollisionDispatcher* dispatcher = new CollisionDispatcher(); @@ -163,7 +163,7 @@ void UserCollisionAlgorithm::initPhysics() { CollisionShape* sphereShape = new SphereShape(1); startTransform.setOrigin(SimdVector3(1,2*i,1)); - CcdPhysicsController* boxRigidBody = LocalCreatePhysicsObject(true, 1, startTransform,sphereShape); + LocalCreatePhysicsObject(true, 1, startTransform,sphereShape); } } m_physicsEnvironmentPtr->setGravity(-1,-10,1); diff --git a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.h b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.h index 7730a98e6..a7f2c2386 100644 --- a/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.h +++ b/Demos/UserCollisionAlgorithm/UserCollisionAlgorithm.h @@ -32,4 +32,5 @@ class UserCollisionAlgorithm : public DemoApplication }; -#endif //USER_COLLISION_ALGORITHM_DEMO_H \ No newline at end of file +#endif //USER_COLLISION_ALGORITHM_DEMO_H + diff --git a/Extras/ConvexDecomposition/ConvexBuilder.cpp b/Extras/ConvexDecomposition/ConvexBuilder.cpp index e0539898d..a11153d84 100644 --- a/Extras/ConvexDecomposition/ConvexBuilder.cpp +++ b/Extras/ConvexDecomposition/ConvexBuilder.cpp @@ -8,6 +8,10 @@ #include "fitsphere.h" #include "bestfitobb.h" +unsigned int MAXDEPTH = 8 ; +float CONCAVE_PERCENT = 1.0f ; +float MERGE_PERCENT = 2.0f ; + CHull::CHull(const ConvexResult &result) { mResult = new ConvexResult(result); @@ -147,8 +151,6 @@ CHull * ConvexBuilder::canMerge(CHull *a,CHull *b) if (!tcount) return 0; - unsigned int *idx = &indices[0]; - HullResult hresult; HullLibrary hl; HullDesc desc; diff --git a/Extras/ConvexDecomposition/ConvexBuilder.h b/Extras/ConvexDecomposition/ConvexBuilder.h index 7cd774a03..5fc5545e7 100644 --- a/Extras/ConvexDecomposition/ConvexBuilder.h +++ b/Extras/ConvexDecomposition/ConvexBuilder.h @@ -79,7 +79,7 @@ class ConvexBuilder : public ConvexDecompInterface public: ConvexBuilder(ConvexDecompInterface *callback); - ~ConvexBuilder(void); + virtual ~ConvexBuilder(void); bool isDuplicate(unsigned int i1,unsigned int i2,unsigned int i3, unsigned int ci1,unsigned int ci2,unsigned int ci3); @@ -108,3 +108,4 @@ public: }; #endif //CONVEX_BUILDER_H + diff --git a/Extras/ConvexDecomposition/ConvexDecomposition.cpp b/Extras/ConvexDecomposition/ConvexDecomposition.cpp index 492e19cf5..b58dcc428 100644 --- a/Extras/ConvexDecomposition/ConvexDecomposition.cpp +++ b/Extras/ConvexDecomposition/ConvexDecomposition.cpp @@ -337,9 +337,6 @@ void calcConvexDecomposition(unsigned int vcount, } } - unsigned int fsize = ifront.size()/3; - unsigned int bsize = iback.size()/3; - // ok... here we recursively call if ( ifront.size() ) { diff --git a/Extras/ConvexDecomposition/ConvexDecomposition.h b/Extras/ConvexDecomposition/ConvexDecomposition.h index 5bfe308f7..0e5db4132 100644 --- a/Extras/ConvexDecomposition/ConvexDecomposition.h +++ b/Extras/ConvexDecomposition/ConvexDecomposition.h @@ -1,219 +1,219 @@ -#ifndef CONVEX_DECOMPOSITION_H - -#define CONVEX_DECOMPOSITION_H - -/*---------------------------------------------------------------------- -Copyright (c) 2004 Open Dynamics Framework Group -www.physicstools.org -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided -that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list of conditions -and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -Neither the name of the Open Dynamics Framework Group nor the names of its contributors may -be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ------------------------------------------------------------------------*/ - -// http://codesuppository.blogspot.com -// -// mailto: jratcliff@infiniplex.net -// -// http://www.amillionpixels.us -// - - -#ifdef WIN32 -#include //memcpy -#endif -#include +#ifndef CONVEX_DECOMPOSITION_H + +#define CONVEX_DECOMPOSITION_H + +/*---------------------------------------------------------------------- +Copyright (c) 2004 Open Dynamics Framework Group +www.physicstools.org +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided +that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions +and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +Neither the name of the Open Dynamics Framework Group nor the names of its contributors may +be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +-----------------------------------------------------------------------*/ + +// http://codesuppository.blogspot.com +// +// mailto: jratcliff@infiniplex.net +// +// http://www.amillionpixels.us +// + + +#ifdef WIN32 +#include //memcpy +#endif +#include #include - - - -static unsigned int MAXDEPTH=8; -static float CONCAVE_PERCENT=1.0f; -static float MERGE_PERCENT=2.0f; - -#include -typedef std::vector< unsigned int > UintVector; - - - -namespace ConvexDecomposition -{ - - class ConvexResult - { - public: - ConvexResult(void) - { - mHullVcount = 0; - mHullVertices = 0; - mHullTcount = 0; - mHullIndices = 0; - } - - ConvexResult(unsigned int hvcount,const float *hvertices,unsigned int htcount,const unsigned int *hindices) - { - mHullVcount = hvcount; - if ( mHullVcount ) - { - mHullVertices = new float[mHullVcount*sizeof(float)*3]; - memcpy(mHullVertices, hvertices, sizeof(float)*3*mHullVcount ); - } - else - { - mHullVertices = 0; - } - - mHullTcount = htcount; - - if ( mHullTcount ) - { - mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; - memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 ); - } - else - { - mHullIndices = 0; - } - - } - - ConvexResult(const ConvexResult &r) - { - mHullVcount = r.mHullVcount; - if ( mHullVcount ) - { - mHullVertices = new float[mHullVcount*sizeof(float)*3]; - memcpy(mHullVertices, r.mHullVertices, sizeof(float)*3*mHullVcount ); - } - else - { - mHullVertices = 0; - } - mHullTcount = r.mHullTcount; - if ( mHullTcount ) - { - mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; - memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 ); - } - else - { - mHullIndices = 0; - } - } - - ~ConvexResult(void) - { - delete mHullVertices; - delete mHullIndices; - } - - // the convex hull. - unsigned int mHullVcount; - float * mHullVertices; - unsigned int mHullTcount; - unsigned int *mHullIndices; - - float mHullVolume; // the volume of the convex hull. - - float mOBBSides[3]; // the width, height and breadth of the best fit OBB - float mOBBCenter[3]; // the center of the OBB - float mOBBOrientation[4]; // the quaternion rotation of the OBB. - float mOBBTransform[16]; // the 4x4 transform of the OBB. - float mOBBVolume; // the volume of the OBB - - float mSphereRadius; // radius and center of best fit sphere - float mSphereCenter[3]; - float mSphereVolume; // volume of the best fit sphere - - - - }; - - class ConvexDecompInterface - { - public: - - virtual void ConvexDebugTri(const float *p1,const float *p2,const float *p3,unsigned int color) { }; - virtual void ConvexDebugPoint(const float *p,float dist,unsigned int color) { }; - virtual void ConvexDebugBound(const float *bmin,const float *bmax,unsigned int color) { }; - virtual void ConvexDebugOBB(const float *sides, const float *matrix,unsigned int color) { }; - - virtual void ConvexDecompResult(ConvexResult &result) = 0; - - - - }; - - // just to avoid passing a zillion parameters to the method the - // options are packed into this descriptor. - class DecompDesc - { - public: - DecompDesc(void) - { - mVcount = 0; - mVertices = 0; - mTcount = 0; - mIndices = 0; - mDepth = 5; - mCpercent = 5; - mPpercent = 5; - mMaxVertices = 32; - mSkinWidth = 0; - mCallback = 0; - } - - // describes the input triangle. - unsigned int mVcount; // the number of vertices in the source mesh. - const float *mVertices; // start of the vertex position array. Assumes a stride of 3 floats. - unsigned int mTcount; // the number of triangles in the source mesh. - unsigned int *mIndices; // the indexed triangle list array (zero index based) - - // options - unsigned int mDepth; // depth to split, a maximum of 10, generally not over 7. - float mCpercent; // the concavity threshold percentage. 0=20 is reasonable. - float mPpercent; // the percentage volume conservation threshold to collapse hulls. 0-30 is reasonable. - - // hull output limits. - unsigned int mMaxVertices; // maximum number of vertices in the output hull. Recommended 32 or less. - float mSkinWidth; // a skin width to apply to the output hulls. - - ConvexDecompInterface *mCallback; // the interface to receive back the results. - - }; - - // perform approximate convex decomposition on a mesh. - unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced. - - - void calcConvexDecomposition(unsigned int vcount, - const float *vertices, - unsigned int tcount, - const unsigned int *indices, - ConvexDecompInterface *callback, - float masterVolume, - unsigned int depth); - - -}; - - -#endif + + + +extern unsigned int MAXDEPTH ; +extern float CONCAVE_PERCENT ; +extern float MERGE_PERCENT ; + +#include +typedef std::vector< unsigned int > UintVector; + + + +namespace ConvexDecomposition +{ + + class ConvexResult + { + public: + ConvexResult(void) + { + mHullVcount = 0; + mHullVertices = 0; + mHullTcount = 0; + mHullIndices = 0; + } + + ConvexResult(unsigned int hvcount,const float *hvertices,unsigned int htcount,const unsigned int *hindices) + { + mHullVcount = hvcount; + if ( mHullVcount ) + { + mHullVertices = new float[mHullVcount*sizeof(float)*3]; + memcpy(mHullVertices, hvertices, sizeof(float)*3*mHullVcount ); + } + else + { + mHullVertices = 0; + } + + mHullTcount = htcount; + + if ( mHullTcount ) + { + mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; + memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 ); + } + else + { + mHullIndices = 0; + } + + } + + ConvexResult(const ConvexResult &r) + { + mHullVcount = r.mHullVcount; + if ( mHullVcount ) + { + mHullVertices = new float[mHullVcount*sizeof(float)*3]; + memcpy(mHullVertices, r.mHullVertices, sizeof(float)*3*mHullVcount ); + } + else + { + mHullVertices = 0; + } + mHullTcount = r.mHullTcount; + if ( mHullTcount ) + { + mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3]; + memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 ); + } + else + { + mHullIndices = 0; + } + } + + ~ConvexResult(void) + { + delete mHullVertices; + delete mHullIndices; + } + + // the convex hull. + unsigned int mHullVcount; + float * mHullVertices; + unsigned int mHullTcount; + unsigned int *mHullIndices; + + float mHullVolume; // the volume of the convex hull. + + float mOBBSides[3]; // the width, height and breadth of the best fit OBB + float mOBBCenter[3]; // the center of the OBB + float mOBBOrientation[4]; // the quaternion rotation of the OBB. + float mOBBTransform[16]; // the 4x4 transform of the OBB. + float mOBBVolume; // the volume of the OBB + + float mSphereRadius; // radius and center of best fit sphere + float mSphereCenter[3]; + float mSphereVolume; // volume of the best fit sphere + + + + }; + + class ConvexDecompInterface + { + public: + + virtual void ConvexDebugTri(const float *p1,const float *p2,const float *p3,unsigned int color) { }; + virtual void ConvexDebugPoint(const float *p,float dist,unsigned int color) { }; + virtual void ConvexDebugBound(const float *bmin,const float *bmax,unsigned int color) { }; + virtual void ConvexDebugOBB(const float *sides, const float *matrix,unsigned int color) { }; + + virtual void ConvexDecompResult(ConvexResult &result) = 0; + + + + }; + + // just to avoid passing a zillion parameters to the method the + // options are packed into this descriptor. + class DecompDesc + { + public: + DecompDesc(void) + { + mVcount = 0; + mVertices = 0; + mTcount = 0; + mIndices = 0; + mDepth = 5; + mCpercent = 5; + mPpercent = 5; + mMaxVertices = 32; + mSkinWidth = 0; + mCallback = 0; + } + + // describes the input triangle. + unsigned int mVcount; // the number of vertices in the source mesh. + const float *mVertices; // start of the vertex position array. Assumes a stride of 3 floats. + unsigned int mTcount; // the number of triangles in the source mesh. + unsigned int *mIndices; // the indexed triangle list array (zero index based) + + // options + unsigned int mDepth; // depth to split, a maximum of 10, generally not over 7. + float mCpercent; // the concavity threshold percentage. 0=20 is reasonable. + float mPpercent; // the percentage volume conservation threshold to collapse hulls. 0-30 is reasonable. + + // hull output limits. + unsigned int mMaxVertices; // maximum number of vertices in the output hull. Recommended 32 or less. + float mSkinWidth; // a skin width to apply to the output hulls. + + ConvexDecompInterface *mCallback; // the interface to receive back the results. + + }; + + // perform approximate convex decomposition on a mesh. + unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced. + + + void calcConvexDecomposition(unsigned int vcount, + const float *vertices, + unsigned int tcount, + const unsigned int *indices, + ConvexDecompInterface *callback, + float masterVolume, + unsigned int depth); + + +}; + + +#endif diff --git a/Extras/ConvexDecomposition/cd_hull.cpp b/Extras/ConvexDecomposition/cd_hull.cpp index 0987edd09..da7a45284 100644 --- a/Extras/ConvexDecomposition/cd_hull.cpp +++ b/Extras/ConvexDecomposition/cd_hull.cpp @@ -1725,7 +1725,6 @@ int AssertIntact(ConvexH &convex) { inext = estart; } assert(convex.edges[inext].p == convex.edges[i].p); - HalfEdge &edge = convex.edges[i]; int nb = convex.edges[i].ea; assert(nb!=255); if(nb==255 || nb==-1) return 0; @@ -1852,10 +1851,6 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice) int i; int vertcountunder=0; int vertcountover =0; - int edgecountunder=0; - int edgecountover =0; - int planecountunder=0; - int planecountover =0; static Array vertscoplanar; // existing vertex members of convex that are coplanar vertscoplanar.count=0; static Array edgesplit; // existing edges that members of convex that cross the splitplane @@ -1886,7 +1881,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice) else { assert(vertflag[i].planetest == OVER); vertflag[i].overmap = vertcountover++; - vertflag[i].undermap = -1; // for debugging purposes + vertflag[i].undermap = 255; // for debugging purposes } } int vertcountunderold = vertcountunder; // for debugging only @@ -1897,11 +1892,9 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice) for(int currentplane=0; currentplane FloatVector; class InPlaceParserInterface { public: - virtual int ParseLine(int lineno,int argc,const char **argv) =0; // return TRUE to continue parsing, return FALSE to abort parsing process + virtual ~InPlaceParserInterface () {} ; + + virtual int ParseLine(int lineno,int argc,const char **argv) =0; // return TRUE to continue parsing, return FALSE to abort parsing process }; enum SeparatorType @@ -157,23 +159,23 @@ public: void SetHardSeparator(char c) // add a hard separator { - mHard[c] = ST_HARD; + mHard[(int)c] = ST_HARD; } void SetHard(char c) // add a hard separator { - mHard[c] = ST_HARD; + mHard[(int)c] = ST_HARD; } void SetCommentSymbol(char c) // comment character, treated as 'end of string' { - mHard[c] = ST_EOS; + mHard[(int)c] = ST_EOS; } void ClearHardSeparator(char c) { - mHard[c] = ST_DATA; + mHard[(int)c] = ST_DATA; } @@ -181,7 +183,7 @@ public: bool EOS(char c) { - if ( mHard[c] == ST_EOS ) + if ( mHard[(int)c] == ST_EOS ) { return true; } @@ -261,7 +263,7 @@ InPlaceParser::~InPlaceParser(void) bool InPlaceParser::IsHard(char c) { - return mHard[c] == ST_HARD; + return mHard[(int)c] == ST_HARD; } char * InPlaceParser::AddHard(int &argc,const char **argv,char *foo) @@ -280,7 +282,7 @@ char * InPlaceParser::AddHard(int &argc,const char **argv,char *foo) bool InPlaceParser::IsWhiteSpace(char c) { - return mHard[c] == ST_SOFT; + return mHard[(int)c] == ST_SOFT; } char * InPlaceParser::SkipSpaces(char *foo) @@ -550,10 +552,9 @@ class GeometryInterface { public: - virtual void NodeTriangle(const GeometryVertex *v1,const GeometryVertex *v2,const GeometryVertex *v3) - { - } + virtual void NodeTriangle(const GeometryVertex *v1,const GeometryVertex *v2,const GeometryVertex *v3) {} + virtual ~GeometryInterface () {} }; diff --git a/Extras/ConvexDecomposition/concavity.cpp b/Extras/ConvexDecomposition/concavity.cpp index 45a3cb95e..134af5ceb 100644 --- a/Extras/ConvexDecomposition/concavity.cpp +++ b/Extras/ConvexDecomposition/concavity.cpp @@ -113,7 +113,6 @@ static void intersect(const float *p1,const float *p2,float *split,const float * { float dp1 = DistToPt(p1,plane); - float dp2 = DistToPt(p2,plane); float dir[3]; @@ -129,7 +128,6 @@ static void intersect(const float *p1,const float *p2,float *split,const float * split[0] = (dir[0]*t)+p1[0]; split[1] = (dir[1]*t)+p1[1]; split[2] = (dir[2]*t)+p1[2]; - } @@ -602,8 +600,6 @@ float computeConcavity(unsigned int vcount, float bmin[3]; float bmax[3]; - float diagonal = getBoundingRegion( result.mNumOutputVertices, result.mOutputVertices, sizeof(float)*3, bmin, bmax ); - float dx = bmax[0] - bmin[0]; float dy = bmax[1] - bmin[1]; float dz = bmax[2] - bmin[2]; @@ -614,8 +610,6 @@ float computeConcavity(unsigned int vcount, center.y = bmin[1] + dy*0.5f; center.z = bmin[2] + dz*0.5f; - float boundVolume = dx*dy*dz; - volume = computeMeshVolume2( result.mOutputVertices, result.mNumFaces, result.mIndices ); #if 1 diff --git a/Extras/ConvexDecomposition/meshvolume.cpp b/Extras/ConvexDecomposition/meshvolume.cpp index 6dd0bf03e..c98f522e5 100644 --- a/Extras/ConvexDecomposition/meshvolume.cpp +++ b/Extras/ConvexDecomposition/meshvolume.cpp @@ -43,7 +43,6 @@ float computeMeshVolume(const float *vertices,unsigned int tcount,const unsigned { float volume = 0; - const float *p0 = vertices; for (unsigned int i=0; iincludes[2 * ctxt->nbIncludes + 1] = (xmlNodePtr) doc; ctxt->nbIncludes++; } +#endif /** * xmlSchematronPopInclude: @@ -996,6 +998,7 @@ xmlSchematronParsePattern(xmlSchematronParserCtxtPtr ctxt, xmlNodePtr pat) * * Returns the updated node pointer */ +#if 0 static xmlNodePtr xmlSchematronLoadInclude(xmlSchematronParserCtxtPtr ctxt, xmlNodePtr cur) { @@ -1051,6 +1054,7 @@ done: xmlFree(URI); return(ret); } +#endif /** * xmlSchematronParse: diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index 2f0b4adb8..543c43862 100644 --- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -327,13 +327,13 @@ static void DrawAabb(IDebugDraw* debugDrawer,const SimdVector3& from,const SimdV CcdPhysicsEnvironment::CcdPhysicsEnvironment(Dispatcher* dispatcher,OverlappingPairCache* pairCache) -:m_scalingPropagated(false), -m_numIterations(10), +: m_numIterations(10), m_numTimeSubSteps(1), m_ccdMode(0), m_solverType(-1), m_profileTimings(0), -m_enableSatCollisionDetection(false) +m_enableSatCollisionDetection(false), +m_scalingPropagated(false) { for (int i=0;im_broadphaseHandle); - BroadphaseInterface* scene = GetBroadphase(); - - CollisionShape* shapeinterface = ctrl->GetCollisionShape(); assert(shapeinterface); @@ -695,10 +692,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep) Profiler::endBlock("DispatchAllCollisionPairs"); #endif //USE_QUICKPROF - - int numRigidBodies = m_controllers.size(); - - m_islandManager->UpdateActivationState(GetCollisionWorld(),GetCollisionWorld()->GetDispatcher()); { @@ -1445,10 +1438,6 @@ void CcdPhysicsEnvironment::removeConstraint(int constraintId) PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* ignoreClient, float fromX,float fromY,float fromZ, float toX,float toY,float toZ, float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ) { - - - float minFraction = 1.f; - SimdVector3 rayFrom(fromX,fromY,fromZ); SimdVector3 rayTo(toX,toY,toZ); @@ -1629,9 +1618,6 @@ void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctr void CcdPhysicsEnvironment::CallbackTriggers() { - - CcdPhysicsController* ctrl0=0,*ctrl1=0; - if (m_triggerCallbacks[PHY_OBJECT_RESPONSE] || (m_debugDrawer && (m_debugDrawer->GetDebugMode() & IDebugDraw::DBG_DrawContactPoints))) { //walk over all overlapping pairs, and if one of the involved bodies is registered for trigger callback, perform callback diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h index cd510f1c5..2ff079b95 100644 --- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h +++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h @@ -264,3 +264,4 @@ protected: }; #endif //CCDPHYSICSENVIRONMENT + diff --git a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp index 57d004869..12abc9126 100644 --- a/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/ParallelIslandDispatcher.cpp @@ -286,13 +286,13 @@ void ParallelIslandDispatcher::DispatchAllCollisionPairs(OverlappingPairCache* p { //m_blockedForChanges = true; - int i; - int dispatcherId = GetUniqueId(); assert(0); /* + int dispatcherId = GetUniqueId(); + int i; for (i=0;i constraint.GetRigidBodyB().m_islandTag1) { - simulationIslands[constraint.GetRigidBodyA().m_islandTag1].m_constraintIndices.push_back(i); + simulationIslands[constraint.GetRigidBodyA().m_islandTag1].m_constraintIndices.push_back(ui); } else { - simulationIslands[constraint.GetRigidBodyB().m_islandTag1].m_constraintIndices.push_back(i); + simulationIslands[constraint.GetRigidBodyB().m_islandTag1].m_constraintIndices.push_back(ui); } } @@ -203,4 +203,4 @@ bool ParallelPhysicsEnvironment::proceedDeltaTimeOneStep(float timeStep) return true; -} \ No newline at end of file +} diff --git a/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp index eb3b7f235..f313f8cf3 100644 --- a/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/SimulationIsland.cpp @@ -92,7 +92,7 @@ bool SimulationIsland::Simulate(IDebugDraw* debugDrawer,int numSolverIterations, overlappingPairs.resize(this->m_overlappingPairIndices.size()); //gather overlapping pair info - int i; + unsigned int i; for (i=0;i