Need a laser beam particle effect example

Posted By: Ercoles

Need a laser beam particle effect example - 12/13/12 12:30

Can anyone provide a laser beam particle effect example, like a function which takes start and destination inputs and generates a laser beam from start to destination coordinates?
Posted By: Ayumi

Re: Need a laser beam particle effect example - 12/13/12 13:11

Laser Beam
http://aum.conitec.net/aum26/english/aum26/index.html

Laser eyes
http://aum.conitec.net/aum29/english/aum29/index.html
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 14:15

They are good examples but I need one done only with SED script editor and maybe a pcx file. I need an example causing a line from a corner of the screen to the middle.
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/13/12 14:41

You're not asking for a sample but for a completed piece of work. Go through the tutorials and try if for yourself. If you get into any difficulties don't hesitate to ask for advice here. But please don't ask other people to do the work for you.

And please DO NOT CROSSPOST. tired

http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=413369#Post413369
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 16:38

Ok I have managed to make this code which seems to do what I need:

ENTITY* gun1;
ENTITY* gun2;

function p_alphafade(PARTICLE *p)
{
p.alpha -= p.skill_a*time_step;
if (p.alpha <= 0) p.lifespan = 0;
}

function p_trace(PARTICLE *p)
{
set(p, BRIGHT|TRANSLUCENT|BEAM);
p.size = 1;
p.skill_a = 20; // fade factor
p.event = p_alphafade;
p.red =255;
p.blue=20;
p.green=128;
}

action tracer_right()
{
VECTOR last_pos;
while(1){
vec_set(last_pos,my.x);
my.z +=1.5;
my.y +=2;
if (my.y>1){break;}
effect(p_trace,1,my.x,vec_sub(last_pos,my.x));
wait(1);
}
}

action tracer_left()
{
VECTOR last_pos;
while(1){
vec_set(last_pos,my.x);
my.z +=1.5;
my.y -=2;
if (my.y<-1){break;}
effect(p_trace,1,my.x,vec_sub(last_pos,my.x));
wait(1);
}
}

function main()
{
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
video_window(NULL,NULL,0,"Laser demo");
vec_set(camera.x,vector(-250,0,50));
vec_set(camera.pan,vector(0,-15,0));
while (1){
if (mouse_left == 1){
gun1=ent_create(NULL,vector(-100,-170,-80),tracer_right);
gun2=ent_create(NULL,vector(-100,170,-80),tracer_left);
}
//if(proc_status(tracer_right) == 0){ent_remove(gun1);}
//if(proc_status(tracer_left) == 0){ent_remove(gun2);}
wait(1);
}
}

However the entities need to be destroyed otherwise after a couple of fires they will cause an error. I tried using the commented lines in the main function but they causes errors.
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/13/12 17:10

Excellent work. And you did it all by yourself. :-)
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 17:13

Thanks

However the entities need to be destroyed otherwise after a couple of fires they will cause an error. I tried using the commented lines in the main function but they causes errors.
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/13/12 17:17

What error do these entities cause?
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 18:51

Everytime I press the mouse button a new entity is created. After several clicks it gave me an error:

Not enough entities reserved(1000)

So I think that I must kill the entities created with each mouse click when the particle effect has finished.
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 19:15

I have solved it by using this in the fire loop:

if(proc_status(tracer_right) < 5){gun1=ent_create(NULL,vector(-100,-170,-80),tracer_right);}
if(proc_status(tracer_left) < 5){gun2=ent_create(NULL,vector(-100,170,-80),tracer_left);}

This way it is not causing the error so often(only rarely). But do I still need to kill the entities created or particle entities die by themselves?

I added these lines instead of the commented ones but do not seem to make much difference:

if(proc_status(tracer_right) == 0){ptr_remove(gun1);}
if(proc_status(tracer_left) == 0){ptr_remove(gun2);}
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/13/12 19:37

I have set the main function to:

function main()
{ var i; var j;
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
video_window(NULL,NULL,0,"Laser demo");
vec_set(camera.x,vector(-250,0,50));
vec_set(camera.pan,vector(0,-15,0));
while (1){
if (mouse_left == 1){
if(proc_status(tracer_right) < 5){gun1=ent_create(NULL,vector(-100,-170,-80),tracer_right);i++;}
if(proc_status(tracer_left) < 5){gun2=ent_create(NULL,vector(-100,170,-80),tracer_left);j++;}
}
if((proc_status(tracer_right) == 0) && (i>0)){ptr_remove(gun1);i--;}
if((proc_status(tracer_left) == 0) && (j>0)){ptr_remove(gun2);j--;}
wait(1);
}
}

