summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-04-16 03:08:48 +0200
committerMatthias Schiffer <matthias@gamezock.de>2010-04-16 03:08:48 +0200
commita19dc0d6aa982d138f46305cdea6443cb45a5fd3 (patch)
treeeb846615b4d22e2f1e76272b1460cc879f52f937 /src
parent5951108c0a47fed6d78e442ae4233d9d34eafe13 (diff)
downloadhtanks-a19dc0d6aa982d138f46305cdea6443cb45a5fd3.tar
htanks-a19dc0d6aa982d138f46305cdea6443cb45a5fd3.zip
Added more models and render with perspective transform now
Diffstat (limited to 'src')
-rw-r--r--src/GLX.hs9
-rw-r--r--src/HTanks.hs8
-rw-r--r--src/Model.hs4
-rw-r--r--src/Render.hs76
4 files changed, 60 insertions, 37 deletions
diff --git a/src/GLX.hs b/src/GLX.hs
index 9ad6392..8dbca6a 100644
--- a/src/GLX.hs
+++ b/src/GLX.hs
@@ -11,7 +11,7 @@ import Data.Maybe (isJust)
import Data.Ratio
import Graphics.Rendering.OpenGL.GL (($=), GLdouble, GLfloat, Vector3(..), Capability(..))
-import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho, translate, scale, rotate)
+import Graphics.Rendering.OpenGL.GL.CoordTrans (matrixMode, MatrixMode(..), viewport, Position(..), Size(..), loadIdentity, ortho, translate, scale, rotate, frustum)
import Graphics.X11.Types
import Graphics.X11.Xlib.Atom (internAtom)
@@ -205,10 +205,11 @@ resize lw lh w h = do
matrixMode $= Projection
loadIdentity
- ortho (-sf*aspectf) (sf*aspectf) (-sf) sf (-1) 1
- scale 1 1 (0.1 :: GLfloat)
+ --ortho (-sf*aspectf) (sf*aspectf) (-sf) sf (-1) 1
+ --scale 1 1 (0.1 :: GLfloat)
+ frustum (-sf*aspectf) (sf*aspectf) (-sf) sf 10 100
rotate (-30) $ Vector3 1 0 (0 :: GLfloat)
- translate $ Vector3 (-(fromIntegral lw)/2) (-(fromIntegral lh)/2) (0 :: GLfloat)
+ translate $ Vector3 (-(fromIntegral lw)/2) ((fromIntegral lh)/2) (-11 :: GLfloat)
matrixMode $= Modelview 0
diff --git a/src/HTanks.hs b/src/HTanks.hs
index 82338a4..2fd2148 100644
--- a/src/HTanks.hs
+++ b/src/HTanks.hs
@@ -33,12 +33,14 @@ main = do
when (initialized gl) $ do
currentTime <- getCurrentTime
- let gamestate = GameState {level = theLevel, tanks = [ Tank 5.0 5.0 0 0 1.5 270 False 3 1 5 1
- , Tank 5.0 3.5 0 0 1.5 270 False 3 1 5 1
+ let gamestate = GameState {level = theLevel, tanks = [ Tank 7.0 4.0 0 0 1.5 270 False 3 1 5 1
+ , Tank 4.0 4.0 0 0 1.5 270 False 3 1 5 1
+ , Tank 10.0 4.0 0 0 1.5 270 False 3 1 5 1
], bullets = []}
mainstate = MainState {run = True, driver = SomeDriver gl, time = currentTime, players =
[ SomePlayer humanPlayer
- , SomePlayer $ CPUPlayer 0
+ , SomePlayer $ CPUPlayer (-90)
+ , SomePlayer $ CPUPlayer 90
], textures = M.empty, models = M.empty, gameState = gamestate}
runMain mainstate $ do
diff --git a/src/Model.hs b/src/Model.hs
index 0c273e9..e2c045a 100644
--- a/src/Model.hs
+++ b/src/Model.hs
@@ -6,10 +6,12 @@ module Model ( Model(..)
import Paths_htanks
import Data.Obj3D.GL (InterleavedObj)
-data Model = ModelTank
+data Model = ModelTank | ModelBullet | ModelBlock
deriving (Eq, Ord, Show)
modelPath :: Model -> IO FilePath
modelPath t = getDataFileName $ "model/" ++ (name t) ++ ".obj"
where
name ModelTank = "tank"
+ name ModelBullet = "bullet"
+ name ModelBlock = "cube"
diff --git a/src/Render.hs b/src/Render.hs
index 91146ba..aa084d8 100644
--- a/src/Render.hs
+++ b/src/Render.hs
@@ -80,7 +80,7 @@ setup = do
shadeModel $= Smooth
lighting $= Enabled
light (Light 0) $= Enabled
- position (Light 0) $= Vertex4 (-1) (-1) 1 (0 :: GLfloat)
+ position (Light 0) $= Vertex4 (-1) (-1) 1.5 (0 :: GLfloat)
colorMaterial $= Just (Front, AmbientAndDiffuse)
clientState VertexArray $= Enabled
@@ -96,6 +96,8 @@ setup = do
getTexture TextureCrosshair
getModel ModelTank
+ getModel ModelBullet
+ getModel ModelBlock
return ()
@@ -113,6 +115,8 @@ render = do
textureCrosshair <- getTexture TextureCrosshair
modelTank <- getModel ModelTank
+ modelBullet <- getModel ModelBullet
+ modelBlock <- getModel ModelBlock
(lw, lh) <- gets (level . gameState) >>= \l -> return (fromIntegral . levelWidth $ l :: GLfloat, fromIntegral . levelHeight $ l :: GLfloat)
@@ -127,17 +131,17 @@ render = do
normal $ Normal3 0 0 (1 :: GLfloat)
unsafeRenderPrimitive Quads $ do
- texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
- vertex $ Vertex2 0 lh
+ texCoord $ TexCoord2 (-0.5 :: GLfloat) (-0.5 :: GLfloat)
+ vertex $ Vertex2 (-1) (lh+1)
- texCoord $ TexCoord2 (lw/2) 0
- vertex $ Vertex2 lw lh
+ texCoord $ TexCoord2 (lw/2+0.5) (-0.5)
+ vertex $ Vertex2 (lw+1) (lh+1)
- texCoord $ TexCoord2 (lw/2) (lh/2)
- vertex $ Vertex2 lw 0
+ texCoord $ TexCoord2 (lw/2+0.5) (lh/2+0.5)
+ vertex $ Vertex2 (lw+1) (-1)
- texCoord $ TexCoord2 0 (lh/2)
- vertex $ Vertex2 (0 :: GLfloat) (0 :: GLfloat)
+ texCoord $ TexCoord2 (-0.5) (lh/2+0.5)
+ vertex $ Vertex2 (-1 :: GLfloat) (-1 :: GLfloat)
bindInterleavedArrays modelTank
@@ -163,30 +167,44 @@ render = do
unsafePreservingMatrix $ do
rotate 90 $ Vector3 1 0 (0 :: GLfloat)
drawObject modelTank 0
+
+ texture Texture2D $= Disabled
+ bindInterleavedArrays modelBullet
forM_ bulletlist $ \bullet -> unsafePreservingMatrix $ do
- let x = realToFrac . bulletX $ bullet
- y = realToFrac . bulletY $ bullet
- rotDir = realToFrac . bulletDir $ bullet
-
- translate $ Vector3 x y (0.2 :: GLfloat)
- rotate 30 $ Vector3 1 0 (0 :: GLfloat)
- rotate rotDir $ Vector3 0 0 (1 :: GLfloat)
+ let x = realToFrac . bulletX $ bullet
+ y = realToFrac . bulletY $ bullet
+ rotDir = realToFrac . bulletDir $ bullet
- textureBinding Texture2D $= Just textureBullet
+ translate $ Vector3 x y (0.25 :: GLfloat)
+ rotate (rotDir-90) $ Vector3 0 0 (1 :: GLfloat)
- unsafeRenderPrimitive Quads $ do
- texCoord $ TexCoord2 (0 :: GLfloat) (0 :: GLfloat)
- vertex $ Vertex3 (-0.1 :: GLfloat) (-0.1 :: GLfloat) 0
-
- texCoord $ TexCoord2 (0 :: GLfloat) (1 :: GLfloat)
- vertex $ Vertex3 (-0.1 :: GLfloat) (0.1 :: GLfloat) 0
-
- texCoord $ TexCoord2 (1 :: GLfloat) (1 :: GLfloat)
- vertex $ Vertex3 (0.1 :: GLfloat) (0.1 :: GLfloat) 0
-
- texCoord $ TexCoord2 (1 :: GLfloat) (0 :: GLfloat)
- vertex $ Vertex3 (0.1 :: GLfloat) (-0.1 :: GLfloat) 0
+ unsafePreservingMatrix $ do
+ drawObject modelBullet 0
+
+ bindInterleavedArrays modelBlock
+
+ texture Texture2D $= Enabled
+ textureBinding Texture2D $= Just textureWood
+ forM_ [0.5..13.5] $ \x -> unsafePreservingMatrix $ do
+ translate $ Vector3 x 8.5 (0.5 :: GLfloat)
+ rotate 90 $ Vector3 1 0 (0 :: GLfloat)
+ drawObject modelBlock 0
+
+ forM_ [0.5..13.5] $ \x -> unsafePreservingMatrix $ do
+ translate $ Vector3 x (-0.5) (0.5 :: GLfloat)
+ rotate 90 $ Vector3 1 0 (0 :: GLfloat)
+ drawObject modelBlock 0
+
+ forM_ [-0.5..8.5] $ \y -> unsafePreservingMatrix $ do
+ translate $ Vector3 (-0.5) y (0.5 :: GLfloat)
+ rotate 90 $ Vector3 1 0 (0 :: GLfloat)
+ drawObject modelBlock 0
+
+ forM_ [-0.5..8.5] $ \y -> unsafePreservingMatrix $ do
+ translate $ Vector3 14.5 y (0.5 :: GLfloat)
+ rotate 90 $ Vector3 1 0 (0 :: GLfloat)
+ drawObject modelBlock 0
depthFunc $= Just Always