Prop sphere: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(useful: a perfect vphysics sphere)
 
(full documentation, plus new source code to extend the ent into something production-quality)
Line 1: Line 1:
{{stub}}
'''prop_sphere''' is an unlisted entity not referenced in any of Valve's stock [[FGD]]s, even though it is available to all of them.


{{wrongtitle|prop_sphere}}
It is essentially a [[prop_physics]] with a perfectly spherical [[VPhysics]] collision model. If you want to create an spherical entity, it is far more efficient to use prop_sphere than try to create a spherical [[collision mesh]]!


'''prop_sphere''' is an unlisted entity not referenced in any stock [[FGD]]s. It creates an entity with a perfectly spherical [[VPhysics]] collision model.
{{tip|The only spherical model in Half-Life 2 is <code>models\combine_helicopter\helicopter_bomb01.mdl</code>. Unfortunately it is made of wood!}}


== Keyvalues ==
== Stock FGD ==


;model
If you don't intend to make any changes to the entity's C++ code, use this:
:Path to visual .mdl file for the entity, relative to mod root
:e.g. <code>models/combine_helicopter/helicopter_bomb01.mdl</code>


[[category:entities]]
<source lang=ini>
@PointClass base(BasePropPhysics, RenderFields) studioprop() = prop_sphere : "Creates a perfect sphere."
[
]
</source>
 
== Extending prop_sphere ==
 
The following simple addition to <code>CPhysSphere</code>:
 
* Allows level designers to configure the collision model's radius
* Fully applies the [[prop_data]] and [[$surfaceprop]] of the chosen [[model]].
 
=== C++ ===
 
Open \server\props.cpp and replace the existing <code>CPhysSphere</code> with this:
 
<source lang=cpp>
class CPhysSphere : public CPhysicsProp
{
DECLARE_CLASS( CPhysSphere, CPhysicsProp );
DECLARE_DATADESC();
public:
 
float m_fRadius;
 
bool CreateVPhysics()
{
SetSolid( SOLID_BBOX );
SetCollisionBounds( -Vector(m_fRadius), Vector(m_fRadius) );
objectparams_t params = g_PhysDefaultObjectParams;
params.pGameData = static_cast<void *>(this);
IPhysicsObject *pPhysicsObject = physenv->CreateSphereObject( m_fRadius, GetModelPtr()->GetRenderHdr()->textureindex, GetAbsOrigin(), GetAbsAngles(), &params, false );
 
if ( pPhysicsObject )
{
VPhysicsSetObject( pPhysicsObject );
SetMoveType( MOVETYPE_VPHYSICS );
pPhysicsObject->Wake();
}
return true;
}
};
 
LINK_ENTITY_TO_CLASS( prop_sphere, CPhysSphere );
 
BEGIN_DATADESC( CPhysSphere )
DEFINE_KEYFIELD( m_fRadius, FIELD_FLOAT, "radius"),
END_DATADESC()
</source>
 
=== Extended FGD ===
 
<source lang=ini>
@PointClass base(BasePropPhysics, RenderFields) studioprop() sphere(radius) = prop_sphere : "Creates a perfect sphere."
[
radius(float) : "Radius" : 12 : ""
]
</source>
 
== Stock Keyvalues ==
 
<div style="overflow:auto;max-height:30em;">
*{{KV BasePropPhysics}}
*{{KV RenderFields}}
</div>
 
== Stock Flags ==
 
<div style="overflow:auto;max-height:30em;">
*{{Fl BasePropPhysics}}
</div>
 
== Stock Inputs ==
 
<div style="overflow:auto;max-height:30em;">
*{{I BasePropPhysics}}
*{{I RenderFields}}
</div>
 
== Stock Outputs ==
 
<div style="overflow:auto;max-height:30em;">
*{{O BasePropPhysics}}
</div>
 
{{wrongtitle|prop_sphere}} [[Category:Entities]] [[Category:Free source code]]

