Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2011, 5:07:42 AM (13 years ago)
Author:
rgrieder
Message:

Updated Bullet from v2.77 to v2.78.
(I'm not going to make a branch for that since the update from 2.74 to 2.77 hasn't been tested that much either).

You will HAVE to do a complete RECOMPILE! I tested with MSVC and MinGW and they both threw linker errors at me.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp

    r8351 r8393  
    1515
    1616#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
    17 
    18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape()
    19 {
    20 
     17#include "btConvexPolyhedron.h"
     18#include "LinearMath/btConvexHullComputer.h"
     19#include <new>
     20
     21btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
     22m_polyhedron(0)
     23{
     24
     25}
     26
     27btPolyhedralConvexShape::~btPolyhedralConvexShape()
     28{
     29        if (m_polyhedron)
     30        {
     31                btAlignedFree(m_polyhedron);
     32        }
     33}
     34
     35bool    btPolyhedralConvexShape::initializePolyhedralFeatures()
     36{
     37        if (m_polyhedron)
     38                btAlignedFree(m_polyhedron);
     39       
     40        void* mem = btAlignedAlloc(sizeof(btConvexPolyhedron),16);
     41        m_polyhedron = new (mem) btConvexPolyhedron;
     42
     43        btAlignedObjectArray<btVector3> tmpVertices;
     44        for (int i=0;i<getNumVertices();i++)
     45        {
     46                btVector3& newVertex = tmpVertices.expand();
     47                getVertex(i,newVertex);
     48        }
     49
     50        btConvexHullComputer conv;
     51        conv.compute(&tmpVertices[0].getX(), sizeof(btVector3),tmpVertices.size(),0.f,0.f);
     52
     53       
     54
     55        btAlignedObjectArray<btVector3> faceNormals;
     56        int numFaces = conv.faces.size();
     57        faceNormals.resize(numFaces);
     58        btConvexHullComputer* convexUtil = &conv;
     59
     60       
     61       
     62        m_polyhedron->m_faces.resize(numFaces);
     63        int numVertices = convexUtil->vertices.size();
     64        m_polyhedron->m_vertices.resize(numVertices);
     65        for (int p=0;p<numVertices;p++)
     66        {
     67                m_polyhedron->m_vertices[p] = convexUtil->vertices[p];
     68        }
     69
     70        for (int i=0;i<numFaces;i++)
     71        {
     72                int face = convexUtil->faces[i];
     73                //printf("face=%d\n",face);
     74                const btConvexHullComputer::Edge*  firstEdge = &convexUtil->edges[face];
     75                const btConvexHullComputer::Edge*  edge = firstEdge;
     76
     77                btVector3 edges[3];
     78                int numEdges = 0;
     79                //compute face normals
     80
     81                btScalar maxCross2 = 0.f;
     82                int chosenEdge = -1;
     83
     84                do
     85                {
     86                       
     87                        int src = edge->getSourceVertex();
     88                        m_polyhedron->m_faces[i].m_indices.push_back(src);
     89                        int targ = edge->getTargetVertex();
     90                        btVector3 wa = convexUtil->vertices[src];
     91
     92                        btVector3 wb = convexUtil->vertices[targ];
     93                        btVector3 newEdge = wb-wa;
     94                        newEdge.normalize();
     95                        if (numEdges<2)
     96                                edges[numEdges++] = newEdge;
     97
     98                        edge = edge->getNextEdgeOfFace();
     99                } while (edge!=firstEdge);
     100
     101                btScalar planeEq = 1e30f;
     102
     103               
     104                if (numEdges==2)
     105                {
     106                        faceNormals[i] = edges[0].cross(edges[1]);
     107                        faceNormals[i].normalize();
     108                        m_polyhedron->m_faces[i].m_plane[0] = -faceNormals[i].getX();
     109                        m_polyhedron->m_faces[i].m_plane[1] = -faceNormals[i].getY();
     110                        m_polyhedron->m_faces[i].m_plane[2] = -faceNormals[i].getZ();
     111                        m_polyhedron->m_faces[i].m_plane[3] = planeEq;
     112
     113                }
     114                else
     115                {
     116                        btAssert(0);//degenerate?
     117                        faceNormals[i].setZero();
     118                }
     119
     120                for (int v=0;v<m_polyhedron->m_faces[i].m_indices.size();v++)
     121                {
     122                        btScalar eq = m_polyhedron->m_vertices[m_polyhedron->m_faces[i].m_indices[v]].dot(faceNormals[i]);
     123                        if (planeEq>eq)
     124                        {
     125                                planeEq=eq;
     126                        }
     127                }
     128                m_polyhedron->m_faces[i].m_plane[3] = planeEq;
     129        }
     130
     131
     132        if (m_polyhedron->m_faces.size() && conv.vertices.size())
     133        {
     134
     135                for (int f=0;f<m_polyhedron->m_faces.size();f++)
     136                {
     137                       
     138                        btVector3 planeNormal(m_polyhedron->m_faces[f].m_plane[0],m_polyhedron->m_faces[f].m_plane[1],m_polyhedron->m_faces[f].m_plane[2]);
     139                        btScalar planeEq = m_polyhedron->m_faces[f].m_plane[3];
     140
     141                        btVector3 supVec = localGetSupportingVertex(-planeNormal);
     142
     143                        if (supVec.dot(planeNormal)<planeEq)
     144                        {
     145                                m_polyhedron->m_faces[f].m_plane[0] *= -1;
     146                                m_polyhedron->m_faces[f].m_plane[1] *= -1;
     147                                m_polyhedron->m_faces[f].m_plane[2] *= -1;
     148                                m_polyhedron->m_faces[f].m_plane[3] *= -1;
     149                                int numVerts = m_polyhedron->m_faces[f].m_indices.size();
     150                                for (int v=0;v<numVerts/2;v++)
     151                                {
     152                                        btSwap(m_polyhedron->m_faces[f].m_indices[v],m_polyhedron->m_faces[f].m_indices[numVerts-1-v]);
     153                                }
     154                        }
     155                }
     156        }
     157
     158       
     159
     160        m_polyhedron->initialize();
     161
     162        return true;
    21163}
    22164
     
    192334}
    193335
     336
     337
     338
Note: See TracChangeset for help on using the changeset viewer.