ianmackenzie/elm-3d-camera/1.1.0

NOTE: the latest version is 4.0.1

Viewpoint3d

A Viewpoint3d represents the position and orientation of a camera in 3D.

type alias Viewpoint3d =
Viewpoint3d

Constructors

{ focalPoint : Point3d
, eyePoint : Point3d
, upDirection : Direction3d
}
-> Viewpoint3d

Construct a Viewpoint3d at the given eye point looking towards the given focal point, with the given global up direction (which will typically be Direction3d.positiveZ or Direction3d.positiveY). For example, to construct a viewpoint at the point (10, 0, 5) looking towards the origin:

viewpoint =
    Viewpoint3d.lookAt
        { eyePoint =
            Point3d.fromCoordinates ( 10, 0, 5 )
        , focalPoint = Point3d.origin
        , upDirection = Direction3d.positiveZ
        }


Viewpoint3d.eyePoint viewpoint
--> Point3d.fromCoordinates ( 10, 0, 5 )


Viewpoint3d.xDirection viewpoint
--> Direction3d.positiveY


Viewpoint3d.yDirection viewpoint
--> Direction3d.fromAzimuthAndElevation
-->     (degrees 180)
-->     (degrees 63.43)


Viewpoint3d.viewDirection viewpoint
--> Direction3d.fromAzimuthAndElevation
-->     (degrees 180)
-->     (degrees -26.57)

That is likely all you need to know but if you are interested in the details and corner cases, read on!

The view direction of the returned viewpoint will point from the eye point to the focal point. The Y direction will be chosen to be as close to the global up direction as possible (the viewpoint will not have any 'roll') and the X direction will point to the right.

If the direction from the eye point to the focal point is parallel to the global up direction (that is, the viewpoint represents looking straight up or straight down) then the X and Y directions will be chosen arbitrarily.

If the given eye point and focal point are coincident (so that there is no well- defined view direction), then the returned frame will have its Y direction set to the global up direction and its X and view directions will be chosen arbitrarily.

Properties

eyePoint : Viewpoint3d -> Point3d

Get the actual eye point of a viewpoint.

viewDirection : Viewpoint3d -> Direction3d

Get the viewing direction of a viewpoint.

viewPlane : Viewpoint3d -> SketchPlane3d

The view plane of a viewpoint is a SketchPlane3d perpendicular to the view direction, with origin point equal to the eye point. For an observer looking straight down the view direction, the X direction of the view plane points to the right and the Y direction points up; this means that the view plane's normal direction is the opposite of the view direction. (Note that the Y direction will not be equal to the global up direction unless the view direction is horizontal).

xDirection : Viewpoint3d -> Direction3d

Get the X (right) direction of a viewpoint's view plane.

yDirection : Viewpoint3d -> Direction3d

Get the Y (local up) direction of a viewpoint's view plane.

Matrices

viewMatrix : Viewpoint3d -> Mat4

Get the view matrix of a viewpoint. Multiplying by this matrix transforms from world coordinates to eye coordinates.

modelViewMatrix : Frame3d -> Viewpoint3d -> Mat4

Construct a WebGL model-view matrix given a viewpoint and a Frame3d that defines the position and orientation of an object;

Viewpoint3d.modelViewMatrix modelFrame viewpoint

is equivalent to

Matrix4.mul
    (Viewpoint3d.viewMatrix viewpoint)
    (Frame3d.toMat4 modelFrame)

Multiplying by this matrix transforms from object coordinates to eye coordinates.