math/ matrix.bi

Summary
math/ matrix.bi
LicenseCopyright © 2009, FreeBASIC Extended Library Development Group
ext.math
matrixStandard OpenGL style (column major) matrix class for 3D programming.
Functions
constructorDefault constructor initializing the matrix to 0
constructorConstructor used to set matrix values to a set of vectors.
constructorConstructs a matrix from another.
LoadIdentity“Resets” a transformation matrix with no rotation, translation, scaling or skewing.
IdentityReturns the identity matrix, a matrix whose axis are normalized on the x, y and z axis, and whose position is at the origin (0, 0, 0).
LookAtSimplifies the construction of camera systems commonly used in 3d games.
PointAtSimplifies the creation of aligned matrices
InverseThis function is useful if you need the inverse matrix for calculating the local position of a vector, such as a light source.
InvertInverts the matrix.
Invert_copyReturns the inverse of the matrix.
PlanarProjectionBuilds a planar projection matrix using vector4d and plane(vector4d).
InfiniteProjectionBuilds an infinite projection matrix using fov(field of view), aspectratio( aspect ratio ) and znear( znear )
AxisAngle
Translategeneric translation function
Rotategeneric rotation function
Rotategeneric rotation function
ScaleScales each axis of the matrix by scalar
ScaleScales each axis of the matrix independently
Gram_ScmidtCalculates an orthonormal matrix with the forward vector aligned with vector “d”, while “vectors “up” and “right” are calculated using the “Gram Schmidt” method.
Properties
Rightsetter for the right vector component
Upsetter for the up vector component
Forwardsetter for the forward vector component
Positionsetter for the position vector component
Rightgetter for the right vector component
Upgetter for the up vector component
Forwardgetter for the forward vector component
Positiongetter for the position vector component
GetArrayDataReturns a pointer to the matrix data for passing to OpenGL functions.

License

Copyright © 2009, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com- /p- /fb-extended-lib- /wiki- /License

ext.math

matrix

Standard OpenGL style (column major) matrix class for 3D programming.

Usage

For simplicity, any reference to plane, will be vector4d for this library.

Summary
Functions
constructorDefault constructor initializing the matrix to 0
constructorConstructor used to set matrix values to a set of vectors.
constructorConstructs a matrix from another.
LoadIdentity“Resets” a transformation matrix with no rotation, translation, scaling or skewing.
IdentityReturns the identity matrix, a matrix whose axis are normalized on the x, y and z axis, and whose position is at the origin (0, 0, 0).
LookAtSimplifies the construction of camera systems commonly used in 3d games.
PointAtSimplifies the creation of aligned matrices
InverseThis function is useful if you need the inverse matrix for calculating the local position of a vector, such as a light source.
InvertInverts the matrix.
Invert_copyReturns the inverse of the matrix.
PlanarProjectionBuilds a planar projection matrix using vector4d and plane(vector4d).
InfiniteProjectionBuilds an infinite projection matrix using fov(field of view), aspectratio( aspect ratio ) and znear( znear )
AxisAngle
Translategeneric translation function
Rotategeneric rotation function
Rotategeneric rotation function
ScaleScales each axis of the matrix by scalar
ScaleScales each axis of the matrix independently
Gram_ScmidtCalculates an orthonormal matrix with the forward vector aligned with vector “d”, while “vectors “up” and “right” are calculated using the “Gram Schmidt” method.
Properties
Rightsetter for the right vector component
Upsetter for the up vector component
Forwardsetter for the forward vector component
Positionsetter for the position vector component
Rightgetter for the right vector component
Upgetter for the up vector component
Forwardgetter for the forward vector component
Positiongetter for the position vector component
GetArrayDataReturns a pointer to the matrix data for passing to OpenGL functions.

Functions

constructor

declare constructor(byref c as single =  0)

Default constructor initializing the matrix to 0

Parameters

coptional value to initialize the matrix to, defaults to 0.

constructor

declare constructor(byref r as vector3d,
byref u as vector3d,
byref f as vector3d,
byref p as vector3d)

Constructor used to set matrix values to a set of vectors.

Parameters

rthe “right” vector.
uthe “up” vector.
fthe “forward” vector.
pthe “position” vector.

constructor

declare constructor(byref x as matrix)

Constructs a matrix from another.

LoadIdentity

declare sub LoadIdentity()

”Resets” a transformation matrix with no rotation, translation, scaling or skewing.

Identity

declare static function Identity ( ) as matrix

Returns the identity matrix, a matrix whose axis are normalized on the x, y and z axis, and whose position is at the origin (0, 0, 0).

Returns

Returns the identity matrix.

LookAt

declare sub LookAt(byref v1 as vector3d,
byref v2 as vector3d,
byref vup as vector3d)

Simplifies the construction of camera systems commonly used in 3d games.

Parameters

v1center of rotation: an example would be to send the player’s position vector
v2view vector: an example would be to send the player’s forward vector
vupup vector: in a first person shooter, this would amost always be a <vector3d>(0,1,0)

PointAt

declare sub PointAt(byref v1 as vector3d,
byref v2 as vector3d)

Simplifies the creation of aligned matrices

Parameters

v1center of rotation: an example would be to send the player’s position vector
v2arbitrary point in space to align the matrices forward vector with

Inverse

declare function Inverse() as matrix

This function is useful if you need the inverse matrix for calculating the local position of a vector, such as a light source.  It’s commonly used for such things as shadow volume projection and bump mapping in 3d scenes.  This function is especially useful because the OpenGL API does not provide an inverse matrix function.

Returns

The inverse of the matrix.

Invert

declare sub Invert()

