Did a bit more Collada physics importing work.
Also did a quick workaround to allow different camera UP. This demo stuff really needs to be cleaned up now!
This commit is contained in:
@@ -27,7 +27,8 @@ subject to the following restrictions:
|
||||
#include "CollisionShapes/TriangleMeshShape.h"
|
||||
|
||||
|
||||
|
||||
extern SimdVector3 gCameraUp;
|
||||
extern int gForwardAxis;
|
||||
|
||||
#include "CollisionShapes/Simplex1to4Shape.h"
|
||||
#include "CollisionShapes/EmptyShape.h"
|
||||
@@ -44,6 +45,9 @@ subject to the following restrictions:
|
||||
|
||||
#include "GLDebugDrawer.h"
|
||||
|
||||
//either FCollada or Collada-dom
|
||||
#define USE_FCOLLADA 1
|
||||
#ifdef USE_FCOLLADA
|
||||
|
||||
//Collada Physics test
|
||||
//#define NO_LIBXML //need LIBXML, because FCDocument/FCDPhysicsRigidBody.h needs FUDaeWriter, through FCDPhysicsParameter.hpp
|
||||
@@ -67,11 +71,14 @@ subject to the following restrictions:
|
||||
#include "FCDocument/FCDPhysicsAnalyticalGeometry.h"
|
||||
|
||||
|
||||
//aaa
|
||||
|
||||
|
||||
#else
|
||||
//Use Collada-dom
|
||||
|
||||
#include "dae.h"
|
||||
#include "dom/domCOLLADA.h"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -216,6 +223,8 @@ void CreatePhysicsObject(bool isDynamic, float mass, const SimdTransform& startT
|
||||
|
||||
|
||||
|
||||
#ifdef USE_FCOLLADA
|
||||
|
||||
|
||||
bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
{
|
||||
@@ -281,7 +290,11 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
//right now as we would also have to migrate all the animation curves.
|
||||
|
||||
|
||||
//FRTScaleList scaleTransforms;
|
||||
SimdVector3 localScaling(1.f,1.f,1.f);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SimdTransform accumulatedWorldTransform;
|
||||
accumulatedWorldTransform.setIdentity();
|
||||
@@ -290,6 +303,19 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
|
||||
for (uint32 i=0; i<numTransforms; i++)
|
||||
{
|
||||
|
||||
if (targetNode->GetTransforms()[i]->GetType() == FCDTransform::SCALE)
|
||||
{
|
||||
|
||||
FCDTScale* scaleTrans = (FCDTScale*)targetNode->GetTransforms()[i];
|
||||
const FMVector3& scaling = scaleTrans->GetScale();
|
||||
localScaling[0] = scaling.x;
|
||||
localScaling[1] = scaling.y;
|
||||
localScaling[2] = scaling.z;
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
FMMatrix44 mat = (targetNode->GetTransforms()[i])->ToMatrix();
|
||||
SimdVector3 pos(mat.GetTranslation().x,mat.GetTranslation().y,mat.GetTranslation().z);
|
||||
|
||||
@@ -303,6 +329,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
|
||||
//TODO: check pre or post multiply
|
||||
accumulatedWorldTransform = accumulatedWorldTransform * trans;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -552,6 +579,7 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
|
||||
} else
|
||||
{
|
||||
printf("static not yet?\n");
|
||||
|
||||
//should be static triangle mesh!
|
||||
|
||||
@@ -751,6 +779,9 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
printf("create Physics Object\n");
|
||||
//void CreatePhysicsObject(bool isDynamic, float mass, const SimdTransform& startTransform,CollisionShape* shape)
|
||||
|
||||
collisionShape->setLocalScaling(localScaling);
|
||||
ms[numObjects].m_localScaling = localScaling;
|
||||
|
||||
CreatePhysicsObject(isDynamic, mymass, accumulatedWorldTransform,collisionShape);
|
||||
|
||||
|
||||
@@ -768,7 +799,10 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
//Collada-dom
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -780,6 +814,8 @@ GLDebugDrawer debugDrawer;
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
gCameraUp = SimdVector3(0,0,1);
|
||||
gForwardAxis = 1;
|
||||
|
||||
///Setup a Physics Simulation Environment
|
||||
CollisionDispatcher* dispatcher = new CollisionDispatcher();
|
||||
@@ -793,6 +829,7 @@ int main(int argc,char** argv)
|
||||
physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
|
||||
|
||||
|
||||
|
||||
/// Import Collada 1.4 Physics objects
|
||||
|
||||
//char* filename = "analyticalGeomPhysicsTest.dae";//ColladaPhysics.dae";
|
||||
@@ -800,7 +837,7 @@ int main(int argc,char** argv)
|
||||
|
||||
//char* filename = "friction.dae";
|
||||
|
||||
|
||||
#ifdef USE_FCOLLADA
|
||||
|
||||
FCDocument* document = new FCDocument();
|
||||
FUStatus status = document->LoadFromFile(filename);
|
||||
@@ -818,7 +855,150 @@ int main(int argc,char** argv)
|
||||
printf("ConvertColladaPhysicsToBulletPhysics failed\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
//Collada-dom
|
||||
DAE *collada = new DAE;
|
||||
|
||||
|
||||
int res = collada->load(filename);//,docBuffer);
|
||||
if (res != DAE_OK)
|
||||
{
|
||||
printf("DAE/Collada-dom: Couldn't load %s\n",filename);
|
||||
} else
|
||||
{
|
||||
|
||||
domCOLLADA *dom = collada->getDom(filename);
|
||||
if ( !dom )
|
||||
{
|
||||
printf("COLLADA File loaded to the dom, but query for the dom assets failed \n" );
|
||||
printf("COLLADA Load Aborted! \n" );
|
||||
delete collada;
|
||||
|
||||
} else
|
||||
{
|
||||
|
||||
//succesfully loaded file, now convert data
|
||||
|
||||
if ( dom->getAsset()->getUp_axis() )
|
||||
{
|
||||
domAsset::domUp_axis * up = 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" );
|
||||
break;
|
||||
case UPAXISTYPE_Y_UP:
|
||||
printf(" Y Axis is Up for this file \n" );
|
||||
printf(" COLLADA_RT set to Y Up \n" );
|
||||
|
||||
break;
|
||||
case UPAXISTYPE_Z_UP:
|
||||
printf(" Z Axis is Up for this file \n" );
|
||||
printf(" All Geometry and Hiearchies must be converted!\n" );
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Load all the geometry libraries
|
||||
for ( int i = 0; i < dom->getLibrary_geometries_array().getCount(); i++)
|
||||
{
|
||||
domLibrary_geometriesRef libgeom = 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: numTriangleGroups:%i numPolygonGroups:%i\n",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
|
||||
|
||||
for ( int i = 0; i < dom->getLibrary_physics_scenes_array().getCount(); i++)
|
||||
{
|
||||
domLibrary_physics_scenesRef physicsScenesRef = dom->getLibrary_physics_scenes_array()[i];
|
||||
for (int s=0;s<physicsScenesRef->getPhysics_scene_array().getCount();s++)
|
||||
{
|
||||
domPhysics_sceneRef physicsSceneRef = physicsScenesRef->getPhysics_scene_array()[s];
|
||||
|
||||
for (int m=0;m<physicsSceneRef->getInstance_physics_model_array().getCount();m++)
|
||||
{
|
||||
domInstance_physics_modelRef modelRef = physicsSceneRef->getInstance_physics_model_array()[m];
|
||||
|
||||
for (int r=0;r<modelRef->getInstance_rigid_body_array().getCount();r++)
|
||||
{
|
||||
domInstance_rigid_bodyRef rigidbodyRef = modelRef->getInstance_rigid_body_array()[r];
|
||||
domInstance_rigid_body::domTechnique_commonRef techniqueRef = rigidbodyRef->getTechnique_common();
|
||||
|
||||
if (techniqueRef)
|
||||
{
|
||||
float mass = techniqueRef->getMass()->getValue();
|
||||
bool isDynamics = techniqueRef->getDynamic()->getValue();
|
||||
printf("mass = %f, isDynamics %i\n",mass,isDynamics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//we don't handle constraints just yet
|
||||
for (int c=0;c<modelRef->getInstance_rigid_constraint_array().getCount();i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
clientResetScene();
|
||||
|
||||
setCameraDistance(26.f);
|
||||
@@ -911,7 +1091,8 @@ void renderme()
|
||||
}
|
||||
|
||||
char extraDebug[125];
|
||||
sprintf(extraDebug,"islId, Body=%i , %i",physObjects[i]->GetRigidBody()->m_islandTag1,physObjects[i]->GetRigidBody()->m_debugBodyId);
|
||||
|
||||
sprintf(extraDebug,"islandId=%i, Body=%i, ShapeType=%s",physObjects[i]->GetRigidBody()->m_islandTag1,physObjects[i]->GetRigidBody()->m_debugBodyId,physObjects[i]->GetRigidBody()->GetCollisionShape()->GetName());
|
||||
physObjects[i]->GetRigidBody()->GetCollisionShape()->SetExtraDebugInfo(extraDebug);
|
||||
GL_ShapeDrawer::DrawOpenGL(m,physObjects[i]->GetRigidBody()->GetCollisionShape(),wireColor,getDebugMode());
|
||||
|
||||
@@ -1136,6 +1317,7 @@ float gOldPickingDist = 0.f;
|
||||
RigidBody* pickedBody = 0;//for deactivation state
|
||||
|
||||
|
||||
|
||||
SimdVector3 GetRayTo(int x,int y)
|
||||
{
|
||||
float top = 1.f;
|
||||
@@ -1151,7 +1333,8 @@ SimdVector3 GetRayTo(int x,int y)
|
||||
rayForward*= farPlane;
|
||||
|
||||
SimdVector3 rightOffset;
|
||||
SimdVector3 vertical(0.f,1.f,0.f);
|
||||
SimdVector3 vertical = gCameraUp;
|
||||
|
||||
SimdVector3 hor;
|
||||
hor = rayForward.cross(vertical);
|
||||
hor.normalize();
|
||||
|
||||
@@ -170,6 +170,8 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (useWireframeFallback)
|
||||
{
|
||||
/// for polyhedral shapes
|
||||
@@ -195,12 +197,6 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
|
||||
glEnd();
|
||||
|
||||
|
||||
|
||||
if (debugMode==IDebugDraw::DBG_DrawText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->GetName());
|
||||
}
|
||||
|
||||
if (debugMode==IDebugDraw::DBG_DrawFeaturesText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->GetExtraDebugInfo());
|
||||
@@ -230,6 +226,8 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +260,17 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
|
||||
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_BUFFER_BIT);
|
||||
if (debugMode==IDebugDraw::DBG_DrawText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->GetName());
|
||||
}
|
||||
|
||||
if (debugMode==IDebugDraw::DBG_DrawFeaturesText)
|
||||
{
|
||||
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),shape->GetExtraDebugInfo());
|
||||
}
|
||||
glEnable(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPopMatrix();
|
||||
glPopMatrix();
|
||||
|
||||
@@ -105,22 +105,40 @@ void toggleIdle() {
|
||||
}
|
||||
}
|
||||
|
||||
#include "SimdMatrix3x3.h"
|
||||
|
||||
SimdVector3 gCameraUp(0,1,0);
|
||||
int gForwardAxis = 2;
|
||||
|
||||
void setCamera() {
|
||||
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
float rele = ele * 0.01745329251994329547;// rads per deg
|
||||
float razi = azi * 0.01745329251994329547;// rads per deg
|
||||
eye[0] = DISTANCE * sin(razi) * cos(rele);
|
||||
eye[1] = DISTANCE * sin(rele);
|
||||
eye[2] = DISTANCE * cos(razi) * cos(rele);
|
||||
|
||||
|
||||
SimdQuaternion rot(gCameraUp,razi);
|
||||
|
||||
|
||||
SimdVector3 eyePos(0,0,0);
|
||||
eyePos[gForwardAxis] = -DISTANCE;
|
||||
|
||||
SimdVector3 forward(eyePos[0],eyePos[1],eyePos[2]);
|
||||
SimdVector3 right = gCameraUp.cross(forward);
|
||||
SimdQuaternion roll(right,-rele);
|
||||
|
||||
eyePos = SimdMatrix3x3(rot) * SimdMatrix3x3(roll) * eyePos;
|
||||
|
||||
eye[0] = eyePos.getX();
|
||||
eye[1] = eyePos.getY();
|
||||
eye[2] = eyePos.getZ();
|
||||
|
||||
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
|
||||
gluLookAt(eye[0], eye[1], eye[2],
|
||||
center[0], center[1], center[2],
|
||||
0, 1, 0);
|
||||
gCameraUp.getX(),gCameraUp.getY(),gCameraUp.getZ());
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ using namespace FUDaeWriter;
|
||||
FCDPhysicsSceneNode::FCDPhysicsSceneNode(FCDocument* document) : FCDEntity(document, "PhysicsSceneNode")
|
||||
{
|
||||
//FIXME: no default values are specified in the 1.4 spec!
|
||||
gravity.x = 0.f; gravity.y = -9.8f; gravity.z = 0.f;
|
||||
gravity.x = 0.f; gravity.y = 0.f; gravity.z = -9.8f;
|
||||
timestep = 1.f;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,11 +103,14 @@ namespace FUXmlParser
|
||||
// Returns the string value of a node's property
|
||||
string ReadNodeProperty(xmlNode* node, const char* property)
|
||||
{
|
||||
string ret;
|
||||
string ret="";
|
||||
if (node != NULL && property != NULL)
|
||||
{
|
||||
xmlChar* data = xmlGetProp(node, xmlT(property));
|
||||
if (data != NULL) ret = (const char*) data;
|
||||
if (data != NULL)
|
||||
{
|
||||
ret = (const char*) data;
|
||||
}
|
||||
xmlFree(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -535,6 +535,7 @@ PHY_IPhysicsController* CcdPhysicsController::GetReplica()
|
||||
DefaultMotionState::DefaultMotionState()
|
||||
{
|
||||
m_worldTransform.setIdentity();
|
||||
m_localScaling.setValue(1.f,1.f,1.f);
|
||||
}
|
||||
|
||||
|
||||
@@ -552,9 +553,9 @@ void DefaultMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
|
||||
|
||||
void DefaultMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
|
||||
{
|
||||
scaleX = 1.;
|
||||
scaleY = 1.;
|
||||
scaleZ = 1.;
|
||||
scaleX = m_localScaling.getX();
|
||||
scaleY = m_localScaling.getY();
|
||||
scaleZ = m_localScaling.getZ();
|
||||
}
|
||||
|
||||
void DefaultMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
|
||||
|
||||
@@ -208,6 +208,7 @@ class DefaultMotionState : public PHY_IMotionState
|
||||
virtual void calculateWorldTransformations();
|
||||
|
||||
SimdTransform m_worldTransform;
|
||||
SimdVector3 m_localScaling;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions=" "
|
||||
Optimization="2"
|
||||
AdditionalIncludeDirectories=".;..\..;..\..\Bullet;..\..\BulletDynamics;..\..\LinearMath;..\..\Extras\PhysicsInterface\Common;..\..\Extras\ConvexDecomposition;..\..\Glut;..\..\Demos\OpenGL;..\..\Extras\PhysicsInterface\CcdPhysics;..\..\Extras\FCollada;..\..\Extras\FCollada\LibXML\include"
|
||||
AdditionalIncludeDirectories=".;..\..;..\..\Bullet;..\..\BulletDynamics;..\..\LinearMath;..\..\Extras\PhysicsInterface\Common;..\..\Extras\ConvexDecomposition;..\..\Glut;..\..\Demos\OpenGL;..\..\Extras\PhysicsInterface\CcdPhysics;..\..\Extras\FCollada;..\..\Extras\FCollada\LibXML\include;..\..\Extras\COLLADA_DOM\include;..\..\Extras\COLLADA_DOM\include\1.4"
|
||||
PreprocessorDefinitions="NDEBUG;_CONSOLE;WIN32"
|
||||
StringPooling="true"
|
||||
ExceptionHandling="0"
|
||||
@@ -152,7 +152,7 @@
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions=" "
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".;..\..;..\..\Bullet;..\..\BulletDynamics;..\..\LinearMath;..\..\Extras\PhysicsInterface\Common;..\..\Extras\ConvexDecomposition;..\..\Glut;..\..\Demos\OpenGL;..\..\Extras\PhysicsInterface\CcdPhysics;..\..\Extras\FCollada;..\..\Extras\FCollada\LibXML\include"
|
||||
AdditionalIncludeDirectories=".;..\..;..\..\Bullet;..\..\BulletDynamics;..\..\LinearMath;..\..\Extras\PhysicsInterface\Common;..\..\Extras\ConvexDecomposition;..\..\Glut;..\..\Demos\OpenGL;..\..\Extras\PhysicsInterface\CcdPhysics;..\..\Extras\FCollada;..\..\Extras\FCollada\LibXML\include;..\..\Extras\COLLADA_DOM\include;..\..\Extras\COLLADA_DOM\include\1.4"
|
||||
PreprocessorDefinitions="_DEBUG;_CONSOLE;WIN32"
|
||||
MinimalRebuild="true"
|
||||
ExceptionHandling="0"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user