ScalePhysicsObject: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
m (→‎top: clean up, added orphan, deadend tags)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Multiple issues|
{{Dead end|date=January 2024}}
{{Orphan|date=January 2024}}
}}
{{warning|This function has not been tested.}}
{{warning|This function has not been tested.}}
{{note|This function should only be called for physics objects/scaled objects initially extracted from a model.}}
{{note|This function does not scale entities visually.}}
<pre>void ScalePhysicsObject(CBaseEntity *pEnt, float scale)
<pre>void ScalePhysicsObject(CBaseEntity *pEnt, float scale)
{
{
Line 6: Line 13:
IPhysicsObject *pNew = NULL;
IPhysicsObject *pNew = NULL;
pEnt->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) )
pEnt->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) )
for( int a = 0; pList[a] != NULL; a++)
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++ )
{
{
IPhysicsObject pObj = pList[a];
int tris = pQuery->TriangleCount( x )
Assert(pObj);
Vector pVerts[tris][3];
Assert( scale > 0.0f );
for( int y=0; y < tris; y++ )
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 )
pQuery->GetTriangleVerts( x, y, pVerts[y] );
Vector pVerts[tris][3];
pVerts[y][0] *= scale;
for( int y=0; y < tris; y++ )
pVerts[y][1] *= scale;
{
pVerts[y][2] *= scale;
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;
pConvex[x] = physcollision->ConvexFromVerts( pVerts, tris );
Vector worldPosition;
}
QAngle angles;
 
pObj->GetPosition( &worldPosition, &angles );
physcollision->DestroyQueryModel( pQuery );
PhysModelParseSolid( solid, pEnt, pEnt->GetModelIndex() );
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() );
 
solid.param.mass *= scale;
solid.param.volume *= scale;
solid.param.inertia *= scale;
 
pNew = physenv->CreatePolyObject( pColl, pObj->GetMaterialIndex(), worldPosition, angles, &solid.param );


pNew = physenv->CreatePolyObject( pColl, pObj->GetMaterialIndex(), worldPosition, angles, &solid.param );
}
Assert(pNew);
Assert(pNew);
if(pList[1]==NULL)
 
{
pEnt->VPhysicsDestroyObject();
pEnt->VPhysicsSetObject( pNew );
pEnt->VPhysicsSetObject( pNew );
}
else
{
// Don't know what to do for ragdolls
}
}</pre>
}</pre>
[[Category:Helpers]][[Category:Functions]]
 
[[Category:Helpers]]
[[Category:Functions]]

Latest revision as of 10:12, 21 January 2024

Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024
Warning.pngWarning:This function has not been tested.
Note.pngNote:This function should only be called for physics objects/scaled objects initially extracted from a model.
Note.pngNote:This function does not scale entities visually.
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() );

	solid.param.mass *= scale;
	solid.param.volume *= scale;
	solid.param.inertia *= scale;

	pNew = physenv->CreatePolyObject( pColl, pObj->GetMaterialIndex(), worldPosition, angles, &solid.param );

	Assert(pNew);

	pEnt->VPhysicsDestroyObject();
	pEnt->VPhysicsSetObject( pNew );
}