突击队式的视线算法

时间:2010-07-12 10:07:27

标签: algorithm

你能指点我一篇关于视线渲染算法的文章吗?我正在寻找类似于Commandos系列游戏(由Pyro Studios)使用的东西。必须渲染视线锥/三角形(在俯视图中),并且由障碍物引起适当的阴影。 感谢

1 个答案:

答案 0 :(得分:1)

在伪代码中:

function get_visible_objects(observer)

  /* get the list of objects inside the cone of vision */
  in_cone = get_the_objects_inside(observer.cone)

  /* sort the objects by proximity to the observer */
  sorted = in_cone.sort_by_distance_to(observer)

  /* visible is the result. start with all the objects in the cone */
  visible = sorted.copy

  /* parse the objects in the cone, from nearest to the observer to farthest away,
     and remove any objects occluded */
  for each object in sorted do
    /* remove any other object that is occluded by object */
    to_remove = []
    for each other in visible do
      if object.occludes(other) then
        to_remove.add(other)
      end
    end
    visible = visible - to_remove
  end

  return visible
end