[B3D]Bezier Spline z.B. für Partikel
Übersicht

![]() |
FoppeleBetreff: [B3D]Bezier Spline z.B. für Partikel |
![]() Antworten mit Zitat ![]() |
---|---|---|
Wie der Name schon vermuten lässt, kann man mit dieser Funktion Bezier Spline Bewegung erzeugen.
Auf konstante Geschwindigkeit habe ich verzichtet, dadurch wird die Berechnung schneller und es lassen sich grosse Partikelwolken damit kontrollieren. In diesem Beispiel werden die Kontrollpunkte des Splines zufällig erzeugt, Ihr könnt die Funktion aber natürlich auch mit anderweitig erzeugten Koordinaten füttern. Wer eine konstante Geschwindigkeit haben will kann sich melden, es sind nur ein paar zusätzliche Zeilen Code. Viel Spass ![]() Code: [AUSKLAPPEN] Graphics3D 800,600,32,2 SetBuffer BackBuffer() frametimer= CreateTimer(30) light=CreateLight(2) LightColor light,50,50,50 PositionEntity light,100,100,100 Global cam=CreateCamera() PositionEntity cam,0,7,-7 RotateEntity cam,45,0,0 CameraClsColor cam,100,100,200 ;--------------------------------------------------------------------------------------------------------------------------- Type particleType Field particlemesh ; Unser PartikelType, CP1,2,3 sind die Kontrollpunkte des Splines, Field ColorR Field ColorB Field ColorG ; die anderen Blitzarrays werden zum Zwischenspeichern benötigt Field CP1#[3] Field CP2#[3] Field CP3#[3] Field WP1#[3] Field WP2#[3] Field VecWP1toCP2#[3] Field VecCP2toWP2#[3] Field percentonPath# End Type Global p.particleType ;---------------------------------------------------------------------------------------------------------------------------- Type trailType Field trailmesh Field alpha# Field destroycounter End Type Global t.trailType ;---------------------------------------------------------------------------------------------------------------------------- Global Particlecount=1 Global TrailsOnOff=0 Global Trailspawn=0 newParticle() ;------------------------------------------------------------------------------------------------------- While Not KeyHit(1) If KeyHit(57) Then newParticle() Particlecount = Particlecount+1 EndIf If KeyHit(28) Then TrailsOnOff = (TrailsOnOff+1) Mod 2 EndIf Trailspawn = (Trailspawn+1) Mod 4 bezierSimple(1) killTrails() UpdateWorld RenderWorld Text 50,550,"Leertaste für neue Partikel" Text 50,565,"Enter für Trails on/off (CPU intensiv bei vielen Partikeln)" Text 650,550,Particlecount WaitTimer frametimer Flip 0 Wend ;---------------------------------------------------------------------------------------------------------- Function newParticle() p.particleType=New particleType p\particlemesh=CreateCube() ScaleEntity p\particlemesh,0.3,0.3,0.3 p\ColorR = Rnd(0,255) p\ColorB = Rnd(0,255) p\ColorG = Rnd(0,255) EntityColor p\particlemesh,p\ColorR,p\ColorB,p\ColorG p\percentonPath=100 ; initialisieren mit 100 für verzögerungsfreien Start ;Kontrollpunkte setzen, alles auf Null für normalen Start oder andere Werte, z.B. für Explosionen p\CP1[1]=0 p\CP1[2]=0 p\CP1[3]=0 p\CP2[1]=0 p\CP2[2]=0 p\CP2[3]=0 p\CP3[1]=0 p\CP3[2]=0 p\CP3[3]=0 End Function ;------------------------------------------------------------------------------------------------------- Function bezierSimple(speed) For p.particleType = Each particleType If p\percentonPath=0 Then ; Berechne WP1 und WP2 aus CP1,2,3 Local VecCP1to2#[3] Local VecCP2to3#[3] VecCP1to2[1] = p\CP2[1]-p\CP1[1] VecCP1to2[2] = p\CP2[2]-p\CP1[2] VecCP1to2[3] = p\CP2[3]-p\CP1[3] VecCP2to3[1] = p\CP3[1]-p\CP2[1] VecCP2to3[2] = p\CP3[2]-p\CP2[2] VecCP2to3[3] = p\CP3[3]-p\CP2[3] p\WP1[1] = p\CP1[1]+VecCP1to2[1]/2 p\WP1[2] = p\CP1[2]+VecCP1to2[2]/2 p\WP1[3] = p\CP1[3]+VecCP1to2[3]/2 p\WP2[1] = p\CP2[1]+VecCP2to3[1]/2 p\WP2[2] = p\CP2[2]+VecCP2to3[2]/2 p\WP2[3] = p\CP2[3]+VecCP2to3[3]/2 ; Berechne Hilfsvektoren p\VecWP1toCP2[1] = p\CP2[1] - p\WP1[1] p\VecWP1toCP2[2] = p\CP2[2] - p\WP1[2] p\VecWP1toCP2[3] = p\CP2[3] - p\WP1[3] p\VecCP2toWP2[1] = p\WP2[1] - p\CP2[1] p\VecCP2toWP2[2] = p\WP2[2] - p\CP2[2] p\VecCP2toWP2[3] = p\WP2[3] - p\CP2[3] EndIf ; Berechne neue Position Local VectoVec#[3] VectoVec[1] = (p\CP2[1] + p\VecCP2toWP2[1]*p\percentonPath/100) - (p\WP1[1] + p\VecWP1toCP2[1]*p\percentonPath/100) VectoVec[2] = (p\CP2[2] + p\VecCP2toWP2[2]*p\percentonPath/100) - (p\WP1[2] + p\VecWP1toCP2[2]*p\percentonPath/100) VectoVec[3] = (p\CP2[3] + p\VecCP2toWP2[3]*p\percentonPath/100) - (p\WP1[3] + p\VecWP1toCP2[3]*p\percentonPath/100) Local nextPosition#[3] nextPosition[1] = p\WP1[1] + (p\VecWP1toCP2[1]*p\percentonPath/100) + (VectoVec[1]*p\percentonPath/100) nextPosition[2] = p\WP1[2] + (p\VecWP1toCP2[2]*p\percentonPath/100) + (VectoVec[2]*p\percentonPath/100) nextPosition[3] = p\WP1[3] + (p\VecWP1toCP2[3]*p\percentonPath/100) + (VectoVec[3]*p\percentonPath/100) ; Bewege Entity PositionEntity p\particlemesh,nextPosition[1],nextPosition[2],nextPosition[3] ; Speichere Fortschritt p\percentonPath = p\percentonPath + speed ; Kontrollpunkte weiterreichen If p\percentonPath>100 Then p\CP1[1]=p\CP2[1] p\CP1[2]=p\CP2[2] p\CP1[3]=p\CP2[3] p\CP2[1]=p\CP3[1] p\CP2[2]=p\CP3[2] p\CP2[3]=p\CP3[3] p\CP3[1]=Rnd(-8,8) ; Hier können neue Waypoints eingefügt werden!!! p\CP3[2]=Rnd(-8,8) p\CP3[3]=Rnd(-8,8) p\percentonPath = 0 EndIf ; Trails machen If TrailsOnOff=1 And Trailspawn = 0 Then t.trailType = New trailType t\trailmesh = CreateCube() t\alpha = 1.0 ScaleEntity t\trailmesh,0.3,0.3,0.3 EntityColor t\trailmesh,p\ColorR,p\ColorB,p\ColorG PositionEntity t\trailmesh,nextPosition[1],nextPosition[2],nextPosition[3] EndIf Next End Function ;----------------------------------------------------------------------------------------------------------------------------- Function killTrails() For t.trailType = Each trailType t\destroycounter = t\destroycounter + 1 t\alpha = t\alpha - 0.01 EntityAlpha t\trailmesh,t\alpha If t\destroycounter = 100 Then FreeEntity t\trailmesh Delete t EndIf Next End Function |
||
HoneschBetreff: lol |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hab 2000 gemacht^^ lol ![]() |
||
Das Leben ist wie ein Computerspiel. Scheiß Handlung aber geile Grafik ! |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group