Changeset 7983 for code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
- Timestamp:
- Feb 27, 2011, 7:43:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r5781 r7983 18 18 #include "LinearMath/btAabbUtil2.h" 19 19 #include "LinearMath/btIDebugDraw.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 #define RAYAABB2 … … 79 80 btVector3 color[4]= 80 81 { 81 btVector3( 255,0,0),82 btVector3(0, 255,0),83 btVector3(0,0, 255),84 btVector3(0, 255,255)82 btVector3(1,0,0), 83 btVector3(0,1,0), 84 btVector3(0,0,1), 85 btVector3(0,1,1) 85 86 }; 86 87 #endif //DEBUG_PATCH_COLORS … … 475 476 ///what about division by zero? --> just set rayDirection[i] to 1.0 476 477 btVector3 rayDirectionInverse; 477 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];478 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];479 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];478 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 479 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 480 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 480 481 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 481 482 #endif … … 494 495 bounds[1] = rootNode->m_aabbMaxOrg; 495 496 /* Add box cast extents */ 496 bounds[0] += aabbMin;497 bounds[1] += aabbMax;497 bounds[0] -= aabbMax; 498 bounds[1] -= aabbMin; 498 499 499 500 aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg); … … 562 563 lambda_max = rayDirection.dot(rayTarget-raySource); 563 564 ///what about division by zero? --> just set rayDirection[i] to 1.0 564 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[0];565 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[1];566 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[2];565 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0]; 566 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1]; 567 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2]; 567 568 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0}; 568 569 #endif … … 618 619 bounds[1] = unQuantize(rootNode->m_quantizedAabbMax); 619 620 /* Add box cast extents */ 620 bounds[0] += aabbMin;621 bounds[1] += aabbMax;621 bounds[0] -= aabbMax; 622 bounds[1] -= aabbMin; 622 623 btVector3 normal; 623 624 #if 0 … … 831 832 } 832 833 833 unsigned btQuantizedBvh::calculateSerializeBufferSize() 834 unsigned btQuantizedBvh::calculateSerializeBufferSize() const 834 835 { 835 836 unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding(); … … 842 843 } 843 844 844 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) 845 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) const 845 846 { 846 847 btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); … … 1144 1145 } 1145 1146 1146 1147 1148 1147 void btQuantizedBvh::deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData) 1148 { 1149 m_bvhAabbMax.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMax); 1150 m_bvhAabbMin.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMin); 1151 m_bvhQuantization.deSerializeFloat(quantizedBvhFloatData.m_bvhQuantization); 1152 1153 m_curNodeIndex = quantizedBvhFloatData.m_curNodeIndex; 1154 m_useQuantization = quantizedBvhFloatData.m_useQuantization!=0; 1155 1156 { 1157 int numElem = quantizedBvhFloatData.m_numContiguousLeafNodes; 1158 m_contiguousNodes.resize(numElem); 1159 1160 if (numElem) 1161 { 1162 btOptimizedBvhNodeFloatData* memPtr = quantizedBvhFloatData.m_contiguousNodesPtr; 1163 1164 for (int i=0;i<numElem;i++,memPtr++) 1165 { 1166 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeFloat(memPtr->m_aabbMaxOrg); 1167 m_contiguousNodes[i].m_aabbMinOrg.deSerializeFloat(memPtr->m_aabbMinOrg); 1168 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1169 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1170 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1171 } 1172 } 1173 } 1174 1175 { 1176 int numElem = quantizedBvhFloatData.m_numQuantizedContiguousNodes; 1177 m_quantizedContiguousNodes.resize(numElem); 1178 1179 if (numElem) 1180 { 1181 btQuantizedBvhNodeData* memPtr = quantizedBvhFloatData.m_quantizedContiguousNodesPtr; 1182 for (int i=0;i<numElem;i++,memPtr++) 1183 { 1184 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1185 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1186 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1187 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1188 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1189 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1190 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1191 } 1192 } 1193 } 1194 1195 m_traversalMode = btTraversalMode(quantizedBvhFloatData.m_traversalMode); 1196 1197 { 1198 int numElem = quantizedBvhFloatData.m_numSubtreeHeaders; 1199 m_SubtreeHeaders.resize(numElem); 1200 if (numElem) 1201 { 1202 btBvhSubtreeInfoData* memPtr = quantizedBvhFloatData.m_subTreeInfoPtr; 1203 for (int i=0;i<numElem;i++,memPtr++) 1204 { 1205 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1206 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1207 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1208 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1209 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1210 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1211 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1212 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1213 } 1214 } 1215 } 1216 } 1217 1218 void btQuantizedBvh::deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData) 1219 { 1220 m_bvhAabbMax.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMax); 1221 m_bvhAabbMin.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMin); 1222 m_bvhQuantization.deSerializeDouble(quantizedBvhDoubleData.m_bvhQuantization); 1223 1224 m_curNodeIndex = quantizedBvhDoubleData.m_curNodeIndex; 1225 m_useQuantization = quantizedBvhDoubleData.m_useQuantization!=0; 1226 1227 { 1228 int numElem = quantizedBvhDoubleData.m_numContiguousLeafNodes; 1229 m_contiguousNodes.resize(numElem); 1230 1231 if (numElem) 1232 { 1233 btOptimizedBvhNodeDoubleData* memPtr = quantizedBvhDoubleData.m_contiguousNodesPtr; 1234 1235 for (int i=0;i<numElem;i++,memPtr++) 1236 { 1237 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeDouble(memPtr->m_aabbMaxOrg); 1238 m_contiguousNodes[i].m_aabbMinOrg.deSerializeDouble(memPtr->m_aabbMinOrg); 1239 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1240 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1241 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1242 } 1243 } 1244 } 1245 1246 { 1247 int numElem = quantizedBvhDoubleData.m_numQuantizedContiguousNodes; 1248 m_quantizedContiguousNodes.resize(numElem); 1249 1250 if (numElem) 1251 { 1252 btQuantizedBvhNodeData* memPtr = quantizedBvhDoubleData.m_quantizedContiguousNodesPtr; 1253 for (int i=0;i<numElem;i++,memPtr++) 1254 { 1255 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1256 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1257 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1258 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1259 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1260 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1261 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1262 } 1263 } 1264 } 1265 1266 m_traversalMode = btTraversalMode(quantizedBvhDoubleData.m_traversalMode); 1267 1268 { 1269 int numElem = quantizedBvhDoubleData.m_numSubtreeHeaders; 1270 m_SubtreeHeaders.resize(numElem); 1271 if (numElem) 1272 { 1273 btBvhSubtreeInfoData* memPtr = quantizedBvhDoubleData.m_subTreeInfoPtr; 1274 for (int i=0;i<numElem;i++,memPtr++) 1275 { 1276 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1277 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1278 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1279 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1280 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1281 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1282 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1283 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1284 } 1285 } 1286 } 1287 1288 } 1289 1290 1291 1292 ///fills the dataBuffer and returns the struct name (and 0 on failure) 1293 const char* btQuantizedBvh::serialize(void* dataBuffer, btSerializer* serializer) const 1294 { 1295 btQuantizedBvhData* quantizedData = (btQuantizedBvhData*)dataBuffer; 1296 1297 m_bvhAabbMax.serialize(quantizedData->m_bvhAabbMax); 1298 m_bvhAabbMin.serialize(quantizedData->m_bvhAabbMin); 1299 m_bvhQuantization.serialize(quantizedData->m_bvhQuantization); 1300 1301 quantizedData->m_curNodeIndex = m_curNodeIndex; 1302 quantizedData->m_useQuantization = m_useQuantization; 1303 1304 quantizedData->m_numContiguousLeafNodes = m_contiguousNodes.size(); 1305 quantizedData->m_contiguousNodesPtr = (btOptimizedBvhNodeData*) (m_contiguousNodes.size() ? serializer->getUniquePointer((void*)&m_contiguousNodes[0]) : 0); 1306 if (quantizedData->m_contiguousNodesPtr) 1307 { 1308 int sz = sizeof(btOptimizedBvhNodeData); 1309 int numElem = m_contiguousNodes.size(); 1310 btChunk* chunk = serializer->allocate(sz,numElem); 1311 btOptimizedBvhNodeData* memPtr = (btOptimizedBvhNodeData*)chunk->m_oldPtr; 1312 for (int i=0;i<numElem;i++,memPtr++) 1313 { 1314 m_contiguousNodes[i].m_aabbMaxOrg.serialize(memPtr->m_aabbMaxOrg); 1315 m_contiguousNodes[i].m_aabbMinOrg.serialize(memPtr->m_aabbMinOrg); 1316 memPtr->m_escapeIndex = m_contiguousNodes[i].m_escapeIndex; 1317 memPtr->m_subPart = m_contiguousNodes[i].m_subPart; 1318 memPtr->m_triangleIndex = m_contiguousNodes[i].m_triangleIndex; 1319 } 1320 serializer->finalizeChunk(chunk,"btOptimizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_contiguousNodes[0]); 1321 } 1322 1323 quantizedData->m_numQuantizedContiguousNodes = m_quantizedContiguousNodes.size(); 1324 // printf("quantizedData->m_numQuantizedContiguousNodes=%d\n",quantizedData->m_numQuantizedContiguousNodes); 1325 quantizedData->m_quantizedContiguousNodesPtr =(btQuantizedBvhNodeData*) (m_quantizedContiguousNodes.size() ? serializer->getUniquePointer((void*)&m_quantizedContiguousNodes[0]) : 0); 1326 if (quantizedData->m_quantizedContiguousNodesPtr) 1327 { 1328 int sz = sizeof(btQuantizedBvhNodeData); 1329 int numElem = m_quantizedContiguousNodes.size(); 1330 btChunk* chunk = serializer->allocate(sz,numElem); 1331 btQuantizedBvhNodeData* memPtr = (btQuantizedBvhNodeData*)chunk->m_oldPtr; 1332 for (int i=0;i<numElem;i++,memPtr++) 1333 { 1334 memPtr->m_escapeIndexOrTriangleIndex = m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex; 1335 memPtr->m_quantizedAabbMax[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[0]; 1336 memPtr->m_quantizedAabbMax[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[1]; 1337 memPtr->m_quantizedAabbMax[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[2]; 1338 memPtr->m_quantizedAabbMin[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[0]; 1339 memPtr->m_quantizedAabbMin[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[1]; 1340 memPtr->m_quantizedAabbMin[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[2]; 1341 } 1342 serializer->finalizeChunk(chunk,"btQuantizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_quantizedContiguousNodes[0]); 1343 } 1344 1345 quantizedData->m_traversalMode = int(m_traversalMode); 1346 quantizedData->m_numSubtreeHeaders = m_SubtreeHeaders.size(); 1347 1348 quantizedData->m_subTreeInfoPtr = (btBvhSubtreeInfoData*) (m_SubtreeHeaders.size() ? serializer->getUniquePointer((void*)&m_SubtreeHeaders[0]) : 0); 1349 if (quantizedData->m_subTreeInfoPtr) 1350 { 1351 int sz = sizeof(btBvhSubtreeInfoData); 1352 int numElem = m_SubtreeHeaders.size(); 1353 btChunk* chunk = serializer->allocate(sz,numElem); 1354 btBvhSubtreeInfoData* memPtr = (btBvhSubtreeInfoData*)chunk->m_oldPtr; 1355 for (int i=0;i<numElem;i++,memPtr++) 1356 { 1357 memPtr->m_quantizedAabbMax[0] = m_SubtreeHeaders[i].m_quantizedAabbMax[0]; 1358 memPtr->m_quantizedAabbMax[1] = m_SubtreeHeaders[i].m_quantizedAabbMax[1]; 1359 memPtr->m_quantizedAabbMax[2] = m_SubtreeHeaders[i].m_quantizedAabbMax[2]; 1360 memPtr->m_quantizedAabbMin[0] = m_SubtreeHeaders[i].m_quantizedAabbMin[0]; 1361 memPtr->m_quantizedAabbMin[1] = m_SubtreeHeaders[i].m_quantizedAabbMin[1]; 1362 memPtr->m_quantizedAabbMin[2] = m_SubtreeHeaders[i].m_quantizedAabbMin[2]; 1363 1364 memPtr->m_rootNodeIndex = m_SubtreeHeaders[i].m_rootNodeIndex; 1365 memPtr->m_subtreeSize = m_SubtreeHeaders[i].m_subtreeSize; 1366 } 1367 serializer->finalizeChunk(chunk,"btBvhSubtreeInfoData",BT_ARRAY_CODE,(void*)&m_SubtreeHeaders[0]); 1368 } 1369 return btQuantizedBvhDataName; 1370 } 1371 1372 1373 1374 1375
Note: See TracChangeset
for help on using the changeset viewer.