Skip to content

Commit

Permalink
missing cardinal file + some minor fiddling on the raytracer front
Browse files Browse the repository at this point in the history
  • Loading branch information
noinia committed Jan 19, 2025
1 parent 1cee863 commit 22ea251
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
7 changes: 4 additions & 3 deletions hgeometry-examples/raytracer/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ rayColor gen = rayColor'
Nothing -> pure backgroundColor
Just (obj,q) -> do
let normal = normalUnitVectorAt q (obj^.geom)
v <- uniformUpwardDirectionWrt normal gen
v <- (normal ^+^) <$>
uniformUpwardDirectionWrt normal gen
-- shoot a new ray
(blend 0.5 (opaque black))
(blend 0.1 (opaque black))
<$> rayColor' (HalfLine (q^.core) v) (depth-1) scene

-- -- | Compute the color of the object at the intersection point with the ray
Expand Down Expand Up @@ -229,7 +230,7 @@ renderWithProgress reportProgress screenDims@(Vector2 w h) camera scene = do
viewportDims
screenDims

theViewport = Vector2 topLeft (topLeft .+^ (xVec ^+^ yVec))
-- theViewport = Vector2 topLeft (topLeft .+^ (xVec ^+^ yVec))


--------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion hgeometry-examples/raytracer/Settings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fromDesiredHeight desiredHeight = let Vector2 w h = fromIntegral <$> outputDimen

-- | The number of samples we take for each pixel
numSamplesPerPixel :: Int
numSamplesPerPixel = 10 -- 100
numSamplesPerPixel = 20 -- 100

-- | Maximum complexity of a single ray; (in number of segments)
maxRayComplexity :: Int
Expand Down
59 changes: 59 additions & 0 deletions hgeometry/kernel/src/HGeometry/Direction/Cardinal.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
--------------------------------------------------------------------------------
-- |
-- Module : HGeometry.Direction.Cardinal
-- Copyright : (C) Frank Staals
-- License : see the LICENSE file
-- Maintainer : Frank Staals
--
-- Cardinal and Intercardinal directions.
--
--------------------------------------------------------------------------------
module HGeometry.Direction.Cardinal
( CardinalDirection(..)
-- , _North, _East, _South, _West
, oppositeDirection

, InterCardinalDirection(..)
-- , _NorthWest, _NorthEast, _SouthEast, _SouthWest

, interCardinalsOf
) where

import GHC.Generics (Generic)
import HGeometry.Vector

--------------------------------------------------------------------------------

-- | The four cardinal directions.
data CardinalDirection = North | East | South | West deriving (Show,Read,Eq,Ord,Enum,Bounded)
-- makePrisms ''CardinalDirection

--------------------------------------------------------------------------------
-- * Functions on Cardinal Directions

-- | Computes the direction opposite to the given one.
oppositeDirection :: CardinalDirection -> CardinalDirection
oppositeDirection = \case
North -> South
East -> West
South -> North
West -> East

--------------------------------------------------------------------------------

-- | Intercardinal directions
data InterCardinalDirection = NorthWest | NorthEast | SouthEast | SouthWest
deriving (Show,Read,Eq,Ord,Enum,Generic)
-- makePrisms ''InterCardinalDirection

--------------------------------------------------------------------------------
-- * Functions on InterCardinal Directions

-- | Get the two intercardinal directions, in increasing order,
-- corresponding to the cardinal direction.
interCardinalsOf :: CardinalDirection -> Vector 2 InterCardinalDirection
interCardinalsOf = \case
North -> Vector2 NorthWest NorthEast
East -> Vector2 NorthEast SouthEast
South -> Vector2 SouthEast SouthWest
West -> Vector2 SouthWest NorthWest

0 comments on commit 22ea251

Please sign in to comment.