but still though very rarely I get that error.
Posted By: Kartoffel

Re: Need a laser beam particle effect example - 12/13/12 19:45

I'm sorry I can't help you with your problem but I think the people helping you with this would
appreciate it if you'll write your code with the code tags for easier reading / understanding:

[code] (your code here) [/code]
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/13/12 20:31

From the first code sample you posted just place an "ptr_remove(me);" in your tracer_xxxxx functions just after the while loop. That should do the trick.
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/14/12 17:34

I am a bit confused on the vectors. If I tilt or pan the camera the 2 beam starting points will need to shift as well. What formula do I need to use so that the starting points are always on the left and right of the camera even when I tilt or pan?
Posted By: Superku

Re: Need a laser beam particle effect example - 12/14/12 17:58

You need to use vec_rotate, f.i. as follows:

VECTOR temp;
vec_set(temp,vector(16,-8,0)); // in front of the camera and 8 quants to the right side
vec_rotate(temp,camera.pan);
vec_add(temp,camera.x);
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 07:57

Is it possible to use the c_move command with beam particles?

What I need is that the laser beam particle always moves from its start position at vector(camera.x,camera.y-400,camera.z) or vector(camera.x,camera.y+400,camera.z) to the vector(camera.x+400, camera.y, camera.z-30)

c_move can do that but can it be used with beam particles?

Also the manual in the effect command mentions a Beam Length but I cannot find any description how to use it. Can someone shed some light on this?
Posted By: 3run

Re: Need a laser beam particle effect example - 12/15/12 09:13

You can't use "c_move" with particles (you need collusions, or don't you just know how to move them?).
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 09:53

Originally Posted By: 3run
You can't use "c_move" with particles (you need collusions, or don't you just know how to move them?).


No I do not need collisions, I just do not know how to handle the vector mathematics.
Posted By: 3run

Re: Need a laser beam particle effect example - 12/15/12 09:57

Code:
VECTOR vTemp;
// move in X direction, with speed 15:
vec_set(vTemp, vector(15, 0, 0));
// rotate vector above with camera angles (make movement local):
vec_rotate(vTemp, camera.pan);
// apply to particle:
vec_set(p.vel_x, vTemp);

If what I wrote right here, is just like a Chinese language for you, go learn from workshops, AUM and manual!
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 10:37

In which function should this go the tracer_XXXXX or the p_trace function?
Posted By: 3run

Re: Need a laser beam particle effect example - 12/15/12 10:59

OMFG... Are you kidding mate? We are talking about particles, right?
p.vel_x only will work in the body of the particle function!

GO READ FUCKING MANUAL!
Code:
function blah_particle(PARTICLE* p){
VECTOR vTemp;
// move in X direction, with speed 15:
vec_set(vTemp, vector(15, 0, 0));
// rotate vector above with camera angles (make movement local):
vec_rotate(vTemp, camera.pan);
// apply to particle:
vec_set(p.vel_x, vTemp);
}

And don't ask such a silly question, or very soon no one will answer them.
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 13:10

You seem not understand me, so I posted the whole routine here:

ENTITY* gun1;
ENTITY* gun2;

function p_alphafade(PARTICLE *p)
{
p.alpha -= p.skill_a*time_step;
if (p.alpha <= 0) p.lifespan = 0;
}

function p_trace(PARTICLE *p)
{
VECTOR vTemp;
set(p, BRIGHT|TRANSLUCENT|BEAM);
p.size = 1;
p.skill_a = 10; // fade factor
p.event = p_alphafade;
p.red =255;
p.blue=20;
p.green=128;
}

action tracer_right()
{
VECTOR vTemp;
vec_set(vTemp, vector(0, 150, 30));
vec_rotate(vTemp, camera.pan);
effect(p_trace,1,vector(camera.x+100+(150*cos(camera.pan)),camera.y-(150*sin(camera.pan)),camera.z-30),vTemp);
}

