2D Ragdolls

Übersicht BlitzBasic Allgemein

Gehe zu Seite 1, 2, 3  Weiter

Neue Antwort erstellen

 

Gast

Betreff: 2D Ragdolls

BeitragSa, Jan 15, 2005 20:31
Antworten mit Zitat
Ich weiß, das meine Frage extrem kompliziert ist, aber hat jemand eine Ahnung, wie man 2D-Ragdolls realisieren kann, also z.B. ein Männchen, das, wenn es von einer Explosion weggerissen wird, realistisch wegfliegt (inklusive hochgerissener Arme etc.) und dann mit dem Oberkörper auf einer Kiste landet, die Beine jedoch herunterhängen.
Ein Beispiel dafür wäre Soldat, das benutzt zwar DirectX, ist aber 2D.

Vielen Dank im Vorraus

Hubsi

BeitragSa, Jan 15, 2005 20:47
Antworten mit Zitat
Benutzer-Profile anzeigen
Wenn ich denn Talent dafür hätte würde ich ganz einfach die komplette Flugphase als animiertes Bild pinseln und die Flugbahn mit einem großen Radius (Sin/Cos) gestalten. Die Steuerung müsste man eben für die kurze Zeit dem Spieler aus der hand nehmen, aber damit kann sicher jeder leben. Die technische Seite ist gar nicht mal so schwer, grafisch ist der Aufwand dafür wohl riesig Very Happy
Den ganzen Doag im Bett umanandflagga und iaz daherkema und meine Hendl`n fressn...

rambo256

BeitragSo, Jan 16, 2005 10:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Naja,ob das die optimale Lösung ist Wink

Ragdoll ist ja eine Art Skelettanimation (scheiss Ausdruck ich weiß Wink ).
Also es basiert auf einzelnen "Knochen",für die dann die Bewegung ausgerechnet wird. Also würde ich auch dementsprechend das grafisch umsetzen,die Spielfigur aufteilen,d.h. alle Extremitäten getrennt,kopf,Fuß,Ober und Unterkörper.
Tja dann das technische... Da hätte ich jetzt im moment keine Ideen für Confused
Asus F53z

Das Leben ist eine reine Konkatenation...

Hubsi

BeitragSo, Jan 16, 2005 11:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Ahso! Mit Ragdolls konnte ich nicht gleich was anfangen, dachte das wär ein Spiel oder so Very Happy Wenn Du das mit richtiger Grafik umsetzen willst wirds extrem schwierig. Mein Grundgedanke wäre dazu die Pos der einzelnen Gelenke Genick, Hüfte, Knie usw. in ein Array zu speichern, durch Lines zu verbinden und bei der Explosion entsprechend zu verschieben. Also die Hüfte etwas nach hinten, den Kopf ein wenig nach unten, blabla. Fragt sich nur ob der Effekt den Aufwand rechtfertigt Very Happy
Den ganzen Doag im Bett umanandflagga und iaz daherkema und meine Hendl`n fressn...

rambo256

BeitragSo, Jan 16, 2005 15:03
Antworten mit Zitat
Benutzer-Profile anzeigen
Klar,weil man das dann für alles verwenden kann!
Man brauch dann auch keine Laufanimation oder sonstige Animationen mehr machen,sondern man sagt dann praktisch: rechtes bein: erheb dich dann linkes bein usw ^^
Damit kann man dann ganz geile reale Sachen mit machen Very Happy
Asus F53z

Das Leben ist eine reine Konkatenation...
 

Klaas

BeitragSo, Jan 16, 2005 15:50
Antworten mit Zitat
Benutzer-Profile anzeigen
so, ich hab mich mal drangesetzt.
Ist nichts komplettes aber evtl ein Ansatz. Natürlich müßtest du für Bilder als Glieder den Winkel zwischen Parent und child errechen. Das sollte aber ja kein Problem sein.

Schaus dir mal an und sieh ob du damit weiterarbeiten kannst
Code: [AUSKLAPPEN]

Graphics 800,600,32,2
SetBuffer(BackBuffer())

