aeroson

C# Portal Based Occlusion Culling usage

Nov 8th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2. Occlusion.ConvexPolygon CreatePolygonFor(VoxelDungeon.Corridor corridor, VoxelDungeon.Corridor.PositionNode pathNode)
  3. {
  4.  
  5. Vector3 pos = new Vector3(pathNode.position.x, mapData.config.groundPlaneHeight, pathNode.position.y) - Vector3.one;
  6. float h = corridor.height+2;
  7.  
  8. int width = corridor.width;
  9. int wStart = width / 2;
  10. int wEnd = width - wStart;
  11.  
  12. Quaternion rot;
  13. if(MapData.IsHorizontalFromTop(pathNode.direction)) rot=Quaternion.LookRotation(new Vector3(1,0,0), Vector3.up);
  14. else rot=Quaternion.LookRotation(new Vector3(0,0,1), Vector3.up);
  15.  
  16. var polygon = new Occlusion.ConvexPolygon();
  17. polygon.points.Add(rot * new Vector3(-wStart, h, 0) + pos);
  18. polygon.points.Add(rot * new Vector3(wEnd, h, 0) + pos);
  19. polygon.points.Add(rot * new Vector3(wEnd, 0, 0) + pos);
  20. polygon.points.Add(rot * new Vector3(-wStart, 0, 0) + pos);
  21. return polygon;
  22. }
  23.  
  24.  
  25. void Update()
  26. {
  27. if (!isGenerated) return;
  28.  
  29. Camera cam = manager.camera.current;
  30. Vector3 poi = cam.transform.position;// manager.actor.player.position;
  31.  
  32. Int3 poii = WorldToLocal(poi);
  33.  
  34. VoxelDungeon.OwnerNode owner = null;
  35. for (int i = 0; i < 8 && owner == null; i++)
  36. {
  37. owner = mapData.GetOwnerAt(
  38. poii.x + tilesOffsets[i, 0],
  39. poii.y + tilesOffsets[i, 1],
  40. poii.z + tilesOffsets[i, 2]
  41. );
  42.  
  43. }
  44. if (owner == null) return;
  45.  
  46. NodeData node;
  47. if (!voxelMapNodeToContainer.TryGetValue(owner, out node)) return;
  48.  
  49. node.occlusionArea.StartPropagate(cam);
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment