MCPcopy Create free account
hub / github.com/carbonengine/trinity / CalculateSkinnedBoundingSphere

Method CalculateSkinnedBoundingSphere

trinity/Tr2GrannyAnimation.cpp:1357–1407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1355}
1356
1357Vector4 Tr2GrannyAnimation::CalculateSkinnedBoundingSphere( granny_file_info* fi )
1358{
1359 PrePhysicsAnimation( 0, IdentityMatrix() );
1360
1361 if( !m_meshBinding )
1362 {
1363 return Vector4( 0.f, 0.f, 0.f, -1.f );
1364 }
1365
1366 if( !fi )
1367 {
1368 fi = GetFileInfo();
1369 }
1370 if( !fi )
1371 {
1372 return Vector4( 0.f, 0.f, 0.f, -1.f );
1373 }
1374
1375 // Known input and output vertex format
1376 granny_mesh* mesh = fi->Models[m_modelIndex]->MeshBindings[m_meshBindingIndex].Mesh;
1377 granny_int32x vertCount = GrannyGetMeshVertexCount( mesh );
1378
1379 std::vector<granny_pwn313_vertex> sourceVerts( vertCount );
1380 std::vector<granny_pn33_vertex> deformedVerts( vertCount );
1381
1382 GrannyCopyMeshVertices( mesh, GrannyPWN313VertexType, &sourceVerts[0] );
1383
1384 granny_mesh_deformer* deformer = GrannyNewMeshDeformer( GrannyPWN313VertexType,
1385 GrannyPN33VertexType,
1386 GrannyDeformPositionNormal,
1387 GrannyDontAllowUncopiedTail );
1388 if( !deformer )
1389 {
1390 return Vector4( 0.f, 0.f, 0.f, -1.f );
1391 }
1392
1393 GrannyDeformVertices( deformer, GrannyGetMeshBindingFromBoneIndices( m_meshBinding ), (granny_real32*)GrannyGetWorldPoseComposite4x4Array( m_worldPose ), vertCount, &sourceVerts[0], &deformedVerts[0] );
1394
1395 // Gather a list of pointers to the positions
1396 std::vector<const Vector3*> points( vertCount );
1397 for( int32_t p = 0; p < vertCount; ++p )
1398 {
1399 points[p] = (const Vector3*)&deformedVerts[p].Position;
1400 }
1401
1402 // Calculate the bounding sphere
1403 Vector4 boundingSphere;
1404 BoundingSphereFromPoints( boundingSphere, &points[0], points.size() );
1405
1406 return boundingSphere;
1407}
1408#endif
1409
1410const cmf::Skeleton* Tr2GrannyAnimation::GetSkeleton() const

Callers

nothing calls this directly

Calls 3

BoundingSphereFromPointsFunction · 0.85
sizeMethod · 0.80
Vector4Class · 0.50

Tested by

no test coverage detected