changed camera to new model

This commit is contained in:
Nicole Dresselhaus 2014-04-21 19:46:24 +02:00
parent e2da50b6d9
commit 06bd9c4214
3 changed files with 10 additions and 13 deletions

View File

@ -43,11 +43,12 @@ import Graphics.GLUtil.BufferObjects (offset0)
import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader
-- Our modules -- Our modules
import Map.Graphics import Map.Graphics
import Render.Misc (checkError, createFrustum, getCam, curb, import Render.Misc (checkError, createFrustum, curb,
genColorData) genColorData)
import Render.Render (initRendering, import Render.Render (initRendering,
initMapShader, initMapShader,
initHud) initHud)
import Render.Types
import UI.Callbacks import UI.Callbacks
import Types import Types
import Importer.IQM.Parser import Importer.IQM.Parser
@ -146,10 +147,7 @@ main =
, _yAngle = pi/2 , _yAngle = pi/2
, _zDist = 10 , _zDist = 10
, _frustum = frust , _frustum = frust
, _camPosition = Types.Position , _camObject = createFlatCam 25 25
{ Types.__x = 25
, Types.__y = 25
}
} }
, _io = IOState , _io = IOState
{ _clock = now { _clock = now
@ -209,8 +207,7 @@ draw = do
numVert = state ^. gl.glMap.mapVert numVert = state ^. gl.glMap.mapVert
map' = state ^. gl.glMap.stateMap map' = state ^. gl.glMap.stateMap
frust = state ^. camera.frustum frust = state ^. camera.frustum
camX = state ^. camera.camPosition._x camPos = state ^. camera.camObject
camY = state ^. camera.camPosition._y
zDist' = state ^. camera.zDist zDist' = state ^. camera.zDist
tessFac = state ^. gl.glMap.stateTessellationFactor tessFac = state ^. gl.glMap.stateTessellationFactor
when (state ^. ui . uiHasChanged) prepareGUI when (state ^. ui . uiHasChanged) prepareGUI
@ -264,7 +261,7 @@ draw = do
checkError "copy projection" checkError "copy projection"
--set up camera --set up camera
let ! cam = getCam (camX,camY) zDist' xa ya let ! cam = getCam camPos zDist' xa ya
with (distribute cam) $ \ptr -> with (distribute cam) $ \ptr ->
glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat))) glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (L.M44 CFloat)))
checkError "copy cam" checkError "copy cam"
@ -387,8 +384,7 @@ run = do
- 0.2 * kyrot * mults - 0.2 * kyrot * mults
mody y' = y' + 0.2 * kxrot * mults mody y' = y' + 0.2 * kxrot * mults
- 0.2 * kyrot * multc - 0.2 * kyrot * multc
modify $ (camera.camPosition._x %~ modx) modify $ camera.camObject %~ (\c -> moveBy c (\(x,y) -> (modx x,mody y)))
. (camera.camPosition._y %~ mody)
{- {-
--modify the state with all that happened in mt time. --modify the state with all that happened in mt time.

View File

@ -89,7 +89,7 @@ lookAt eye center up' =
y@(V3 yx yy yz) = normalize (cross z x) 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 -- ^ Distance from Target
-> Double -- ^ Angle around X-Axis (angle down/up) -> Double -- ^ Angle around X-Axis (angle down/up)
-> Double -- ^ Angle around Y-Axis (angle left/right) -> 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' z = realToFrac z'
dist = realToFrac dist' dist = realToFrac dist'
xa = realToFrac xa' xa = realToFrac xa'
ya = realToFrac ya' ya = realToFrac ya'-}
curb :: Ord a => a -> a -> a -> a curb :: Ord a => a -> a -> a -> a
curb l h x curb l h x

View File

@ -10,6 +10,7 @@ import Linear.Matrix (M44)
import Control.Monad.RWS.Strict (RWST) import Control.Monad.RWS.Strict (RWST)
import Control.Lens import Control.Lens
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject) import Graphics.Rendering.OpenGL.GL.Texturing.Objects (TextureObject)
import Render.Types
--Static Read-Only-State --Static Read-Only-State
@ -41,7 +42,7 @@ data CameraState = CameraState
, _yAngle :: !Double , _yAngle :: !Double
, _zDist :: !Double , _zDist :: !Double
, _frustum :: !(M44 CFloat) , _frustum :: !(M44 CFloat)
, _camPosition :: !Position --TODO: Get rid of cam-prefix , _camObject :: !Camera
} }
data IOState = IOState data IOState = IOState