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

Safe HaskellNone
LanguageHaskell2010

Imj.Geo.Continuous

Contents

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

Instances

Eq (Vec2 a) Source # 

Methods

(==) :: Vec2 a -> Vec2 a -> Bool #

(/=) :: Vec2 a -> Vec2 a -> Bool #

Ord (Vec2 a) Source # 

Methods

compare :: 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 # 

Methods

showsPrec :: 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.

pos2vec :: Coords Pos -> Vec2 Pos Source #

Convert a discrete position to a continuous position.

vec2pos :: Vec2 Pos -> Coords Pos Source #

Convert a continuous position to a discrete position.

speed2vec :: Coords Vel -> Vec2 Vel Source #

Convert a discrete speed to a continuous speed.

vec2speed :: Vec2 Vel -> Coords Vel Source #

Convert a continuous speed to a discrete speed.

Sampled continuous geometry

Circle

translatedFullCircle Source #

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.

translatedFullCircleFromQuarterArc Source #

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

parabola :: Vec2 Pos -> Vec2 Vel -> Frame -> Vec2 Pos Source #

Using equation [2] in "Constant linear acceleration in any direction":

\[ \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

polyExtremities Source #

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.

rotateByQuarters :: Vec2 Pos -> [Vec2 Pos] Source #

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

data Vel Source #

Phantom type : velocity

data Acc Source #

Phantom type : acceleration