From c328cb53b1fdbaadf165f84a49dc5070a89f0fc6 Mon Sep 17 00:00:00 2001 From: Daniel Buckmaster Date: Mon, 18 Aug 2014 08:19:45 +1000 Subject: [PATCH] Implemented physics collision for MeshRoad. According to deepscratch's post in the forum: http://www.garagegames.com/community/forums/viewthread/130181/1#comment-826897 --- Engine/source/environment/meshRoad.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Engine/source/environment/meshRoad.cpp b/Engine/source/environment/meshRoad.cpp index 6a5e3fbd1..453250568 100644 --- a/Engine/source/environment/meshRoad.cpp +++ b/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 ); + } } }