Flashadvisor logo
:: Desktop Shortcut
:: Flash Help
Advices from Experts

 Submit Here! · Link to Us · Newsletter · Tell a Friend ·

      Add Tutorial |

 

Advertise here










 

Google

Search WWW   
FlashAdvisor.com

 Home > Tutorials  > 3D






How To Create the 3D Object in Flash

Author: Sergey Kamenev | Email


Advertisement


All the calculations are done now. Now we are turning to Flash.

Let's create a Symbol named by FlatT. It the FlatT create a Symbol named by FlatT_, in FlatT_ - Symbol named by FlatT__,
and at last in it draw such chipped square:



. Give the names to the created objects.
FlatT__ inside FlatT_ name by mvFlatT__, FlatT_ inside FlatT name by mvFlatT_,
and FlatT on the scene name by mvFlatT. We shall use FlatT and FlatT_ for deformation
of the flat object, FlatT__ - to rotate the flat object in its own plane around its centre.
ActionScript will be inside FlatT only.
Imitation of the object named by mvFlatT in space will be made by the function
placeOnSphere(xc,yc,vn,amn,nclF,nclB,vl), where xc, yc are co-ordinates of the sphere centre,
vn - object with three fields vn.x_, vn.y_ and vn.z_ - co-ordinates of the object centre,
that we want to look like moving in space,
amn - rotation angle of the flat object in its own plane around its centre,
nclF - the color of the forward side of the flat object, nclB - the color of the back side,
and vl - the object like vn but for light source.
Variable names are very close to the names that we used in the geometrical part of this lesson.
The code of script can be optimized but after this it will not like geometrical part.
Here is the code of this function:







4 function placeOnSphere(xc,yc,vn,amn,nclF,nclB,vl)
5 {
6 var rad;
7 var l_,h_,w_;
8 var vf;
9 var tan_gamma;
10 var q_;var oe;
11
12 if(Math.abs(vn.x_)<0.001)
13 vn.x_=0;
14 if(Math.abs(vn.y_)<0.001)
15 vn.y_=0;
16 if(Math.abs(vn.z_)<0.001)
17 vn.z_=0;
18 XM=vn.x_;YM=vn.y_;ZM=vn.z_;
19 rad=Math.sqrt(vn.x_*vn.x_+vn.y_*vn.y_+vn.z_*vn.z_);
20
21 vf=new Object();
22 vf.x_=vn.y_;vf.y_=vn.z_;
23
24 placeXYZ(xc,yc,vf);
25
26 mirrorM(vn);
27
28 tan_gamma=def_tan_gamma(rad,vf);
29 l_=defL_(vn);
30 h_=defH_(rad,vn);
31 if(tan_gamma!='i')
32 {
33 if(vn.y_>=0)
34 gamma=Math.PI+Math.atan(tan_gamma);
35 else
36 gamma=Math.PI-Math.atan(tan_gamma);
37 }
38 else
39 gamma=Math.PI/2;
40 w_=h_/Math.sin(gamma);
41
42 oe=new Object();
43 q_=defQ_(l_,w_,gamma,oe);
44 mvFlatT_._xscale=oe.p_*100;
45 mvFlatT_._yscale=q_*100;
46 mvFlatT_._rotation=oe.fi/Math.PI*180;
47 if(vn.y_*vn.z_<0)
48 mvFlatT_._rotation=-mvFlatT_._rotation;
49 _yscale=oe.delta*100;
50 _rotation=oe.sigma/Math.PI*180;
51 if(vn.y_*vn.z_<0)
52 _rotation=-_rotation;
53
54 rotateN(vn,amn);
55
56 if(vl!=null)
57 lightM(vn,nclF,nclB,vl);
58 }

Internal variables of this function:

rad - sphere radius.

l_,h_,w_ - l, h, w from the geometrical part of this lesson.

vf - the object with the co-cordinates vf.x_ and vf.y_ on the plane (x and y).

tan_gamma - tg γ.

q_ - something close to q - fraction of the initial length (vertical size) of the flat object.

oe - object with the fields p_, g_, delta, fi, sigma - p, g, δ,
φ and σ correspondingly.
The field p_, like the field q_ is also fraction of the initial length (horizontal size) of the flat object.

Lines 12 - 17 are for checking of co-ordinates if they are too small, it is better to assign them to zero
to avoid inaccurate calculations.
In the line 18 we assign global variables for external using.

In the line 19 we calculate radius of the sphere on which we want to stick mvFlat.

In the lines 21 and 22 we create the object vf (co-ordinates on plane).

In the line 24 we call the function placeXYZ(xc,yc,vf), that places the mvFlat in the specific point of the screen.

In the line 26 the function mirrorM(vn) converts the mvFlat, if it is on the back side of the sphere.

In the line 28 the function def_tan_gamma returns tg γ,
if it exists, or 'i' otherwise.
The lines 29 and 30 calculate l_ and h_, the lines 31 - 42, to our mind, do not need comments.

In the line 43 the function defQ_(l_,w_,gamma,oe) returns q_,
and assigns all the fields of object oe.

Further (the lines 44 - 48) we change length and width of the mvFlatT_, and rotate it.
In the line 49 we squeeze the mvFlatT from up to down, and in the lines 50 - 52 rutate back.
Pay attention that the first time we rotate the mvFlatT_, but backwards we rotate the mvFlatT.

In the line 54 we rotate the object around its centre on the angle amn, and in 57th - light up if vl is not null.

Here is other method of the FlatT:







function attachSymbol(ssn)
{
mvFlatT_.mvFlatT__._visible=0;
mvFlatT_.attachMovie(ssn,'mvFlatTAt__',1);
}

It allows us to replace the mvFlatT__ on any object we have.

Other function we shall not describe because you can find them in
FLA.


How can we use it?..







Example. Flat Object On the Sphere
Download





| 1 | 2 | 3 | 4 |

Rate This Tutorial :
We hope the information helped you. If you have any questions or comments, please don't hesitate to post them on the Forums section
Submit your Tutorial at Click Here
  

Home | About Us | Contact Us | Feedback | Advertise with us

Best viewed in 800x600 resolution with Internet Explorer.

Site Developed and Hosted by  ethicsolutions.com
All rights reserved with FlashAdvisor

Flash is a registered trademark of Adobe Systems, Inc.

37 users online