Occlusion System
Blitz3D Forums/Blitz3D Programming/Occlusion System
| ||
Hi, I'm having some problems with an occlusion system. I've reached the point where I need help from a better programmer than me. The problem seems to be with the pre-calculated bounding boxes for each zone in the level map - but I'm not sure of this. The code with level map is here: http://www.octanedigitalstudios.com/downloads/Occlusion.zip Here's just the code: Any help would be much appreciated. Regards, Rogue Vector |
| ||
I think if your just referring to what is being displayed on the text then replace your Occlusion_Update function with this one (you weren't displaying each line on seperate y axis):Function Occlusion_Update(v_playerX#, v_playerY#, v_playerZ#) Text 5,30, "X: " + v_playerX Local n=0 For g_current_zone = Each TZone If (IsInsideZone(v_playerX, v_playerY, v_playerZ, g_current_zone)) n=n+1 Text 5, 60+(n*20), "Zone name: " + g_current_zone\name ;**** TEMPORARILY DE-ACTIVATED UNTIL CORRECT ZONE IS SHOWN ON SCREEN **** ; HAVEN'T BEEN ABLE TO TEST THIS BIT YET. ;If Not(g_last_zone = Handle g_current_zone) ; HideAllZones() ; ShowEntity g_current_zone\entity ; For l_index = 0 To VIS_MAX_ZONES ; ShowEntity g_current_zone\can_see[l_index] ; Next ; g_last_zone = Handle g_current_zone ; Exit ;EndIf ; *********************************************************************** EndIf Next End Function Notice the use of local var n. |
| ||
Okay! But the problem is with the bounding boxes. They're supposed to encapsulate each of the rooms. The system uses the bounding box to determine if the player is inside a particular room. It hides the rooms that cannot be seen based on this determination. It looks like the scale and alignment of the bounding boxes doesn't match the scale and alignment of the level geometry. Regards, Rogue Vector |
| ||
Sorry but I must be missing something, how can you tell. It doesn't appear that your displaying the bounding boxes so I can't see how you know if it's working or not. tis early in the morning (for me), so if I'm missing the obvious then please tell me. but help me to help you :) |
| ||
The bounding boxes are defined mathematically when the level map is loaded. They don't exist as 3D objects. They are described using the following numerical values: [min_X, max_X], [min_Y, max_Y], [min_Z, max_Z] They are stored in the TZone object. It is the calculation of these values that seems to be wrong. But I can't see where I've gone wrong. Regards, Rogue Vector |
| ||
You need to create the bounding boxes by parsing all vertices and get their true world coordinates trough TFormPoint. At least that's what I do with water zones and it seems to work, even with scaled levels. I TForm them before I check them for Min/Max and then store them in an array, and in the inside-zone-check I don't have to TFormPoint anymore. |
| ||
Ah I see, jfk is right, use tformpoint to convert the vertices to 3dworld coords first... i.e.:TFormPoint VertexX#(surface, m),VertexY#(surface, m),VertexZ#(surface, m),zone\entity,0 Then use TFormedX#,TFormedY#,TFormedZ# to get the transformed coords. Hope that helps. |
| ||
Just posting what I wrote in the case it might help you. I'm afraid that I don't have the time to go over it all, but since you wrote your own occlusion system you might get it. Portals. (E.g., what Quake 1/2/3 use, except you have to place the portals yourself or write your own code to generate them and split the meshes accordingly.) A simple bounding box one. (Similar to what you're doing, I think.) Math code needed for both of them. Stack code needed by both. |
| ||
Noel, I'm sure there is some good stuff there, why not put it in the code archives :) |
| ||
I've implemented the TFormPoint stuff and it has improved the system slightly. Here's the latest code for the occlusion system. You'll need to download the test level (see above). Zones 1 and 7 are correctly mapped with a bounding box, but for some reason the other (in-between)zones are still messed up. Regards, Rogue Vector. |
| ||
Well if you have overlapping zones, you may have to show multiple zones. And make sure to compare the players position globally. And as I said, use the world locations of the vertices to store min and max xyz (aka bounding box) of the children. oh yes and don't forget to set min to max and max to min before xou start comparing each childs vertices, somethinglike this:minx=100000 maxx=-100000 for i=1 to countvertices(s) get vertex locations if x < minx then minx=x endif next store bounding box |