• allegro5.a5_display
  • allegro5.a5_file
  • allegro5.a5_font
  • allegro5.a5_image
  • allegro5.a5_joystick
  • allegro5.a5_main
  • allegro5.a5_misc
  • allegro5.a5_opengl
  • allegro5.a5_shader
  • allegro5.a5_sound
  • allegro5.a5_thread
  • allegro5.a5_triangles
  • animation
  • array
  • atlas
  • buffer
  • color
  • common
  • csg.csg_aabb
  • csg.csg
  • csg.csg_octree
  • csg.csg_shapes
  • csg.csg_test
  • data
  • display
  • exception
  • file
  • font
  • glsl
  • grid
  • hash
  • image
  • image_op
  • index
  • ini
  • isometric
  • joystick
  • keyboard
  • land
  • layer
  • list
  • log
  • main
  • map
  • mem
  • mouse
  • net
  • noise
  • openglutil
  • perlin
  • pixelmask
  • plasma
  • pool
  • protobuf
  • queue
  • random
  • runner
  • shader
  • sound
  • sprite
  • thread
  • tilegrid
  • triangles
  • util2d
  • util3d
  • util
  • view
  • voronoi
  • widget.base
  • widget.board
  • widget.book
  • widget.box
  • widget.button
  • widget.checkbox
  • widget.container
  • widget.edit
  • widget.gul
  • widget.hbox
  • widget.layout
  • widget
  • widget.menu
  • widget.mover
  • widget.panel
  • widget.scrollbar
  • widget.scrolling
  • widget.sizer
  • widget.slider
  • widget.spin
  • widget.text
  • widget.theme
  • widget.vbox
  • widget.widget_list
  • yaml.external
  • yaml.internal
  • yaml
  • yaml.xml

land.util3d

translation matrix to translate by xt/yt/zt

T = 1 0 0 xt
    0 1 0 yt
    0 0 1 zt
    0 0 0 1

rotation matrix into coordinate system given by 3 vectors x=xx/yx/zx, y=xy/yy/zy, z=xz/yz/zz

R = xx xy xz 0
    yx yy yz 0
    zx zy zz 0
    0  0  0  1

scaling matrix to scale by xs/ys/zs

S = xs 0  0  0
    0  ys 0  0
    0  0  zs 0
    0  0  0  1

inv(T) = 1 0 0 -xt
         0 1 0 -yt
         0 0 1 -zt
         0 0 0 1

inv(R) = xx yx zx 0
         xy yy zy 0
         xz yz zz 0
         0  0  0  1

T x = x + xt
  y = y + yt
  z = z + zt
  1 = 1

R x = xx x + xy y + xz z
  y = yx x + yy y + yz z
  z = zx x + zy y + zz z
  1 = 1

rotate first then translate

T R = xx xy xz xt
      yx yy yz yt
      zx zy zz zt
      0  0  0  1

T R x = xx x + xy y + xz z + xt
    y   yx x + yy y + yz z + yt
    z   zx x + zy y + zz z + zt
    1   1

translate first then rotate

R T = xx xy xz xx xt + xy yt + xz zt
      yx yy yz yx xt + yy yt + yz zt
      zx zy zz zx xt + zy yt + zz zt
      0  0  0  1

scale first then translate

T S = 1 0 0 xt   xs 0  0  0   xs 0  0  xt
      0 1 0 yt * 0  ys 0  0 = 0  ys 0  yt
      0 0 1 zt   0  0  zs 0   0  0  zs zt
      0 0 0 1    0  0  0  1   0  0  0  1

T S x = xs * x + xt
    y   ys * y + yt
    z   zs * z + zt
    1   1

translate first then scale

S T = xs 0  0  0   1 0 0 xt   xs 0  0  xs*xt
      0  ys 0  0 * 0 1 0 yt = 0  ys 0  ys*yt
      0  0  zs 0   0 0 1 zt   0  0  zs zs*zt
      0  0  0  1   0 0 0 1    0  0  0  1

S T x = xs * x + xs * xt
    y   ys * y + ys * yt
    z   zs * z + zs * zt
    1   1

translate first then arbitrary affine matrix

A T = A0 A1 A2 A3   1 0 0 xt    A0 A1 A2 A0*xt+A1*yt+A2*zt+A3
      A4 A5 A6 A7 * 0 1 0 yt =  A4 A5 A6 A4*xt+A5*yt+A7*zt+A7
      A8 A9 Aa Ab   0 0 1 zt    A8 A9 Aa A8*xt+A9*yt+Aa*zt+Ab
      0  0  0  1    0 0 0 1     0  0  0  1

scale first then arbitrary affine matrix

A S = A0 A1 A2 A3   xs 0  0  0   A0*xs A1*ys A2*zs A3
      A4 A5 A6 A7 * 0  ys 0  0 = A4*xs A5*ys A6*zs A7
      A8 A9 Aa Ab   0  0  zs 0   A8*xs A9*ys Aa*zs Ab
      0  0  0  1    0  0  0  1   0     0     0     1 

