Over the few years I’ve used flash, for some reason my ultimate actionscripting dream has been to create a field of 3D grass :thumb:. Being more of an artist, I had no idea how to do this for the longest time, and tried all sorts of pathetic exponential models, none involving practical 3D calculation. AHH! So finally I came across kirupa.com and decided to use trig. Haha… Now I’m getting somewhere… uh… sort of.
So anyways, here’s my hopelessly simple “3D engine”
iname = this._name;
distance = Math.sqrt(Math.pow(_root["map"]["pos"]._x-_root["map"][iname]._x, 2)+Math.pow(_root["map"]["pos"]._y-_root["map"][iname]._y, 2));
differencex = _root["map"]["pos"]._x - _root["map"][iname]._x;
differencey = _root["map"]["pos"]._y - _root["map"][iname]._y;
angle1 = Math.atan2(Number(differencex), Number(differencey))*(Number(180)/Math.PI)
this._x = Number(_parent.centerh) + Number(angle1)*Number(-1)*Number(_parent.scale);
this._y = Number(_parent.centerv);
this._xscale = (Number(100)-Math.pow(Number(distance),1));
this._yscale = (Number(100)-Math.pow(Number(distance),1));
if (_parent.scale*(_root["map"]["pos"]._y-_root["map"][iname]._y)<Number(0)) {
this._visible = 0;
} else {
this._visible = 1;
}
(Yeah… I use Number() a lot :crazy: )
And the .fla: (attached)
I wanted to make this as simple and “physical” as possible. What I have is a small map in the corner with the “person” object (viewpoint) and all my “grass” objects. This is a sort of “Map Editor” if you will. Then there are the “actual” grass clips in the root scene with identical instance names (g1, g2, … g12).
All the 3D calculations are done by the “actual” grass (by the AS above), based on the distances between the viewpoint clip (“pos”) in the map and their corresponding grass clips also in the map. For now, you just drag the viewpoint around to change view.
I was highly surprised to find that this all seems to work fine. Except, the “person” is still 0 inches tall, flat on the “ground”. So the next step is elevation and scaling, and well, that’s where my math ability stops :crying:.
Isn’t there just some simple trig equation to add to the “this._x” and “this._y” portions of the AS to simulate an elevated viewpoint?
Thanks for any help!