3
我想用opengl來製作等距圖紙。使用Opengl的等距投影
據: http://en.wikipedia.org/wiki/Isometric_projection#Mathematics
「,這是通過首先尋找直朝向一個面進行下一步立方體旋轉±45°圍繞豎直軸線,隨後的約±35.264°的旋轉(準確地說反正弦。 (tan 30°)或arctan(sin 45°))。「
但很顯然我錯過了一些細節。這種代碼雖然有些作品,但它卻處於一個奇怪的角度。黃色應該是最底線。
import Graphics.UI.GLFW
import Graphics.Rendering.OpenGL
main :: IO()
main = do
initialize
openWindow (Size 800 600) [] Window
windowTitle $= "Test Projection"
clearColor $= Color4 0 0 0 1
pointSize $= 3
lineWidth $= 1
blend $= Enabled
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
viewport $= (Position 0 0, Size 800 600)
matrixMode $= Projection
loadIdentity
-- ortho (-2) (2) (-2) 2 (-20.0) 20.0
matrixMode $= Modelview 0
loadIdentity
rotate (35.264) (Vector3 1.0 0.0 0.0 :: Vector3 GLfloat)
rotate (-45) (Vector3 0.0 1.0 0.0 :: Vector3 GLfloat)
clear [ColorBuffer]
renderPrimitive Lines $ do
color $ Color3 1 zero zero
vertex' (0,0,0)
vertex' (1,0,0)
color $ Color3 zero 1 zero
vertex' (0,0,0)
vertex' (0,1,0)
color $ Color3 zero zero 1
vertex' (0,0,0)
vertex' (0,0,1)
color $ Color3 1 1 zero
vertex' (1,0,0)
vertex' (0,1,0)
swapBuffers
getChar
return()
vertex' :: Integral a => (a, a, a) -> IO()
vertex' (x, y, z) = vertex (Vertex3 (f x) (f y) (f z))
where f p = fromIntegral p :: GLint
zero :: GLfloat
zero = 0.0
謝謝了。事情現在變得更有意義。 – user1149863 2012-01-15 00:16:37
事實上,我昨晚一直熬到昨天晚上想弄清楚我做錯了什麼。 – user1149863 2012-01-15 00:18:12