|
|
CreateCube() Hooray
I've been working on making a dynamic city where the buildings are represented by cubes. I've made the whole 3d engine.. but it kind of.. doesn't work. Damn. Can anyone help?
It was working.. until I added the createCube() function. Here's my code so far (the file is total ASv1)-
Code:
this.createEmptyMovieClip("box", 1);
origin = new Object();
origin.x = 200;
origin.y = 100;
focallength = 200;
create3dpoint = function (x, y, z) {
point = new object();
point.x = x;
point.y = y;
point.z = z;
return point;
};
convert = function (point3d, focallength) {
point2d = new object();
scaleratio = focallength/(focallength+point3d.z);
point2d.x = point3d.x*scaleratio;
point2d.y = point3d.y*scaleratio;
return point2d;
};
createCube = function (x, y, z, height, width, depth) {
cube = new object();
cube.x = x;
cube.y = y;
cube.z = z;
cube.h = height;
cube.w = width;
cube.d = depth;
cube.pointsarray = [
create3dPoint(x+width/2, y+height/2, z+depth/2),
create3dPoint(x-width/2, y+height/2, z+depth/2),
create3dPoint(x+width/2, y-height/2, z+depth/2),
create3dPoint(x+width/2, y+height/2, z-depth/2),
create3dPoint(x-width/2, y-height/2, z+depth/2),
create3dPoint(x+width/2, y-height/2, z-depth/2),
create3dPoint(x-width/2, y+height/2, z-depth/2),
create3dPoint(x-width/2, y-height/2, z-depth/2)];
return cube;
};
cubesarray = [
createCube(0, 0, 0, 50, 50, 100),
createCube(100, 0, 0, 50, 50, 100)];
move = function () {
for (k=0; k<cubesarry.length; k++) {
cube = cubesarray[k];
cube.point2ds = new Array();
for (i=0; i<cube.pointsarray.length; i++) {
point = cube.pointsarray[i];
point.x += -(_xmouse-origin.x)/20;
point.y += -(_ymouse-origin.y)/20;
cube.point2ds[i] = convert(point, focallength);
cube.point2ds[i].x += origin.x;
cube.point2ds[i].y += origin.y;
}
this.clear();
this.lineStyle(2, 0x000000, 50);
this.moveTo(cube.point2ds[0].x, cube.point2ds[0].y);
this.lineTo(cube.point2ds[1].x, cube.point2ds[1].y);
this.lineTo(cube.point2ds[2].x, cube.point2ds[2].y);
this.lineTo(cube.point2ds[3].x, cube.point2ds[3].y);
this.lineTo(cube.point2ds[0].x, cube.point2ds[0].y);
this.moveTo(cube.point2ds[4].x, cube.point2ds[4].y);
this.lineTo(cube.point2ds[5].x, cube.point2ds[5].y);
this.lineTo(cube.point2ds[6].x, cube.point2ds[6].y);
this.lineTo(cube.point2ds[7].x, cube.point2ds[7].y);
this.lineTo(cube.point2ds[4].x, cube.point2ds[4].y);
this.moveTo(cube.point2ds[0].x, cube.point2ds[0].y);
this.lineTo(cube.point2ds[4].x, cube.point2ds[4].y);
this.moveTo(cube.point2ds[1].x, cube.point2ds[1].y);
this.lineTo(cube.point2ds[5].x, cube.point2ds[5].y);
this.moveTo(cube.point2ds[2].x, cube.point2ds[2].y);
this.lineTo(cube.point2ds[6].x, cube.point2ds[6].y);
this.moveTo(cube.point2ds[3].x, cube.point2ds[3].y);
this.lineTo(cube.point2ds[7].x, cube.point2ds[7].y);
}
};
box.onEnterFrame = move;
Thanks smart do0ds.
FlashKit > Flash Help > Flash ActionScript
Posted on: 08-02-2004, 02:33 AM
View Complete Forum Thread with Replies
Sponsored Links:
Another Day Another Array, Hooray
If any kind soul can see their way to helping me out of this hole it would be much appreciated, I've got myself very dirty, its dark and damp and the actionscript is playing tricks on my mind.
In the infamous words of Panelope Pitstop"HEEYLLP".
The problem is I can get my movies to load.
Thanks in advance guys.
ActionScript Code:
swapDepths(30)
var names = new Array(7)
names[1] = "what"
names[2] = "where"
names[3] = "why"
names[4] = "places"
names[5] = "here"
names[6] = "hot air"
var section = new Array(7)
//
area1 = "what.swf";
area2 = "where.swf";
area3 = "why.swf";
area4 = "places.swf";
area5 = "here.swf";
area6 = "hotair.swf";
//
for (i=1; i<=6; i++) {
nav.duplicateMovieClip("nav"+(i+0), +i)
//height = _root.holder.nav._height+2;
//width = _root.holder.nav._width+1;
//_root.holder["nav"+(i+0)]._y = _root.clip._y+height*i;
//_root.holder["nav"+(i+0)]._x = _root.clip._x+width*i;
_root.holder["nav"+(i+0)]._x = 80*i
_root.holder["nav"+(i+0)]._y = -10
_root.holder["nav"+(i+0)]._alpha = 100
_root.holder["nav"+(i+0)].names = names[i]
_root.holder["nav"+i].section = _root["area"+i]
_root.holder["nav"+i].onPress = function() {
//getURL(this.section)
//loadMovieNum(this.section + i,"GET");
loadMovie(this.section, "_root.moviecontainer", "GET");
}
}
_root.holder["nav"+(i+1)]._alpha = 90
_root.holder["nav"+(i+1)].names = names[i]
_root.holder.nav._visible = false
stop()
View Replies !
View Related
Well Written Tutorials Kirupa... Hooray...
i've just completed the 'add thumbnails' tutorial. and i have to say, it is one the best tutorials i have come across in my feverish exploration of the net to find what i needed...
i'm building the gallery into a portfolio....
my plan was to reload the xml actionscript into each new frame on the main timeline to create new galleries.
but i'm finding that the old actionscript doesn't clear despite changing the name of the xml file loaded.
have tried renaming etc. how would i clear previous frames to allow the new actionscript to work on each new page?
i realise this is probably an incredibly easy thing to do... i feel a bit like the village idiot...
can anyone help me?
View Replies !
View Related
|
|
|