-
Notifications
You must be signed in to change notification settings - Fork 0
Transformations
A explaination for how lambda transformation functions work.
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
DiscreteTransformclass. 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 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 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 endCartesian 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 endColor 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 endIf 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 endNote: If the
fillfunction is used, these extra parameters are not provided.
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 endThis 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>)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 endCartesian Transformation:
function(x, y, t) return x, y + t endIn 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 endCartesian Transformation with dummy variable:
function(x, y, _, t) return x, y + t endThen 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>.
The information presented in this wiki is not guaranteed to be accurate. The information presented may be a few versions old.