Be a Supporter!

AS:3Dimensions-Basic

  • 5,822 Views
  • 27 Replies
New Topic Respond to this Topic
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
AS:3Dimensions-Basic Aug. 11th, 2005 @ 05:16 AM Reply

AS Mains Power Supply

-_--_--_--_--_--_--_--_--_--_--_--_--_--_-
-_--_--_--_--_--_--_--_-
-¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯-
-¯--¯--¯--¯--¯--¯--¯--¯-

AS:3Dimensions - Basic

-----------

The idea of using 3D in flash is that you simulate a third axis:
I am going to discuss just the basics for 3D in flash in this thread:

(the example im going to discuss)

In the example you can see a random arrangement of balls linked to the centre which spins around the X and Y axis with the mouse;

-----------

Creating the 3rd axis:
the 3rd axis is called the z-axis: since flash does not support 3d, you have to simulate it by using projection which can be done by simply scalling the objects using perspective

with perspective, the further something is away from the camera (for this basic 3d thread, ill just say the screen), the smaller the object gets, but also, the closer it seems to appear to the origin (1 point perspective with the vanishing point on the origin) as you can see on this here:

click me or perish ^^

//

to find out where the object (coordinate) appears on the screen you can use this formula

scalar = 500/(n+z); 500 being a constant which you can change (changes the overall look of the projection)

n is an important number which keeps the projection looking real, ever tried dividing 500 by 0? the n value is to keep the division by a number more than 0

then:

screenX = coordX*scalar;
screenY = coordY*scalar;

screenX and Y is where you would place the object in flashes coordinate system (you could then add a value to each to make it be centred in the middle of the screen instead of the top-left)

//

for example, in my example: the coordinate of each ball is random value for each axis from -100 to 100:
to keep the division by above 0, i would set n to a number more than 100 (i used 200) it doesnt really matter what number you use aslong as it keeps the z values more than 0, the higher the value of n, the smaller the resultant coordinate is:

for each 3d coordinate i would then do this: (supposing each 3d coordinate is stored in an object with variables x,y and z)

var scalar:Number = 500/(200+coord.z);
var screenX:Number = 275+coord.x*scalar;
var screenY:Number = 275+coord.y*scalar;

(im using the values 275 because the stage in my example is 550*550)

for each ball i then set its _x and _y to screenX and screenY

ball._x = screenX;
ball._y = screenY;

//

so what about scaling the balls and the transparency effect for further away balls?

you can mess around getting a good effect just by using the coord.z or the scalar number for example in my example:

ball._xscale = ball._yscale = ball._alpha = scalar*30;

//

the last thing for the rendering is this: the z-sorting of the objects
this is very simple and very important: you need to order the balls in flashes depths so that the balls in front are at the front and balls at the back are at the back behind the others:

you can do this using flashes swapDepths() function

for example in my example:

ball.swapDepths(-coord.z*100);

(the reason it is -coord.z is because the closer balls have a smaller z-value whereas the further away balls have a larger z-value so you need to swap it around so that the closer balls appear ontop)

-_--_--_--_--_--_--_--_--_--_--_--_--_--_-
-_--_--_--_--_--_--_--_-
-¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯-
-¯--¯--¯--¯--¯--¯--¯--¯-

the last thing is 3d rotation:

3d rotation uses matrices, but dont worry if you dont know what these are, you dont actually have to use matrice math for the rotations:

any rotation can be described by a matrix and this is where they come in, like i said they are not actually neccesary to use explicitly

a rotation about the x-axis is: (A being the angle)
x2 = x
y2 = y*cosA - z*sinA
z2 = y*sinA + z*cosA

a rotaion about the y-axis is:
x2 = x*cosA + z*sinA;
y2 = y;
z2 = -x*sinA + z*cosA;

a rotation about the z-axis is:
x2 = x*cosA - y*sinA;
y2 = x*sinA + y*cosA;
z2 = z;

note that rotations are done around the origin:

-_--_--_--_--_--_--_--_--_--_--_--_--_--_-
-_--_--_--_--_--_--_--_-
-¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯-
-¯--¯--¯--¯--¯--¯--¯--¯-

putting it all together you now have the basis to create my sample: and for anyone wanting it:
here is the source code:

-_--_--_--_--_--_--_--_--_--_--_--_--_--_-
-_--_--_--_--_--_--_--_-
-¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯--¯-
-¯--¯--¯--¯--¯--¯--¯--¯-

