Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 4d-labyrinth.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cabal-version: >=1.10
executable 4d-labyrinth
main-is: Main.hs
other-modules: Object
Objects.Cube, Objects.Octahedron
Objects.Cube, Objects.Octahedron, Objects.Diamond
Transformation, Scene, SceneTO
Wireframe
Render
Expand All @@ -39,6 +39,6 @@ executable 4d-labyrinth
RotationMethods
other-extensions: TemplateHaskell, Rank2Types, ScopedTypeVariables
DeriveFunctor
build-depends: base >=4.9 && <4.11, OpenGL >=3.0 && <3.1, MonadRandom >=0.5 && <0.6, sdl2 >=2.2 && <2.5, lens >=4.15 && <4.17, linear >=1.20 && <1.21, containers >=0.5 && <0.6, bytestring >=0.10 && <0.11, filepath >=1.4 && <1.5, adjunctions >=4.3 && <4.5, array >=0.5 && <0.6, mtl >=2.2 && <2.3
build-depends: base >=4.9 && <4.12, OpenGL >=3.0 && <3.1, MonadRandom >=0.5 && <0.6, sdl2 >=2.2 && <2.5, lens >=4.15 && <4.17, linear >=1.20 && <1.21, containers >=0.5 && <0.6, bytestring >=0.10 && <0.11, filepath >=1.4 && <1.5, adjunctions >=4.3 && <4.5, array >=0.5 && <0.6, mtl >=2.2 && <2.3
hs-source-dirs: src
default-language: Haskell2010
34 changes: 34 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:

let

inherit (nixpkgs) pkgs;

f = { mkDerivation, adjunctions, array, base, bytestring
, containers, filepath, lens, linear, MonadRandom, mtl, OpenGL
, sdl2, stdenv
}:
mkDerivation {
pname = "4d-labyrinth";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
adjunctions array base bytestring containers filepath lens linear
MonadRandom mtl OpenGL sdl2
];
license = stdenv.lib.licenses.gpl3;
};

haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};

variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;

drv = variant (haskellPackages.callPackage f {});

in

if pkgs.lib.inNixShell then drv.env else drv
7 changes: 5 additions & 2 deletions src/Transformation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ rotation plane angle = Transformation
l = column plane . plane

-- Composition and identity transformation.
instance (SomeVector v, Num a) =>
Semigroup (Transformation v a) where
Transformation rot2 trans2 <> Transformation rot1 trans1 =
Transformation (rot2 !*! rot1) ((rot2 !* trans1) ^+^ trans2)

instance (SomeVector v, Num a) =>
Monoid (Transformation v a) where
mempty = Transformation identity zero
mappend (Transformation rot2 trans2) (Transformation rot1 trans1) =
Transformation (rot2 !*! rot1) ((rot2 !* trans1) ^+^ trans2)

-- Actually, rigid transformations form a group, not just a monoid.
-- (And computing the inverse is not very expensive,
Expand Down