Type bone
   Field x#,y#
   Field oldx#,oldy#
   Field offx#,offy#
   Field fric#
   Field length#
   Field parent.bone
End Type

;ein paar Knochen erstellen
a.bone = createBone(350,350,0,0,0.97,Null)
b.bone = createBone(350,350,-10,0,0.8,a)
c.bone = createBone(350,370,0,0,0.8,b)
d.bone = createBone(350,390,0,0,0.8,c)

b.bone = createBone(350,350,10,0,0.8,a)
c.bone = createBone(350,370,0,0,0.8,b)
d.bone = createBone(350,390,0,0,0.8,c)

b.bone = createBone(350,350,0,0,0.7,a)
c.bone = createBone(350,370,0,0,0.7,b)
d.bone = createBone(350,390,0,0,0.7,c)

b.bone = createBone(350,390,7,0,0.97,d)
c.bone = createBone(350,410,0,0,0.97,b)
d1.bone = createBone(350,430,0,0,0.97,c)

b.bone = createBone(350,390,-7,0,0.97,d)
c.bone = createBone(350,410,0,0,0.97,b)
d1.bone = createBone(350,430,0,0,0.97,c)


timer = CreateTimer(25)

While Not KeyHit(1)
   WaitTimer(timer)
   Cls
   
   a\x = MouseX()
   a\y = MouseY()
   
   ;alle knochen berechnen
   For bone.bone = Each bone
      doBone(bone)
   Next
   ;alle knochen zeichnen
   For bone.bone = Each bone
      drawBone(bone)
   Next
   Flip
   
Wend
End

Function doBone(b.bone)   
   If b\parent = Null Then Return

   ;trägheit
   old_dx# = b\x - b\oldx
   old_dy# = b\y - b\oldy
   
   ;werte für den nächsten Durchgang speichern
   b\oldx = b\x
   b\oldy = b\y

   ;trägheit mit reibung anwenden
   b\x = b\x + old_dx * b\fric
   b\y = b\y + old_dy * b\fric

   ;Schwerkraft
   b\y = b\y + 4
   
   ;positions unterschied zwischen parent und child
   dx# = b\x - b\parent\x
   dy# = b\y - b\parent\y
   
   ;abstand zwischen parent und child
   mag# = Sqr(dx^2 + dy^2)
   
   ;unterschied zu der angestrebten länge
   delta# = mag - b\length   
   
   ; wenn der unterschied größer ist als der Schwellwert dann korriegieren
   If Abs(delta) > 0.1 Then
      ;normalisieren
      ; dadurch erhält man einen wert zwischen -1 und 1 der die richtung
      ;der abweichung angibt (Vektorrechnung)
      nx# = dx / mag
      ny# = dy / mag
      
      ;die Position um die Differenz korrigieren
      ;etwas weniger nehmen um aufschwingen zu dämpfen
      b\x = b\x - (nx * delta * 0.99)
      b\y = b\y - (ny * delta * 0.99)
   End If
   
   ;die position noch um den Offset versetzen
   b\x = b\x + b\offx
   b\y = b\y + b\offy
End Function

