Particles on the screen [SOLVED]

Posted By: VeT

Particles on the screen [SOLVED] - 04/19/09 13:12

Okay, as Jcl said( http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=261620#Post261620 ), i'm trying to

Quote:

You can solve this problem already in world coordinates, in the particle function:

- get the distance vector from the camera to the particle
- rotate this vector by the same euler angle you added to the camera angle.
- get the distance vector from the rotated vector to the original vector
- add this new distance vector to the particle position.

This should keep your particles in front of the camera regardless of the rotation.


i tried
Code:
	var tVec[3];
	var tVec2[3];
	vec_diff(tVec,p.x,camera.x);
	vec_rotate(tVec,camera.pan);
	
	vec_diff(tVec2,p.x,tVec);
	vec_add(p.x,tVec2);


but looking like i missed something ((
PS: I based on the particle flame http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=220514#Post220514
Posted By: VeT

Re: Particles on the screen - 04/20/09 10:05

http://rapidshare.com/files/223527306/TestLevel.rar.html

Okay, here is the level, where you can rotate camera (controls as usual, you press 0 and then cursor left-right keys) and see that particles problem

In Particles.c there is commented(line 40) code:
Code:
	var tVec[3];
	var tVec2[3];
	vec_diff(tVec,p.x,camera.x);
	vec_rotate(tVec,camera.pan);
	
	vec_diff(tVec2,p.x,tVec);
	vec_add(p.x,tVec2);


it seems not to work properly, can anyone help?
Posted By: Poison

Re: Particles on the screen - 04/20/09 10:44

Hey vet, this seems to be working:
but not that good...-.-

Code:
VECTOR tVec;
VECTOR tVec2;
vec_diff(tVec,camera.x,p.x);
vec_rotate(tVec,camera.pan);
	
vec_diff(tVec2,camera.x,tVec);
vec_set(p.x,tVec2);

Posted By: VeT

Re: Particles on the screen - 04/20/09 11:14

hm... with "set" it works better than with "add".. but theoretically it may work better with "add"...
Posted By: EvilSOB

Re: Particles on the screen - 04/20/09 13:16

This is as close as I can get. Not quite the way JCL suggested, but I couldnt get his suggestion to work at all.

This is still a bit "twitchy" when camera movement/rotation starts but that MAY be due to an over-abundance of particles,
the machine Im testing this on is a dog-box....
Code:
//NO changes in any other functions but these two...

function flame_alphafade(PARTICLE *p)
{
	start_color[0] = 200;
	start_color[1] = 180;
	start_color[2] = 100;
	
	end_color[0] = 128;
	end_color[1] = 50;
	end_color[2] = 50;
	
	vec_lerp(current_color[0], end_color[0], start_color[0], p.lifespan / flame_lifespan);

	p.red = current_color[0];
	p.green = current_color[1];
	p.blue = current_color[2];
	
	p.alpha = p.lifespan / flame_lifespan * 100;// * 0.3;
	if (p.alpha <= 0) p.lifespan = 0;
	
	
	VECTOR tVec;
	vec_diff(tVec, p.x, p.skill_x);                             //subtract Old camera position
	vec_rotate(tVec, vec_diff(NULL, camera.pan, p.skill1));     //rotate by old camera pan/tilt/roll
	vec_add(tVec, camera.x);    //add new camera position
	vec_set(p.x, tVec);         //position particle accordingly    
	//
	vec_set(p.skill1, camera.pan);	//set new LAST camera pan/tilt/roll
	vec_set(p.skill_x, camera.x);	//set new LAST camera position
}

// particle function: generates a fading explosion into vel direction
function effect_flame(PARTICLE *p)
{
   var temp[3];
   flame_randomize(temp, 1);
   vec_add (p.vel_x, temp);
   p.bmap = flame_particle;
   p.flags |= (BRIGHT | MOVE | TRANSLUCENT);
   p.lifespan = flame_lifespan;
   p.size = 3;
   vec_set(p.skill1, camera.pan);	//set LAST camera pan/tilt/roll
   vec_set(p.skill_x, camera.x);	//set LAST camera position
   p.event = flame_alphafade; // change to a shorter, faster function
}



Posted By: VeT

Re: Particles on the screen - 04/20/09 13:29

What "dog-box" is? smile very fast or very old?

Crash in the empty pointer in flame_alphafade, i'll study it.
Anyway, thank you for your help, you're great smile
Posted By: VeT

Re: Particles on the screen - 04/20/09 13:37

Code:
	VECTOR tVec;
	VECTOR tVec2;
	vec_diff(tVec, p.x, p.skill_x);                             //subtract Old camera position
	vec_diff(tVec2, camera.pan, p.skill1);
	vec_rotate(tVec, tVec2);     //rotate by old camera pan/tilt/roll
	
	vec_add(tVec, camera.x);    //add new camera position
	vec_set(p.x, tVec);         //position particle accordingly    
	//
	vec_set(p.skill1, camera.pan);	//set new LAST camera pan/tilt/roll
	vec_set(p.skill_x, camera.x);	//set new LAST camera position

WOW laugh laugh laugh laugh
Posted By: EvilSOB

Re: Particles on the screen - 04/20/09 14:07

vec_diff returning a pointer to itself must be a newer version that what you have.
Funny, manual doesnt say so...

Dog-box is ancient old hardware. P4-3Gig, 512M-Ram 128M-Video.

Glad I could help.
© 2024 lite-C Forums