From 06bd9c421456e483293f823e44167baeefe6db31 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Mon, 21 Apr 2014 19:46:24 +0200 Subject: [PATCH] changed camera to new model --- src/Main.hs | 16 ++++++---------- src/Render/Misc.hs | 4 ++-- src/Types.hs | 3 ++- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 73279e8..469eae5 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -43,11 +43,12 @@ import Graphics.GLUtil.BufferObjects (offset0) import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader -- Our modules import Map.Graphics -import Render.Misc (checkError, createFrustum, getCam, curb, +import Render.Misc (checkError, createFrustum, curb, genColorData) import Render.Render (initRendering, initMapShader, initHud) +import Render.Types import UI.Callbacks import Types import Importer.IQM.Parser @@ -146,10 +147,7 @@ main = , _yAngle = pi/2 , _zDist = 10 , _frustum = frust - , _camPosition = Types.Position - { Types.__x = 25 - , Types.__y = 25 - } + , _camObject = createFlatCam 25 25 } , _io = IOState { _clock = now @@ -209,8 +207,7 @@ draw = do numVert = state ^. gl.glMap.mapVert map' = state ^. gl.glMap.stateMap frust = state ^. camera.frustum - camX = state ^. camera.camPosition._x - camY = state ^. camera.camPosition._y + camPos = state ^. camera.camObject zDist' = state ^. camera.zDist tessFac = state ^. gl.glMap.stateTessellationFactor when (state ^. ui . uiHasChanged) prepareGUI @@ -264,7 +261,7 @@ draw = do checkError "copy projection" --set up camera - let ! cam = getCam (camX,camY) zDist' xa ya + let ! cam = getCam camPos zDist' xa ya with (distribute cam) $ \ptr -> glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat))) checkError "copy cam" @@ -387,8 +384,7 @@ run = do - 0.2 * kyrot * mults mody y' = y' + 0.2 * kxrot * mults - 0.2 * kyrot * multc - modify $ (camera.camPosition._x %~ modx) - . (camera.camPosition._y %~ mody) + modify $ camera.camObject %~ (\c -> moveBy c (\(x,y) -> (modx x,mody y))) {- --modify the state with all that happened in mt time. diff --git a/src/Render/Misc.hs b/src/Render/Misc.hs index 1c6f092..48e84f9 100644 --- a/src/Render/Misc.hs +++ b/src/Render/Misc.hs @@ -89,7 +89,7 @@ lookAt eye center up' = y@(V3 yx yy yz) = normalize (cross z x) -getCam :: (Double, Double) -- ^ Target in x/z-Plane +{-getCam :: (Double, Double) -- ^ Target in x/z-Plane -> Double -- ^ Distance from Target -> Double -- ^ Angle around X-Axis (angle down/up) -> Double -- ^ Angle around Y-Axis (angle left/right) @@ -110,7 +110,7 @@ getCam (x',z') dist' xa' ya' = lookAt (cpos ^+^ at') at' up z = realToFrac z' dist = realToFrac dist' xa = realToFrac xa' - ya = realToFrac ya' + ya = realToFrac ya'-} curb :: Ord a => a -> a -> a -> a curb l h x diff --git a/src/Types.hs b/src/Types.hs index d7c1196..c22735b 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -10,6 +10,7 @@ import Linear.Matrix (M44) import Control.Monad.RWS.Strict (RWST) import Control.Lens import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject) +import Render.Types --Static Read-Only-State @@ -41,7 +42,7 @@ data CameraState = CameraState , _yAngle :: !Double , _zDist :: !Double , _frustum :: !(M44 CFloat) - , _camPosition :: !Position --TODO: Get rid of cam-prefix + , _camObject :: !Camera } data IOState = IOState