Function createBone.bone(x#,y#,offx#,offy#,frict#,parent.bone)
   bone.bone = New bone
   bone\x = x + offx
   bone\y = y + offy
   bone\oldx = x + offx
   bone\oldy = y + offy
   bone\offx = offx
   bone\offy = offy
   bone\fric = frict
   bone\parent = parent
   
   If parent <> Null Then
      bone\length = Sqr((bone\x - bone\parent\x)^2 + (bone\y - bone\parent\y)^2)
   End If
   
   
   Return bone
End Function

Function drawBone(bone.bone)
   Color(255,255,255)
   If bone\parent <> Null Then
      Line(bone\x,bone\y,bone\parent\x,bone\parent\y)
   End If
   Color(255,50,50)
   Oval(bone\x-2,bone\y-2,5,5)
End Function
[/code]

rambo256

BeitragSo, Jan 16, 2005 15:55
Antworten mit Zitat
Benutzer-Profile anzeigen
Ey das is cool!!!

Werde vll mal nachher was draus machen...
mal sehen...
Asus F53z

Das Leben ist eine reine Konkatenation...

rambo256

BeitragSo, Jan 16, 2005 16:06
Antworten mit Zitat
Benutzer-Profile anzeigen
Sry für Doppelpost,aber das ist mir gerade erst eingefallen:

Ein Hacken hat das ja mit Ragdoll:

Bei B2D: man kann nicht in Echtzeit rotieren,aber es gibt eine Kollisionsoutine die pixelgenau funktioniert.

Bei B3D: man kann in Echtzeit rotieren,aber es gibt keine pixelgenaue Kollisionsroutine

das ist halt so ein Problem bei dieser Sache Sad
Asus F53z

Das Leben ist eine reine Konkatenation...
 

Klaas

BeitragSo, Jan 16, 2005 16:12
Antworten mit Zitat
Benutzer-Profile anzeigen
Das ist aber kein Problem welches man nicht lösen könnte.

bei B2D: berechnest du einfach die rotierten Bilder vor
auch wen das ein wenig mehr Speicher kostet, das ist bei einem modernen PC doch garkein Problem mehr.

bei B3D: nimmt man zur berechnung der Kollision einfach Bilder (brauchen ja nur 2 farbig sein) zum zeichnen allerdings nimmt man die 3D Engine

Vertex

BeitragSo, Jan 16, 2005 19:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Super Sache mit den Ragdolls!

In wie weit lässt sich da Kollision mit einbauen? Kann ich ein Bone einfach auf Schnitt mit einer anderen linie prüfen und dann zurück setzen? Sprich x#, und y# manuell ändern, ohne das dabei die Länge geändert wird?

mfg olli

Edit: Ok super, das geht wirklich. Hier wenn man mal nur in einen Rahmen das ganze machen will:
Code: [AUSKLAPPEN]
   ;alle knochen berechnen
   For bone.bone = Each bone
      If bone\x# > 500 Then bone\x# = 500
      If bone\y# > 500 Then bone\y# = 500
      If bone\x# < 100 Then bone\x# = 100
      If bone\y# < 100 Then bone\y# = 100
      doBone(bone)
   Next
vertex.dreamfall.at | GitHub
 

Gast

BeitragSo, Jan 16, 2005 19:51
Antworten mit Zitat
So vielen Dank erstmal, aber wies meinst du (Klaas) das eigentlich mit der Kollision in 3D?
Soll ich für jedes Bild 360 zweifarbige Rotationsbilder erstellen? (Das wäre ja extrem viel Aufwand)

stfighter01

BeitragSo, Jan 16, 2005 20:18
Antworten mit Zitat
Benutzer-Profile anzeigen
schätze es reicht wenn du nur alle 5-10 grad ein neues image verwendest.
Denken hilft!
 

Klaas

BeitragSo, Jan 16, 2005 22:20
Antworten mit Zitat
Benutzer-Profile anzeigen
360 Bilder sind wirklich ein wenig zu viel ... je nach größe der Bilder solltest du (wie von stfighter01 vorgeschlagen) größere Winkelschritte wählen.
Du brauchst die Bilder ja auch nicht malen, du kopierst das orginal einfach und rotierst es dann ein stück (in Blitz).

Bei dem 3D meine ich, das man zwar Sprites nimmt um die Bilder darzustellen aber die Kollisionen unsichtbar mittels standart Bitmap kollisionen berechnet. Um die Kollision zu ermitteln braucht man die Bilder ja nicht auf den Screen zu zeichnen.

rambo256

BeitragSo, Jan 16, 2005 22:54
Antworten mit Zitat
Benutzer-Profile anzeigen
Ich hab mal Vertex idee aufgegriffen und versucht sie umzusetzen.Ich habe das dann mit der Funktion intersection_collide() versucht:

Hier die Abfrage der einzelnen Bones:

Code: [AUSKLAPPEN]
Function check_collide(bone.bone)
      
      For l.coll_line = Each coll_Line
       
       If bone\parent <> Null Then
         bone\collide = Lines_Intersect(bone\parent\x,bone\parent\y,bone\x,bone\y,l\x1,l\y1,l\x2,l\y2)
      EndIf
      
      If bone\collide=0 Or bone\collide<0 Or bone\collide>1 Or bone\collide<0 Or bone\collide>1 Then
         
         bone\collide = False
         
         Else

         
         Text 0,0,"true"
         ;bone\x = bone\oldx
         ;bone\y = bone\oldy
            
      EndIf
      

      
      Next
   
End Function


und hier die Funktion die überprüft,ob sich 2 linien schneiden:

Code: [AUSKLAPPEN]
Global intersection_x#                     
Global intersection_y#
Global intersection_ab#
Global intersection_cd#

Function Lines_Intersect(ax#, ay#, bx#, by#, cx#, cy#, dx#, dy#)
  rn# = (ay#-cy#)*(dx#-cx#) - (ax#-cx#)*(dy#-cy#)
  rd# = (bx#-ax#)*(dy#-cy#) - (by#-ay#)*(dx#-cx#)
  If rd# = 0
    Return False
  Else
    sn# = (ay#-cy#)*(bx#-ax#) - (ax#-cx#)*(by#-ay#)
    intersection_ab# = rn# / rd#
    intersection_cd# = sn# / rd#
    intersection_x#  = ax# + intersection_ab#*(bx#-ax#)
    intersection_y#  = ay# + intersection_ab#*(by#-ay#)
    Return True
  EndIf
End Function


So eigentlich dürfte das doch gehen,aber ich bekomme immer nur zurück das er diese linie schneidet:
l\x1 = 200
l\y1 = 200
l\x2 = 300
l\y2 = 200


kann mir jemand vll sagen was ich nicht bedacht habe,sodass es nicht funktioniert Question

THX!


Edit: Arrgh,blöder Anfängerfehler,das muss natürlich so heißen:

Code: [AUSKLAPPEN]
If collide=0 Or intersection_ab#<0 Or intersection_ab#>1 Or intersection_cd#<0 Or intersection_cd#>1 Then
         
         collide = False
         
         Else

         
         Text 0,0,"true"
         ;bone\x = bone\oldx
         ;bone\y = bone\oldy
            
      EndIf
Asus F53z

Das Leben ist eine reine Konkatenation...
 

Klaas

BeitragSo, Jan 16, 2005 23:13
Antworten mit Zitat
Benutzer-Profile anzeigen
@rambo256: ich glaub irgendetwas stimmt nicht mit deinem Line_intersect code .. ich hab mal ein anderen Probiert:

Code: [AUSKLAPPEN]

Global intersection_x#                     
Global intersection_y#
Global intersection_ab#
Global intersection_cd#

Graphics 800,600,32,2
SetBuffer(BackBuffer())

Type bone
   Field x#,y#
   Field oldx#,oldy#
   Field offx#,offy#
   Field vx#,vy#
   Field fric#
   Field length#
   Field parent.bone
   
   Field collide
End Type

Type coll_Line
   Field x1#,y1#
   Field x2#,y2#
End Type

;ein paar Knochen erstellen
a.bone = createBone(350,350,0,0,0.97,Null)
b.bone = createBone(350,350,-10,0,0.8,a)
c.bone = createBone(350,370,0,0,0.8,b)
d.bone = createBone(350,390,0,0,0.8,c)

b.bone = createBone(350,350,10,0,0.8,a)
c.bone = createBone(350,370,0,0,0.8,b)
d.bone = createBone(350,390,0,0,0.8,c)

b.bone = createBone(350,350,0,0,0.7,a)
c.bone = createBone(350,370,0,0,0.7,b)
d.bone = createBone(350,390,0,0,0.7,c)

b.bone = createBone(350,390,7,0,0.97,d)
c.bone = createBone(350,410,0,0,0.97,b)
d1.bone = createBone(350,430,0,0,0.97,c)

b.bone = createBone(350,390,-7,0,0.97,d)
c.bone = createBone(350,410,0,0,0.97,b)
d1.bone = createBone(350,430,0,0,0.97,c)

cl.coll_line = New coll_line
cl\x1 = 50
cl\y1 = 500
cl\x2 = 700
cl\y2 = 550

cl = New coll_line
cl\x1 = 350
cl\y1 = 400
cl\x2 = 400
cl\y2 = 450

timer = CreateTimer(25)

While Not KeyHit(1)
   WaitTimer(timer)
   Cls
   
;   If MouseDown(1)
      a\x = MouseX()
      a\y = MouseY()
;   End If
   
   ;alle knochen berechnen
   For bone.bone = Each bone
      doBone(bone)
      check_collide(bone.bone)
   Next
   ;alle knochen zeichnen
   For bone.bone = Each bone
      drawBone(bone)
   Next
   For cl.coll_line = Each coll_line
      drawColli(cl)
   Next
   
   Flip
Wend
End


Function doBone(b.bone)   
   ;trägheit
   old_dx# = b\x - b\oldx
   old_dy# = b\y - b\oldy
   
   ;werte für den nächsten Durchgang speichern
   b\oldx = b\x
   b\oldy = b\y

   ;trägheit mit reibung anwenden
   b\x = b\x + old_dx * b\fric
   b\y = b\y + old_dy * b\fric

   ;Schwerkraft
   b\y = b\y + 4
   
   ;positions unterschied zwischen parent und child
   If b\parent <> Null Then
      dx# = b\x - b\parent\x
      dy# = b\y - b\parent\y
   End If

   ;abstand zwischen parent und child
   mag# = Sqr(dx^2 + dy^2)
   
   ;unterschied zu der angestrebten länge
   delta# = mag - b\length   
   
   ; wenn der unterschied größer ist als der Schwellwert dann korriegieren
   If Abs(delta) > 0.1 Then
      ;normalisieren
      ; dadurch erhält man einen wert zwischen -1 und 1 der die richtung
      ;der abweichung angibt (Vektorrechnung)
      nx# = dx / mag
      ny# = dy / mag
     
      ;die Position um die Differenz korrigieren
      ;etwas weniger nehmen um aufschwingen zu dämpfen
      b\x = b\x - (nx * delta * 0.99)
      b\y = b\y - (ny * delta * 0.99)
   End If
   
   vx# = b\x - b\oldx
   vy# = b\y - b\oldy
   
   ;die position noch um den Offset versetzen
   b\x = b\x + b\offx
   b\y = b\y + b\offy
   
End Function

Function createBone.bone(x#,y#,offx#,offy#,frict#,parent.bone)
   bone.bone = New bone
   bone\x = x + offx
   bone\y = y + offy
   bone\oldx = x + offx
   bone\oldy = y + offy
   bone\offx = offx
   bone\offy = offy
   bone\fric = frict
   bone\parent = parent
   
   If parent <> Null Then
      bone\length = Sqr((bone\x - bone\parent\x)^2 + (bone\y - bone\parent\y)^2)
   End If
   
   
   Return bone
End Function

Function drawBone(bone.bone)
   Color(255,255,255)
   If bone\parent <> Null Then
      Line(bone\x,bone\y,bone\parent\x,bone\parent\y)
   End If
   Color(255,50,50)
   Oval(bone\x-2,bone\y-2,5,5)
End Function

Function drawColli(co.coll_line)
   Color(20,255,20)
   Line co\x1,co\y1,co\x2,co\y2
End Function

Function check_collide(bone.bone)
   For l.coll_line = Each coll_Line
      If bone\parent <> Null Then
         bone\collide = LinesCross(bone\parent\x,bone\parent\y,bone\x,bone\y,l\x1,l\y1,l\x2,l\y2)
         If bone\collide Then
            bone\x = bone\oldx
            bone\y = bone\oldy
         End If
      EndIf
   Next
End Function

Function LinesCross(x0#,y0#, x1#,y1#, x2#,y2#, x3#,y3# )
    
   n# = (y0#-y2#)*(x3#-x2#) - (x0#-x2#)*(y3#-y2#)
   d# = (x1#-x0#)*(y3#-y2#) - (y1#-y0#)*(x3#-x2#)
   
   If Abs(d#) < 0.0001
      ; Lines are parallel!
      Return False
   Else
      ; Lines might cross!
      Sn# = (y0#-y2#)*(x1#-x0#) - (x0#-x2#)*(y1#-y0#)

      AB# = n# / d#
      If AB#>0.0 And AB#<1.0
         CD# = Sn# / d#
         If CD#>0.0 And CD#<1.0
            ; Intersection Point
            X# = x0# + AB#*(x1#-x0#)
                Y# = y0# + AB#*(y1#-y0#)
            Return True
         End If
      End If
   
      ; Lines didn't cross, because the intersection was beyond the end points of the lines
   EndIf

   ; Lines do not cross!
   Return False

End Function


aber wie du siehst ist das ergebniss nicht so berauschend

mein Vorschlag:

man berechnet die LineIntersektion von den Kollisionslinien zu bone\oldx, bone\oldy, bone\x,bone\y
Damit erhält man die Information ob ein "Vertex" eine Linie durchflogen hat. Dann sollte man den Abprallwinkel berechnen und den Vertex entsprechend bewegen.
Dann würde das Ragdoll schön abprallen.

rambo256

BeitragSo, Jan 16, 2005 23:33
Antworten mit Zitat
Benutzer-Profile anzeigen
jo ich habs schon hinbekommen,aber mein ergebnis gleicht sich deinem,ich mache das jetzt mal so wie du das vorgeschlagen hast,das probier ich mal aus.Hoffe das schaff ich heute noch bis 23:00,wenn nicht dann werde ich mich morgen dransetzen,wenn es die Zeit zulässt.
Asus F53z

Das Leben ist eine reine Konkatenation...

rambo256

BeitragMo, Jan 17, 2005 0:01
Antworten mit Zitat
Benutzer-Profile anzeigen
Sry für Doppelpost,aber ich habe was das umgesetzt was Klaas meinte.
Hier der Code:
Code: [AUSKLAPPEN]


Graphics 800,600,32,2
SetBuffer(BackBuffer())

Type bone
   Field x#,y#
   Field oldx#,oldy#
   Field offx#,offy#
   Field fric#
   Field length#
   Field parent.bone
   Field collide
   Field vx#,vy#
End Type


Type coll_line

  Field x1#,y1#
  Field x2#,y2#

End Type


;Ein paar kollisionslinien erstellen

l.coll_line = New coll_line

l\x1# = 250
l\y1# = 400+x

l\x2# = 500
l\y2# = 400




;ein paar Knochen erstellen
a.bone = createBone(310,350,0,0,0.97,Null)
b.bone = createBone(310,350,-10,0,0.8,a)
c.bone = createBone(310,370,0,0,0.8,b)
d.bone = createBone(310,390,0,0,0.8,c)

b.bone = createBone(310,350,10,0,0.8,a)
c.bone = createBone(310,370,0,0,0.8,b)
d.bone = createBone(310,390,0,0,0.8,c)

b.bone = createBone(310,350,0,0,0.7,a)
c.bone = createBone(310,370,0,0,0.7,b)
d.bone = createBone(310,390,0,0,0.7,c)

b.bone = createBone(310,390,7,0,0.97,d)
c.bone = createBone(310,410,0,0,0.97,b)
d1.bone = createBone(310,430,0,0,0.97,c)

b.bone = createBone(310,390,-7,0,0.97,d)
c.bone = createBone(310,410,0,0,0.97,b)
d1.bone = createBone(310,430,0,0,0.97,c)




timer = CreateTimer(25)

While Not KeyHit(1)
   WaitTimer(timer)
   Cls
   
   If MouseDown(1)
     a\x = MouseX()
     a\y = MouseY()
   End If
   
   ;alle knochen berechnen
   For bone.bone = Each bone
      doBone(bone)
      check_collide(bone.bone)
   Next
   ;alle knochen zeichnen
   For bone.bone = Each bone
      drawBone(bone)
   Next
   For cl.coll_line = Each coll_line
      drawColli(cl)
   Next
   
   Flip
Wend
End


Function doBone(b.bone)   
   ;trägheit
   old_dx# = b\x - b\oldx
   old_dy# = b\y - b\oldy
   
   ;werte für den nächsten Durchgang speichern
   b\oldx = b\x
   b\oldy = b\y

   ;trägheit mit reibung anwenden
   b\x = b\x + old_dx * b\fric
   b\y = b\y + old_dy * b\fric

   ;Schwerkraft
   b\y = b\y + 4
   
   ;positions unterschied zwischen parent und child
   If b\parent <> Null Then
      dx# = b\x - b\parent\x
      dy# = b\y - b\parent\y
   End If

   ;abstand zwischen parent und child
   mag# = Sqr(dx^2 + dy^2)
   
   ;unterschied zu der angestrebten länge
   delta# = mag - b\length   
   
   ; wenn der unterschied größer ist als der Schwellwert dann korriegieren
   If Abs(delta) > 0.1 Then
      ;normalisieren
      ; dadurch erhält man einen wert zwischen -1 und 1 der die richtung
      ;der abweichung angibt (Vektorrechnung)
      nx# = dx / mag
      ny# = dy / mag
     
      ;die Position um die Differenz korrigieren
      ;etwas weniger nehmen um aufschwingen zu dämpfen
      b\x = b\x - (nx * delta * 0.99)
      b\y = b\y - (ny * delta * 0.99)
   End If
   
   vx# = b\x - b\oldx
   vy# = b\y - b\oldy
   
   ;die position noch um den Offset versetzen
   b\x = b\x + b\offx
   b\y = b\y + b\offy
   
End Function

Function createBone.bone(x#,y#,offx#,offy#,frict#,parent.bone)
   bone.bone = New bone
   bone\x = x + offx
   bone\y = y + offy
   bone\oldx = x + offx
   bone\oldy = y + offy
   bone\offx = offx
   bone\offy = offy
   bone\fric = frict
   bone\parent = parent
   
   If parent <> Null Then
      bone\length = Sqr((bone\x - bone\parent\x)^2 + (bone\y - bone\parent\y)^2)
   End If
   
   
   Return bone
End Function

Function drawBone(bone.bone)
   Color(255,255,255)
   If bone\parent <> Null Then
      Line(bone\x,bone\y,bone\parent\x,bone\parent\y)
   End If
   Color(255,50,50)
   Oval(bone\x-2,bone\y-2,5,5)
End Function

Function drawColli(co.coll_line)
   Color(20,255,20)
   Line co\x1,co\y1,co\x2,co\y2
End Function

Function check_collide(bone.bone)
   For l.coll_line = Each coll_Line
      If bone\parent <> Null Then
         bone\collide = LinesCross(bone\oldx,bone\oldy,bone\x,bone\y,l\x1,l\y1,l\x2,l\y2)
         If bone\collide Then
         line_angle = ATan2((l\x2#-l\x1#),(l\y2#-l\y1#))
         coll_angle#= line_angle +180

         bone\x = bone\oldx + (Cos(coll_angle))
         bone\y = bone\oldy + (Sin(coll_angle))
         bone\parent\x = bone\parent\oldx
            bone\parent\y = bone\parent\oldy
         End If
      EndIf
   Next
End Function


Function Anatomie(bone.bone)

   If bone\parent <> Null Then
   
      
   
   EndIf
   

End Function

Function LinesCross(x0#,y0#, x1#,y1#, x2#,y2#, x3#,y3# )
   
   n# = (y0#-y2#)*(x3#-x2#) - (x0#-x2#)*(y3#-y2#)
   d# = (x1#-x0#)*(y3#-y2#) - (y1#-y0#)*(x3#-x2#)
   
   If Abs(d#) < 0.0001
      ; Lines are parallel!
      Return False
   Else
      ; Lines might cross!
      Sn# = (y0#-y2#)*(x1#-x0#) - (x0#-x2#)*(y1#-y0#)

      AB# = n# / d#
      If AB#>0.0 And AB#<1.0
         CD# = Sn# / d#
         If CD#>0.0 And CD#<1.0
            ; Intersection Point
            X# = x0# + AB#*(x1#-x0#)
                Y# = y0# + AB#*(y1#-y0#)
            Return True
         End If
      End If
   
      ; Lines didn't cross, because the intersection was beyond the end points of the lines
   EndIf

   ; Lines do not cross!
   Return False

End Function



Morgen werde ich dann mal schauen,ob ich dann die menschliche anatomie reinbringen kann,also das er stehen kann.
danach versuche ich,ein solches Skelett für die Seitenansicht herzustellen,das ist deswegen problematisch,da es in BB2D keinen z-Buffer gibt.Auch für lines nicht.Wenn dann müsst ich das dann schon in 3D und mit Sprites verwirklichen,aber das kommt erst morgen Smile
Asus F53z

Das Leben ist eine reine Konkatenation...
 

Klaas

BeitragMo, Jan 17, 2005 1:01
Antworten mit Zitat
Benutzer-Profile anzeigen
also mit dem apprallen meinte ich ein wenig anderst.

ich hab leider zu wenig zeit das voll auszuarbeiten aber ich möchte dir noch einen Code-Schnipsel geben der dir evtl. weiter hilft:

Code: [AUSKLAPPEN]

nx# = CollisionNX(game_obj\entity,1)
ny# = CollisionNY(game_obj\entity,1)
nz# = CollisionNZ(game_obj\entity,1)

Velocity# = Sqr(game_obj\Vx#^2 + game_obj\Vy#^2 + game_obj\Vz#^2)

; Calculate the direction vector. The direction vector is a normal and has a length of 1.

Direction_X# = game_obj\Vx# / Velocity#
Direction_Y# = game_obj\Vy# / Velocity#
Direction_Z# = game_obj\Vz# / Velocity#

; If the ball collided with the level, apply ground friction.
Velocity# = Velocity# * bounce_factor

; Make sure the velocity doesn't go negative. You can never have a negative velocity.
If (Velocity# < 0) Then Velocity# = 0
   
; Convert the ball's velocity and direction back into a motion vector.
game_obj\Vx# = Direction_X# * Velocity#
game_obj\Vy# = Direction_Y# * Velocity#
game_obj\Vz# = Direction_Z# * Velocity#
   
; Compute the dot product of the ball's motion vector and the normal of the surface collided with.
VdotN# = game_obj\Vx#*Nx# + game_obj\Vy#*Ny# + game_obj\Vz#*Nz#

; Calculate the normal force.
NFx# = -2.0 * Nx# * VdotN#
NFy# = -2.0 * Ny# * VdotN#
NFz# = -2.0 * Nz# * VdotN#

; Add the normal force to the motion vector.
game_obj\Vx# = game_obj\Vx# + NFx#
game_obj\Vy# = game_obj\Vy# + NFy#
game_obj\Vz# = game_obj\Vz# + NFz#


das ist ein 3D code für korrektes apprallen (einfallswinkel = ausfallswinkel)

Wenn du das auf die Punkte umcodest dann hast du wirkliches apprallen
 

Gast

BeitragMo, Jan 17, 2005 20:09
Antworten mit Zitat
Jaja, das ist ja alles schön und gut, aber nicht unbedingt realistisch, da die Rotation völlig unbeachtet bleibt (Körper dreht sich nicht)
 

Gast

BeitragMo, Jan 17, 2005 20:12
Antworten mit Zitat
Da gibts bei gamedev.net unter articles echt geile beispiele, das problem ist nur, das die OpenGL benutzen.
Werde aber mal versuchen, ob ich das nicht nach BlitzBasic portieren kann...

Gehe zu Seite 1, 2, 3  Weiter

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group