action tracer_left()
{
VECTOR vTemp;
vec_set(vTemp, vector(0, -150, 30));
vec_rotate(vTemp, camera.pan);
effect(p_trace,1,vector(camera.x+100+(150*cos(camera.pan)),camera.y+(150*sin(camera.pan)),camera.z-30),vTemp);
}

function main()
{
video_screen = 1;
video_mode = 12;
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
video_window(NULL,NULL,0,"Laser demo");
camera.x=0;
camera.y=0;
camera.z=0;
camera.pan=0;
camera.tilt=0;
while (1){
//camera.pan -= mouse_force.x*2;
//camera.tilt += mouse_force.y*2;
if (mouse_left == 1){
if(proc_status(tracer_right) < 5)
{
gun1=ent_create(NULL,NULL,tracer_right);
}
if(proc_status(tracer_left) < 5)
{
gun2=ent_create(NULL,NULL,tracer_left);
}
}
wait(1);
}
}

The routine as it is will show 2 lasers firing to a fixed point in the middle. What I need is that when I uncomment the 2 lines which allow panning and tilting of the camera the 2 lasers remain firing in the middle and not go to different directions.
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/15/12 16:35

http://tutorial.3dgamestudio.net/

Seriously.

The resource leak still exists btw.
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 18:32

I read those tutorials but they do not say much about vectors. There are many vector commands in the manual which could be helpful for this task but tutorials about them are rare. I think that vec_for_screen or vec_to_screen could be usefull for this task.
Posted By: Ercoles

Re: Need a laser beam particle effect example - 12/15/12 19:57

At last I did it and the solution was really the vec_for_screen command, for the benefit of other people here is the code:


function p_alphafade(PARTICLE *p)
{
p.alpha -= p.skill_a*time_step;
if (p.alpha <= 0) p.lifespan = 0;
}

function p_trace(PARTICLE *p)
{
VECTOR vTemp;
set(p, BRIGHT|TRANSLUCENT|BEAM);
p.size = 1;
p.skill_a = 10; // fade factor
p.event = p_alphafade;
p.red =255;
p.blue=20;
p.green=128;
}

action tracer_right()
{
VECTOR v1;
v1.x = mouse_pos.x;
v1.y = mouse_pos.y;
v1.z = 15;
vec_for_screen(v1,camera);
VECTOR v2;
vec_set(v2, vector(0, 50, -30));
vec_rotate(v2, camera.pan);
effect(p_trace,1,v1,v2);
ent_remove(me);
}

action tracer_left()
{
VECTOR v1;
v1.x = mouse_pos.x;
v1.y = mouse_pos.y;
v1.z = 15;
vec_for_screen(v1,camera);
VECTOR v2;
vec_set(v2, vector(0, -50, -30));
vec_rotate(v2, camera.pan);
effect(p_trace,1,v1,v2);
ent_remove(me);
}

function main()
{
video_screen = 1;
video_mode = 12;
mouse_mode = 4;
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
video_window(NULL,NULL,0,"Laser demo");
camera.x=0;
camera.y=0;
camera.z=0;
camera.pan=0;
camera.tilt=0;
while (1){
//camera.pan -= mouse_force.x*2;
//camera.tilt += mouse_force.y*2;
if (mouse_left == 1){
if(proc_status(tracer_right) < 1)
{
ent_create(NULL,NULL,tracer_right);
}
if(proc_status(tracer_left) < 1)
{
ent_create(NULL,NULL,tracer_left);
}
}
wait(1);
}
}
Posted By: Uhrwerk

Re: Need a laser beam particle effect example - 12/15/12 22:21

Originally Posted By: Ercoles
I read those tutorials but they do not say much about vectors.
My recommendation was not limited to vectors but to general stuff. Your code and your answers show that you're missing important basic knowledge.
Originally Posted By: Ercoles
There are many vector commands in the manual which could be helpful for this task but tutorials about them are rare.

Vector tutorials do not make much sense because they are a tools to achieve things, like bricks for a bricklayer. Now, a tutorial about bricks wouldn't help a brickalyer much, would it? He has to learn about bricks while learning how to lay bricks.
Originally Posted By: Erocles
I think that vec_for_screen or vec_to_screen could be usefull for this task.
You're right about this.

And PLEASE: indent your code and use code tags as Kartoffel already told you.
© 2024 lite-C Forums