Curving Lightning Bolts
Blitz3D Forums/Blitz3D Programming/Curving Lightning Bolts
| ||
Simple concept, though I'm having one heck of a time making this work the way I want to. Basically, I want to curve my lightning bolts (picture below). I've tried using Sin to interpolate between two positions, but that didn't work out so I'm going to ask here. Basically, I want to create a curve between points A and B. Right now, the bolts are straight-ish lines, like so: Basically, I want them to curve like this: This is the code I'm using at the moment: Function Strike(X#,Y#,Z#,TX#,TY#,TZ#,Amount) SetEmitterLifeSpan 0,Rand(10,20) DX# = TX-X DY# = TY-Y DZ# = TZ-Z For N# = 0 To Amount From# = 1.0-Sin((N/Float(Amount))*90) If N = Amount Or N = 0 Then SetEmitterColorFrom 0,0,0,0,0 SetEmitterColorTo 0,0,0,0,0 Else SetEmitterColorFrom 0,220,255,255,1 SetEmitterColorTo 0,220,255,255,1 EndIf SetEmitterPosition gLightning,X+DX*From,Y+DY*From,Z+DZ*From CreateParticle gLightning Next End Function So what I need help with is figuring out how I can make these bolts arc. I'll probably skim my math book in the mean time, but if anyone knows of a sure-fire way to do this I'd be really grateful. Thanks in advance for any help. |
| ||
Surely if you add a gravity component. The bolts would arc gently to the ground. Just like particles do. |
| ||
There's a problem with that: these bolts wouldn't only go down. In any case, I've got a few ideas that might work (all of which involve Sin and Cos). Wish me luck. |
| ||
good luck. This looks like a great effect! |
| ||
dill: You'd be suprised how cool it looks in real-time :P Anyhow, I decided that I'm gonna just hack it and provide the arc length (in a given direction). That said, results: I'm having way too much fun with this stuff. |
| ||
/me gives the thumbs up |
| ||
Hi Folks, Usual "I'm making this up as I go along" answer from me, but couldn't you wrap your lightning texture around part of a sphere? Don't know if that would work, but I think people have done similar things with textures and cylinders to good effect. Later, Jes |
| ||
Noel, how did you achive the glow effect?. Is it a sphereical mapped texture?. Me get's ideas... |
| ||
Ross: Basically it's just a small portion of the particle texture being stretched across the bolt, as its life decreases it moves the small portion across the bitmap (basically making it slowly shrink and change color and what have you). So, the glow is just part of the bitmap. If you want the code for that process, it's under (in Lotus) c_particle.bb in the UpdateLotusParticles() function in the 'trail' drawing portion of the code (search for "P\Mesh = cP_TRAIL"). No sphere mapping is used. |
| ||
one way that you could do it is besier mapping or for that matter cubic mapping... you chose 3 points and then use it to interpolate between the three points smoothely it works really really well i have made to functions to do this... and some small example code... here ya go, hope it helpsP0 = 100 P1 = 150 P2 = 50 P3 = 100 X0 = 100 X1 = 125 X2 = 175 X3 = 200 SetBuffer BackBuffer() While Not KeyDown(1) Cls Color 255,255,255 Rect X0-5,P0-5,10,10 Rect X1-5,P1-5,10,10 Rect X2-5,P2-5,10,10 Rect X3-5,P3-5,10,10 If MouseDown(1) And MouseX()>X0-5 And MouseX()<X0+5 And MouseY()>P0-5 And MouseY()<P0+5 P0 = MouseY() X0 = MouseX() EndIf If MouseDown(1) And MouseX()>X1-5 And MouseX()<X1+5 And MouseY()>P1-5 And MouseY()<P1+5 P1 = MouseY() X1 = MouseX() EndIf If MouseDown(1) And MouseX()>X2-5 And MouseX()<X2+5 And MouseY()>P2-5 And MouseY()<P2+5 P2 = MouseY() X2 = MouseX() EndIf If MouseDown(1) And MouseX()>X3-5 And MouseX()<X3+5 And MouseY()>P3-5 And MouseY()<P3+5 P3 = MouseY() X3 = MouseX() EndIf Color 255,0,0 For i# = 0.0 To 1.0 Step 0.01 ;Line Quadratic#(i#-0.01,X0,X1,X2),Quadratic#(i#-0.01,P0,P1,P2),Quadratic#(i#,X0,X1,X2),Quadratic#(i#,P0,P1,P2) Line Cubic#(i#-0.01,X0,X1,X2,X3),Cubic#(i#-0.01,P0,P1,P2,P3),Cubic#(i#,X0,X1,X2,X3),Cubic#(i#,P0,P1,P2,P3) Next Flip False Wend Function Quadratic#(t#,P0,P1,P2) Return (1.0-t#)^2*P0 + 2*P1*(t#*(1-t#)) + P2 * t^2 End Function Function Cubic#(t#,P0,P1,P2,P3) Return P0*(1-t#)^3 + 3*P1*(t#*(1-t#)^2) + 3*P2*(t#^2*(1-t#)) + P3*t#^3 End Function if there is anything that u dont understand then let me know and i would be happy to help looks fantastic btw |