Simple 3D library

A library for simple 3D transformations.

File:
Simple3D.lib
Version:
1.0
Author:
John Master

Contents

Details
Constants
Sub routines


Details

This library is kind of pointless, but you can use it to perform very simple 3D transformations for rendering some oldschool effects. Please see the examples for better understanding. If you want to do more advanced stuff than what's presented in the examples, you probably need to develop this library a bit.


Constants

Point array indexes

Name
Description
S3D_X
3D point x-coordinate.
S3D_Y
3D point y-coordinate.
S3D_Z
3D point z-coordinate.
S3D_PX
Projected x-coordinate.
S3D_PY
Projected y-coordinate.
S3D_PZ
Projected z-coordinate.


Subroutines

Setup

Name
Parameters
Brief description
procedure
S3D_SetView
fov#, zMin#, zMax#
Set view properties.

Transformations

Name
Parameters
Brief description
procedure
S3D_ClearTransformation
Clear transformation.
procedure
S3D_Translate
x#, y#, z#
Translate.
procedure
S3D_RotateX
a#
Rotate around x-axis.
procedure
S3D_RotateY
a#
Rotate around y-axis.
procedure
S3D_RotateZ
a#
Rotate around z-axis.
procedure
S3D_Scale
x#, y#, z#
Scale.

Transformation stack

Name
Parameters
Brief description
procedure
S3D_PushTransformation
Push transformation to stack.
procedure
S3D_PopTransformation
Pop transformation from stack.

Projection

Name
Parameters
Brief description
procedure
S3D_Project
&dstX, &dstY, x#, y#, z#
Project a point.
procedure
S3D_Project_3f
&dstX#, &dstY#, &dstZ#, x#, y#, z#
Project a point.
procedure
S3D_Project_3fv
&points#[][]
Project an array of points.


Subroutine documentation

procedure S3D_SetView ( fov#, zMin#, zMax# )

Set properties of the 3D view. The default view has a 60 degree field of view and a 'zMin' and 'zMax' value of 0.1 and 10.0. The 'zMin' and 'zMax' values doesn't make much sense unless you evolve into doing polygon clipping and such. Simply keep 'zMin' larger than 0 and 'zMax' larger than 'zMin' or stick with the mentioned values.

Parameter
Mode
Description
fov
In
Field of view.
zMin
In
Minimum z value for clipping.
zMax
In
Maximum z value for clipping.

[ Back ]


procedure S3D_ClearTransformation ( )

Clear the 3D transformation.

[ Back ]


procedure S3D_Translate ( x#, y#, z# )

Translate.

Parameter
Mode
Description
x
In
Translation along x-axis.
y
In
Translation along y-axis.
z
In
Translation along z-axis.

[ Back ]


procedure S3D_RotateX ( a# )

Rotate around x-axis.

Parameter
Mode
Description
a
In
Angle.

[ Back ]


procedure S3D_RotateY ( a# )

Rotate around y-axis.

Parameter
Mode
Description
a
In
Angle.

[ Back ]


procedure S3D_RotateZ ( a# )

Rotate around z-axis.

Parameter
Mode
Description
a
In
Angle.

[ Back ]


procedure S3D_Scale ( x#, y#, z# )

Scale along all axis. Note, that for no scaling along an axis, the value to use is 1, not 0.

Parameter
Mode
Description
x
In
Scale factor along x-axis.
y
In
Scale factor along y-axis.
z
In
Scale factor along z-axis.

[ Back ]


procedure S3D_PushTransformation ( )

Push transformation to stack.

[ Back ]


procedure S3D_PopTransformation ( )

Pop transformation from stack.

[ Back ]


procedure S3D_Project ( &dstX, &dstY, x#, y#, z# )

Project a 3D point, in the current transformation frame, to screen coordinates.

Parameter
Mode
Description
dstX
Out
Destination x-coordinate in screen space.
dstY
Out
Destination y-coordinate in screen space.
x
In
X-coordinate of 3D point.
y
In
Y-coordinate of 3D point.
z
In
Z-coordinate of 3D point.

[ Back ]


procedure S3D_Project_3f ( &dstX#, &dstY#, &dstZ#, x#, y#, z# )

Project a 3D point, in the current transformation frame, to screen coordinates. The difference between this function and 'S3D_Project' is that you also get a z-coordinate for the projected point, that you can use for sorting and other things.

Parameter
Mode
Description
dstX
Out
Destination x-coordinate in screen space.
dstY
Out
Destination y-coordinate in screen space.
dstZ
Out
Destination z-coordinate.
x
In
X-coordinate of 3D point.
y
In
Y-coordinate of 3D point.
z
In
Z-coordinate of 3D point.

[ Back ]


procedure S3D_Project_3fv ( &points#[][] )

This function does the same thing as 'S3D_Project_3f' but on a whole array of 3D points. The array must be a 2D array with (atleast) 6 fields in its second dimension. The first three fields represent the 3D point's x, y and z coordinates, while the next three fields are the resulting projected x, y and z coordinates. You can use the constants S3D_X, S3D_Y and S3D_Z for the 3D point fields, and S3D_PX, S3D_PY and S3D_PZ for the projected point fields.

Parameter
Mode
Description
points
In-out
An array of 3D points to be projected.

[ Back ]


Generated with NLDoc 20140630.