NaN?

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

N0X

Betreff: NaN?

BeitragSo, Feb 21, 2010 12:43
Antworten mit Zitat
Benutzer-Profile anzeigen
Hey!
Ich programmiere gerade an einem Ego-Shooter.
Wenn ich meine Maus am Anfang sehr stark bewege, wird der gesamte Bildschirm schwarz.
Wenn ich jetzt mit "W,A,S,D" steuere, zeigt er mit DebugLog die Koordinaten: "NaN" an. (bei allen 3)
Warum?

Code: [AUSKLAPPEN]
Const PLY=1,TER=2
Global Sprung,j#,grav# = 1.4
Global dx#,dy#,speed#=2
Global tempFade#,fadeSpeed#=1.4
Global schuss_speed# = 100.0
Global ammo=40,mag=4,health=100,w_schuss

Global drawLochX,drawLochY,drawLochZ

Type schuss
   Field x#,y#,z#
   Field mesh
End Type

;---------------------------------;

timer = CreateTimer(60)

SeedRnd MilliSecs()

Graphics3D 640,480,32,2
SetBuffer BackBuffer()

Global piv = CreatePivot():PositionEntity piv,-500,22,0
Global cam = CreateCamera()
Global cub = LoadMesh("models\weapon_1.3ds",cam)  ;ak47.b3d
PositionEntity cub,8,-5,10                 ;5,-8,13
ScaleEntity cub,.3,.3,.3

Global bullet = LoadMesh("models\bullet.3ds",cub):PositionEntity bullet,0,0,500
HideEntity bullet

monitor = LoadMesh("models\monitor.b3d")
PositionEntity monitor,-350,70,-150

light = CreateLight()
map = LoadMesh("models\map_1.3ds"):PositionEntity map,0,-1,0
Global geg = LoadMesh("models\gegner.3ds"):HideEntity geg
ScaleEntity geg,.3,.3,.3

fade1 = LoadImage("gfx\1.png")
fade2 = LoadImage("gfx\2.png")

Global loch = LoadSprite("gfx\loch.png")

Global s1 = LoadSound("sfx\weapons\glock\glock18-1.wav")
Global s2 = LoadSound("sfx\weapons\glock\glock_sliderelease.wav")

EntityType cam,PLY
EntityType map,TER

EntityRadius cam,20,20

;----------------------------------------------------------------------------|

Collisions PLY,TER,2,2
While Not KeyHit(1)
   WaitTimer(timer)
   
   If tempFade# >= 20.0 Then tempFade# = 20.0
   If tempFade# <= 0.0 Then tempFade# = 0.0
   
   ex = EntityX(cam)
   ey = EntityY(cam)
   ez = EntityZ(cam)+10
   
   move()
   jump()
   mouse()
   shot()
   
   TranslateEntity cam,0,j#,0
   TranslateEntity cam,0,-1,0
   
   ;---------------------;
   Flip 0
   UpdateWorld()
   RenderWorld()
   Text 0,0,EntityX(cam)
   Text 0,12,EntityY(cam)
   Text 0,24,EntityZ(cam)
   
   Text 0,48,"Leben: "+health
   Text 0,60,"Munition: "+ammo
   Text 0,72,"Magazin: "+mag
   
   ;Fadenkreuz
   gX = GraphicsWidth()/2
   gY = GraphicsHeight()/2
   DrawImage fade1,(gX-1.5),(gY-16)-tempFade#
   DrawImage fade1,(gX-1.5),(gY+16)+tempFade#
   DrawImage fade2,(gX-23.5)-tempFade#,(gY+6)
   DrawImage fade2,(gX+8.5)+tempFade#,(gY+6)
Wend
End

Function move()
   If KeyDown(17) Then
      MoveEntity cam,0,0,speed#
      tempFade# = tempFade# + fadeSpeed#
   EndIf
   
   If KeyDown(31) Then
      MoveEntity cam,0,0,-speed#
      tempFade# = tempFade# + fadeSpeed#
   EndIf
   
   If KeyDown(30) Then
      MoveEntity cam,-speed#,0,0
      tempFade# = tempFade# + fadeSpeed#
   EndIf
   
   If KeyDown(32) Then
      MoveEntity cam,speed#,0,0
      tempFade# = tempFade# + fadeSpeed#
   EndIf
   
   If KeyDown(42) Or KeyDown(54) Then
      speed# = 4
   Else
      speed# = 2
   EndIf
   
   If Not(KeyDown(17) Or KeyDown(31) Or KeyDown(30) Or KeyDown(32)) Then
      tempFade# = tempFade# -1.4
   EndIf
   
   If KeyHit(57) Then j# = 8:Sprung = 1
End Function

Function jump()
   If Sprung = 1 Then
      j# = (j# - 0.3)
      If j# <= 0 Then
         j# = 0
         j# = (j# - grav#)
         If EntityCollided(cam,TER) Then Sprung = 0
      EndIf
   EndIf
   
   If Sprung = 0 Then S# = -1
End Function

