src/thirdparty/particles/ParticleDLL/action_api.cpp

Go to the documentation of this file.
00001 // action_api.cpp
00002 //
00003 // Copyright 1997-2006 by David K. McAllister
00004 //
00005 // This file implements the action API calls by creating
00006 // action class instances, which are either executed or
00007 // added to an action list.
00008 
00009 #include "papi.h"
00010 #include "ParticleState.h"
00011 
00012 PARTICLEDLL_API void pAvoid(float magnitude, float epsilon, float look_ahead, const pDomain &dom)
00013 {
00014     PAAvoid *S = new PAAvoid();
00015 
00016     S->position = dom.copy();
00017     S->magnitude = magnitude;
00018     S->epsilon = epsilon;
00019     S->look_ahead = look_ahead;
00020 
00021     S->SetKillsParticles(false);
00022     S->SetDoNotSegment(false);
00023 
00024     _GetPState().SendAction(S);
00025 }
00026 
00027 PARTICLEDLL_API void pBounce(float friction, float resilience, float cutoff, const pDomain &dom)
00028 {
00029     PABounce *S = new PABounce();
00030 
00031     S->position = dom.copy();
00032     S->oneMinusFriction = 1.0f - friction;
00033     S->resilience = resilience;
00034     S->cutoffSqr = fsqr(cutoff);
00035 
00036     S->SetKillsParticles(false);
00037     S->SetDoNotSegment(false);
00038 
00039     _GetPState().SendAction(S);
00040 }
00041 
00042 PARTICLEDLL_API void pCopyVertexB(bool copy_pos, bool copy_vel)
00043 {
00044     PACopyVertexB *S = new PACopyVertexB;
00045 
00046     S->copy_pos = copy_pos;
00047     S->copy_vel = copy_vel;
00048 
00049     S->SetKillsParticles(false);
00050     S->SetDoNotSegment(false);
00051 
00052     _GetPState().SendAction(S);
00053 }
00054 
00055 PARTICLEDLL_API void pDamping(const pVec &damping,
00056                               float vlow, float vhigh)
00057 {
00058     PADamping *S = new PADamping;
00059 
00060     S->damping = damping;
00061     S->vlowSqr = fsqr(vlow);
00062     S->vhighSqr = fsqr(vhigh);
00063 
00064     S->SetKillsParticles(false);
00065     S->SetDoNotSegment(false);
00066 
00067     _GetPState().SendAction(S);
00068 }
00069 
00070 PARTICLEDLL_API void pRotDamping(const pVec &damping,
00071                                  float vlow, float vhigh)
00072 {
00073     PADamping *S = new PADamping;
00074 
00075     S->damping = damping;
00076     S->vlowSqr = fsqr(vlow);
00077     S->vhighSqr = fsqr(vhigh);
00078 
00079     S->SetKillsParticles(false);
00080     S->SetDoNotSegment(false);
00081 
00082     _GetPState().SendAction(S);
00083 }
00084 
00085 PARTICLEDLL_API void pExplosion(const pVec &center, float velocity,
00086                                 float magnitude, float stdev, float epsilon, float age)
00087 {
00088     PAExplosion *S = new PAExplosion;
00089 
00090     S->center = center;
00091     S->velocity = velocity;
00092     S->magnitude = magnitude;
00093     S->stdev = stdev;
00094     S->epsilon = epsilon;
00095     S->age = age;
00096 
00097     if(S->epsilon < 0.0f)
00098         S->epsilon = P_EPS;
00099 
00100     S->SetKillsParticles(false);
00101     S->SetDoNotSegment(false);
00102 
00103     _GetPState().SendAction(S);
00104 }
00105 
00106 PARTICLEDLL_API void pFollow(float magnitude, float epsilon, float max_radius)
00107 {
00108     PAFollow *S = new PAFollow;
00109 
00110     S->magnitude = magnitude;
00111     S->epsilon = epsilon;
00112     S->max_radius = max_radius;
00113 
00114     S->SetKillsParticles(false);
00115     S->SetDoNotSegment(true);
00116 
00117     _GetPState().SendAction(S);
00118 }
00119 
00120 PARTICLEDLL_API void pFountain()
00121 {
00122     PAFollow *S = new PAFollow;
00123 
00124     S->SetKillsParticles(true);
00125     S->SetDoNotSegment(true);
00126 
00127     _GetPState().SendAction(S);
00128 }
00129 
00130 PARTICLEDLL_API void pGravitate(float magnitude, float epsilon, float max_radius)
00131 {
00132     PAGravitate *S = new PAGravitate;
00133 
00134     S->magnitude = magnitude;
00135     S->epsilon = epsilon;
00136     S->max_radius = max_radius;
00137 
00138     S->SetKillsParticles(false);
00139     S->SetDoNotSegment(true);
00140 
00141     _GetPState().SendAction(S);
00142 }
00143 
00144 PARTICLEDLL_API void pGravity(const pVec &dir)
00145 {
00146     PAGravity *S = new PAGravity;
00147 
00148     S->direction = dir;
00149 
00150     S->SetKillsParticles(false);
00151     S->SetDoNotSegment(false);
00152 
00153     _GetPState().SendAction(S);
00154 }
00155 
00156 PARTICLEDLL_API void pJet(const pDomain &dom, const pDomain &accel)
00157 {
00158     // ParticleState &PS = _GetPState();
00159 
00160     PAJet *S = new PAJet();
00161 
00162     S->dom = dom.copy();
00163     S->acc = accel.copy();
00164 
00165     S->SetKillsParticles(false);
00166     S->SetDoNotSegment(false);
00167 
00168     _GetPState().SendAction(S);
00169 }
00170 
00171 PARTICLEDLL_API void pKillOld(float age_limit, bool kill_less_than)
00172 {
00173     PAKillOld *S = new PAKillOld;
00174 
00175     S->age_limit = age_limit;
00176     S->kill_less_than = kill_less_than;
00177 
00178     S->SetKillsParticles(true);
00179     S->SetDoNotSegment(false);
00180 
00181     _GetPState().SendAction(S);
00182 }
00183 
00184 PARTICLEDLL_API void pMatchVelocity(float magnitude, float epsilon, float max_radius)
00185 {
00186     PAMatchVelocity *S = new PAMatchVelocity;
00187 
00188     S->magnitude = magnitude;
00189     S->epsilon = epsilon;
00190     S->max_radius = max_radius;
00191 
00192     S->SetKillsParticles(false);
00193     S->SetDoNotSegment(true);
00194 
00195     _GetPState().SendAction(S);
00196 }
00197 
00198 PARTICLEDLL_API void pMatchRotVelocity(float magnitude, float epsilon, float max_radius)
00199 {
00200     PAMatchRotVelocity *S = new PAMatchRotVelocity;
00201 
00202     S->magnitude = magnitude;
00203     S->epsilon = epsilon;
00204     S->max_radius = max_radius;
00205 
00206     S->SetKillsParticles(false);
00207     S->SetDoNotSegment(true);
00208 
00209     _GetPState().SendAction(S);
00210 }
00211 
00212 PARTICLEDLL_API void pMove()
00213 {
00214     PAMove *S = new PAMove;
00215 
00216     S->SetKillsParticles(false);
00217     S->SetDoNotSegment(false);
00218 
00219     _GetPState().SendAction(S);
00220 }
00221 
00222 PARTICLEDLL_API void pOrbitLine(const pVec &p, const pVec &axis,
00223                                 float magnitude, float epsilon, float max_radius)
00224 {
00225     PAOrbitLine *S = new PAOrbitLine;
00226 
00227     S->p = p;
00228     S->axis = axis;
00229     S->axis.normalize();
00230     S->magnitude = magnitude;
00231     S->epsilon = epsilon;
00232     S->max_radius = max_radius;
00233 
00234     S->SetKillsParticles(false);
00235     S->SetDoNotSegment(false);
00236 
00237     _GetPState().SendAction(S);
00238 }
00239 
00240 PARTICLEDLL_API void pOrbitPoint(const pVec &center, float magnitude, float epsilon, float max_radius)
00241 {
00242     PAOrbitPoint *S = new PAOrbitPoint;
00243 
00244     S->center = center;
00245     S->magnitude = magnitude;
00246     S->epsilon = epsilon;
00247     S->max_radius = max_radius;
00248 
00249     S->SetKillsParticles(false);
00250     S->SetDoNotSegment(false);
00251 
00252     _GetPState().SendAction(S);
00253 }
00254 
00255 PARTICLEDLL_API void pRandomAccel(const pDomain &dom)
00256 {
00257     PARandomAccel *S = new PARandomAccel();
00258 
00259     S->gen_acc = dom.copy();
00260     S->SetKillsParticles(false);
00261     S->SetDoNotSegment(false);
00262 
00263     _GetPState().SendAction(S);
00264 }
00265 
00266 PARTICLEDLL_API void pRandomDisplace(const pDomain &dom)
00267 {
00268     PARandomDisplace *S = new PARandomDisplace();
00269 
00270     S->gen_disp = dom.copy();
00271     S->SetKillsParticles(false);
00272     S->SetDoNotSegment(false);
00273 
00274     _GetPState().SendAction(S);
00275 }
00276 
00277 PARTICLEDLL_API void pRandomVelocity(const pDomain &dom)
00278 {
00279     PARandomVelocity *S = new PARandomVelocity();
00280 
00281     S->gen_vel = dom.copy();
00282     S->SetKillsParticles(false);
00283     S->SetDoNotSegment(false);
00284 
00285     _GetPState().SendAction(S);
00286 }
00287 
00288 PARTICLEDLL_API void pRandomRotVelocity(const pDomain &dom)
00289 {
00290     PARandomRotVelocity *S = new PARandomRotVelocity();
00291 
00292     S->gen_vel = dom.copy();
00293     S->SetKillsParticles(false);
00294     S->SetDoNotSegment(false);
00295 
00296     _GetPState().SendAction(S);
00297 }
00298 
00299 PARTICLEDLL_API void pRestore(float time_left, bool vel, bool rvel)
00300 {
00301     PARestore *S = new PARestore;
00302 
00303     S->time_left = time_left;
00304     S->restore_velocity = vel;
00305     S->restore_rvelocity = rvel;
00306 
00307     S->SetKillsParticles(false);
00308     S->SetDoNotSegment(false);
00309 
00310     _GetPState().SendAction(S);
00311 }
00312 
00313 PARTICLEDLL_API void pSink(bool kill_inside, const pDomain &dom)
00314 {
00315     PASink *S = new PASink();
00316 
00317     S->position = dom.copy();
00318     S->kill_inside = kill_inside;
00319 
00320     S->SetKillsParticles(true);
00321     S->SetDoNotSegment(false);
00322 
00323     _GetPState().SendAction(S);
00324 }
00325 
00326 PARTICLEDLL_API void pSinkVelocity(bool kill_inside, const pDomain &dom)
00327 {
00328     PASinkVelocity *S = new PASinkVelocity();
00329 
00330     S->velocity = dom.copy();
00331     S->kill_inside = kill_inside;
00332 
00333     S->SetKillsParticles(true);
00334     S->SetDoNotSegment(false);
00335 
00336     _GetPState().SendAction(S);
00337 }
00338 
00339 PARTICLEDLL_API void pSort(const pVec &eye, const pVec &look)
00340 {
00341     PASort *S = new PASort;
00342 
00343     S->Eye = eye;
00344     S->Look= look;
00345 
00346     S->SetKillsParticles(false);
00347     S->SetDoNotSegment(true); // WARNING: Particles aren't a function of other particles, but since it can screw up the working set thing, I'm setting it true.
00348 
00349     _GetPState().SendAction(S);
00350 }
00351 
00352 PARTICLEDLL_API void pSource(float particle_rate, const pDomain &dom)
00353 {
00354     ParticleState &PS = _GetPState();
00355 
00356     PASource *S = new PASource();
00357 
00358     S->position = dom.copy();
00359     S->positionB = PS.VertexB->copy();
00360     S->upVec = PS.Up->copy();
00361     S->velocity = PS.Vel->copy();
00362     S->rvelocity = PS.RotVel->copy();
00363     S->size = PS.Size->copy();
00364     S->color = PS.Color->copy();
00365     S->alpha = PS.Alpha->copy();
00366     S->particle_rate = particle_rate;
00367     S->age = PS.Age;
00368     S->age_sigma = PS.AgeSigma;
00369     S->vertexB_tracks = PS.vertexB_tracks;
00370 
00371     S->SetKillsParticles(false);
00372     S->SetDoNotSegment(true); // WARNING: Particles aren't a function of other particles, but does affect the working sets optimizations
00373 
00374     _GetPState().SendAction(S);
00375 }
00376 
00377 PARTICLEDLL_API void pSpeedLimit(float min_speed, float max_speed)
00378 {
00379     PASpeedLimit *S = new PASpeedLimit;
00380 
00381     S->min_speed = min_speed;
00382     S->max_speed = max_speed;
00383 
00384     S->SetKillsParticles(false);
00385     S->SetDoNotSegment(false);
00386 
00387     _GetPState().SendAction(S);
00388 }
00389 
00390 PARTICLEDLL_API void pTargetColor(const pVec &color, float alpha, float scale)
00391 {
00392     PATargetColor *S = new PATargetColor;
00393 
00394     S->color = color;
00395     S->alpha = alpha;
00396     S->scale = scale;
00397 
00398     S->SetKillsParticles(false);
00399     S->SetDoNotSegment(false);
00400 
00401     _GetPState().SendAction(S);
00402 }
00403 
00404 PARTICLEDLL_API void pTargetSize(const pVec &size, const pVec &scale)
00405 {
00406     PATargetSize *S = new PATargetSize;
00407 
00408     S->size = size;
00409     S->scale = scale;
00410 
00411     S->SetKillsParticles(false);
00412     S->SetDoNotSegment(false);
00413 
00414     _GetPState().SendAction(S);
00415 }
00416 
00417 PARTICLEDLL_API void pTargetVelocity(const pVec &vel, float scale)
00418 {
00419     PATargetVelocity *S = new PATargetVelocity;
00420 
00421     S->velocity = vel;
00422     S->scale = scale;
00423 
00424     S->SetKillsParticles(false);
00425     S->SetDoNotSegment(false);
00426 
00427     _GetPState().SendAction(S);
00428 }
00429 
00430 PARTICLEDLL_API void pTargetRotVelocity(const pVec &vel, float scale)
00431 {
00432     PATargetRotVelocity *S = new PATargetRotVelocity;
00433 
00434     S->velocity = vel;
00435     S->scale = scale;
00436 
00437     S->SetKillsParticles(false);
00438     S->SetDoNotSegment(false);
00439 
00440     _GetPState().SendAction(S);
00441 }
00442 
00443 // If in immediate mode, quickly add a vertex.
00444 // If building an action list, call pSource.
00445 PARTICLEDLL_API void pVertex(const pVec &pos, long data)
00446 {
00447     ParticleState &PS = _GetPState();
00448 
00449     if(PS.in_new_list) {
00450         pSource(1, PDPoint(pos));
00451         return;
00452     }
00453 
00454     // Immediate mode. Quickly add the vertex.
00455     pVec siz, up, vel, rvel, col, alpha, posB;
00456     if(PS.vertexB_tracks)
00457         posB = pos;
00458     else
00459         posB = PS.VertexB->Generate();
00460     siz = PS.Size->Generate();
00461     up = PS.Up->Generate();
00462     vel = PS.Vel->Generate();
00463     rvel = PS.RotVel->Generate();
00464     col = PS.Color->Generate();
00465     alpha = PS.Alpha->Generate();
00466     PS.GetPGroup(PS.pgroup_id).Add(pos, posB, up, vel, rvel, siz, col, alpha.x(), PS.Age, PS.Mass, data);
00467 }
00468 
00469 PARTICLEDLL_API void pVortex(const pVec &tip, const pVec &axis,
00470                              float magnitude, float tightnessExponent, float rotSpeed,
00471                              float epsilon, float max_radius)
00472 {
00473     PAVortex *S = new PAVortex;
00474 
00475     S->tip = tip;
00476     S->axis = axis;
00477     S->magnitude = magnitude;
00478     S->tightnessExponent = tightnessExponent;
00479     S->rotSpeed = rotSpeed;
00480     S->epsilon = epsilon;
00481     S->max_radius = max_radius;
00482 
00483     S->SetKillsParticles(false);
00484     S->SetDoNotSegment(false);
00485 
00486     _GetPState().SendAction(S);
00487 }

Generated on Sat Mar 15 22:55:58 2008 for Armagetron Advanced by  doxygen 1.5.4