minib3d - Hilfe bei Picking GELÖST
Übersicht

ShamanBetreff: minib3d - Hilfe bei Picking GELÖST |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
ich hab minib3d so geändert, dass manche Mesh's nicht in die Renderlis aufgenommen werden.
Also muss man sich um picking + rendern selber kümmern. Dabei ist ein Problem beim Picking aufgekommen. Ich hab einen haufen von Objekten, die in einem 3d-raster mit zellen-länge 1 angeordnet sind (Minecraft-style). Ich kann auch abfragen, ob an einer Position eine Box sich befindet (absolute Koordinaten). Allerdings funktionniert das Picking nicht: Code: [AUSKLAPPEN] Method CameraPick:TVector(cam:TCamera,vx#,vy#) vy#=TGlobal.height-vy# Local px! Local py! Local pz! gluUnProject(vx#,vy#,0.0,cam.mod_mat!,cam.proj_mat!,cam.viewport,Varptr px!,Varptr py!,Varptr pz!) Local x#=Float(px!) Local y#=Float(py!) Local z#=-Float(pz!) gluUnProject(vx#,vy#,1.0,cam.mod_mat!,cam.proj_mat!,cam.viewport,Varptr px!,Varptr py!,Varptr pz!) Local x2#=Float(px!) Local y2#=Float(py!) Local z2#=-Float(pz!) _picked = Pick(x:Float, y:Float, z:Float, x2:Float, y2:Float, z2:Float) Return _picked End Method Method Pick:TVector(x:Float,y:Float,z:Float,x2:Float,y2:Float,z2:Float) Local source:TVector = TVector.Create(x,y,z) Local dir:TVector = TVector.Create(x2-x,y2-y,z2-z) Local distance:Double = dir.Length() dir.Normalize() 'Print "picking:" 'Print "Distance="+distance 'Print "Source: x="+Int(source.x)+" y="+Int(source.y)+" z="+Int(source.z) 'now, we have a source, a direction and a distance 'so we can walk along the line to find the first box. Local pos:TVector Local i:Float For i=0 To distance Step 0.5 '0.5 for secure pos = source.Add(dir.Multiply(i)) If _isBoxAt(pos.x, pos.y, pos.z) = True Then 'Box found 'Print "Box found" Return pos EndIf Next 'No box found Return Null End Method Der Rückgabewert ist falsch, außerdem ist das ergebnis von den Kamera-einstellungen und position unabhängig. Warum? |
||
- Zuletzt bearbeitet von Shaman am Fr, Okt 14, 2011 10:58, insgesamt einmal bearbeitet
Shaman |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Gelöst:
1: Rundungsfehler, Vectorauflösung von Float auf Double geändert 2: z-Achse vergessen zu invertieren |
||
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group