ScalePhysicsObject: Difference between revisions
Jump to navigation
Jump to search
Warning:This function has not been tested.
mNo edit summary |
mNo edit summary |
||
Line 6: | Line 6: | ||
IPhysicsObject *pNew = NULL; | IPhysicsObject *pNew = NULL; | ||
pEnt->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ) | pEnt->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ) | ||
if(pList[1]!=NULL) | |||
{ | { | ||
IPhysicsObject pObj = pList[ | Assert(pList[1]==NULL); // Don't know what to do for ragdolls | ||
return; | |||
} | |||
IPhysicsObject pObj = pList[0]; | |||
Assert(pObj); | |||
Assert( scale > 0.0f ); | |||
CPhysCollide *pColl = pObj->GetCollide(); | |||
ICollisionQuery *pQuery = physcollision->CreateQueryModel( pColl ); | |||
int convexCount = pQuery->ConvexCount(); | |||
CPhysConvex *pConvex[convexCount]; | |||
for( int x=0; x < convexCount; x++ ) | |||
{ | |||
int tris = pQuery->TriangleCount( x ) | |||
Vector pVerts[tris][3]; | |||
for( int y=0; y < tris; y++ ) | |||
{ | { | ||
pQuery->GetTriangleVerts( x, y, pVerts[y] ); | |||
pVerts[y][0] *= scale; | |||
pVerts[y][1] *= scale; | |||
pVerts[y][2] *= scale; | |||
} | } | ||
solid_t solid; | pConvex[x] = physcollision->ConvexFromVerts( pVerts, tris ); | ||
} | |||
physcollision->DestroyQueryModel( pQuery ); | |||
pColl = physcollision->ConvertConvexToCollide( pConvex, convexCount ); // Don't need to free convex objects, this call does | |||
solid_t solid; | |||
Vector worldPosition; | |||
QAngle angles; | |||
pObj->GetPosition( &worldPosition, &angles ); | |||
PhysModelParseSolid( solid, pEnt, pEnt->GetModelIndex() ); | |||
pNew = physenv->CreatePolyObject( pColl, pObj->GetMaterialIndex(), worldPosition, angles, &solid.param ); | |||
Assert(pNew); | Assert(pNew); | ||
pEnt->VPhysicsDestroyObject(); | |||
pEnt->VPhysicsSetObject( pNew ); | |||
}</pre> | }</pre> | ||
[[Category:Helpers]][[Category:Functions]] | [[Category:Helpers]][[Category:Functions]] |
Revision as of 09:07, 24 July 2006

void ScalePhysicsObject(CBaseEntity *pEnt, float scale) { Assert(pEnt); IPhysicsObject *pList[32]; IPhysicsObject *pNew = NULL; pEnt->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) ) if(pList[1]!=NULL) { Assert(pList[1]==NULL); // Don't know what to do for ragdolls return; } IPhysicsObject pObj = pList[0]; Assert(pObj); Assert( scale > 0.0f ); CPhysCollide *pColl = pObj->GetCollide(); ICollisionQuery *pQuery = physcollision->CreateQueryModel( pColl ); int convexCount = pQuery->ConvexCount(); CPhysConvex *pConvex[convexCount]; for( int x=0; x < convexCount; x++ ) { int tris = pQuery->TriangleCount( x ) Vector pVerts[tris][3]; for( int y=0; y < tris; y++ ) { pQuery->GetTriangleVerts( x, y, pVerts[y] ); pVerts[y][0] *= scale; pVerts[y][1] *= scale; pVerts[y][2] *= scale; } pConvex[x] = physcollision->ConvexFromVerts( pVerts, tris ); } physcollision->DestroyQueryModel( pQuery ); pColl = physcollision->ConvertConvexToCollide( pConvex, convexCount ); // Don't need to free convex objects, this call does solid_t solid; Vector worldPosition; QAngle angles; pObj->GetPosition( &worldPosition, &angles ); PhysModelParseSolid( solid, pEnt, pEnt->GetModelIndex() ); pNew = physenv->CreatePolyObject( pColl, pObj->GetMaterialIndex(), worldPosition, angles, &solid.param ); Assert(pNew); pEnt->VPhysicsDestroyObject(); pEnt->VPhysicsSetObject( pNew ); }