rotate by an angle around vector 0/0/1

Ra = +cos -sin 0 0
     +sin +cos 0 0
     0    0    1 0
     0    0    0 1

same but arbitrary affine matrix afterwards

A Ra = A0*c+A1*s -A0*s+A1*c A2 A3
       A4*c+A5*s -A4*s+A5*c A6 A7
       A8*c+A9*s -A8*s+A9*c Aa Ab
       0         0          0  1

LandVector

A simple 3D vector, with some extra useful methods for quaternions, transformations and rotation.

Land4x4Matrix

LandQuaternion

A quaternion can be useful to hold rotations, as it is much easier to use for physics code. For example a 3x3 matrix has too much redundancy (9 values instead of 3), and so usually will be hard to deal with or lead to wrong results. A quaternion instead will hold not much more than just the orientation (4 values instead of 3).

Orientation basically is a direction, with an additional rotation. For
example, a 3d vector plus an angle would describe it. Since the length of
the 3d vector does not matter, just 3 angles also are enough (pitch, yaw,
roll). Obviously, we can convert from any form to any other, quaternions
just have properties which make them easy to use in physics code.

land_vector

Parameters: LandFloat x, LandFloat y, LandFloat z

Returns: LandVector

land_vector_from_array

Parameters: LandFloat * a

Returns: LandVector

land_vector_iadd

Parameters: LandVector * v, LandVector w

land_vector_isub

Parameters: LandVector * v, LandVector w

land_vector_imul

Parameters: LandVector * v, LandFloat s

land_vector_idiv

Parameters: LandVector * v, LandFloat s

land_vector_neg

Parameters: LandVector v

Returns: LandVector

land_vector_mul

Parameters: LandVector v, LandFloat s

Returns: LandVector

land_vector_div

Parameters: LandVector v, LandFloat s

Returns: LandVector

land_vector_add

Parameters: LandVector v, LandVector w

Returns: LandVector

land_vector_add4

Parameters: LandVector v, LandVector w, LandVector a, LandVector b

Returns: LandVector

land_vector_add8

Parameters: LandVector v, LandVector w, LandVector a, LandVector b, LandVector c, LandVector d, LandVector e, LandVector f

Returns: LandVector

land_vector_sub

Parameters: LandVector v, LandVector w

Returns: LandVector

land_vector_lerp

Parameters: LandVector v, LandVector w, LandFloat t

Returns: LandVector

land_vector_dot

Parameters: LandVector v, LandVector w

Returns: LandFloat

The dot product is a number. The number corresponds to the cosine between the two vectors times their lengths. So the angle between the vectors would be: angle = acos(v . w / (|v| * |w|)). If the dot product is 0, the two vectors conversely are orthogonal. The sign can be used to determine which side of a plane a point is on.

land_vector_cross

Parameters: LandVector v, LandVector w

Returns: LandVector

The cross product results in a vector orthogonal to both v and w. The length of the resulting vector corresponds to the sine of the angle between the two vectors and their lengths. So the angle between the vectors would be: angle = asin(|v x w| / (|v| * |w|)). If the cross product is the 0 vector, the two input vectors are parallel.

land_vector_norm

Parameters: LandVector v

Returns: LandFloat

Return the norm of the vector.

land_vector_normalize

Parameters: LandVector v

Returns: LandVector

Return a normalized version of the vector.

land_vector_quatmul

Parameters: LandVector v, LandQuaternion q

Returns: LandQuaternion

Multiply the vector with a quaternion. The result is a quaternion. For example if your vector is a rotation, the resulting quaternion will be a quaternion who rotates whatever it did plus this additional rotation.

land_vector_transform

Parameters: LandVector v, LandVector p, LandVector r, LandVector u, LandVector b

Returns: LandVector

Return a new vector obtained by transforming this vector by a coordinate system with the given origin and given right/up/back vectors. This is used if the vector is in world coordinates, and you want to transform it to camera coordinates, where p/r/u/b define camera position and orientation.

land_vector_matmul

Parameters: LandVector v, Land4x4Matrix * m

Returns: LandVector

land_vector_backtransform

Parameters: LandVector v, LandVector p, LandVector r, LandVector u, LandVector b

Returns: LandVector

Do the inverse of transform, i.e. you can use it to transform from camera back to world coordinates.

land_vector_rotate

Parameters: LandVector v, LandVector a, double angle

Returns: LandVector

Rotate the vector around axis a by angle in counter clockwise direction. If this vector is a point in world space, then the axis of rotation is defined by the origin and the a vector.

land_vector_reflect

Parameters: LandVector v, LandVector n

Returns: LandVector

Given the normal of a plane, reflect the vector off the plane. If the vector is a point in 3D space, and the plane goes through the origin, the result is a point reflected by the plane.

land_quaternion

Parameters: LandFloat w, LandFloat x, LandFloat y, LandFloat z

Returns: LandQuaternion

land_quaternion_from_array

Parameters: LandFloat * f

Returns: LandQuaternion

land_quaternion_to_array

