2 registered members (7th_zorro, howardR),
1,001
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Lightning-Strike Generator.
[Re: Germanunkol]
#282465
08/01/09 10:58
08/01/09 10:58
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Looks great, and uses random bmap's as particles right? But MY aim was to aviod using any external files. It was more a mental exercise than enything.
Still, everyone has different needs. And youve used mine to achieve yours. Well done.
Just curious... How many different bmaps are in the random list? Have you tried letting a few of them have branches? What did it look like?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Lightning-Strike Generator.
[Re: EvilSOB]
#317949
04/03/10 19:36
04/03/10 19:36
|
Joined: Apr 2010
Posts: 52 Hamburg, Germany
JXT
Junior Member
|
Junior Member
Joined: Apr 2010
Posts: 52
Hamburg, Germany
|
Hi everyone ^^ I just wanted to use this generator... but it doesn't work I tried you "test"-code and it doesn't work, too... Please help me...
|
|
|
Re: Lightning-Strike Generator.
[Re: JXT]
#318038
04/04/10 14:49
04/04/10 14:49
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hmm, it seems it hasnt worked only since 7.82 Im looking into this now.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Lightning-Strike Generator.
[Re: EvilSOB]
#318044
04/04/10 15:41
04/04/10 15:41
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
OK, this could take a while, cause its no longer up to me. This is being caused either by a new engine bug, or an old "undocumented feature" I was using, and has been repaired. I am using dummy entities to pass data to the particles, but its stopped working for some reason, and Im going to chase this up in the "Bugs" forum. For the time being, here is an older version. Its not quite as powerful, or as "pretty" but it does still work in newer engine versions.
#include <acknex.h>
#include <default.c>
//
//
//////////////////////////////////////////////////////////////////////////////////////////
// 3D-LIGHTNING-BOLT-SPAWN //
// ----------------------- //
// //
// Author : EvilSOB //
// Date : 25-07-2009 //
// //
//////////////////////////////////////////////////////////////////////////////////////////
//LB_spawn(VECTOR* start, VECTOR* finish, long Div, float branch, long depth, long size)//
//--------------------------------------------------------------------------------------//
// Parameters:: //
// start = Start Vector of Lightning Bolt (sky) //
// finish = Target Vector of Lightning Bolt (ground) //
// Div = Number of primary "segments" in central bolt (suggest 20) //
// branch = 0.0->1.0 chance to "branch" at primary segment point. (suggest 0.4) //
// depth = depth of complexity to calculate into branches. (suggest 4) //
// size = diameter in quants of "core" bolt.(2^depth minimum) (suggest 8) //
// //
//////////////////////////////////////////////////////////////////////////////////////////
// Example:: //
// LB_spawn(start, finish, 20, 0.4, 4, 8); //
// //
//////////////////////////////////////////////////////////////////////////////////////////
// //
void LB_segment_fade(PARTICLE* p)
{ p.alpha -= 20 * p.skill_a * time_step;
if (p.alpha <= 0) p.lifespan = 0;
}
//
void LB_segment_flare(PARTICLE* p)
{ vec_set(p.blue, vector(128,0,0));
set(p, BEAM|BRIGHT|TRANSLUCENT|UNLIT|CAST);
p.alpha = 50;
p.size = (long)you*3;
p.skill_a = 0.3;
p.event = LB_segment_fade;
}
//
void LB_segment_core(PARTICLE* p)
{ vec_set(p.blue, vector(255,128,128));
set(p, BEAM|BRIGHT|TRANSLUCENT|UNLIT|CAST);
p.alpha = 100;
p.size = (long)you;
p.skill_a = 1.5;
p.event = LB_segment_fade;
}
//
void LB_draw_segment(VECTOR *start, VECTOR *finish, long size)
{ me = size;
VECTOR tmpV; vec_set(tmpV, finish); vec_sub(tmpV,start);
effect(LB_segment_core, 5, start, tmpV);
effect(LB_segment_flare, 1, start, tmpV);
me = size;
}
//
//
void LB_randomize(VECTOR* point, float noise)
{
point.x += random(noise*2)-noise;
point.y += random(noise*2)-noise;
point.z += random(noise)-noise/2;
}
//
void LB_subdivide(VECTOR* A, VECTOR* B, long Div, float noise, VECTOR** Points)
{ VECTOR *points = (VECTOR*)malloc(sizeof(VECTOR)*Div);
if(!Points) free(*Points); *Points = points;
var idx; for(idx=0; idx<Div; idx++)
{ vec_lerp(points[idx], A, B, (float)idx/(Div-1));
if((idx>0)&&(idx<(Div-1))) LB_randomize(points[idx], noise);
}
}
//
void LB_spawn(VECTOR* start,VECTOR* finish,long Div,float branch,long depth,long size)
{ VECTOR A, B; vec_set(A, start); vec_set(B, finish); wait(1);
long i, cnt, seg_size=vec_dist(A,B)/Div;
VECTOR *fine=0, *crude=0; LB_subdivide(A, B, Div, vec_dist(A,B)/(Div+1), crude);
for(i=1; i<Div; i++)
{ LB_subdivide(crude[i-1],crude[i],Div/2,vec_dist(crude[i-1],crude[i])/Div/2+1,fine);
for(cnt=1; cnt<(Div/2); cnt++) LB_draw_segment(fine[cnt-1], fine[cnt], size);
if((depth>1)&&(random(1)<branch))
{ VECTOR tmpV; vec_set(tmpV,crude[i]); LB_randomize(tmpV, vec_dist(A,B)/5);
LB_spawn(crude[i-1], tmpV, Div/2, branch, depth-1, size/2);
} }
free(crude); free(fine);
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//
VECTOR start, finish;
void strike() { LB_spawn(start, finish, 20, 0.4, 4, 8); }
//
//
function main()
{
level_load(NULL); wait(2); diag("\n\n\n");
vec_set(sky_color, vector(1,1,1));
vec_set(camera.x, vector(-700,0,255));
//
on_space = strike;
//
vec_set(start, vector(0,0,500));
vec_set(finish, vector(0,100,0));
LB_spawn(start, finish, 20, 0.4, 4, 8);
//
while(1)
{
draw_point3d(start, vector(255,200,200), 100, 10);
draw_point3d(finish, vector(255,200,200), 100, 10);
wait(1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Lightning-Strike Generator.
[Re: EvilSOB]
#318049
04/04/10 16:49
04/04/10 16:49
|
Joined: Apr 2010
Posts: 52 Hamburg, Germany
JXT
Junior Member
|
Junior Member
Joined: Apr 2010
Posts: 52
Hamburg, Germany
|
Thank you Has to work anyhow ^^ €: even it's an older version, it's AWESOME!!! Thank you EvilSOB
Last edited by JXT; 04/04/10 16:52.
|
|
|
Re: Lightning-Strike Generator.
[Re: mikaldinho]
#318141
04/05/10 14:59
04/05/10 14:59
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
OK, Ive found the problem, and it wasnt an engine bug, it was a timing bug in my code. It appears (in MY opinion) the A7 7.82.2 is "cleaner" when removing entities, where there was a (behind the scenes) one-frame lag between the execution of an ent_remove and the actual memory getting flushed and re-used. Now there is no longer that lag, it highlighted my timing problem. So here is the fix. Just replace the old LB_spawn (from Version 2.0) with this.
//
void LB_spawn(VECTOR* Start, VECTOR* Finish, long Div, float Branch, long Depth, long Size, COLOR* Core, COLOR* Flare, var Seed)
{ if(Div<3) return;
if(!Seed) Seed = timer();
VECTOR A, B, C, D, tmpV, corec, flarec, *fine=0, *crude=0; vec_zero(flarec);
vec_set(A, Start); vec_set(B, Finish); vec_set(corec, Core);
if(Flare) vec_set(flarec, Flare);
wait(1);
long i, cnt, seg_size = vec_dist(A,B)/Div; random_seed(Seed);
LB_divide(A, B, Div, vec_dist(A,B)/(Div+1), crude);
me = ent_create(NULL, NULL, NULL); me.skill2 = Size;
vec_set(me.skill3, corec); vec_set(me.skill6, flarec);
for(i=1; i<Div; i++)
{ LB_divide(crude[i-1],crude[i],Div/2,vec_dist(crude[i-1],crude[i])/Div/2+1,fine);
for(cnt=1; cnt<(Div/2); cnt++)
{ vec_set(tmpV, fine[cnt]); vec_sub(tmpV, fine[cnt-1]);
if(vec_length(tmpV))
vec_scale(tmpV, vec_length(tmpV)/vec_length(tmpV));
if(vec_length(flarec)) effect(LB_segment_flare, 1, fine[cnt-1], tmpV);
effect(LB_segment_core, 1, fine[cnt-1], tmpV); }
if((Depth>1)&&(random(1)<Branch)&&(i<(Div-1)))
{ vec_diff(C, crude[i], crude[i-1]);
vec_diff(D, crude[i], crude[i+1]);
vec_lerp(tmpV, D, C, random(1)+0.35);
vec_normalize(tmpV, random(seg_size*(Div-i))*0.6); vec_add(tmpV,crude[i]);
LB_spawn(crude[i], tmpV,Div*0.6,Branch,Depth-1,Size*0.6, corec, flarec, Seed+random(15));
} }
wait(1); ent_remove(me); free(crude); free(fine);
}
//
Sorry guys. My bad. {EDIT] This code has also been fixed in Ver 2.0 and Ver 2.1 in the top post of this thread.
Last edited by EvilSOB; 04/06/10 07:53.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|