createEmptyMovieClip("balls", 0);
balls._x = balls._y = 275;
balls.attachMovie("cball", "centreball", 1);
balls.centreball.coord = {x:0, y:0, z:0};
var i:Number;
for (i = 0; i < 20; i++)
{
var m:MovieClip = balls.attachMovie("ball", "ball" + i, balls.getNextHighestDepth());
m.coord = {x:random(181) - 90, y:random(181) - 90, z:random(181) - 90};
}
delete m;
var dy:Number = 0, dx:Number = 0;
var pi:Number = Math.PI/180;
function render():Void
{
balls.clear();
balls.lineStyle(1, 0x0000000, 50);
var it:String;
for (it in balls)
{
var coord:Object = balls[it].coord;
//rotate
var sin:Number = Math.sin(dy * pi);
var cos:Number = Math.cos(dy * pi);
//
var tmp:Number = (sin * coord.y) + (cos * coord.z);
coord.y = (cos * coord.y) - (sin * coord.z);
coord.z = tmp;
//
sin = Math.sin(dx * pi);
cos = Math.cos(dx * pi);
//
tmp = (sin * coord.x) + (cos * coord.z);
coord.x = (cos * coord.x) - (sin * coord.z);
coord.z = tmp;
//
delete tmp;
delete sin;
delete cos;
//
//render
var pers:Number = 500 / (coord.z + 200);
var cx:Number = coord.x * pers;
var cy:Number = coord.y * pers;
balls[it]._x = cx;
balls[it]._y = cy;
balls[it]._xscale = balls[it]._yscale = balls[it]._alpha = pers * 30;
if (it != "centreball")
{
balls.lineStyle(1, 0x0000000, pers * 20);
balls.moveTo(cx, cy);
balls.lineTo(0, 0);
}
balls[it].swapDepths(-coord.z * 100);
balls[it].coord = coord;
}
}
render();
//
var mx:Number = _xmouse, my:Number = _ymouse;
this.onMouseMove = function()
{
dx = _xmouse - mx;
dy = _ymouse - my;
mx = _xmouse;
my = _ymouse;
render();
};

If anyone has more questions please ask


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
DFox
DFox
  • Member since: Aug. 9, 2003
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 05:27 AM Reply

Great tutorial!


BBS Signature
jdfnskindj
jdfnskindj
  • Member since: May. 22, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 05:32 AM Reply

My friend made a tut exactly like this....

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 06:01 AM Reply

At 8/11/05 05:32 AM, maxponte wrote: My friend made a tut exactly like this....

you implying i didnt make it? :/


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 08:20 AM Reply

Wow, for a 14 year old guy you are pretty sexy at AS! (no gay come-on intended)

A decent tutorial, could have been a little clearer but I think I understood the fundamentals.

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 08:21 AM Reply

im gunna start on the intermediate one now (to deal with fills and basic lighting)

then ill do a expert one for dealing with cameras etc


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
Rustygames
Rustygames
  • Member since: May. 7, 2005
  • Offline.
Forum Stats
Member
Level 19
Programmer
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 09:12 AM Reply

At 8/11/05 08:21 AM, dELta_Luca wrote: im gunna start on the intermediate one now (to deal with fills and basic lighting)

then ill do a expert one for dealing with cameras etc

Awesome tutorial

Just like your algorithm one I mayb need to read this one about 4 or 5 times to get it but when I do I will continue to the intermiediate
heh


- Matt, Rustyarcade.com

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 09:42 AM Reply

At 8/11/05 08:21 AM, dELta_Luca wrote: im gunna start on the intermediate one now (to deal with fills and basic lighting)

then ill do a expert one for dealing with cameras etc

Cool, nice tutorial.

Just one thing, with the next tutorial you should use bold, underlining and italics to headline different sections, quote, or whatever.. just to make it a little clearer.


Sup, bitches :)

BBS Signature
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 09:44 AM Reply

well the next one is just about done (i just need to make the sample movie) and its probably not going to be too easy to understand compared to this one (alot more complicated) but meh, i dont think ill bother with the advanced one (too much work and far too advanced)


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS:3Dimensions-Basic Aug. 11th, 2005 @ 10:13 AM Reply

my method is faster :P but not by alot

nice tutorial :)

JCesta
JCesta
  • Member since: Jul. 8, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:3Dimensions-Basic Sep. 15th, 2005 @ 10:13 PM Reply

wow... blown away, somwere in there my mind fizzled out

Rammer
Rammer
  • Member since: Jun. 8, 2003
  • Offline.
Forum Stats
Member
Level 33
Programmer
Response to AS:3Dimensions-Basic Sep. 15th, 2005 @ 11:52 PM Reply

im 14 too, but you just made me feel way stupid because im not quite that smart with AS yet ):

meanie


snyggys

OXXOI77777
OXXOI77777
  • Member since: Jul. 6, 2005
  • Offline.
Forum Stats
Member
Level 17
Musician
Response to AS:3Dimensions-Basic Feb. 11th, 2006 @ 01:26 AM Reply

but what are you soposed to DO ???????????


///////////////////////////////////
///////////////////////////////////
\\\\\\\\\\\[magic]\\\\\\\\\\\

BBS Signature
Edvin
Edvin
  • Member since: Feb. 3, 2004
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS:3Dimensions-Basic Feb. 11th, 2006 @ 04:27 AM Reply

At 2/11/06 01:26 AM, Droneavp23 wrote: but what are you soposed to DO ???????????

Dance with lamas.

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS:3Dimensions-Basic Feb. 11th, 2006 @ 04:30 AM Reply

