explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!


2 Comments

Note to Self: Odds, Evens, -1 & 1

[BEST]

var isOdd:Boolean = Boolean( numberToCheck & 1 );
//for random odd/even
var isOdd:Boolean = Boolean( Math.round( Math.random() ) & 1 );

[BETTER]

Math.round( Math.random() ) == 0 ? 1 : -1;

[GOOD]

odd or even  = Math.round(Math.random() * 100) % 2 == 0 ? "even" : "odd";
-1 or 1 = Math.round(Math.random() * 100) % 2 == 0 ? 1 :- 1;
Advertisements


1 Comment

Bitmap Fills oriented for Isometric Projection

Notes to self…

Given an image suitable for use as a bitmap fill, certain matrix transformations need to be done in order to orient the image to the xy, xz, and yz planes in the xyz octant.  Assume the following octant orientations:

myIso

Here are the following matrix tranformations:

  • XY plane orientation – this is the equivalent to rotating the image by 45º and then reducing the height by half the original scale.

    var m:Matrix = new Matrix();
    m.rotate(Math.PI / 4);
    var m2:Matrix = new Matrix();
    m2.scale(1, 0.5);
    m.concat(m2);

  • XZ plane orientation – this is simply skewing the image in the flash-based coordinate system along the  y axis.  Since most isometric projections (including the as3isolib) use a 2:1 ratio, we use Math.atan(0.5) rather than Math.PI / 6.

    var m:Matrix = new Matrix();
    m.b = Math.atan(0.5);

  • YZ plane orientation – same as the XZ plane however we use the skew value * -1;

    var m:Matrix = new Matrix();
    m.b = Math.atan(-0.5);