Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Particles Generation In An Elliptical PATH

Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-19-2007 03:59
first the concept,

we need to make an object move in an elliptical path, and drop particles as it goes, the following code gives us a circular path...

vector vPosOffset = <.0, .0, 3.0>; //-- a point 3 meters from the top of our object
integer vIntArc = 6.0; //-- number of degrees to travel around the arc each call
rotation vRotArc; //-- where we'll hold the calculated rotation

in state_entry...
vRotArc = llEuler2Rot( <.0, vIntArc * DEG_TO_RAD, .0> );

and our call is...
llSetPrimitiveParams( [PRIM_POSITION, vPosNew,
PRIM_ROTATION, vgRotDegrees * llGetLocalRot()] );

now if viewed from an angle, you'll notice this gives an ellipse shape, so what we do in the below code, is turn the prim a little bit, but ignore the depth of that turn, flattening our circle into the viewed ellipse (there are other ways via math to do this, I was lazy) and then dropping particles as we go...

CODE

//--// Proof of Concept //--//
//-- please note this code is NOT optimal

vector vgVecOffSet = <.0, .0, 3.0>;
float vgIntDegrees = 6.0;
rotation vgRotDegrees;
integer vgBooIsOn;

default{
state_entry(){
//-- this line is just to give us an angle for the circle to flatten
llSetRot( llEuler2Rot( <.0, .0, 45.0> * DEG_TO_RAD ) );
vgRotDegrees = llEuler2Rot( <.0, vgIntDegrees, .0> * DEG_TO_RAD );
llParticleSystem( [PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_DROP,
PSYS_PART_START_COLOR, <1.0, .0, .0>,
PSYS_PART_END_COLOR, <.0, .0, 1.0>,
PSYS_PART_START_SCALE, <.25, .25, .25>,
PSYS_PART_END_SCALE, <.25, .25, .25>,
PSYS_PART_MAX_AGE, 0.0,
PSYS_PART_MAX_AGE, 30.0,
PSYS_SRC_BURST_RATE, 0.0] );
}

touch_start(integer total_number){
vgBooIsOn = !vgBooIsOn;
llSetTimerEvent( .35 * vgBooIsOn );
}

timer(){
vector vPosCurrent = llGetLocalPos();
vector vPosNew = vPosCurrent + (vgVecOffSet - vgVecOffSet * vgRotDegrees) * llGetLocalRot();
vPosNew.y = vPosCurrent.y;
llSetPrimitiveParams( [PRIM_POSITION, vPosNew,
PRIM_ROTATION, vgRotDegrees * llGetLocalRot()] );
}
}

//-- QEF


Further exploration:
a similar effect can be achieved by setting the particles to form at a set distance, and move the object in a line while rotating the first 180deg, and then walking back down the line on the back 180deg. in effect stretching the circle that that is being made by rotating the object...

new thought:
another possibility is to adjust the particle start position from the emitter, while rotating it in increments, this would require no movement (only rotation) but repeated calls to the particle system

if I have time I'll code examples of both those alternatives later, or if someone feels plucky they can add them to this thread =)

thanks go to Debbie Trilling for suggesting this go in the Scripting Library
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
11-25-2007 11:22
library bump-age
_____________________
i've got nothing. ;)