[Mathe, minib3d] 3D-Gravitiation im Planetensystem

Übersicht BlitzMax, BlitzMax NG Allgemein

Neue Antwort erstellen

ZEVS

Betreff: [Mathe, minib3d] 3D-Gravitiation im Planetensystem

BeitragFr, Sep 02, 2011 16:27
Antworten mit Zitat
Benutzer-Profile anzeigen
Dieser Thread wurde als Folge dieses Beitrages erstellt. Hätte ich aber vorher machen sollen.

Die folgenden Funktionen enthalten einen Fehler, der mein Projekt auf Eis gelegt hat. Beide funktionieren eigentlich ganz gut, aber bei einer Kombination komme ich irgendwann auf falsche Ergebnisse.
BlitzMax: [AUSKLAPPEN]
Function getVector:Float[](pitch#, yaw#, radius#)
Local result:Float[3]

pitch = (pitch+360) Mod 360
yaw = (yaw +360) Mod 360

'50% Ausprobieren + 50% Mathe -> diese Lösung

result[0] = Sin(yaw)*Cos(pitch)*radius
result[1] = Sin(pitch)*radius
result[2] = -Cos(pitch)*Cos(yaw)*radius

Return result
End Function

Function getVectorInfo:Float[](x#, y#, z#)
Local result:Float[2]
'thank you, Noobody; https://www.blitzforum.de/forum/viewtopic.php?p=297457#297457

result[0] = (ATan2(y, Sqr(x*x + z*z))+360) Mod 360
result[1] = (ATan2(-z, -x) - 90 +360) Mod 360

Return result
End Function

Ziel: Dreidimensionale Gravitationsunterstützung als Planetensystem. Heißt: Winkel -> Vektor, Vektor aktualisieren und Vektor -> Winkel. Scheitert so aber Sad

Ein Test (beide Kegel sollten immer exakt parallel sein, was bei pitch > 180° aber nicht mehr klappt)
Code: [AUSKLAPPEN]
SuperStrict

Import sidesign.minib3d

Const sx:Int=800,sy:Int=600

Graphics3D sx,sy,16,2

Local cam:TCamera=CreateCamera()
CameraRange cam,.5,500
PositionEntity cam,0,0,-50

Local light:TLight=CreateLight(1)
RotateEntity light,90,0,0
PositionEntity light, 0, 5, -25

Global cone:TMesh = CreateCone()
RotateMesh cone, 90, 0, 0
ScaleEntity cone, 2, 2, 10

Global cone2:TMesh = CreateCone()
RotateMesh cone2, 90, 0, 0
ScaleEntity cone2, 2, 2, 10
PositionEntity cone2, 10, 0, 0
EntityColor cone2, 255, 0, 0

Local sphere:TMesh = CreateSphere()
EntityColor sphere, 0, 0, 255

Const radius%= 12

OnEnd cleanUp

Function cleanUp()
  GCCollect
End Function

Local timer:TTimer = CreateTimer(60)
Global pitch#, yaw#, roll#

Repeat
  If KeyDown(KEY_P) Then
    If KeyDown(KEY_LEFT) Then
      pitch :- 1
    ElseIf KeyDown(KEY_RIGHT)
      pitch :+ 1
    EndIf
  ElseIf KeyDown(KEY_Y) Then
    If KeyDown(KEY_LEFT) Then
      yaw   :- 1
    ElseIf KeyDown(KEY_RIGHT)
      yaw   :+ 1
    EndIf
  ElseIf KeyDown(KEY_R) Then
    If KeyDown(KEY_LEFT) Then
      roll  :- 1
    ElseIf KeyDown(KEY_RIGHT)
      roll  :+ 1
    EndIf
  EndIf
  pitch :Mod 360
  yaw   :Mod 360
  roll  :Mod 360
  RotateEntity cone, pitch, yaw, roll
  Local pos#[] = getVector(pitch, yaw, radius)
  PositionEntity sphere, EntityX(cone)+pos[0], EntityY(cone)+pos[1], EntityZ(cone)+pos[2]
  'pitch = pos[0]
  'yaw   = pos[1]
  RotateEntity cone, pitch, yaw, roll
  pos = getVector(pitch, yaw, .1)
  MoveEntity cone, pos[0], pos[1], pos[2]
  pos = getVector(EntityPitch(cone2), EntityYaw(cone2), .1)
  MoveEntity cone2, pos[0], pos[1], pos[2]
  UpdateWorld
  RenderWorld
  Text 0, 0,  "Pitch: "+EntityPitch(cone)
  Text 0, 30, "Yaw: "  +EntityYaw(cone)
  Text 0, 60, "Roll: " +EntityRoll(cone)
  Flip
  WaitTimer timer
Until KeyHit(KEY_ESCAPE)



Function normalDeg#(deg#)
  Return (deg+360) Mod 360
End Function
Function degDiff#(deg1#, deg2#)
  deg1 = normalDeg(deg1)
  deg2 = normalDeg(deg2)
  Return Min(deg1-deg2, Min((deg1+360)-deg2, deg1-(deg2+360)))
End Function


Function getVector:Float[](pitch#, yaw#, radius#)
  Local result:Float[5]

  pitch = (pitch+360) Mod 360
  yaw   = (yaw  +360) Mod 360


  result[0] = Sin(yaw)*Cos(pitch)*radius
  result[1] = Sin(pitch)*radius
  result[2] = -Cos(pitch)*Cos(yaw)*radius

     'DEBUG

  Local info:Float[] = getVectorInfo(result[0], result[1], result[2])


  If Abs(info[0] - pitch) > 1 Then
    DebugLog "pitch = "+pitch+"; info[0] = "+info[0]
  EndIf
  If Abs(info[1] - yaw) > 1 Then
    DebugLog "yaw   = "+yaw+"; info[1] = "+info[1]
  EndIf
  If Abs(info[0] - pitch) > 1 Or Abs(info[1] - yaw) > 1 Then
    DebugLog "result[0] = "+result[0]
    DebugLog "result[1] = "+result[1]
    DebugLog "result[2] = "+result[2]
    DebugLog ""
  EndIf

  'result[3] = info[0]
  'result[4] = info[1]



  RotateEntity cone2, info[0], info[1], 0
  Return result
End Function

Function getVectorInfo:Float[](x#, y#, z#)
  Local result:Float[2]
              'thank you, Noobody; http://www.blitzforum.de/forum/viewtopic.php?p=297457#297457

  result[0] = (ATan2(y, Sqr(x*x + z*z))+360) Mod 360
  result[1] = (ATan2(-z, -x) - 90      +360) Mod 360

  'If result[0] >= 90 And result[0] <= 270 Then result[1] = (result[1] + 180) Mod 360

  Return result
End Function

End

einfach die letzten Zeilen ändern und es richtig machen; übersteigt meine (aber nicht eure) Fähigkeiten.

ZEVS

Xeres

Moderator

BeitragFr, Sep 02, 2011 16:33
Antworten mit Zitat
Benutzer-Profile anzeigen
~VERSCHOBEN~

MiniB3D gehört auch nach BlitzMax.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

ZEVS

BeitragFr, Sep 02, 2011 16:50
Antworten mit Zitat
Benutzer-Profile anzeigen
Da hast du aber noch was zu tun:
https://www.blitzforum.de/foru...ht=minib3d
https://www.blitzforum.de/foru...ht=minib3d
https://www.blitzforum.de/foru...ht=minib3d
usw.
Suche doch mal nach minib3d im Forum Blitz3D. Die Meinungen zur Position von minib3d-Fragen ist durchaus kontrovers: https://www.blitzforum.de/foru...272#392272
Midimaster hat Folgendes geschrieben:
grundsätzlich vorneweg: was in B3D geht, geht auch in MiniB3D, also ist das B3D-forum deine beste Quelle.

Es handelt sich hierbei ja um keine spezifische Frage zu minib3d, was den B3Dlern durchaus egal sein könnte, sondern um eine Frage zur 3D-Mathematik. 3D-Fragen gehören in ein Forum, bei dem 3D das Thema ist, wenn es solch ein Forum gibt, das ist meine Meinung.

ZEVS

Xeres

Moderator

BeitragFr, Sep 02, 2011 16:57
Antworten mit Zitat
Benutzer-Profile anzeigen
Solange du ganz spezifisch BlitzMax Code postest, gehört er in die BlitzMax Sektion - so einfach ist das. Rolling Eyes
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group