netwire-4.0.0: Flexible wire arrows for FRP

Copyright(c) 2012 Ertugrul Soeylemez
LicenseBSD3
MaintainerErtugrul Soeylemez <es@ertes.de>
Safe HaskellNone
LanguageHaskell2010

Control.Wire.Prefab.Move

Contents

Description

This module provides the wires for various kinds of moving objects. In particular this includes various calculus wires like integrals and differentials.

Synopsis

Calculus

Integrals

integral :: VectorSpace b => b -> Wire e m (b, Scalar b) b Source

Integral wire. Produces position from velocity in the sense of the given vector space.

  • Depends: previous instant.

integral_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => b -> Wire e m b b Source

Same as integral, but with respect to time.

  • Depends: previous instant.

integralLim Source

Arguments

:: VectorSpace b 
=> (w -> b -> b -> b)

Post-update function.

-> b

Initial value.

-> Wire e m ((b, w), Scalar b) b 

Variant of integral, where you can specify a post-update function, which receives the previous position as well as the current (in that order). This is useful for limiting the output (think of robot arms that can't be moved freely).

  • Depends: current instant if the post-update function is strict in its first argument, previous instant if not.

integralLim_ :: (Monad m, VectorSpace b, Scalar b ~ Time) => (w -> b -> b -> b) -> b -> Wire e m (b, w) b Source

Same as integralLim, but with respect to time.

  • Depends: previous instant.

Differentials

derivative Source

Arguments

:: (Eq dt, Fractional dt, VectorSpace b, Scalar b ~ dt) 
=> (b -> dt -> b)

Handle exceptional change rates (receives dx and dt).

-> b

Initial position.

-> Wire e m (b, dt) b 

Derivative. Receives x and dt and calculates the change rate dx/dt. Note that dt despite its name does not have to be time.

The exception handler function is called when dt is zero. That function's result is the wire's output for those instants. If you don't want to handle exceptional cases specially, just pass (^/) as the handler function.

  • Depends: current instant.

derivative_ Source

Arguments

:: (Monad m, VectorSpace b, Scalar b ~ Time) 
=> (b -> Time -> b)

Handle exceptional cases.

-> b

Initial position.

-> Wire e m b b 

Same as derivative, but with respect to time.

  • Depends: current instant.

Simulations/games

object Source

Arguments

:: (VectorSpace b, Scalar b ~ dt) 
=> (w -> ObjectState b -> ObjectState b)

Post-move update function.

-> ObjectState b

Initial state.

-> Wire e m (ObjectDiff b, w, dt) (ObjectState b) 

Objects are generalized integrals. They are controlled through velocity and/or acceleration and can be collision-checked as well as instantly teleported.

The post-move update function receives the world state and the current object state. It is applied just before the wire produces its output. You can use it to perform collision-checks or to limit the velocity.

Note that teleportation doesn't change the velocity.

  • Depends: current instant.

object_ Source

Arguments

:: (Monad m, VectorSpace b, Scalar b ~ Time) 
=> (w -> ObjectState b -> ObjectState b)

Post-move update function.

-> ObjectState b

Initial state.

-> Wire e m (ObjectDiff b, w) (ObjectState b) 

Same as object, but with respect to time.

  • Depends: current instant.

data ObjectState a Source

Object state. This includes the position and velocity.

Constructors

ObjectState 

Fields

objPosition :: a

Position.

objVelocity :: a

Velocity.

Instances

Eq a => Eq (ObjectState a) 
Data a => Data (ObjectState a) 
Ord a => Ord (ObjectState a) 
Read a => Read (ObjectState a) 
Show a => Show (ObjectState a) 
Typeable (* -> *) ObjectState 

data ObjectDiff a Source

Differential for objects.

Constructors

Accelerate a

Accelerate (units per second).

Position a

Teleport to the given position instantly (velocity will be unchanged).

Velocity a

Specify velocity (units per second).

Instances

Eq a => Eq (ObjectDiff a) 
Data a => Data (ObjectDiff a) 
Ord a => Ord (ObjectDiff a) 
Read a => Read (ObjectDiff a) 
Show a => Show (ObjectDiff a) 
Typeable (* -> *) ObjectDiff