Revision as of 07:36, 14 June 2009

prop_sphere is an unlisted entity not referenced in any of Valve's stock FGDs, even though it is available to all of them.

It is essentially a prop_physics with a perfectly spherical VPhysics collision model. If you want to create an spherical entity, it is far more efficient to use prop_sphere than try to create a spherical collision mesh!

Tip.pngTip:The only spherical model in Half-Life 2 is models\combine_helicopter\helicopter_bomb01.mdl. Unfortunately it is made of wood!

Stock FGD

If you don't intend to make any changes to the entity's C++ code, use this:

@PointClass base(BasePropPhysics, RenderFields) studioprop() = prop_sphere : "Creates a perfect sphere."
[
]

Extending prop_sphere

The following simple addition to CPhysSphere:

  • Allows level designers to configure the collision model's radius
  • Fully applies the prop_data and $surfaceprop of the chosen model.

C++

Open \server\props.cpp and replace the existing CPhysSphere with this:

class CPhysSphere : public CPhysicsProp
{
	DECLARE_CLASS( CPhysSphere, CPhysicsProp );
	DECLARE_DATADESC();
public:

	float m_fRadius;

	bool CreateVPhysics()
	{
		SetSolid( SOLID_BBOX );
		SetCollisionBounds( -Vector(m_fRadius), Vector(m_fRadius) );
		objectparams_t params = g_PhysDefaultObjectParams;
		params.pGameData = static_cast<void *>(this);
		IPhysicsObject *pPhysicsObject = physenv->CreateSphereObject( m_fRadius, GetModelPtr()->GetRenderHdr()->textureindex, GetAbsOrigin(), GetAbsAngles(), &params, false );

		if ( pPhysicsObject )
		{
			VPhysicsSetObject( pPhysicsObject );
			SetMoveType( MOVETYPE_VPHYSICS );
			pPhysicsObject->Wake();
		}
	
		return true;
	}
};

LINK_ENTITY_TO_CLASS( prop_sphere, CPhysSphere );

BEGIN_DATADESC( CPhysSphere )
	DEFINE_KEYFIELD( m_fRadius, FIELD_FLOAT, "radius"),
END_DATADESC()

Extended FGD

@PointClass base(BasePropPhysics, RenderFields) studioprop() sphere(radius) = prop_sphere : "Creates a perfect sphere."
[
	radius(float) : "Radius" : 12 : ""
]

Stock Keyvalues

  • Note.pngNote:Page left for viewable history, content moved to prop_physics
  • RenderFields:


Render Mode (rendermode) <byte choices>
Set a non-standard rendering mode on this entity.
Render Modes
  • 0: Normal
  • 1: Color
  • 2: Texture
  • 3: Glow
  • 4: Solid/Alphatest Obsolete
  • 5: Additive
  • 6: Removed, does nothing Obsolete
  • 7: Additive Fractional Frame
  • 8: Alpha Add
  • 9: World Space Glow
  • 10: Don't Render
Render FX (renderfx) <byte choices>
Various somewhat legacy alpha effects. See render effects.
Render Amount / Transparency (renderamt) <byte>
Transparency amount, requires a Render Mode other than Normal. 0 is invisible, 255 is fully visible.
Render Color (R G B) (rendercolor) <color255>
Color tint.

Stock Flags

  • Note.pngNote:Page left for viewable history, content moved to prop_physics

Stock Inputs

  • Note.pngNote:Page left for viewable history, content moved to prop_physics
  • RenderFields:
Alpha <integer 0–255>
Sets the entity's transparency to a number from 0 (invisible) to 255 (fully visible). Requires the entity to have its rendermode set to a number other than 0.
Color <color255RedirectInput/color32>
Sets an RGB color for the entity.

Stock Outputs

  • Note.pngNote:Page left for viewable history, content moved to prop_physics

Template:Wrongtitle