Flash
Aus Wikizone
Version vom 16. Dezember 2007, 14:01 Uhr von 91.32.43.24 (Diskussion) (→Tipps und Tricks für Flash und ActionScript)
Tipps und Tricks für Flash und ActionScript
Flash - Standalone Applications
3D-Pyramide mit Flash (aus Flashforum)
lois
27-01-2003, 23:59
Geschrieben von Hamster2k
3d Engine programmieren ;) anders gehts nicht.
IS aber n Haufen Arbeit.
MfG
ach wenn man es einmal gemacht hat, dann ist es wirklich nicht mehr schwierig:
movieclip.prototype.d3tod2 = function(x3d, y3d, z3d, lookatz) {
z2d = Math.sqrt(x3d*x3d+y3d*y3d+z3d*z3d);
//z3d; Math.sqrt(x3d*x3d+y3d*y3d+z3d*z3d);
scale2d = 100*lookatz/z2d;
if (z2d>0) {
x2d = x3d/z2d*lookatz;
y2d = y3d/z2d*lookatz;
}
};
x=new Array(-10,10,10,-10,0);
y=new Array(10,10,-10,-10,0);
z=new Array(0,0,0,0,10);
//farben
farbe=new Array("0xff0000","0x00ff00","0x0000ff","0xFFFF00");
//diese Punktkombinationen ergeben eine Fläche
shape=new Array("0_1_4","1_2_4","2_3_4","3_0_4");
//Kantenlänge (100px) liegt in der variable a
a=100;
punkte = z.length-1;
anzahl = shape.length-1;
//Erstellung der movieclips...Schaltfächen
for (i=0; i<=anzahl; i++) {
shape[i] = shape[i].split("_");
_root.createEmptyMovieClip("flaeche" add i, i);
//Definition als Schaltfäche
_root["flaeche"add i].hitArea();
//Vorbereitung für Testaktion; kann später gelöscht werden
_root["flaeche"add i].i=i;
//Schaltflächenaktion
_root["flaeche"add i].onRelease = function() {
//hier die Aktionen entsprechend einbinden!!!
trace(this.i);
}
}
winkelx = 0;
winkely = 0;
_root.onEnterFrame = function() {
winkelx = (_root._ymouse-200)/10;
winkely = (_root._xmouse-275)/10;
for (i=0; i<=punkte; i++) {
// x-rotation
radius = Math.sqrt(y[i]*y[i]+z[i]*z[i]);
rot = Math.atan(y[i]/z[i]);
if (y[i] == 0 and z[i] == 0) {
rot = 0;
}
if (z[i]<0) {
rot = rot+Math.PI;
}
rot = rot+winkelx/360*2*Math.PI;
yx = radius*Math.sin(rot);
zx = radius*Math.cos(rot);
// y-rotation
radius = Math.sqrt(x[i]*x[i]+zx*zx);
alpha = Math.atan(x[i]/zx);
if (x[i] == 0 and zx == 0) {
alpha = 0;
}
if (zx<0) {
alpha = alpha+Math.PI;
}
alpha = alpha+winkely/360*2*Math.PI;
x[i] = radius*Math.sin(alpha);
z[i] = radius*Math.cos(alpha);
y[i] = yx;
}
for (i=0; i<=anzahl; i++) {
depths = 0;
for (j=0; j<shape[i].length; j++) {
num = shape[i][j];
d3tod2(x[num], y[num], Number(z[num])+4, 100);
set("px" add j, x2d+275);
set("py" add j, y2d+200);
depths = depths+10000-z2d;
}
with (_root["flaeche" add i]) {
clear();
lineStyle(1, 0x000000, 100);
beginFill(farbe[i]);
moveTo(px0, py0);
for (j=1; j<shape[i].length; j++) {
lineTo(eval("px" add j), eval("py" add j));
}
depths = depths/shape[i].length;
endFill();
swapDepths(depths*1000+i);
}
}
};
Gruß
Alois