HGamer3D-Data 0.3.2 → 0.4.0
raw patch · 13 files changed
+444/−289 lines, 13 filesdep +clockPVP ok
version bump matches the API change (PVP)
Dependencies added: clock
API changes (from Hackage documentation)
- HGamer3D.Data.Operation3D: class Direction3D t
- HGamer3D.Data.Operation3D: class Orientation3D t
- HGamer3D.Data.Operation3D: class Position3D t
- HGamer3D.Data.Operation3D: class Scale3D t
- HGamer3D.Data.Operation3D: direction3D :: Direction3D t => t -> IO Vec3
- HGamer3D.Data.Operation3D: directionTo3D :: Direction3D t => t -> Vec3 -> IO ()
- HGamer3D.Data.Operation3D: orientation3D :: Orientation3D t => t -> IO UnitQuaternion
- HGamer3D.Data.Operation3D: orientationTo3D :: Orientation3D t => t -> UnitQuaternion -> IO ()
- HGamer3D.Data.Operation3D: pitch3D :: Orientation3D t => t -> Angle -> IO ()
- HGamer3D.Data.Operation3D: position3D :: Position3D t => t -> IO Vec3
- HGamer3D.Data.Operation3D: positionTo3D :: Position3D t => t -> Vec3 -> IO ()
- HGamer3D.Data.Operation3D: roll3D :: Orientation3D t => t -> Angle -> IO ()
- HGamer3D.Data.Operation3D: scale3D :: Scale3D t => t -> IO Vec3
- HGamer3D.Data.Operation3D: scaleTo3D :: Scale3D t => t -> Vec3 -> IO ()
- HGamer3D.Data.Operation3D: translate3D :: Position3D t => t -> Vec3 -> IO ()
- HGamer3D.Data.Operation3D: yaw3D :: Orientation3D t => t -> Angle -> IO ()
- HGamer3D.Data.ScreenGeometry: Point :: Int -> Int -> Point
- HGamer3D.Data.ScreenGeometry: Rectangle :: Int -> Int -> Int -> Int -> Rectangle
- HGamer3D.Data.ScreenGeometry: Window :: Int -> Window
- HGamer3D.Data.ScreenGeometry: data Point
- HGamer3D.Data.ScreenGeometry: data Rectangle
- HGamer3D.Data.ScreenGeometry: data Window
- HGamer3D.Data.ScreenGeometry: instance Eq Point
- HGamer3D.Data.ScreenGeometry: instance Eq Rectangle
- HGamer3D.Data.ScreenGeometry: instance Show Point
- HGamer3D.Data.ScreenGeometry: instance Show Rectangle
- HGamer3D.Data.ScreenGeometry: pointsFromRect :: Rectangle -> (Point, Point)
- HGamer3D.Data.ScreenGeometry: ptX :: Point -> Int
- HGamer3D.Data.ScreenGeometry: ptY :: Point -> Int
- HGamer3D.Data.ScreenGeometry: rectFromPoints :: Point -> Point -> Rectangle
- HGamer3D.Data.ScreenGeometry: rectHeight :: Rectangle -> Int
- HGamer3D.Data.ScreenGeometry: rectWidth :: Rectangle -> Int
- HGamer3D.Data.ScreenGeometry: rectX :: Rectangle -> Int
- HGamer3D.Data.ScreenGeometry: rectY :: Rectangle -> Int
- HGamer3D.Data.TimeMS: TimeMS :: Int -> TimeMS
- HGamer3D.Data.TimeMS: data TimeMS
- HGamer3D.Data.TimeMS: instance Eq TimeMS
- HGamer3D.Data.TimeMS: instance Show TimeMS
+ HGamer3D.Data: data Window
+ HGamer3D.Data.Colour: aqua :: Colour
+ HGamer3D.Data.Colour: black :: Colour
+ HGamer3D.Data.Colour: blue :: Colour
+ HGamer3D.Data.Colour: darkgrey :: Colour
+ HGamer3D.Data.Colour: fuchsia :: Colour
+ HGamer3D.Data.Colour: green :: Colour
+ HGamer3D.Data.Colour: grey :: Colour
+ HGamer3D.Data.Colour: lime :: Colour
+ HGamer3D.Data.Colour: maroon :: Colour
+ HGamer3D.Data.Colour: navy :: Colour
+ HGamer3D.Data.Colour: olive :: Colour
+ HGamer3D.Data.Colour: purple :: Colour
+ HGamer3D.Data.Colour: red :: Colour
+ HGamer3D.Data.Colour: silver :: Colour
+ HGamer3D.Data.Colour: teal :: Colour
+ HGamer3D.Data.Colour: white :: Colour
+ HGamer3D.Data.Colour: yellow :: Colour
+ HGamer3D.Data.GameTime: getProcessCPUTime :: IO GameTime
+ HGamer3D.Data.GameTime: getThreadCPUTime :: IO GameTime
+ HGamer3D.Data.GameTime: getTime :: IO GameTime
+ HGamer3D.Data.GameTime: instance Num GameTime
+ HGamer3D.Data.GameTime: msec :: TimeSpec -> Int
+ HGamer3D.Data.GameTime: msecT :: Int -> TimeSpec
+ HGamer3D.Data.GameTime: sec :: TimeSpec -> Int
+ HGamer3D.Data.GameTime: secT :: Int -> TimeSpec
+ HGamer3D.Data.GameTime: type GameTime = TimeSpec
+ HGamer3D.Data.GameTime: usec :: TimeSpec -> Int
+ HGamer3D.Data.GameTime: usecT :: Int -> TimeSpec
+ HGamer3D.Data.Geometry2D: Point :: a -> a -> Point a
+ HGamer3D.Data.Geometry2D: Rectangle :: a -> a -> a -> a -> Rectangle a
+ HGamer3D.Data.Geometry2D: data Point a
+ HGamer3D.Data.Geometry2D: data Num a => Rectangle a
+ HGamer3D.Data.Geometry2D: instance (Eq a, Num a) => Eq (Rectangle a)
+ HGamer3D.Data.Geometry2D: instance (Num a, Show a) => Show (Rectangle a)
+ HGamer3D.Data.Geometry2D: pointsFromRect :: Num a => Rectangle a -> (Point a, Point a)
+ HGamer3D.Data.Geometry2D: ptX :: Point a -> a
+ HGamer3D.Data.Geometry2D: ptY :: Point a -> a
+ HGamer3D.Data.Geometry2D: rectFromPoints :: Num a => Point a -> Point a -> Rectangle a
+ HGamer3D.Data.Geometry2D: rectHeight :: Rectangle a -> a
+ HGamer3D.Data.Geometry2D: rectWidth :: Rectangle a -> a
+ HGamer3D.Data.Geometry2D: rectX :: Rectangle a -> a
+ HGamer3D.Data.Geometry2D: rectY :: Rectangle a -> a
+ HGamer3D.Data.Transform3D: class HasOrientation t
+ HGamer3D.Data.Transform3D: class HasPosition t
+ HGamer3D.Data.Transform3D: class HasSize t
+ HGamer3D.Data.Transform3D: orientation :: HasOrientation t => t -> IO Orientation
+ HGamer3D.Data.Transform3D: orientationTo :: HasOrientation t => t -> Orientation -> IO ()
+ HGamer3D.Data.Transform3D: pitch :: Orientation -> Angle -> Orientation
+ HGamer3D.Data.Transform3D: position :: HasPosition t => t -> IO Position
+ HGamer3D.Data.Transform3D: positionTo :: HasPosition t => t -> Position -> IO ()
+ HGamer3D.Data.Transform3D: roll :: Orientation -> Angle -> Orientation
+ HGamer3D.Data.Transform3D: scale :: Size -> Vec3 -> Size
+ HGamer3D.Data.Transform3D: size :: HasSize t => t -> IO Size
+ HGamer3D.Data.Transform3D: sizeTo :: HasSize t => t -> Size -> IO ()
+ HGamer3D.Data.Transform3D: translate :: Position -> Position -> Position
+ HGamer3D.Data.Transform3D: yaw :: Orientation -> Angle -> Orientation
+ HGamer3D.Data.TypeSynonyms: type Orientation = UnitQuaternion
+ HGamer3D.Data.TypeSynonyms: type Position = Vec3
+ HGamer3D.Data.TypeSynonyms: type Size = Vec3
+ HGamer3D.Data.Vector: instance Eq UnitQuaternion
+ HGamer3D.Data.Vector: instance Eq Vec2
+ HGamer3D.Data.Vector: instance Eq Vec3
+ HGamer3D.Data.Vector: instance Eq Vec4
+ HGamer3D.Data.Vector: instance Typeable UnitQuaternion
+ HGamer3D.Data.Vector: instance Typeable Vec2
+ HGamer3D.Data.Vector: instance Typeable Vec3
+ HGamer3D.Data.Vector: instance Typeable Vec4
+ HGamer3D.Data.Vector: unitVec2 :: Vec2
+ HGamer3D.Data.Vector: unitVec3 :: Vec3
+ HGamer3D.Data.Vector: zeroVec3 :: Vec3
+ HGamer3D.Data.Window: Window :: Int -> Window
+ HGamer3D.Data.Window: data Window
Files
- HGamer3D-Data.cabal +3/−3
- HGamer3D/Data.hs +10/−8
- HGamer3D/Data/Colour.hs +44/−5
- HGamer3D/Data/GameTime.hs +92/−0
- HGamer3D/Data/Geometry2D.hs +64/−0
- HGamer3D/Data/Operation3D.hs +0/−101
- HGamer3D/Data/ScreenGeometry.hs +0/−67
- HGamer3D/Data/TimeMS.hs +0/−34
- HGamer3D/Data/Transform3D.hs +96/−0
- HGamer3D/Data/TypeSynonyms.hs +33/−0
- HGamer3D/Data/Vector.hs +70/−36
- HGamer3D/Data/Vector/Instances.hs +0/−35
- HGamer3D/Data/Window.hs +32/−0
HGamer3D-Data.cabal view
@@ -1,5 +1,5 @@ Name: HGamer3D-Data -Version: 0.3.2 +Version: 0.4.0 Synopsis: Game Engine for the Haskell Programmer - Data Definitions and Utilities Description: HGamer3D is a game engine for developing 3D games in the programming @@ -17,9 +17,9 @@ Extra-source-files: Setup.hs Library - Build-Depends: base >= 3 && < 5, FindBin, directory, filepath, vect + Build-Depends: base >= 3 && < 5, FindBin, directory, filepath, vect, clock - Exposed-modules: HGamer3D.Data.Vector,HGamer3D.Data.Vector.Instances,HGamer3D.Data.Colour,HGamer3D.Data.HG3DClass,HGamer3D.Data.Angle,HGamer3D.Data.TimeMS,HGamer3D.Data.Operation3D,HGamer3D.Data.ScreenGeometry,HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Data, HGamer3D.Util + Exposed-modules: HGamer3D.Data.TypeSynonyms, HGamer3D.Data.Vector,HGamer3D.Data.Colour,HGamer3D.Data.HG3DClass,HGamer3D.Data.Angle,HGamer3D.Data.GameTime,HGamer3D.Data.Transform3D,HGamer3D.Data.Geometry2D,HGamer3D.Data.Window,HGamer3D.Util.FileLocation, HGamer3D.Util.UniqueName, HGamer3D.Data, HGamer3D.Util Other-modules: c-sources:
HGamer3D/Data.hs view
@@ -23,22 +23,24 @@ module HGamer3D.Data ( - module HGamer3D.Data.HG3DClass, module HGamer3D.Data.Angle, module HGamer3D.Data.Colour, - module HGamer3D.Data.Operation3D, - module HGamer3D.Data.TimeMS, + module HGamer3D.Data.Transform3D, + module HGamer3D.Data.GameTime, module HGamer3D.Data.Vector, - module HGamer3D.Data.ScreenGeometry + module HGamer3D.Data.Geometry2D, + module HGamer3D.Data.TypeSynonyms, + Window, ) where -import HGamer3D.Data.HG3DClass import HGamer3D.Data.Angle import HGamer3D.Data.Colour -import HGamer3D.Data.Operation3D -import HGamer3D.Data.TimeMS +import HGamer3D.Data.Transform3D +import HGamer3D.Data.GameTime import HGamer3D.Data.Vector -import HGamer3D.Data.ScreenGeometry +import HGamer3D.Data.Geometry2D +import HGamer3D.Data.Window +import HGamer3D.Data.TypeSynonyms
HGamer3D/Data/Colour.hs view
@@ -18,18 +18,57 @@ -- ColourValue.hs --- | HGamer3D colour type +-- | Module providing the Colour type and some standard colours module HGamer3D.Data.Colour ( Colour (Colour, cRed, cGreen, cBlue, cAlpha), + white, + silver, + grey, + darkgrey, + black, + red, + maroon, + yellow, + olive, + lime, + green, + aqua, + teal, + blue, + navy, + fuchsia, + purple ) where + +-- | HGamer3D colour type data Colour = Colour { - cRed :: Float, - cGreen :: Float, - cBlue :: Float, - cAlpha :: Float + cRed :: Float, -- ^ red component ranging from 0.0 to 1.0 + cGreen :: Float, -- ^ green component ranging from 0.0 to 1.0 + cBlue :: Float, -- ^ blue component ranging from 0.0 to 1.0 + cAlpha :: Float -- ^ alpha component ranging from 0.0 to 1.0 with 1.0 being fully opaque } deriving (Eq, Show) + +white = Colour 1.0 1.0 1.0 1.0 +silver = Colour 0.75 0.75 0.75 1.0 +grey = Colour 0.5 0.5 0.5 1.0 +darkgrey = Colour 0.25 0.25 0.25 1.0 +black = Colour 0.0 0.0 0.0 1.0 +red = Colour 1.0 0.0 0.0 1.0 +maroon = Colour 0.5 0.0 0.0 1.0 +yellow = Colour 1.0 1.0 0.0 1.0 +olive = Colour 0.5 0.5 0.0 1.0 +lime = Colour 0.0 1.0 0.0 1.0 +green = Colour 0.0 0.5 0.0 1.0 +aqua = Colour 0.0 1.0 1.0 1.0 +teal = Colour 0.0 0.5 0.5 1.0 +blue = Colour 0.0 0.0 1.0 1.0 +navy = Colour 0.0 0.0 0.5 1.0 +fuchsia = Colour 1.0 0.0 1.0 1.0 +purple = Colour 0.5 0.0 0.5 1.0 + +
+ HGamer3D/Data/GameTime.hs view
@@ -0,0 +1,92 @@+{-# LANGUAGE TypeSynonymInstances #-} +-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011-2013 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- TimeMS.hs + +-- | Module providing the time type for HGamer3D +module HGamer3D.Data.GameTime + +( + GameTime, + sec, + msec, + usec, + + secT, + msecT, + usecT, + + getTime, + getThreadCPUTime, + getProcessCPUTime +) + +where + +import qualified System.Clock as C + +type GameTime = C.TimeSpec + +_toInteger :: C.TimeSpec -> Integer +_toInteger ts = let + s = (fromIntegral (C.sec ts)) :: Integer + ns = (fromIntegral (C.nsec ts)) :: Integer + in s * 1000000000 + ns + +_fromInteger :: Integer -> C.TimeSpec +_fromInteger i = let + s = fromIntegral (i `quot` 1000000000) + ns = fromIntegral (i `rem` 1000000000) + in C.TimeSpec s ns + +instance Num GameTime where + (+) a b = _fromInteger((_toInteger a) Prelude.+ (_toInteger b) ) + (-) a b = _fromInteger((_toInteger a) Prelude.- (_toInteger b) ) + (*) a b = _fromInteger((_toInteger a) Prelude.* (_toInteger b) ) + abs a = _fromInteger( Prelude.abs (_toInteger a)) + signum a = _fromInteger( Prelude.signum (_toInteger a)) + fromInteger i = _fromInteger i + +sec :: C.TimeSpec -> Int +sec ts = fromIntegral ((_toInteger ts) `quot` 1000000000) + +msec :: C.TimeSpec -> Int +msec ts = fromIntegral ((_toInteger ts) `quot` 1000000) + +usec :: C.TimeSpec -> Int +usec ts = fromIntegral ((_toInteger ts) `quot` 1000) + +secT :: Int -> C.TimeSpec +secT i = _fromInteger ((fromIntegral i) * 1000000000) + +msecT :: Int -> C.TimeSpec +msecT i = _fromInteger ((fromIntegral i) * 1000000) + +usecT :: Int -> C.TimeSpec +usecT i = _fromInteger ((fromIntegral i) * 1000) + +getTime :: IO GameTime +getTime = C.getTime C.Realtime + +getThreadCPUTime :: IO GameTime +getThreadCPUTime = C.getTime C.ThreadCPUTime + +getProcessCPUTime :: IO GameTime +getProcessCPUTime = C.getTime C.ProcessCPUTime +
+ HGamer3D/Data/Geometry2D.hs view
@@ -0,0 +1,64 @@+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+-- http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- Rectangle.hs++-- | Type definitions for 2D geometry +module HGamer3D.Data.Geometry2D+(+ -- * Geometry+ Point (..),+ Rectangle (..),+ rectFromPoints,+ pointsFromRect+ +) where+ +import HGamer3D.Data.Vector++-- | A point has two coordinates an x and y one+data Point a = Point {+ ptX :: a,+ ptY :: a+ }+ +-- | A rectangle has an a position as x and y and widht and height+data Num a => Rectangle a = Rectangle {+ rectX :: a,+ rectY :: a,+ rectWidth :: a,+ rectHeight :: a } deriving (Eq, Show)++-- | derive a rectangle from upper left and lower right points+rectFromPoints :: Num a => Point a -> Point a -> Rectangle a+rectFromPoints upperLeft lowerRight = Rectangle rx ry rw rh where+ rx = ptX upperLeft+ ry = ptY upperLeft+ rw = (ptY lowerRight) - rx+ rh = (ptY lowerRight) - ry+ +-- | get upper left and lower right point from a rect+pointsFromRect :: Num a => Rectangle a -> (Point a, Point a)+pointsFromRect rect = (ul, lr) where+ rx = rectX rect+ ry = rectY rect+ rx' = rx + (rectWidth rect)+ ry' = ry + (rectHeight rect)+ ul = Point rx ry+ lr = Point rx' ry'+
− HGamer3D/Data/Operation3D.hs
@@ -1,101 +0,0 @@--- This source file is part of HGamer3D --- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.hgamer3d.org --- --- (c) 2011-2013 Peter Althainz --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. - --- Operation3D.hs - --- | Typeclasses for basic 3D operations -module HGamer3D.Data.Operation3D -( - -- * Types - Position3D (..), - Scale3D (..), - Direction3D (..), - Orientation3D (..), - - -- * Functions - translate3D, - yaw3D, - pitch3D, - roll3D -) - -where - -import HGamer3D.Data.Vector -import HGamer3D.Data.Angle - --- | a type with a Position3D instance can be positioned -class Position3D t where - - -- | get position function - position3D :: t -> IO Vec3 - -- | set position function - positionTo3D :: t -> Vec3 -> IO () - --- | move position function -translate3D :: Position3D t => t -> Vec3 -> IO () -translate3D t v = do - p <- position3D t - positionTo3D t ( v &+ p ) - return () - --- | a type with a Scale3D instance can be scaled -class Scale3D t where - - -- | get scale function - scale3D :: t -> IO Vec3 - -- | set scale function - scaleTo3D :: t -> Vec3 -> IO () - --- | a type with a Direction3D instance can be oriented towards a point (Camera for example) -class Direction3D t where - -- | get direction function - direction3D :: t -> IO Vec3 - -- | set direction function - directionTo3D :: t -> Vec3 -> IO () - --- | a type with an Orientation3D instance can be oriented in space -class Orientation3D t where - -- | get orientation function - orientation3D :: t -> IO UnitQuaternion - -- | set orientation function - orientationTo3D :: t -> UnitQuaternion -> IO () - --- yaw, roll, pitch functions --- functions, to rotate on axis, relative to object -rotRelativeToObjectAxis :: Orientation3D t => t -> Vec3 -> Float -> IO () -rotRelativeToObjectAxis object axis val = do - qob <- orientation3D object - let odir = actU qob axis - let qrot = rotU odir val - let nrot = qrot .*. qob - orientationTo3D object nrot - return () - --- | rotate object on own axis (yaw) by angle -yaw3D :: Orientation3D t => t -> Angle -> IO () -yaw3D object val = rotRelativeToObjectAxis object (Vec3 0.0 1.0 0.0) (fromAngle val) - --- | rotate object on own axis (roll) by angle -roll3D :: Orientation3D t => t -> Angle -> IO () -roll3D object val = rotRelativeToObjectAxis object (Vec3 0.0 0.0 1.0) (fromAngle val) - --- | rotate object on own axis (pitch) by angle -pitch3D :: Orientation3D t => t -> Angle -> IO () -pitch3D object val = rotRelativeToObjectAxis object (Vec3 1.0 0.0 0.0) (fromAngle val) -
− HGamer3D/Data/ScreenGeometry.hs
@@ -1,67 +0,0 @@--- This source file is part of HGamer3D--- (A project to enable 3D game development in Haskell)--- For the latest info, see http://www.hgamer3d.org------ (c) 2014 Peter Althainz------ Licensed under the Apache License, Version 2.0 (the "License");--- you may not use this file except in compliance with the License.--- You may obtain a copy of the License at------ http://www.apache.org/licenses/LICENSE-2.0------ Unless required by applicable law or agreed to in writing, software--- distributed under the License is distributed on an "AS IS" BASIS,--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.--- See the License for the specific language governing permissions and--- limitations under the License.---- Rectangle.hs---- | Type definitions for 2D geometry and windows-module HGamer3D.Data.ScreenGeometry-(- -- * Windowing- Window (..),- - -- * Geometry- Point (..),- Rectangle (..),- rectFromPoints,- pointsFromRect- -) where- --- | A window is simply represented by it's window id, an unsigned C int-data Window = Window Int---- | A point has two coordinates an x and y one-data Point = Point {- ptX::Int, - ptY::Int } deriving (Eq, Show)- --- | A rectangle has an a position as x and y and widht and height-data Rectangle = Rectangle {- rectX :: Int,- rectY :: Int,- rectWidth :: Int,- rectHeight :: Int } deriving (Eq, Show)---- | derive a rectangle from upper left and lower right points-rectFromPoints :: Point -> Point -> Rectangle-rectFromPoints upperLeft lowerRight = Rectangle x y w h where- x = ptX upperLeft- y = ptY upperLeft- w = (ptX lowerRight) - x- h = (ptY lowerRight) - y- --- | get upper left and lower right point from a rect-pointsFromRect :: Rectangle -> (Point, Point)-pointsFromRect rect = (ul, lr) where- x = rectX rect- y = rectY rect- x' = x + (rectWidth rect)- y' = y + (rectHeight rect)- ul = Point x y- lr = Point x' y'-
− HGamer3D/Data/TimeMS.hs
@@ -1,34 +0,0 @@--- This source file is part of HGamer3D --- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.hgamer3d.org --- --- (c) 2011-2013 Peter Althainz --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. - --- TimeMS.hs - --- | Module providing the time type for HGamer3D -module HGamer3D.Data.TimeMS - -( - TimeMS (..) -) - -where - --- | the time type of HGamer3D (in milliseconds) -data TimeMS = TimeMS Int deriving (Eq) -- time in milliseconds - -instance Show TimeMS where - show (TimeMS s) = (show s) ++ " Milliseconds"
+ HGamer3D/Data/Transform3D.hs view
@@ -0,0 +1,96 @@+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2013 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+-- http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- Transform3D.hs++-- | Typeclasses for basic 3D transformations++module HGamer3D.Data.Transform3D+(+ -- * Types+ HasPosition (..),+ HasSize (..),+ HasOrientation (..),+ + -- * Functions+ translate,+ scale, + yaw,+ pitch,+ roll+)++where++import HGamer3D.Data.Vector+import HGamer3D.Data.Angle+import HGamer3D.Data.TypeSynonyms++-- | a type with a HasPosition instance has a Position+class HasPosition t where++ -- | get position function+ position :: t -> IO Position+ -- | set position function+ positionTo :: t -> Position -> IO ()++-- | a type with a HasSize instance has a Size+class HasSize t where + + -- | get scale function+ size :: t -> IO Size+ -- | set scale function+ sizeTo :: t -> Size -> IO ()++-- | a type with an HasOrientation instance has an oriented in space+class HasOrientation t where+ -- | get orientation function+ orientation :: t -> IO Orientation+ -- | set orientation function+ orientationTo :: t -> Orientation -> IO ()+++-- | move the position +translate :: Position -> Position -> Position+translate = (&+)++-- | scale the size+scale :: Size -> Vec3 -> Size+scale = (&!)++-- yaw, roll, pitch functions+-- functions, to rotate on axis, relative to object+rotRelativeToObjectAxis :: Orientation -> Vec3 -> Float -> Orientation+rotRelativeToObjectAxis ori axis val = let+ odir = actU ori axis+ qrot = rotU odir val+ nrot = qrot .*. ori+ in nrot+ +-- | rotate object on own axis (yaw) by angle+yaw :: Orientation -> Angle -> Orientation+yaw ori val = rotRelativeToObjectAxis ori vec3Y (fromAngle val)++-- | rotate object on own axis (roll) by angle+roll :: Orientation -> Angle -> Orientation+roll ori val = rotRelativeToObjectAxis ori vec3Z (fromAngle val)++-- | rotate object on own axis (pitch) by angle+pitch :: Orientation -> Angle -> Orientation+pitch ori val = rotRelativeToObjectAxis ori vec3X (fromAngle val)+
+ HGamer3D/Data/TypeSynonyms.hs view
@@ -0,0 +1,33 @@+-- This source file is part of HGamer3D +-- (A project to enable 3D game development in Haskell) +-- For the latest info, see http://www.hgamer3d.org +-- +-- (c) 2011-2014 Peter Althainz +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- HGamer3D/Data/TypeSynonyms.hs + +-- | Module providing better type names for standard types in HGamer3D +module HGamer3D.Data.TypeSynonyms + +where + +import HGamer3D.Data.Vector + +-- | the Size, Position and Orientation types, implemented as a Vec3 and UnitQuaternion +type Size = Vec3 +type Position = Vec3 +type Orientation = UnitQuaternion + +
HGamer3D/Data/Vector.hs view
@@ -1,36 +1,70 @@--- This source file is part of HGamer3D --- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.hgamer3d.org --- --- (c) 2011-2013 Peter Althainz --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. - --- Vector2.hs - -{-# LANGUAGE GeneralizedNewtypeDeriving #-} - --- book: math3d vector lib --- |Includes the right pieces of the Vect libray of Balazs Komuves. --- see: <http://hackage.haskell.org/package/vect> -module HGamer3D.Data.Vector -( - module Data.Vect.Float, - module Data.Vect.Float.Util.Quaternion -) - -where - -import Data.Vect.Float -import Data.Vect.Float.Util.Quaternion --- book: end +{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving, DeriveDataTypeable #-}++-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2011-2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+-- http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- HGamer3D/Data/Vector.hs+++-- | Vector library for HGamer3D+module HGamer3D.Data.Vector+(+ + -- * the Vect libray of Balazs Komuves, see: <http://hackage.haskell.org/package/vect>+ + module Data.Vect.Float,+ module Data.Vect.Float.Util.Quaternion,++ -- * some constants++ zeroVec3,+ unitVec2,++ zeroVec3,+ unitVec3++)++where++import Data.Typeable+import Data.Vect.Float+import Data.Vect.Float.Util.Quaternion++deriving instance Eq UnitQuaternion+deriving instance Eq Vec2+deriving instance Eq Vec3+deriving instance Eq Vec4++deriving instance Typeable UnitQuaternion+deriving instance Typeable Vec2+deriving instance Typeable Vec3+deriving instance Typeable Vec4++-- | the 2d zero vector+zeroVec2 = Vec2 0.0 0.0++-- | the 2d unity vector+unitVec2 = Vec2 1.0 1.0++-- | the 3d Zero vector+zeroVec3 = Vec3 0.0 0.0 0.0++-- | the 3d Unity vector+unitVec3 = Vec3 1.0 1.0 1.0+
− HGamer3D/Data/Vector/Instances.hs
@@ -1,35 +0,0 @@--- This source file is part of HGamer3D --- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.hgamer3d.org --- --- (c) 2011-2013 Peter Althainz --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. - --- Vector2.hs - -{-# LANGUAGE GeneralizedNewtypeDeriving #-} - --- book: math3d vector lib --- |Includes the right pieces of the Vect libray of Balazs Komuves. --- see: <http://hackage.haskell.org/package/vect> - -module HGamer3D.Data.Vector.Instances -( - module Data.Vect.Float.Instances, -) - -where - -import Data.Vect.Float.Instances --- book: end
+ HGamer3D/Data/Window.hs view
@@ -0,0 +1,32 @@+-- This source file is part of HGamer3D+-- (A project to enable 3D game development in Haskell)+-- For the latest info, see http://www.hgamer3d.org+--+-- (c) 2014 Peter Althainz+--+-- Licensed under the Apache License, Version 2.0 (the "License");+-- you may not use this file except in compliance with the License.+-- You may obtain a copy of the License at+--+-- http://www.apache.org/licenses/LICENSE-2.0+--+-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+-- See the License for the specific language governing permissions and+-- limitations under the License.++-- Rectangle.hs++-- | Type definitions for 2D window+module HGamer3D.Data.Window+(+ -- * Windowing+ Window (..),+ + +) where++-- | A window is simply represented by it's window id, an unsigned C int+data Window = Window Int+