imj-base-0.1.0.2: Game engine with geometry, easing, animated text, delta rendering.

Imj.Geo.Continuous

Synopsis

# Continuous coordinates

data Vec2 a Source #

Continuous 2d coordinates. We use phantom types Pos, Vel, Acc to distinguish between a position, a velocity, and an acceleration.

Constructors

 Vec2 Fields_vec2X :: !Float _vec2Y :: !Float

Instances

 Eq (Vec2 a) Source # Methods(==) :: Vec2 a -> Vec2 a -> Bool #(/=) :: Vec2 a -> Vec2 a -> Bool # Ord (Vec2 a) Source # Methodscompare :: Vec2 a -> Vec2 a -> Ordering #(<) :: Vec2 a -> Vec2 a -> Bool #(<=) :: Vec2 a -> Vec2 a -> Bool #(>) :: Vec2 a -> Vec2 a -> Bool #(>=) :: Vec2 a -> Vec2 a -> Bool #max :: Vec2 a -> Vec2 a -> Vec2 a #min :: Vec2 a -> Vec2 a -> Vec2 a # Show (Vec2 a) Source # MethodsshowsPrec :: Int -> Vec2 a -> ShowS #show :: Vec2 a -> String #showList :: [Vec2 a] -> ShowS #

# Conversion to / from discrete coordinates

Discrete positions are converted to continuous positions by placing them at the "pixel center", ie by applying an offset of (0.5, 0.5) in pos2vec.

Then, during the inverse transformation - in vec2pos, coordinates are just floored.

Discrete speeds are converted with speed2vec. The half-pixel convention is not applied for speeds. The inverse conversion is vec2speed.

Convert a discrete position to a continuous position.

Convert a continuous position to a discrete position.

Convert a discrete speed to a continuous speed.

Convert a continuous speed to a discrete speed.

# Sampled continuous geometry

## Circle

Arguments

 :: Vec2 Pos Center -> Float Radius -> Float The angle corresponding to the first sampled point -> Int The total number of sampled points -> [Vec2 Pos]

Samples a circle.

Arguments

 :: Vec2 Pos Center -> Float Radius -> Float The angle corresponding to the first sampled point -> Int The total number of sampled points per quarter arc. -> [Vec2 Pos]

Samples a circle in an optimized way, to reduce the number of sin and cos calls.

The total number of points will always be a multiple of 4.

## Parabola

$\vec r = \vec r_0 + \vec v_0*t + {1 \over 2}* \vec a*t^2$

$where$

$\vec r = current\;position$

$\vec r_0 = initial\;position$

$\vec v_0 = initial\;velocity$

$\vec a = gravity\;force$

$t = time$

# Polygon extremities

Arguments

 :: Vec2 Pos Center -> Float Radius -> Float Rotation angle -> Int Number of sides of the polygon. -> [Vec2 Pos]

Returns the extremities of a polygon. Note that it is equal to translatedFullCircle

# Vec2 utilities

sumVec2d :: Vec2 a -> Vec2 a -> Vec2 a Source #

Sums two Vec2.

scalarProd :: Float -> Vec2 a -> Vec2 a Source #

Multiplies a Vec2 by a scalar.

Creates a list of 4 Vec2 from a single one by rotating it successively by pi/2.

# Reexports

data Pos Source #

Phantom type : position

Instances

 Source # Using bresenham 2d line algorithm. Methods Source # Using bresenham 2d line algorithm. Methods

data Vel Source #

Phantom type : velocity

data Acc Source #

Phantom type : acceleration