Parameters: LandQuaternion * q, LandFloat * f

land_quaternion_iadd

Parameters: LandQuaternion * q, LandQuaternion p

land_quaternion_imul

Parameters: LandQuaternion * q, LandFloat s

land_quaternion_combine

Parameters: LandQuaternion qa, LandQuaternion qb

Returns: LandQuaternion

land_quaternion_vectors

Parameters: LandQuaternion q, LandVector * r, LandVector * u, LandVector * b

Output three orientation vectors for the quaternion. That is, if the quaternion is used as a 3D orientation, return right/up/back vectors representing the same orientation.

land_quaternion_4x4_matrix

Parameters: LandQuaternion q

Returns: Land4x4Matrix

land_4x4_matrix_mul

Parameters: Land4x4Matrix a, Land4x4Matrix b

Returns: Land4x4Matrix

This multiplies two matrices:

result = a b

When used with 3D transformations, the result has the same effect as first
applying b, then a. For example:

v = land_vector(1, 0, 0)
a = land_4x4_matrix_scale(10, 1, 1)
b = land_4x4_matrix_translate(10, 0, 0)

# This means first b then a, so v is first translated to 11, then
# scaled to 110.
land_vector_matmul(v, land_4x4_matrix_mul(a, b))

# This means v is first scaled to 10, then translated to 20.
land_vector_matmul(v, land_4x4_matrix_mul(b, a))

In words, result[row,column] = a[row,...] * b[...,column].

land_4x4_matrix_scale

Parameters: LandFloat x, LandFloat y, LandFloat z

Returns: Land4x4Matrix

land_4x4_matrix_skew

Parameters: LandFloat xy, LandFloat xz, LandFloat yx, LandFloat yz, LandFloat zx, LandFloat zy

Returns: Land4x4Matrix

land_4x4_matrix_rotate

Parameters: LandFloat x, LandFloat y, LandFloat z, LandFloat angle

Returns: Land4x4Matrix

land_4x4_matrix_identity

no parameters

Returns: Land4x4Matrix

land_4x4_matrix_translate

Parameters: LandFloat x, LandFloat y, LandFloat z

Returns: Land4x4Matrix

T = 1 0 0 xt 0 1 0 yt 0 0 1 zt 0 0 0 1

land_4x4_matrix_perspective

Parameters: LandFloat left, LandFloat bottom, LandFloat nearz, LandFloat right, LandFloat top, LandFloat farz

Returns: Land4x4Matrix

land_4x4_matrix_orthographic

Parameters: LandFloat left, LandFloat top, LandFloat nearz, LandFloat right, LandFloat bottom, LandFloat farz

Returns: Land4x4Matrix

Orthographic means no projection so this would be just an identity matrix. But as convenience this scales and translates to fit into the left/top/right/bottom rectangle and also scales depth.

The point at (left, top, near) will end up at (-1, -1, -1) and the point
at (right, bottom, far) will end up at (1, 1, 1).

O = S(2/w, 2/h, 2/d) T(-cx, -cy, -cz)

O = 2/w 0   0   2/w*-cx
    0   2/h 0   2/h*-cy
    0   0   2/d 2/d*-cz
    0   0   0   1

O x = 2/w*(x-cx)
  y   2/h*(y-cy)
  z   2/d*(z-cz)
  1   1

inv(O) = inv(T) inv(S) = w/2 0   0   cx
                         0   h/2 0   cy
                         0   0   d/2 cz
                         0   0   0   1

O inv(O) = 1 0 0 0
           0 1 0 0
           0 0 1 0
           0 0 0 1

land_4x4_matrix_from_vectors

Parameters: LandVector * p, LandVector * r, LandVector * u, LandVector * b

Returns: Land4x4Matrix

land_4x4_matrix_inverse_from_vectors

Parameters: LandVector * p, LandVector * r, LandVector * u, LandVector * b

Returns: Land4x4Matrix

land_4x4_matrix_get_right

Parameters: Land4x4Matrix * m

Returns: LandVector

land_4x4_matrix_get_up

Parameters: Land4x4Matrix * m

Returns: LandVector

land_4x4_matrix_get_back

Parameters: Land4x4Matrix * m

Returns: LandVector

land_4x4_matrix_get_position

Parameters: Land4x4Matrix * m

Returns: LandVector

land_quaternion_normalize

Parameters: LandQuaternion * q

Normalize the quaternion. This may be useful to prevent deteriorating the quaternion if it is used for a long time, due to floating point inaccuracies.

land_quaternion_slerp

Parameters: LandQuaternion qa, LandQuaternion qb, double t

Returns: LandQuaternion

Given two quaternions, interpolate a quaternion in between. If t is 0 this will return qa, if t is 1 it will return qb.

The rotation will be along the shortest path (not necessarily the shorter
direction though) and the rotation angle will linearly correspond to t.

land_4x4_matrix_to_string

Parameters: Land4x4Matrix * m

Returns: LandBuffer*


Generated: Thu 27 Feb 2020 10:49:37 PM EST