HGamer3D-Data 0.2.0 → 0.3.0
raw patch · 15 files changed
+473/−42 lines, 15 filesdep +FindBindep +directorydep +filepathsetup-changed
Dependencies added: FindBin, directory, filepath
Files
- HGamer3D-Data.cabal +6/−8
- HGamer3D/Data.hs +44/−0
- HGamer3D/Data/Angle.hs +8/−10
- HGamer3D/Data/Colour.hs +3/−6
- HGamer3D/Data/HG3DClass.hs +3/−2
- HGamer3D/Data/Operation3D.hs +101/−0
- HGamer3D/Data/ScreenGeometry.hs +67/−0
- HGamer3D/Data/TimeMS.hs +34/−0
- HGamer3D/Data/Vector.hs +2/−2
- HGamer3D/Data/Vector/Instances.hs +2/−2
- HGamer3D/Util.hs +34/−0
- HGamer3D/Util/FileLocation.hs +88/−0
- HGamer3D/Util/UniqueName.hs +48/−0
- LICENSE +31/−10
- Setup.hs +2/−2
HGamer3D-Data.cabal view
@@ -1,12 +1,10 @@ Name: HGamer3D-Data -Version: 0.2.0 -Synopsis: Windows Game Engine for the Haskell Programmer - Data Definitions +Version: 0.3.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 - language Haskell. The game engine uses available libraries for 3D graphics, - sound, input device handling, gui programming and other areas and make - those functions available for the Haskell programmer by providing - a Haskell API on top of that. HGamer3D is available on Windows only. + language Haskell. HGamer3D is available on Windows and Linux. This + package provides common data definitions and utility functions for HGamer3D. License: OtherLicense License-file: LICENSE @@ -19,9 +17,9 @@ Extra-source-files: Setup.hs Library - Build-Depends: base >= 3 && < 5, vect + Build-Depends: base >= 3 && < 5, FindBin, directory, filepath, vect - Exposed-modules: HGamer3D.Data.Vector,HGamer3D.Data.Vector.Instances,HGamer3D.Data.Colour,HGamer3D.Data.HG3DClass,HGamer3D.Data.Angle + 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 Other-modules: c-sources:
+ HGamer3D/Data.hs view
@@ -0,0 +1,44 @@+-- 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. +-- +-- Data.hs +-- + +-- | Common data definitions for HGamer3D +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.Vector, + module HGamer3D.Data.ScreenGeometry +) + +where + +import HGamer3D.Data.HG3DClass +import HGamer3D.Data.Angle +import HGamer3D.Data.Colour +import HGamer3D.Data.Operation3D +import HGamer3D.Data.TimeMS +import HGamer3D.Data.Vector +import HGamer3D.Data.ScreenGeometry +
HGamer3D/Data/Angle.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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. @@ -18,16 +18,17 @@ -- Angle.hs -{- | - Angles as Degrees or Radians, based on Float datatype --} - +-- | Angles as Degrees or Radians, based on Float datatype module HGamer3D.Data.Angle ( - -- export Radians and Degrees + -- * Data definitions and conversions Angle (..), + Radians (..), + Degrees (..), fromAngle, + + -- * Mathematical functions addA, subA, mulA, @@ -38,9 +39,6 @@ asinA, acosA, atanA, - - Radians (..), - Degrees (..), ) where
HGamer3D/Data/Colour.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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. @@ -18,14 +18,11 @@ -- ColourValue.hs +-- | HGamer3D colour type module HGamer3D.Data.Colour ( - -- export Colour Type again Colour (Colour, cRed, cGreen, cBlue, cAlpha), - - -- export all functions - ) where
HGamer3D/Data/HG3DClass.hs view
@@ -3,9 +3,9 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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. @@ -22,6 +22,7 @@ -- HG3DClass.hs -- +-- | Utility class to encapsulate class pointers module HGamer3D.Data.HG3DClass where -- import C2HS
+ HGamer3D/Data/Operation3D.hs view
@@ -0,0 +1,101 @@+-- 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 view
@@ -0,0 +1,67 @@+-- 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 view
@@ -0,0 +1,34 @@+-- 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/Vector.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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.
HGamer3D/Data/Vector/Instances.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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.
+ HGamer3D/Util.hs view
@@ -0,0 +1,34 @@+-- 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.+-- +-- Util.hs+-- ++-- | Common utilities for HGamer3D+module HGamer3D.Util++(+ module HGamer3D.Util.FileLocation,+ module HGamer3D.Util.UniqueName+)++where++import HGamer3D.Util.FileLocation+import HGamer3D.Util.UniqueName+
+ HGamer3D/Util/FileLocation.hs view
@@ -0,0 +1,88 @@+-- 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.++-- Util.hs++-- | Utility to provide file location information to other parts of HGamer3D+module HGamer3D.Util.FileLocation++(+ + -- * Directories relative to the user-related application directory for HGamer3D+ getAppMediaDirectory,+ getAppConfigDirectory,+ getAppLibDirectory,+ + -- * Directories relative to the executable (prog path)+ getExeMediaDirectory,+ getExeConfigDirectory,+ getExeLibDirectory,+ + -- * General utilities for path handling and finding files+ osSep,+ createDir,+ findFileInDirs+)++where++import Control.Monad+import System.Directory+import System.FilePath+import System.Environment.FindBin++_getHG3DDirectory subdir = do+ appdir <- getAppUserDataDirectory "HGamer3D" + let ndir = appdir ++ [pathSeparator] ++ subdir+ createDirectoryIfMissing True ndir+ return ndir+ +-- | path of media, relative to user app dir for HGamer3D+getAppMediaDirectory = _getHG3DDirectory "media"++-- | path of configuration, relative to user app dir for HGamer3D+getAppConfigDirectory = _getHG3DDirectory "config"++-- | path of libraries, relative to user app dir for HGamer3D+getAppLibDirectory = _getHG3DDirectory "lib"+ +_getBinDir subdir = do+ bdir <- getProgPath+ let ndir = bdir ++ [pathSeparator] ++ ".HGamer3D" ++ [pathSeparator] ++ subdir+ return ndir++-- | path of media, relative to executable+getExeMediaDirectory = _getBinDir "media"++-- | path of configuration, relative to executable+getExeConfigDirectory = _getBinDir "config"++-- | path of libraries, relative to executable+getExeLibDirectory = _getBinDir "lib"++-- | path separator for the filesystem+osSep = [pathSeparator]++-- | create a directory+createDir dir = createDirectoryIfMissing True dir++-- | find a file by searching in multiple directories+findFileInDirs filename listOfDirs = do+ let files = fmap (\d -> d ++ [pathSeparator] ++ filename) listOfDirs+ res <- filterM doesFileExist files+ if length res > 0 then return $ Just (res !! 0) else return Nothing
+ HGamer3D/Util/UniqueName.hs view
@@ -0,0 +1,48 @@+-- 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.++-- UniqueName.hs++-- | Utility to provide a unique name, carries internal state in a IORef+module HGamer3D.Util.UniqueName+(+ + UniqueName,+ createUniqueName,+ nextUniqueName+ +) where++import Data.IORef++data UniqueName = UniqueName String (IORef [Int])++-- | creates a unique name holder+createUniqueName :: String -> IO UniqueName+createUniqueName baseName = do+ ref <- newIORef [0..]+ return $ UniqueName baseName ref+ +-- | delivers the next unique name from the name holder+nextUniqueName :: UniqueName -> IO String+nextUniqueName (UniqueName baseName ref) = do+ name <- atomicModifyIORef ref (\ilist -> (tail ilist, baseName ++ (show (head ilist))))+ return name+ + +
LICENSE view
@@ -1,13 +1,34 @@-(c) 2011-2012 Peter Althainz +LICENSE +------- -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 +(c) 2011-2014 Peter Althainz - 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 (http://www.hgamer3d.org) +---------------------------------- + +HGamer3D is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software 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. + + +Source Code +----------- +You can obtain the latest version of the source code under http://www.bitbucket.org/althainz/HGamer3D + + +Open Source Software Used - Module HGamer3D.Data +------------------------------------------------ + +HGamer3D uses a number of open source software libraries. You are responsible to comply to the licenses of those packages and the licenses of software used by those packages if you use HGamer3D. + +The HGamer3D.Data module uses the following Haskell libraries from Hackage: + +base, license: BSD3 +FindBin, license: BSD3 +directory, license: BSD3 +filepath, license: BSD3 +vect, license: license: BSD3 +
Setup.hs view
@@ -1,8 +1,8 @@ -- This source file is part of HGamer3D -- (A project to enable 3D game development in Haskell) --- For the latest info, see http://www.althainz.de/HGamer3D.html +-- For the latest info, see http://www.hgamer3d.org -- --- (c) 2011 Peter Althainz +-- (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.