Skip to content

Commit

Permalink
Camera rotating, more complex body
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhus committed Mar 26, 2012
1 parent c918d4a commit e605337
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/Caster.hs
Expand Up @@ -17,12 +17,13 @@ import GHC.Float
import Graphics.Gloss.Data.Color import Graphics.Gloss.Data.Color
import Graphics.Gloss.Data.Display import Graphics.Gloss.Data.Display
import qualified Graphics.Gloss.Data.Point as G import qualified Graphics.Gloss.Data.Point as G
import qualified Graphics.Gloss.Interface.Pure.Game as G
import Graphics.Gloss.Field import Graphics.Gloss.Field


import System.Console.CmdArgs.Implicit import System.Console.CmdArgs.Implicit


import DSMC.Traceables import DSMC.Traceables
import DSMC.Types import DSMC.Types hiding (position)
import DSMC.Util.Vector import DSMC.Util.Vector




Expand All @@ -48,9 +49,37 @@ data World = World
-- | Pixels in meter. -- | Pixels in meter.
scaleFactor = 200 scaleFactor = 200


origin = Vector 0 0 0

processEvents :: G.Event -> World -> World
processEvents event world =
case event of
G.EventKey (G.SpecialKey k) G.Down _ _ ->
let
cam = camera world
(pos, dir) = (position cam, direction cam)
(n, sX, sY) = buildCartesian dir
newPos =
case k of
G.KeyLeft -> pos <+> sX
G.KeyRight -> pos <-> sX
G.KeyUp -> pos <+> sY
G.KeyDown -> pos <-> sY
_ -> pos
in
world{camera = cam{position = newPos,
direction = origin <-> newPos}}
G.EventKey _ _ _ _ -> world
G.EventMotion _ -> world

main = main =
let let
body = cylinder (Vector 0.25 1 0) (Vector 0 0 0) 1 body = intersection [sphere (Vector 0 0 0) 1,
plane (Vector 1 0 1) 0,
plane (Vector (-1) 0 1) 0,
complement $
cylinder (Vector 0 1 0) (Vector 0 0 0) 0.2]



(width, height) = (600, 600) (width, height) = (600, 600)
display = InWindow "dsmc-tools CSG raycaster" (width, height) (100, 100) display = InWindow "dsmc-tools CSG raycaster" (width, height) (100, 100)
Expand Down Expand Up @@ -84,7 +113,7 @@ main =
playField display (1, 1) 1 playField display (1, 1) 1
world world
makePixel makePixel
(\_ w -> w) processEvents
(\_ w -> w) (\_ w -> w)




Expand All @@ -99,20 +128,4 @@ main =
-- Options{..} <- cmdArgs $ sample -- Options{..} <- cmdArgs $ sample
-- case bodyDef of -- case bodyDef of
-- Just fname -> print fname -- Just fname -> print fname
-- Nothing -> error "Lol u suck mon" -- Nothing -> error "No body definition given"

-- -- | Calculate color of ray.
-- rayCast :: Ray -> Body -> Color
-- rayCast ray b =
-- let
-- fullTrace = trace b ray
-- hitTrace = intersectTraces fullTrace [((0, Nothing),
-- (infinityP, Nothing))]
-- in
-- if null hitTrace
-- then white
-- else
-- let
-- n = fromJust (snd (fst (head hitTrace)))
-- in
-- scaleColor red ((reverse n) .* (velocity ray))

0 comments on commit e605337

Please sign in to comment.