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

Method CalculateSkinnedBoundingSphere

trinity/Tr2GStateAnimation.cpp:973–1023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

971}
972
973Vector4 Tr2GStateAnimation::CalculateSkinnedBoundingSphere( granny_file_info* fi )
974{
975 PrePhysicsAnimation( 0, IdentityMatrix() );
976
977 if( !m_meshBinding )
978 {
979 return Vector4( 0.f, 0.f, 0.f, -1.f );
980 }
981
982 if( !fi )
983 {
984 fi = GetFileInfo();
985 }
986 if( !fi )
987 {
988 return Vector4( 0.f, 0.f, 0.f, -1.f );
989 }
990
991 // Known input and output vertex format
992 granny_mesh* mesh = fi->Models[m_modelIndex]->MeshBindings[m_meshBindingIndex].Mesh;
993 granny_int32x vertCount = GrannyGetMeshVertexCount( mesh );
994
995 std::vector<granny_pwn313_vertex> sourceVerts( vertCount );
996 std::vector<granny_pn33_vertex> deformedVerts( vertCount );
997
998 GrannyCopyMeshVertices( mesh, GrannyPWN313VertexType, &sourceVerts[0] );
999
1000 granny_mesh_deformer* deformer = GrannyNewMeshDeformer( GrannyPWN313VertexType,
1001 GrannyPN33VertexType,
1002 GrannyDeformPositionNormal,
1003 GrannyDontAllowUncopiedTail );
1004 if( !deformer )
1005 {
1006 return Vector4( 0.f, 0.f, 0.f, -1.f );
1007 }
1008
1009 GrannyDeformVertices( deformer, GrannyGetMeshBindingFromBoneIndices( m_meshBinding ), (granny_real32*)GrannyGetWorldPoseComposite4x4Array( m_worldPose ), vertCount, &sourceVerts[0], &deformedVerts[0] );
1010
1011 // Gather a list of pointers to the positions
1012 std::vector<const Vector3*> points( vertCount );
1013 for( int32_t p = 0; p < vertCount; ++p )
1014 {
1015 points[p] = (const Vector3*)&deformedVerts[p].Position;
1016 }
1017
1018 // Calculate the bounding sphere
1019 Vector4 boundingSphere;
1020 BoundingSphereFromPoints( boundingSphere, &points[0], points.size() );
1021
1022 return boundingSphere;
1023}
1024
1025
1026granny_model* Tr2GStateAnimation::GetGrannyModel() const

Callers

nothing calls this directly

Calls 3

BoundingSphereFromPointsFunction · 0.85
sizeMethod · 0.80
Vector4Class · 0.50

Tested by

no test coverage detected