BSP Loader | Spieler Leaf ermitteln [ERLEDIGT]

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

marcelkroener

Betreff: BSP Loader | Spieler Leaf ermitteln [ERLEDIGT]

BeitragMo, Mai 12, 2008 18:34
Antworten mit Zitat
Benutzer-Profile anzeigen
Hi.
Ich habe ein Problem mit meinem BSP loader.
Mein Programm braucht das Leaf in dem sich der Spieler befindet um zu wissen welche Teile der Map gerendert werden müssen, aber es findet nicht das richtige Leaf.

Hier mein Code:

Code: [AUSKLAPPEN]
Function checkvis(entity) ;(kamera)
   If entity=0 Then Return 0
   x#=EntityX(entity)
   y#=EntityY(entity)
   z#=EntityZ(entity)
   ;getting the leaf where the player is in
   i=0
   While i<node_count-1 ;Alle Nodes durchgehen
      n_pl=node_planenum(i) ;Plane des Nodes
      pnx#=plane_Vecs(n_pl,0) ;Plane x normal
      pny#=plane_Vecs(n_pl,1) ;Plane y normal
      pnz#=plane_Vecs(n_pl,2) ;Plane z normal
      pnd#=plane_dist(n_pl) ;Distanz von 0|0|0 zum nähesten Punkt der Plane

      p#= pnx*x + pny*y + pnz*z + pnd ;spieler vor oder hinter der Plane?
      
      If p>0 Then ;(in front of plane)
         cnum=1
         ;Debug("Node "+i+": Player is in front of plane "+n_pl)
         ;DebugLog("Node "+i+": Player is in front of plane "+n_pl)
      ElseIf p<0 Then ;(behind the plane)
         cnum=0
         ;Debug("Node "+i+": Player is behind the plane "+n_pl)
         ;DebugLog("Node "+i+": Player is behind the plane "+n_pl)
      EndIf
      
      child=node_children(i,cnum)  ;wenn spieler vor der Plane dann linkes child sonst rechtes
      If Sgn(child)>=0 Then   ;wenn child index positiv dann
      i=child ;springe zum child node
      ElseIf Sgn(child)<0 Then ;wenn negativ dann
         player_leaf= -(child+1) ;leaf gefunden
         Exit
      EndIf   
   Wend
   
For i=0 To face_count-1
   EntityColor face_id(i),255,255,255
Next

For i=0 To leaf_count-1
   If i=player_leaf Then
      For i2=leaf_firstleafface(i) To leaf_firstleafface(i)+leaf_numleaffaces(i)-1
         EntityColor face_id(leafface_index(i2)),255,0,0 ;aktuelles leaf rot einfärben
      Next
   EndIf
Next
   
   Return player_leaf
End Function


Ich hab schon vieles ausprobiert, ich kriegs einfach nicht hin.
Die Formel (p#= pnx*x + pny*y + pnz*z + pnd) müsste richtig sein, steht ja auch in der Dokumentation zum BSP file format.
Der Rest scheint auch richtig zu sein.
Vielleicht findet ihr ja nen Fehler, Danke schonmal.

BSP Doku:
http://www.geocities.com/cofrdrbob/bspformat.html
Plane Lump,
Node Lump,
Leaf Lump

BSP Tree erklärung:
http://qxx.planetquake.gamespy.com/bsp/

Problem hat sich erledigt.

richtiger code:
Code: [AUSKLAPPEN]
Function checkvis(entity) ;(player)
   If entity=0 Then Return 0
   x#=EntityX(entity)
   y#=EntityY(entity)
   z#=EntityZ(entity)
   ;getting the leaf where the player is in
   i=0
   While i<node_count
      n_pl=node_planenum(i)
      pnx#=plane_Vecs(n_pl,0)
      pny#=plane_Vecs(n_pl,2)
      pnz#=plane_Vecs(n_pl,1)
      pnd#=plane_dist(n_pl)/10
      p#=0

      p= pnx*x + pny*y + pnz*z - pnd
      
      If p>0 Then ;(in front of plane)
         cnum=0
         ;Debug("Node "+i+": Player is in front of plane "+n_pl)
         ;DebugLog("Node "+i+": Player is in front of plane "+n_pl)
      ElseIf p<0 Then ;(behind the plane)
         cnum=1
         ;Debug("Node "+i+": Player is behind the plane "+n_pl)
         ;DebugLog("Node "+i+": Player is behind the plane "+n_pl)
      EndIf
      
      child=node_children(i,cnum)
      If Sgn(child)>0 Then   
      i=child
      ElseIf Sgn(child)<1 Then
         player_leaf= -(child+1)
         Exit
      EndIf   
   Wend
   
For i=0 To face_count-1
   EntityColor face_id(i),255,255,255
Next

For i=0 To leaf_count-1
   If i=player_leaf Then
      For i2=leaf_firstleafface(i) To leaf_firstleafface(i)+leaf_numleaffaces(i)-1
         EntityColor face_id(leafface_index(i2)),255,0,0
      Next
   EndIf
Next
   
   Return player_leaf
End Function

Plasma

Betreff: hurra

BeitragMi, Mai 14, 2008 22:26
Antworten mit Zitat
Benutzer-Profile anzeigen
es geht weiter ! halt dich ran ..... Shocked

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group