Authoring a Brush Entity/Code: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
(syntax highlighting)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[http://bigger.servemp3.com/web/adult-literacy.html adult literacy core curriculum] [http://jeshu.servemp3.com/glucotrol.htm glucotrol] [http://weigh.servemp3.com/library/telescope.html telescope] [http://while.servemp3.com/resources/aeroflot-airlines.html aeroflot airlines] [http://capdv.servemp3.com/free-movies.html free movies] [http://baffle.servemp3.com/blog/virgin-blue.html virgin blue] [http://rumour.servemp3.com/blog/amway.html amway] [http://jeshu.servemp3.com/dress-wear-wedding.htm dress wear wedding] [http://baffle.servemp3.com/blog/georgia-aquarium.html georgia aquarium] [http://baffle.servemp3.com/blog/immigration.html immigration and naturalization service] [http://baffle.servemp3.com/blog/citalopram.html citalopram] [http://baffle.servemp3.com/blog/shemale-porn.html shemale porn] [http://jeshu.servemp3.com/continental-airlines.htm continental airlines home page] [http://jeshu.servemp3.com/free-indian-sex.htm free indian sex] [http://while.servemp3.com/resources/miacalcin.html miacalcin] [http://shrewd.servemp3.com/web/chopard-watch.htm chopard watch] [http://capdv.servemp3.com/tissot-watches.html tissot watches] [http://rumour.servemp3.com/blog/mortgage-refinancing.html mortgage refinancing no closing cost] [http://baffle.servemp3.com/blog/eq2-macros.html eq2 macros] [http://bigger.servemp3.com/web/blood.html blood] [http://while.servemp3.com/resources/customer-service.html customer service] [http://shrewd.servemp3.com/web/blonde.htm blonde] [http://while.servemp3.com/resources/wedding-cakes.html wedding cakes] [http://while.servemp3.com/resources/we-live-together.html we live together] [http://incite.servemp3.com/q/horoscope-love.html horoscope love sign compatibility] [http://jeshu.servemp3.com/gay-mpegs.htm gay mpegs] [http://baffle.servemp3.com/blog/samsung-pc-suite.html samsung pc suite] [http://rumour.servemp3.com/blog/free-pc-games.html free pc games] [http://jeshu.servemp3.com/wifes.htm wifes] [http://shrewd.servemp3.com/web/black-porn-star.htm black porn star india] [http://incite.servemp3.com/q/sexy-boot.html sexy boot] [http://weigh.servemp3.com/library/balls.html balls] [http://rumour.servemp3.com/blog/toyota-trucks.html toyota trucks] [http://capdv.servemp3.com/hawaiian-airline.html hawaiian airline] [http://incite.servemp3.com/q/fucking-mature.html fucking mature] [http://weigh.servemp3.com/library/kitchener-on.html kitchener on] [http://weigh.servemp3.com/library/flight-jacket.html flight jacket] [http://while.servemp3.com/resources/striptease-video.html striptease video] [http://incite.servemp3.com/q/jewelry-making.html jewelry making kits] [http://jeshu.servemp3.com/buy-viagra-in-the.htm buy viagra in the uk] [http://jeshu.servemp3.com/topshop.htm topshop] [http://bigger.servemp3.com/web/sympathy-card.html sympathy card] [http://rumour.servemp3.com/blog/free-t-mobile.html free t mobile sidekick 2] [http://incite.servemp3.com/q/freeadultmovies.html freeadultmovies] [http://shrewd.servemp3.com/web/car-classic.htm car classic kit] [http://jeshu.servemp3.com/rockport-boat.htm rockport boat shoes] [http://capdv.servemp3.com/discount-wedding.html discount wedding favor] [http://weigh.servemp3.com/library/sierra-nevada.html sierra nevada] [http://rumour.servemp3.com/blog/express-store.html express store] [http://rumour.servemp3.com/blog/baclofen.html baclofen] [http://baffle.servemp3.com/blog/markie-post.html markie post] [http://bigger.servemp3.com/web/mazda-rx7.html mazda rx7] [http://baffle.servemp3.com/blog/water-heater.html water heater] [http://incite.servemp3.com/q/winamp.html winamp] [http://baffle.servemp3.com/blog/gambling-game.html gambling game] [http://capdv.servemp3.com/irrigation-systems.html irrigation systems] [http://baffle.servemp3.com/blog/pheromone.html pheromone] [http://shrewd.servemp3.com/web/lil-bow-wow.htm lil bow wow] [http://rumour.servemp3.com/blog/t-mobile-sidekick.html t-mobile sidekick] [http://jeshu.servemp3.com/scooters-motor.htm scooters motor] [http://baffle.servemp3.com/blog/ephedra-danger.html ephedra danger] [http://jeshu.servemp3.com/doorknobs.htm doorknobs] [http://shrewd.servemp3.com/web/erotig.htm erotig] [http://while.servemp3.com/resources/asian-boy.html asian boy] [http://incite.servemp3.com/q/free-reverse-cell.html free reverse cell phone] [http://shrewd.servemp3.com/web/funny-cartoon.htm funny cartoon] [http://bigger.servemp3.com/web/mercedes.html mercedes] [http://weigh.servemp3.com/library/tamiflu-and-mexico.html tamiflu and mexico] [http://incite.servemp3.com/q/dish-network.html dish network key] [http://while.servemp3.com/resources/female-spanking.html female spanking] [http://incite.servemp3.com/q/wire-jewelry.html wire jewelry] [http://incite.servemp3.com/q/adderall-side.html adderall side effects] [http://while.servemp3.com/resources/anal-sex-gallery.html anal sex gallery] [http://incite.servemp3.com/q/asian-women.html asian women for marriage] [http://bigger.servemp3.com/web/buy-ambien.html buy ambien] [http://bigger.servemp3.com/web/camel-cigarette.html camel cigarette] [http://capdv.servemp3.com/amateur-blog.html amateur blog] [http://shrewd.servemp3.com/web/kentucky-lake.htm kentucky lake house boat rental] [http://baffle.servemp3.com/blog/lapdancing.html lapdancing] [http://incite.servemp3.com/q/adobe-acrobat-distiller.html adobe acrobat distiller free download] [http://bigger.servemp3.com/web/mineral-makeup.html mineral makeup recipes] [http://shrewd.servemp3.com/web/ncaa-sports.htm ncaa sports] [http://capdv.servemp3.com/triamcinolone.html triamcinolone] [http://baffle.servemp3.com/blog/big-breasts.html big breasts] [http://capdv.servemp3.com/nod32-antivirus.html nod32 antivirus] [http://rumour.servemp3.com/blog/jeep-ecm.html jeep ecm] [http://weigh.servemp3.com/library/car-accessories.html car accessories] [http://baffle.servemp3.com/blog/jenifer-aniston.html jenifer aniston] [http://rumour.servemp3.com/blog/performance.html performance appraisals] [http://shrewd.servemp3.com/web/black-hummer-h2.htm black hummer h2] [http://capdv.servemp3.com/filing-bankrupcy.html filing bankrupcy] [http://while.servemp3.com/resources/norton-antivirus.html norton antivirus download free] [http://rumour.servemp3.com/blog/cheap-sex.html cheap sex] [http://while.servemp3.com/resources/hotsex.html hotsex] [http://incite.servemp3.com/q/encore-download.html encore download] [http://capdv.servemp3.com/tila.html tila] [http://baffle.servemp3.com/blog/chanel-replica.html chanel replica handbags] [http://shrewd.servemp3.com/web/hot-install-replace.htm hot install replace spa tub] [http://baffle.servemp3.com/blog/exchange-currency.html exchange currency] [http://baffle.servemp3.com/blog/cheap-vicodin.html cheap vicodin]
<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