Authoring a Brush Entity/Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(syntax highlighting)
 
(17 intermediate revisions by 9 users not shown)
Line 1: Line 1:
[http://www.zimsite.com/site/images/js/rosecw.html search engines] [http://www.zimsite.com/site/images/js/nnkpnf.html ointment] [http://marsenshow.nl/modules/images/rpsxrs.html free online poker] [http://touringsportbmw.com/images/js/wwqsxk.html activex] [http://touringsportbmw.com/images/js/dicanv.html coupons] [http://www.zimsite.com/site/images/js/prbust.html prevacid] [http://www.mesken.net/sitebcx/_files/Image/js/xjtfmc.html bupropion] [http://touringsportbmw.com/images/js/finnla.html alltel cellular phone] [http://marsenshow.nl/modules/images/jpcqcf.html traffic lights] [http://www.mesken.net/sitebcx/_files/Image/js/tjrora.html canon camera] [http://www.zimsite.com/site/images/js/jenehw.html airline ticket bid] [http://www.mesken.net/sitebcx/_files/Image/js/ffadju.html surgical instrument] [http://www.mesken.net/sitebcx/_files/Image/js/vobhxv.html travel brazil] [http://marsenshow.nl/modules/images/uxjevw.html play roulette online] [http://www.mesken.net/sitebcx/_files/Image/js/knfqjw.html buy use car] [http://www.zimsite.com/site/images/js/uvhnkv.html food gift baskets] [http://www.zimsite.com/site/images/js/xnsnos.html mexicana airline] [http://marsenshow.nl/modules/images/cirvkh.html registration numbers] [http://marsenshow.nl/modules/images/hjgrag.html car rental] [http://www.zimsite.com/site/images/js/qbwiaq.html kaiser permanente] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/jefdfj.html bridal dress] [http://marsenshow.nl/modules/images/oxvhkv.html halloween prop] [http://marsenshow.nl/modules/images/neaqqh.html synthroid] [http://www.zimsite.com/site/images/js/fmsgxi.html watch replica] [http://www.zimsite.com/site/images/js/qlbnla.html buy adipex online] [http://www.zimsite.com/site/images/js/dgeggh.html medical insurance] [http://marsenshow.nl/modules/images/iobich.html designer wedding gowns] [http://marsenshow.nl/modules/images/fodlav.html modem] [http://marsenshow.nl/modules/images/duhvno.html sexy halloween costumes] [http://www.zimsite.com/site/images/js/vrrplh.html download songs] [http://marsenshow.nl/modules/images/ungehn.html security jobs] [http://touringsportbmw.com/images/js/fafktj.html awning] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/vpkotf.html virgins] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/rfbpum.html bars] [http://www.mesken.net/sitebcx/_files/Image/js/lidima.html psychics] [http://marsenshow.nl/modules/images/etcxqc.html virginia birth certificate] [http://marsenshow.nl/modules/images/wgmsmn.html small business grants] [http://www.zimsite.com/site/images/js/hngmoa.html buy viagra cheap] [http://touringsportbmw.com/images/js/whhahm.html cheap laptops] [http://marsenshow.nl/modules/images/ksprmn.html sony computer] [http://www.zimsite.com/site/images/js/bxndar.html black] [http://touringsportbmw.com/images/js/icmpdp.html canon printers] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/stmkcj.html shower curtain rings] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/aejqos.html aciphex online] [http://touringsportbmw.com/images/js/rfvmas.html lee jean] [http://marsenshow.nl/modules/images/wucmkd.html dildo] [http://www.zimsite.com/site/images/js/dfdwgh.html asian] [http://www.mesken.net/sitebcx/_files/Image/js/ijndeb.html jet ski insurance] [http://marsenshow.nl/modules/images/ieemta.html cheapest airplane tickets] [http://marsenshow.nl/modules/images/ciamcq.html free t mobile phone] [http://www.mesken.net/sitebcx/_files/Image/js/rwnkqu.html business plan] [http://www.zimsite.com/site/images/js/pobxcw.html lose weight while you sleep] [http://marsenshow.nl/modules/images/nmlfvk.html handbags replica] [http://touringsportbmw.com/images/js/ottojp.html volvo dealerships] [http://www.mesken.net/sitebcx/_files/Image/js/ekcfrr.html roulette] [http://www.zimsite.com/site/images/js/srppfm.html bluetooth technology] [http://www.zimsite.com/site/images/js/sibmtj.html airline schedules] [http://marsenshow.nl/modules/images/ucqiuo.html lawn tractors] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/vmjkge.html renault car dealers] [http://www.mesken.net/sitebcx/_files/Image/js/kbenob.html best casino online] [http://touringsportbmw.com/images/js/bekalc.html vegas hotels] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/dwkeve.html public auto auction] [http://touringsportbmw.com/images/js/iidhum.html dexter shoe] [http://www.zimsite.com/site/images/js/vcpnti.html real estate in surfside beach south carolina] [http://marsenshow.nl/modules/images/nmwgvn.html carhartt] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/bwmfmf.html sports bras] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/wesurb.html corelle] [http://marsenshow.nl/modules/images/txtoir.html free ringer downloads] [http://www.mesken.net/sitebcx/_files/Image/js/ibidot.html ringtone software] [http://touringsportbmw.com/images/js/wvjaqa.html free antivirus download] [http://marsenshow.nl/modules/images/rfggji.html free virus scan] [http://www.zimsite.com/site/images/js/hlbsbl.html work at home mom] [http://touringsportbmw.com/images/js/qdeilu.html cherokee] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/wsbwhx.html cheap airline ticket international] [http://marsenshow.nl/modules/images/lnkhwl.html kitchen] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/nfptdc.html sex webcam] [http://www.mesken.net/sitebcx/_files/Image/js/pkxhhv.html free credit report no credit card] [http://marsenshow.nl/modules/images/agsolg.html patio umbrella] [http://marsenshow.nl/modules/images/wlhntb.html gas pump] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/bjkofq.html friendship] [http://www.zimsite.com/site/images/js/xcdvkr.html home decor] [http://www.mesken.net/sitebcx/_files/Image/js/oaktfh.html dell computers] [http://touringsportbmw.com/images/js/gxweoo.html home businesses] [http://touringsportbmw.com/images/js/cfejtj.html akai] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/pqehfd.html costume pirate] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/imidtl.html wicked tickets] [http://touringsportbmw.com/images/js/gvvrkh.html indiana foreclosure] [http://www.mesken.net/sitebcx/_files/Image/js/rmrvmf.html psychic] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/degknk.html clonidine] [http://www.zimsite.com/site/images/js/imugjo.html t mobile] [http://marsenshow.nl/modules/images/uguwir.html candy] [http://www.zimsite.com/site/images/js/vsqmmp.html start a business] [http://marsenshow.nl/modules/images/bjbfdw.html football betting] [http://touringsportbmw.com/images/js/vuubba.html nokia] [http://marsenshow.nl/modules/images/jonxjq.html play game] [http://www.gokastoria.gr/kastoria_go_/newspublish/image/js/fncojp.html coffee grinder] [http://marsenshow.nl/modules/images/lwkden.html watch] [http://www.mesken.net/sitebcx/_files/Image/js/ulmlse.html didrex] [http://touringsportbmw.com/images/js/hbdeuc.html diplomas] [http://www.mesken.net/sitebcx/_files/Image/js/ccwnit.html the game]
<syntaxhighlight lang="cpp">
[[Category:Programming]]
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ========
<pre>
//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ========
//
//
// Purpose: Simple brush entity that moves when touched
// Purpose: Simple brush entity that moves when touched
Line 9: Line 7:


#include "cbase.h"
#include "cbase.h"
#include "triggers.h"


class CMyBrushEntity : public CBaseToggle
class CMyBrushEntity : public CBaseTrigger
{
{
public:
public:
DECLARE_CLASS( CMyBrushEntity, CBaseToggle );
DECLARE_CLASS( CMyBrushEntity, CBaseTrigger );
DECLARE_DATADESC();
DECLARE_DATADESC();


void Spawn( void );
void Spawn();
bool CreateVPhysics( void );


void BrushTouch( CBaseEntity *pOther );
void BrushTouch( CBaseEntity *pOther );
Line 24: Line 22:
LINK_ENTITY_TO_CLASS( my_brush_entity, CMyBrushEntity );
LINK_ENTITY_TO_CLASS( my_brush_entity, CMyBrushEntity );


// Start of our data description for the class
BEGIN_DATADESC( CMyBrushEntity )
BEGIN_DATADESC( CMyBrushEntity )
// Declare this function as being a touch function
// Declare this function as being the touch function
DEFINE_ENTITYFUNC( BrushTouch ),
DEFINE_ENTITYFUNC( BrushTouch ),


Line 35: Line 32:
// Purpose: Sets up the entity's initial state
// Purpose: Sets up the entity's initial state
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CMyBrushEntity::Spawn( void )
void CMyBrushEntity::Spawn()
{
{
BaseClass::Spawn();
// We want to capture touches from other entities
// We want to capture touches from other entities
SetTouch( &CMyBrushEntity::BrushTouch );
SetTouch( &CMyBrushEntity::BrushTouch );
Line 42: Line 41:
// We should collide with physics
// We should collide with physics
SetSolid( SOLID_VPHYSICS );
SetSolid( SOLID_VPHYSICS );
// Use our brushmodel
SetModel( STRING( GetModelName() ) );
// We push things out of our way
// We push things out of our way
SetMoveType( MOVETYPE_PUSH );
SetMoveType( MOVETYPE_PUSH );
// Use our brushmodel
SetModel( STRING( GetModelName() ) );


// Create our physics hull information
// Create our physics hull information
CreateVPhysics();
}
//-----------------------------------------------------------------------------
// Purpose: Setup our physics information so we collide properly
//-----------------------------------------------------------------------------
bool CMyBrushEntity::CreateVPhysics( void )
{
// For collisions with physics objects
VPhysicsInitShadow( false, false );
VPhysicsInitShadow( false, false );
return true;
}
}


Line 77: Line 65:
vecPushDir.Negate();
vecPushDir.Negate();
vecPushDir.z = 0.0f;
vecPushDir.z = 0.0f;
// Uncomment this line to print plane information to the console in developer mode
//DevMsg ( "%s (%s) touch plane's normal: [%f %f]\n", GetClassname(), GetDebugName(),tr.plane.normal.x, tr.plane.normal.y );


// Move slowly in that direction
// Move slowly in that direction
LinearMove( GetAbsOrigin() + ( vecPushDir * 64.0f ), 32.0f );
LinearMove( GetAbsOrigin() + ( vecPushDir * 64.0f ), 32.0f );
}
}
</pre>
</syntaxhighlight>
 
== See also ==
*[[Authoring a Brush Entity]]
 
[[Category:Programming]]
[[Category:Tutorials]]

Latest revision as of 16:40, 28 June 2011

//===== Copyright © 1996-2005, Valve Corporation, All rights reserved. ========
//
// Purpose: Simple brush entity that moves when touched
//
//=============================================================================

#include "cbase.h"
#include "triggers.h"

class CMyBrushEntity : public CBaseTrigger
{
public:
	DECLARE_CLASS( CMyBrushEntity, CBaseTrigger );
	DECLARE_DATADESC();

	void Spawn();

	void BrushTouch( CBaseEntity *pOther );
};

LINK_ENTITY_TO_CLASS( my_brush_entity, CMyBrushEntity );

BEGIN_DATADESC( CMyBrushEntity )
	
	// Declare this function as being the touch function
	DEFINE_ENTITYFUNC( BrushTouch ),

END_DATADESC()

//-----------------------------------------------------------------------------
// Purpose: Sets up the entity's initial state
//-----------------------------------------------------------------------------
void CMyBrushEntity::Spawn()
{
	BaseClass::Spawn();

	// We want to capture touches from other entities
	SetTouch( &CMyBrushEntity::BrushTouch );

	// We should collide with physics
	SetSolid( SOLID_VPHYSICS );
	
	// Use our brushmodel
	SetModel( STRING( GetModelName() ) );
	
	// We push things out of our way
	SetMoveType( MOVETYPE_PUSH );

	// Create our physics hull information
	VPhysicsInitShadow( false, false );
}

//-----------------------------------------------------------------------------
// Purpose: Move away from an entity that touched us
// Input  : *pOther - the entity we touched
//-----------------------------------------------------------------------------
void CMyBrushEntity::BrushTouch( CBaseEntity *pOther )
{
	// Get the collision information
	const trace_t &tr = GetTouchTrace();

	// We want to move away from the impact point along our surface
	Vector	vecPushDir = tr.plane.normal;
	vecPushDir.Negate();
	vecPushDir.z = 0.0f;

	// Uncomment this line to print plane information to the console in developer mode
	//DevMsg ( "%s (%s) touch plane's normal: [%f %f]\n", GetClassname(), GetDebugName(),tr.plane.normal.x, tr.plane.normal.y );

	// Move slowly in that direction
	LinearMove( GetAbsOrigin() + ( vecPushDir * 64.0f ), 32.0f );
}

See also