Function mouse()
   ;dx#=(GraphicsWidth()/2-MouseX())*0.2
   ;dy#=(GraphicsHeight()/2-MouseY())*0.2
   ;TurnEntity cam,-dy,dx,0
   ;RotateEntity cam,EntityPitch(cam,1),EntityYaw(cam,1),0,1
   ;MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
   RotateEntity cam,EntityPitch(cam)+MouseYSpeed(),EntityYaw(cam)-MouseXSpeed(),0
End Function

Function shot()
   Local mh = MouseHit(1)
   If mh Then
      w_schuss = 1
      ammo = ammo-1
      If ammo=0 Then mag=mag-1:ammo=40
      If ammo >= 0 And mag >= 0 Then
         PlaySound(s1)
      Else
         ammo=0
         mag=0
         PlaySound(s2)
      EndIf
      s.schuss = New schuss
      s\mesh = CopyEntity(bullet)
      EntityParent s\mesh,0
      PositionEntity s\mesh,EntityX(cam),EntityY(cam),EntityZ(cam);-488,EntityY(cam)+19,EntityZ(cam)-5
      RotateEntity s\mesh,EntityPitch(cam),EntityYaw(cam),0
   Else
      w_schuss = 0
   EndIf
   For s.schuss = Each schuss
      MoveEntity s\mesh,0,0,schuss_speed#
      If EntityCollided(s\mesh,TER) Then
         drawLochX = EntityX(s\mesh)
         drawLochY = EntityY(s\mesh)
         drawLochZ = EntityZ(s\mesh)
         FreeEntity s\mesh
         Delete s.schuss
      EndIf
      If EntityDistance(cam,s\mesh) >=3000 Then
         FreeEntity s\mesh
         Delete s.schuss
      EndIf
      PositionEntity loch,drawLochX,drawLochY,drawLochZ
   Next
End Function


Mfg,
N0X
Projekte: |Tibario| http://www.blitzforum.de/worklogs/325/ | 5%

Nicdel

BeitragSo, Feb 21, 2010 13:02
Antworten mit Zitat
Benutzer-Profile anzeigen
Du bist irgendwo im Nichts. NaN steht für "Not an Number", also eine Zahl, die nicht mehr verarebeitet werden kann, da sie zu klein (?) ist.
Desktop: Intel Pentium 4 2650 Mhz, 2 GB RAM, ATI Radeon HD 3850 512 MB, Windows XP
Notebook: Intel Core i7 720 QM 1.6 Ghz, 4 GB DDR3 RAM, nVidia 230M GT, Windows 7
 

mDave

BeitragSo, Feb 21, 2010 13:40
Antworten mit Zitat
Benutzer-Profile anzeigen
Liegt das nicht daran, dass eine Variable fast 0 ist, und dann durch diese Variable geteilt wird?

hazumu-kun

BeitragSo, Feb 21, 2010 20:56
Antworten mit Zitat
Benutzer-Profile anzeigen
NaN ensteht bei Division durch 0 und zuweisung an einen Float.
Float kann per Definition +infinity, -infinity und NaN speichern.
Warum kann es keine omnipotente Macht geben?
Weil diese omnipotente Macht in der Lage sein müsste, einen so schweren Stein zu schaffen, dass sie ihn nicht heben kann
-> nicht omnipotent

Silver_Knee

BeitragSo, Feb 21, 2010 21:01
Antworten mit Zitat
Benutzer-Profile anzeigen
NaN heißt not a number und entsteht daher bei sachen wie Negative wurzel ziehen log(0) oder eben durch null zu teilen

Xeres

Moderator

BeitragSo, Feb 21, 2010 21:07
Antworten mit Zitat
Benutzer-Profile anzeigen
...oder einfach nur so Rolling Eyes
Kamerakoordinaten Speichern und ggf. zurücksetzten.

Code: [AUSKLAPPEN]
Function CheckNaN(Value#)
   ;   http://www.blitzbasic.com/Community/posts.php?topic=38467#426479
   Return (Value + 1) = Value
End Function
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)

FireballFlame

BeitragSo, Feb 21, 2010 21:59
Antworten mit Zitat
Benutzer-Profile anzeigen
Deine Funktion ist nicht ganz richtig, Xeres, die gibt nämlich nicht nur bei NaN True zurück, sondern auch bei Infinity und sehr großen Zahlen. Wink

Bessere Variante:
BlitzBasic: [AUSKLAPPEN]
Function isNaN(Value#)
Return Value=1 And Value=0
End Function
PC: Intel Core i7 @ 4x2.93GHz | 6 GB RAM | Nvidia GeForce GT 440 | Desktop 2x1280x1024px | Windows 7 Professional 64bit
Laptop: Intel Core i7 @ 4x2.00GHz | 8 GB RAM | Nvidia GeForce GT 540M | Desktop 1366x768px | Windows 7 Home Premium 64bit

Xeres

Moderator

BeitragMo, Feb 22, 2010 18:24
Antworten mit Zitat
Benutzer-Profile anzeigen
Zugegeben; andererseits sollte jeder dieser Möglichkeiten normalerweise nicht vorkommen.
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 BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group