Entitydistance(A,B)
Blitz3D Forums/Blitz3D Programming/Entitydistance(A,B)
| ||
Just wondering if anyone could tell me conclusively if the entitydistance causes a considerable performance hit when it is used per cycle (each game loop pass) I already stagger my line picks / entity picks etc, but wondered if I should look at limiting the calls to entitydistance(a,b)a little.... Also, any ideas on how I might approach replacing my rocket smoke particle system (At the moment,my particle system makes puffs of white smoke particles appear at each pass...but have large gaps between particles when my rocket is at top-speed How can I create continuous lines of smoke trails that are always solid regardless of the speed of the emitter (rocket) |
| ||
EntityDistance - not a performance hit, not much different than calculating it yourself with as sqr(dx^2 + dy^2 +dz^2) which unless you are performing thousands each frame should not be an issue. Can't help with your particle effects though... |
| ||
Thermo, that would be hard to do, as your ship will be moving say 2 units per second, and the emitter will be laying down particles from the ships position. Only thing i can suggest is taking the ships last position and current position and creating particles in between. This will increase your particle count however, so you may want to decrease each particles life time to compensate. How to determine a solid line of particles: You would need to take the particles size, and make sure the speed the ship is travelling at, is NOT greater than the particle size. If it is, you won't get a solid line of particles. |
| ||
Thanks Ross. I've been thinking how to approach this and would love to move away from using sprite based emitters. This is due to their limited use in resizing /aligning etc. What if any given smoke-puff began it's life at the same length and approximate shape of the launching missile (SAM)....perhaps a Quad / 3ds Mesh etc. The texture mapped to the mesh would be roughly a rectangle...hazy at the edges to depict smoke... Now lets keep the rocket straight and unwavering on it's trajectory, just for the sake of simplification for this example. As the missiles speed increases, the length of the mesh grows accordingly (some how) Wouldn't this work as a continuous stream of equally spaced (joined)smoke trail? Has anyone else out there managed to do this? Or achieved smoke trails in a better way than just particle blobs? Now I am totally off the subject matter of which I started this thread...apologies. |
| ||
Just fire out 5-6 partcicles behind the missle, each with their own velocity with slight speed variation between the half of the missle's speed and it's full speed and slight size variation. This is by no means working code but will give you more info on the functions involved : Call PARTICLEinit before you main loop Call PARTICLEcreate as and when required Call PARTICLEupdate each loop Call PARTICLEreset when you need to clear them all Type Particle Field Mesh Field Life# Field Vx#, Vy#, Vz# End Type Global PARTICLEnext.Particle PARTICLEinit( 100 ) ;========================================================= ;========================================================= ;========================================================= Function PARTICLEinit( MaxParticles ) ;create MaxParticles for recycling For l = 1 To MaxParticles p.particle = New particle p\Mesh = CopyEntity( PARTICLEmesh ) : HideEntity p\Mesh p\Life = 0 Next PARTICLEnext = First p End Function ;========================================================= ;========================================================= ;========================================================= Function PARTICLEcreate( Emitter , OffsetZ# , Speed# , Number = 5 ) For No = 1 To Number p.particle = PARTICLEnext ;reset life and show p\Life = 1.0 ShowEntity p\Mesh ;get world coords of emitter offset and position particle there TFormPoint Emitter, 0,0, OffsetZ PositionEntity p\Mesh, TFormedX(), TFormedY(), TFormedZ() ;get velocity TFormVector Emitter, Rnd(-.1, .1 ) * Speed, Rnd(-.1, .1 ) * Speed, Rnd(.5, 1 ) * Speed p\Vx = TFormedX() p\Vy = TFormedY() p\Vz = TFormedZ() ;recycle PARTICLEnext = After p If p = Null PARTICLEnext = First Particle Next End Function ;========================================================= ;========================================================= ;========================================================= Function PARTICLEupdate() For p.particle = Each particle ;only move particles that are alive If p\Life > 0 p\Life = p\Life - .01 : If p\Life < 0 p\Life = 0 If p\Life = 0 HideEntity p\Mesh Else TranslateEntity p\Mesh, p\Vx, p\Vy, p\Vz EntityAlpha p\Mesh, p\Life EndIf EndIf Next End Function ;========================================================= ;========================================================= ;========================================================= Function PARTICLEreset() ;reset all particles For p.particle = Each particle p\Life = 0 HideEntity p\Mesh Next End Function |
| ||
Thanks Stevie.... Will give it a go! |
| ||
yes, basically, the method you're looking for (for the particles) would be basic interpolation. First, you establish a number to represent the particle density, how far away each trail particle should be from another. You can then use this number in coordination with the delta XYZ of the missile, and with some simple division, you can get solid interpolation. I'd write out the math for you, but that takes the fun out of programming (and you'll learn nothing being spoon-fed algorithms) In reference to the EntityDistance calls, it's not very laggy, it's just a simple math function. However, people often make the mistake of using this for AI. For example, say there are 10000 enemy AI's, and one good guy AI. You want to make the good guy AI locate which enemy is closest, and attack it. You just ran your head into a concrete wall yesterday, so you decide to call EntityDistance on each enemy AI in reference to the good guy AI. You run it up to find that you're getting 2 frames per second, because, alas, you're performing: sqr((x-x1)^2 + (y-y1)^2 + (z-z1)^2) 10,000 times per frame If you must use this command in large amounts, it's much more efficient to do a two dimensional distance function: sqr((x-x1)^2 + (y-y1)^2) |
| ||
A modern computer should handle 10000 calls to Entitydistance with little fuss. The speed of a 3d vs 2d version of Distance is going to be negligible, even with 10000 calls. If you must use a 2d version of Distance, just compare the squared distance. The below is more efficient than (x-x1)^2 etc... but likely LESS efficient than using the native EntityDistance function which defeats the purpose. ;Is Distance < 100 Distance# = ( (x-x1) * (x-x1) + (y-y1) * (y-y1) ) If Distance < ( 100 * 100 ) { Do Something } |