Browse Source

Implemented physics collision for MeshRoad.

According to deepscratch's post in the forum:
http://www.garagegames.com/community/forums/viewthread/130181/1#comment-826897
Daniel Buckmaster 11 years ago
parent
commit
c328cb53b1
1 changed files with 19 additions and 2 deletions
  1. 19 2
      Engine/source/environment/meshRoad.cpp

+ 19 - 2
Engine/source/environment/meshRoad.cpp

@@ -49,6 +49,7 @@
 #include "collision/concretePolyList.h"
 #include "T3D/physics/physicsPlugin.h"
 #include "T3D/physics/physicsBody.h"
+#include "T3D/physics/physicsCollision.h"
 #include "environment/nodeListManager.h"
 
 #define MIN_METERS_PER_SEGMENT 1.0f
@@ -1722,6 +1723,8 @@ void MeshRoad::_generateSlices()
 
 void MeshRoad::_generateSegments()
 {
+   SAFE_DELETE( mPhysicsRep );
+
    mSegments.clear();
 
    for ( U32 i = 0; i < mSlices.size() - 1; i++ )
@@ -1736,8 +1739,22 @@ void MeshRoad::_generateSegments()
 
    if ( PHYSICSMGR )
    {
-      SAFE_DELETE( mPhysicsRep );
-      //mPhysicsRep = PHYSICSMGR->createBody();
+      ConcretePolyList polylist;
+      if ( buildPolyList( PLC_Collision, &polylist, getWorldBox(), getWorldSphere() ) )
+      {
+         polylist.triangulate();
+
+         PhysicsCollision *colShape = PHYSICSMGR->createCollision();
+         colShape->addTriangleMesh( polylist.mVertexList.address(),
+            polylist.mVertexList.size(),
+            polylist.mIndexList.address(),
+            polylist.mIndexList.size() / 3,
+            MatrixF::Identity );
+
+         PhysicsWorld *world = PHYSICSMGR->getWorld( isServerObject() ? "server" : "client" );
+         mPhysicsRep = PHYSICSMGR->createBody();
+         mPhysicsRep->init( colShape, 0, 0, this, world );
+      }
    }
 }