我正在使用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
points
)。然后,我想监听按键事件,并在该空间内移动一个Camera
对象。这些点应该根据相机的位置和角度进行渲染。 - sdasdadas