Skip to content

Transformations

Syyrion edited this page Sep 10, 2022 · 8 revisions

A explaination for how lambda transformation functions work.


Introduction

Transformations provide a method to completely customize the behavior of walls. There are three types: polar, cartesian, and color. Polar and cartesian transformations are positional transformations and modify the geometry and movement of walls. Color transformations are their own category and modify the colors of verticies.

Transformation parameters are Discrete Function classes. However, they are part of a subclass called the DiscreteTransform class. This class includes one extra function on top of the already included five.

  • DiscreteTransform:run(...)
    Runs the transformation function with any arguments passed to the variadic. This function is equivalent to running:

    DiscreteTransform:get()(<...>)

    The variadic in the above example represents any relevant parameters that might be passed to the transformation function.

Positional Transformations

Positional transformations take a vertex as an input and output a modified vertex. There are two types: polar and cartesian. These transformations work with their respective coordinate systems.

IMPORTANT: When walls are being animated, only one of each transformation is applied to each vertex of each wall.

IMPORTANT: Polar transformations are always applied before cartesian transformations.

Polar Transformations

Polar transformations take two inputs: a radius and an angle in that order, and output a radius and an angle in that order. The function must only output a radius and an angle and nothing else.

Below is the no-operation polar tranformation. It takes the input radius <r> and angle <a> and outputs the same radius and angle.

function(r, a) return r, a end

Cartesian Transformations

Cartesian transformations take two inputs, an x and y coordinate in that order, and output an x and y coordinate in that order. The function must only output an x and y coordinate and nothing else.

Below is the no-operation polar transformation. It takes the coordinates <x> and <y> and outputs the same coordinates.

function(x, y) return x, y end

Color Transformations

Color transformations take in four inputs: the red, green, blue, and alpha channels of a color in that order, and output the red, green, blue, and alpha channels of a color in that order. The function must output four color channels and nothing else.

Below is the no-operation color transformation. It takes the color channels <r>, <g>, <b>, and <a> and outputs the same color channels.

function(r, g, b, a) return r, g, b, a end

If the run function is being used, polar and cartesian coordinate information is passed to the color transformation as shown below. This allows for the color of a wall vertex to change depending on its location.

function(r, g, b, a, radius, angle, x, y) return r, g, b, a end

Note: If the fill function is used, these extra parameters are not provided.

Custom Parameters (Depreciated)

Certain functions from the PolyWall class that handle animating walls include a variadic which allows them to pass custom parameters to transformation functions. These functions are:

  • PolyWall:step(depth, ...)
  • PolyWall:move(depth, mFrameTime, ...)
  • PolyWall:fill(depth, ...)
  • PolyWall:shade(depth, r, g, b, a, ...)
  • PolyWall:update(depth, ...)
  • PolyWall:draw(depth, mFrameTime, r, g, b, a, ...)

Any arguments passed to the variadic are passed to the transformation functions starting after the required parameters.

For example, if a polar transformation function requires an extra value <s> on top of the already necessary radius and angle arguments as shown below:

function(r, a, s) return r * s, a end

This value can be provided by adding it after the necessary parameters of the relevant animation function as shown below (in this case <customParameter>):

PolyWall:move(<depth>, <mFrameTime>, <customParameter>)

Specifying Unique Parameters for Different Transformations

Many of the animation functions use multiple transformation functions during a single call and will simply pass the same custom parameters to all transformation functions. This may pose a problem if unique parameters are necessary for different transformations. For example, polar and cartesian transformations always in pairs and will always be given the same set of custom parameters, but what if both transformations needed different parameters as shown below?

Polar Transformation:

function(r, a, s) return r * s, a end

Cartesian Transformation:

function(x, y, t) return x, y + t end

In this case, the arguments <s> and <t> will always be set to <customParameter0> when calling an animation function which may not be desireable.

PolyWall:move(<depth>, <mFrameTime>, <customParameter0>)

To solve this, add a dummy variable to one of the two transformations:

Polar Transformation:

function(r, a, s) return r * s, a end

Cartesian Transformation with dummy variable:

function(x, y, _, t) return x, y + t end

Then call the animation function with two custom parameters, <customParameter0> and <customParameter1>:

PolyWall:move(<depth>, <mFrameTime>, <customParameter0>, <customParameter1>)

In the example shown, the polar transformation will recieve <customParameter0> as usual. However, the cartesian transformation will ignore <customParameter0> because of the dummy variable and skip to using <customParameter1>.

Clone this wiki locally