我目前正在使用 Haskell 的 OpenGL 绑定编写一个基本的渲染演示。问题是它几乎不能处理 2000 多个顶点。我的伪代码相当于:
terrain = The set of points generated from [-1...1] x [-1...1] x [-1...1].
camera = Camera at position (xc, yc) with angles (ax, ay, az).
while running:
input = anything that moves the camera's position or angles
projected = []
for point in terrain:
projected.append(camera.perspectiveProjection(point))
renderPoints(projected)
问题(我相信)是我手动将我的三维点中的每一个转换为二维,然后使用 OpenGL 来绘制这些点。
我的问题是:我应该喂 OpenGL 三维点,然后使用 OpenGL 已经烘焙的任何投影吗?
(我觉得我理解透视投影的工作原理——我只是不确定我是否应该手动执行此操作。)
编辑:
以下大部分是我的代码。我已经省略了我认为不言自明的部分,只给出了函数定义。
main :: IO()
main = do
(_progName, _args) <- getArgsAndInitialize
initialDisplayMode $= [DoubleBuffered]
_window <- createWindow "Hello, World"
-- The camera position followed by pitch, yaw and roll.
camera <- newIORef Camera [0,0,0] 0 0 0
displayCallback $= display camera
mainLoop
display :: IORef Camera -> DisplayCallback
display camIO = do
camera <- get camIO
clear [ColorBuffer, DepthBuffer]
clear [ColorBuffer]
renderPrimitive Points $ mapM_ vertex
$ map perspectiveProjection camera points
swapBuffers
postRedisplay Nothing