Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Nymphodora), 972 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Electricity script #325235
05/25/10 15:01
05/25/10 15:01
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Probably there are plenty released in the past, but here a tiny one from me:

http://www.youtube.com/watch?v=xE9sZULURKo





Link to model and code:
http://joozey.nl/3dgs/contribs/Electricity.zip

Have fun!



Code:
//defines

//handy
#define new(x) malloc(sizeof(x))
#define remove(x) free(x)



//length of the model (you need to adapt this if you got your own model)
#define ELECTRIC_LENGTH 50

//model name
#define ELECTRICITY_MODEL "electricity.mdl"



//structure
typedef struct
{
	VECTOR start;
	VECTOR end;
	var seconds;
	ENTITY *electricity_entity;
	var deviation;
	
} ELECTRICITY;



//prototypes
void ELECTRICITY_Shoot( ELECTRICITY *e );
void ELECTRICITY_Run( ELECTRICITY *e );
ELECTRICITY *ELECTRICITY_Create( VECTOR *start, VECTOR *end, var seconds, var deviation );
void ELECTRICITY_Remove( ELECTRICITY *e );



//runs as many time as has been assigned on seconds (not really seconds by the way)
void ELECTRICITY_Run( ELECTRICITY *e )
{
	//shoot a new electric (will recursively loop in here again)
	ELECTRICITY_Shoot( e );
	
	//factor for decaying alpha with seconds
	var factor = 100/e->seconds;
	set( e->electricity_entity, TRANSLUCENT );
	
	//loop while we still got seconds
	while( e->seconds > 0 )
	{
		e->seconds -= 1 * time_step;
		e->electricity_entity.alpha -= factor * time_step; //decay alpha
		wait(1);
	}
	
	//remove the entity
	ent_remove( e->electricity_entity );
	remove( e );
}


//create a new electricity (you call this to create a new thunder, also used for recursive loop internally)
ELECTRICITY *ELECTRICITY_Create( VECTOR *start, VECTOR *end, var seconds, var deviation )
{
	ELECTRICITY *e = new(ELECTRICITY);
	
	vec_set( e->start, start );
	vec_set( e->end, end );
	e->seconds = seconds;
	e->deviation = deviation;
	e->electricity_entity = ent_create(ELECTRICITY_MODEL, e->start, NULL);
	
	//start running
	ELECTRICITY_Run( e );	
	
	return e;
}


//remove electricity
//since the run function still uses the electricity when it is removed here, errors may pop up
//so we make sure the run ends, and let the run function take care of removing
//we end the run by putting seconds on 0
void ELECTRICITY_Remove( ELECTRICITY *e )
{
	e->seconds = 0;
}


//shoot a new segment of electricity
void ELECTRICITY_Shoot( ELECTRICITY *e )
{
	VECTOR newStart;
	VECTOR newEnd;
	
	//get direction from current position to global end
	vec_set( newEnd, e->end );
	vec_sub( newEnd, e->start );
	
	//rotate a bit by given deviation
	vec_rotate( newEnd, vector( random(e->deviation*2)-e->deviation, random(e->deviation*2)-e->deviation, random(e->deviation*2)-e->deviation ) );
	
	//scale it to the model's length
	vec_normalize( newEnd, ELECTRIC_LENGTH );
	
	//place it at the previous electric segment
	vec_set( newStart, e->start );
	vec_add( newStart, newEnd );
	
	
	//place the real model
	vec_set( e->electricity_entity.x, e->start );
	
	//rotate the real model
	VECTOR *vAngle = vector( 0, 0, 0 );
	vec_set( vAngle, e->start );
	vec_sub( vAngle, newStart );
	vec_to_angle( e->electricity_entity.pan, vAngle );
	
	
	//since this function is recursive, we need to limit it before it goes endless looping
	//we look if the electric segment approaches the global end, if so, we dont make a new segment anymore
	//
	//TODO: make the last segment end exactly on the designated end position
	//currently it is not exactly on the spot but stops right before or after it
	if( vec_dist( e->start, e->end ) > ELECTRIC_LENGTH + 10 )
	{
		ELECTRICITY *e = ELECTRICITY_Create( newStart, e->end, e->seconds, e->deviation );
	}
	
	//this is the very last segment,we treat it a bit different
	if( vec_dist( e->start, e->end ) <= ELECTRIC_LENGTH + 10 &&
	 	 vec_dist( e->start, e->end ) >= ELECTRIC_LENGTH - 10 )
	{
		//at least give the last segment a deviation of 0 so it will point directly towards global end
		ELECTRICITY *e = ELECTRICITY_Create( newStart, e->end, e->seconds, e->deviation );
	}
}




Click and join the 3dgs irc community!
Room: #3dgs
Re: Electricity script [Re: Joozey] #325248
05/25/10 16:02
05/25/10 16:02
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Nidhogg Offline
Serious User
Nidhogg  Offline
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Thanks Joozey, always enjoy your contribs.


Windows XP SP3
Intel Dual Core CPU: E5200 @ 2.5GHz
4.00GB DDR3 Ram
ASUS P5G41T-M LX
PCIE x16 GeForce GTS 450 1Gb
SB Audigy 4
Spyware Doctor with AntiVirus
Re: Electricity script [Re: Nidhogg] #328061
06/10/10 11:34
06/10/10 11:34
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
T
Tempelbauer Offline
Expert
Tempelbauer  Offline
Expert
T

Joined: Feb 2005
Posts: 3,687
Hessen, Germany
really nice laugh

Re: Electricity script [Re: Tempelbauer] #328238
06/11/10 08:33
06/11/10 08:33
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Glad you like it laugh.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Electricity script [Re: Joozey] #330335
06/27/10 00:01
06/27/10 00:01
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Looks cool Joozey, going to check it out.


Professional A8.30
Spoils of War - East Coast Games
Re: Electricity script [Re: Locoweed] #330914
06/30/10 19:42
06/30/10 19:42
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
little question..
how do i use this?

can´t get an idea from the code Y_Y *sry*


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: Electricity script [Re: Joozey] #330947
07/01/10 05:34
07/01/10 05:34

M
mercuryus
Unregistered
mercuryus
Unregistered
M



looks like the same i did long ago? (http://www.youtube.com/watch?v=iMjcUCPWSWg)
looks like your's don't end in the destination?

Re: Electricity script [Re: ] #331589
07/05/10 09:34
07/05/10 09:34
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline OP
Expert
Joozey  Offline OP
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Yes indeed, I remember that one mercuryus laugh.
Couldn't decide how to end it on the destination, didn't want to scale the model (either all of them a bit, or only the last one to the end). It moves to the end but doesn't stop at the end. Any idea how to make it end without scaling the model? Clipping the model would be better but afaik that's not possible with standard engine functions.


Click and join the 3dgs irc community!
Room: #3dgs
Re: Electricity script [Re: Joozey] #331717
07/05/10 21:54
07/05/10 21:54
Joined: Oct 2002
Posts: 2,256
Oz
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Imagine you would at least have to scale the X size of last model to make it end on destination.


Professional A8.30
Spoils of War - East Coast Games
Re: Electricity script [Re: Locoweed] #331764
07/06/10 06:10
07/06/10 06:10

M
mercuryus
Unregistered
mercuryus
Unregistered
M



Yes - without scaling it's a bit tricky.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1