At 2/11/06 01:26 AM, Droneavp23 wrote: but what are you soposed to DO ???????????

This is where the magic happens:
screenX = coordX*scalar;
screenY = coordY*scalar;

This is more of a theory thread than a "do this and that and you'll get this" thread.


BBS Signature
Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to AS:3Dimensions-Basic Feb. 11th, 2006 @ 07:38 AM Reply

YOU KNOW TOO MUCH!


BBS Signature
Rohedin
Rohedin
  • Member since: Feb. 19, 2006
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS:3Dimensions-Basic Jun. 17th, 2006 @ 11:22 AM Reply

I get the error message:
Scene=Scene 1, Layer=Layer 1, Frame=1: Line 14: '{' expected
function render():Void

Where does the { actually go?


...

authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS:3Dimensions-Basic Jun. 17th, 2006 @ 11:26 AM Reply

At 6/17/06 11:22 AM, Ng_begginer wrote: Where does the { actually go?

right after Void


BBS Signature
Rohedin
Rohedin
  • Member since: Feb. 19, 2006
  • Offline.
Forum Stats
Member
Level 18
Blank Slate
Response to AS:3Dimensions-Basic Jun. 18th, 2006 @ 05:02 AM Reply

At 6/17/06 11:26 AM, authorblues wrote: right after Void

Doesnt work =[


...

DarkNephilim
DarkNephilim
  • Member since: Jul. 11, 2006
  • Offline.
Forum Stats
Member
Level 05
Blank Slate
Response to AS:3Dimensions-Basic Oct. 21st, 2006 @ 03:23 AM Reply

it doesn't work

dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Oct. 21st, 2006 @ 03:44 AM Reply

At 10/21/06 03:23 AM, DarkNephilim wrote: it doesn't work

yes, im well aware that your 13 year old mind cannot comprehend that fact that going up to a girl and saying will you fuck a lama will not work.

please elaborate on WHAT exactly does not work


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
Cybex
Cybex
  • Member since: Mar. 4, 2005
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Oct. 21st, 2006 @ 03:47 AM Reply

Hey delta, how come you're so good at maths? You're a year younger than me, so technically i should be better than you. Do you get home schooled or something? Or have you just taight yourself some of the more advanced maths?

I bet you don't know calculus :P

Do you?
dELtaluca
dELtaluca
  • Member since: Apr. 16, 2004
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Oct. 21st, 2006 @ 04:04 AM Reply

At 10/21/06 03:47 AM, Mogly wrote: Hey delta, how come you're so good at maths? You're a year younger than me, so technically i should be better than you. Do you get home schooled or something? Or have you just taight yourself some of the more advanced maths?

I bet you don't know calculus :P

Do you?

well all my knowledge on vectors, matrices, and just 3d applications have all came from self learning and internet.

im also doing my a levels 2 years early, so yes i do know calculus, for example

int ( e^x.cosx ) dx.

let u = cosx, du/dx = -sinx
let dv/dx =e^x, v = e^x.

int( e^x.cosx ) dx = e^x.cosx + int ( e^x.sinx ) dx.

let v = sinx, du/dx = cosx
let dv/dx = e^x. v = e^x

int( e^x.sinx ) dx = e^x.sinx - int( e^x.cosx ) dx.

let i = int (e^x.cosx ) dx
then 2i = e^x.cosx + e^x.sinx so
int(e^x.cosx ) dx = 0.5(cosx + sinx)e^x + k


using ShamelessPlug; NapePhysicsEngine.advertise();

BBS Signature
DragonFruit-Rock
DragonFruit-Rock
  • Member since: Dec. 31, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS:3Dimensions-Basic Jul. 20th, 2007 @ 07:01 PM Reply

i love how big my ass is, perfect for delta lucas cock to fit down bitchy boy!


If a man that always tells the truth comes up to you and says that another man always tells lies, and the man who always lies come up to you and says "I'm lying", then is he?

BBS Signature
Powergames
Powergames
  • Member since: May. 14, 2006
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to AS:3Dimensions-Basic Aug. 27th, 2007 @ 03:25 PM Reply

At 2/11/06 01:26 AM, OXXOI77777 wrote: but what are you soposed to DO ???????????

i'm with ya man - don't understand a word of it

Spectacle
Spectacle
  • Member since: Apr. 10, 2006
  • Offline.
Forum Stats
Member
Level 20
Blank Slate
Response to AS:3Dimensions-Basic Jan. 11th, 2008 @ 11:27 AM Reply

the full script doesn't seem to work. Is it just because something in that doesn't work in flash 8?


f

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS:3Dimensions-Basic Jan. 11th, 2008 @ 11:49 AM Reply

Did you link 'ball'?


BBS Signature
archeris
archeris
  • Member since: Apr. 1, 2006
  • Offline.
Forum Stats
Member
Level 19
Blank Slate
Response to AS:3Dimensions-Basic May. 16th, 2008 @ 04:22 PM Reply

This post is retarded. There is no tutorial in here...