Discuss and collaborate on GML scripts

You are not logged in.

#1 2010-03-05 16:43:37

Registered: 2010-02-12
Posts: 18

shear transform

Hello all,

I have already submitted the shear script by way of the web interface, but the few d3d-scripts have not changed.
The shear transform has many applications:
1) Anaglyphs. Using rotations for the different eye-views is incorrect. Use shear transforms instead. See
2) Monitor drawing. You can draw a monitor by way of a surface which you use as a texture, but by way of a shear transform, you can draw the image of the monitor directly onto the screen. See
3) Shadow drawing. You can draw shadows of point light by way of drawing onto a surface with the point light as the camera. The same holds for directional lights: use orthogonal camera projection. But shadows of directional lights can also by drawn directly on the screen by way of MitchGraham's method: simply project the scene onto the plane that must contain shadows. If the directional light is orthogonal to the plane, then the projection is simple. If not, then the projection is still simple if you use the shear transform script. See
And I did not mention drawing something skew yet.

**  Usage:
**      d3d_transform_add_shear_z(x,y,z)
**  Arguments:
**      x, y, z: coordinates       
**  Returns:
**      nothing
**  Notes:
**      The z-axis is made skew: points (0,0,t) are draw at (t*x,t*y,t*z). 
**      The x-axis (points (t,0,0)) and the y-axis (points (0,t,0)) stay 
**      the same.
**      The skew transformation is added to the current transformation.
**      This transformation is not orthogonal and hence does not work
**      properly in combination with lighting.
**  brac37
    var xs, ys, zs, n, ya, ya2, za;
    xs = argument0;
    ys = argument1;
    zs = argument2;
    n = sqrt(sqr(xs) + sqr(ys) + sqr(zs));
    za = radtodeg (arctan2 (ys, xs));
    ya2 = 0.5 * arctan2 (zs, sqrt(sqr(xs) + sqr(ys)));
    ya = radtodeg (ya2)
    d3d_transform_add_rotation_z (za);
    d3d_transform_add_scaling (1.414213562373095,1,1.414213562373095*n);
    d3d_transform_add_rotation_y (-45);
    d3d_transform_add_scaling (cos(ya2), 1, sin(ya2));
    d3d_transform_add_rotation_y (ya);
    d3d_transform_add_rotation_z (-za);


Board footer

Powered by FluxBB