Inverts the matrix.  The new matrix value, when multiplied by it’s previous value, results in the identity matrix.

Description

This function is useful if you need the inverse matrix for calculating the local position of a vector, such as a light source.  It’s commonly used for such things as shadow volume projection and bump mapping in 3d scenes.  This function is especially useful because the OpenGL API does not provide an inverse matrix function.

Invert_copy

declare function Invert_copy() as matrix

Returns the inverse of the matrix.

Returns

Returns the inverse of the matrix.

PlanarProjection

declare function PlanarProjection(byref lightpos as vector4d,
byref plane as vector4D) as matrix

Builds a planar projection matrix using vector4d and plane(vector4d).  For simplicity, this library has no “plane” type, it uses vector4d.

Parameters

lightposposition of light source(vector4d)
planeplane to project onto.

Returns

the new planar projection matrix

InfiniteProjection

declare sub InfiniteProjection(byref fov as single,
byref aspectratio as single,
byref znear as single)

Builds an infinite projection matrix using fov(field of view), aspectratio( aspect ratio ) and znear( znear )

Parameters

fov field of view... in opengl, use the same value you would bnormally build your projection matrix with aspectratio... again, in opengl, use the same value you would normally build your projection matrix with znear... and again, in opengl, use the same value you would normally build your projection matrix with

Returns

nothing

AxisAngle

declare sub AxisAngle(byref v as vector3d,
byref angle as single)

Translate

declare sub Translate(byref x as single,
byref y as single,
byref z as single)

generic translation function

Parameters

Xtranslate to x position
Ytranslate to y position
Ztranslate to z position

Rotate

declare sub Rotate(byref anglex as single,
byref angley as single,
byref anglez as single)

generic rotation function

Parameters

anglexangle to rotate about the x axis
angleyangle to rotate about the y axis
anglezangle to rotate about the z axis

Rotate

declare sub Rotate(byref anglex as integer,
byref angley as integer,
byref anglez as integer)

generic rotation function

Parameters

anglexangle to rotate about the x axis
angleyangle to rotate about the y axis
anglezangle to rotate about the z axis

Scale

declare sub Scale(byref scalar as single)

Scales each axis of the matrix by scalar

Parameters

scalaramount to scale by.

Scale

declare sub Scale(byref scalarx as single,
byref scalary as single,
byref scalarz as single)

Scales each axis of the matrix independently

Parameters

scalarxamount to scale the x axis by.
scalaryamount to scale the y axis by.
scalarzamount to scale the z axis by.

Gram_Scmidt

Calculates an orthonormal matrix with the forward vector aligned with vector “d”, while “vectors “up” and “right” are calculated using the “Gram Schmidt” method.

Parameters

dthe vector to use for forward

Properties

Right

declare property Right(byref v as vector3d)

setter for the right vector component

Parameters

vsets the right vector components of the matrix

Up

declare property Up(byref v as vector3d)

setter for the up vector component

Parameters

vsets the up vector components of the matrix

Forward

declare property Forward(byref v as vector3d)

setter for the forward vector component

Parameters

vsets the forward vector components of the matrix

Position

declare property Position(byref v as vector3d)

setter for the position vector component

Parameters

vsets the position vector components of the matrix

Right

declare property Right() as vector3d

getter for the right vector component

Returns

the right vector components of the matrix

Up

declare property Up() as vector3d

getter for the up vector component

Returns

the up vector components of the matrix

Forward

declare property Forward() as vector3d

getter for the forward vector component

Returns

the forward vector components of the matrix

Position

declare property Position() as vector3d

getter for the position vector component

Returns

the position vector components of the matrix

GetArrayData

declare property GetArrayData() as single ptr

Returns a pointer to the matrix data for passing to OpenGL functions.

declare constructor(byref c as single =  0)
Default constructor initializing the matrix to 0
declare sub LoadIdentity()
“Resets” a transformation matrix with no rotation, translation, scaling or skewing.
declare static function Identity ( ) as matrix
Returns the identity matrix, a matrix whose axis are normalized on the x, y and z axis, and whose position is at the origin (0, 0, 0).
declare sub LookAt(byref v1 as vector3d,
byref v2 as vector3d,
byref vup as vector3d)
Simplifies the construction of camera systems commonly used in 3d games.
declare sub PointAt(byref v1 as vector3d,
byref v2 as vector3d)
Simplifies the creation of aligned matrices
declare function Inverse() as matrix
This function is useful if you need the inverse matrix for calculating the local position of a vector, such as a light source.
declare sub Invert()
Inverts the matrix.
declare function Invert_copy() as matrix
Returns the inverse of the matrix.
declare function PlanarProjection(byref lightpos as vector4d,
byref plane as vector4D) as matrix
Builds a planar projection matrix using vector4d and plane(vector4d).
declare sub InfiniteProjection(byref fov as single,
byref aspectratio as single,
byref znear as single)
Builds an infinite projection matrix using fov(field of view), aspectratio( aspect ratio ) and znear( znear )
declare sub AxisAngle(byref v as vector3d,
byref angle as single)
declare sub Translate(byref x as single,
byref y as single,
byref z as single)
generic translation function
declare sub Rotate(byref anglex as single,
byref angley as single,
byref anglez as single)
generic rotation function
declare sub Scale(byref scalar as single)
Scales each axis of the matrix by scalar
declare property Right(byref v as vector3d)
setter for the right vector component
declare property Up(byref v as vector3d)
setter for the up vector component
declare property Forward(byref v as vector3d)
setter for the forward vector component
declare property Position(byref v as vector3d)
setter for the position vector component
declare property GetArrayData() as single ptr
Returns a pointer to the matrix data for passing to OpenGL functions.