HOME | DD

MediaDesign — 3D Flash Engine

Published: 2007-08-21 08:59:09 +0000 UTC; Views: 3701; Favourites: 22; Downloads: 127
Redirect to original
Description My own 3D engine. Not much to say... but have fun

CODE (Put into the first frame of an AS2.0 document):

var origX:Number = Stage.width/2;
var origY:Number = Stage.height/2;
var focalLength:Number = 300;
var pointsArray:Array = new Array(
makePoint(-40, -40, -40),
makePoint(40, -40, -40),
makePoint(40, -40, 40),
makePoint(-40, -40, 40),
makePoint(-40, 40, -40),
makePoint(40, 40, -40),
makePoint(40, 40, 40),
makePoint(-40, 40, 40)
);

this.createEmptyMovieClip("box", 0);

function makePoint(x:Number, y:Number, z:Number) {
var pointObj = new Object();
pointObj.x = x;
pointObj.y = y;
pointObj.z = z;
return pointObj;
}

function calcScale(pointObj3D) {
var pointObj2D = new Object();
var scaleRatio:Number = focalLength/(focalLength+pointObj3D.z);
pointObj2D.x = pointObj3D.x*scaleRatio;
pointObj2D.y = pointObj3D.y*scaleRatio;
return pointObj2D;
}

box.onEnterFrame = drawBox;
function drawBox() {
var screenPoints = new Array();
for (var i:Number = 0; i < pointsArray.length; i++) {
var thisPoint = pointsArray[i];
var angleX:Number = (_ymouse-origY)*.001;
var angleY:Number = (_xmouse-origX)*.001;
var cosX:Number = Math.cos(angleX);
var sinX:Number = Math.sin(angleX);
var cosY:Number = Math.cos(angleY);
var sinY:Number = Math.sin(angleY);
var x1:Number = thisPoint.x*cosY-thisPoint.z*sinY;
var z1:Number = thisPoint.z*cosY+thisPoint.x*sinY;
var y2:Number = thisPoint.y*cosX-z1*sinX;
var z2:Number = z1*cosX+thisPoint.y*sinX;
thisPoint.x = x1;
thisPoint.z = z2;
thisPoint.y = y2;
screenPoints.push(calcScale(thisPoint));
screenPoints[i].x += origX;
screenPoints[i].y += origY;
}
this.clear();
this.lineStyle(1, 0x000000, 100);
// back
this.beginFill(0x000000, 50);
this.moveTo(screenPoints[3].x, screenPoints[3].y);
this.lineTo(screenPoints[7].x, screenPoints[7].y);
this.lineTo(screenPoints[6].x, screenPoints[6].y);
this.lineTo(screenPoints[2].x, screenPoints[2].y);
this.lineTo(screenPoints[3].x, screenPoints[3].y);
this.endFill();
// top
this.beginFill(0x000000, 50);
this.moveTo(screenPoints[0].x, screenPoints[0].y);
this.lineTo(screenPoints[1].x, screenPoints[1].y);
this.lineTo(screenPoints[2].x, screenPoints[2].y);
this.lineTo(screenPoints[3].x, screenPoints[3].y);
this.lineTo(screenPoints[0].x, screenPoints[0].y);
this.endFill();
// bottom
this.beginFill(0x000000, 50);
this.moveTo(screenPoints[4].x, screenPoints[4].y);
this.lineTo(screenPoints[5].x, screenPoints[5].y);
this.lineTo(screenPoints[6].x, screenPoints[6].y);
this.lineTo(screenPoints[7].x, screenPoints[7].y);
this.lineTo(screenPoints[4].x, screenPoints[4].y);
this.endFill();
// front
this.beginFill(0x000000, 50);
this.moveTo(screenPoints[0].x, screenPoints[0].y);
this.lineTo(screenPoints[4].x, screenPoints[4].y);
this.lineTo(screenPoints[5].x, screenPoints[5].y);
this.lineTo(screenPoints[1].x, screenPoints[1].y);
this.lineTo(screenPoints[0].x, screenPoints[0].y);
this.endFill();
}
Related content
Comments: 9

KAPO88 [2011-01-27 22:31:12 +0000 UTC]

Ive been playing with this for 2 hours

👍: 0 ⏩: 0

carrybag93 [2010-08-28 08:04:42 +0000 UTC]

wow...it's screwing with my brain ...
I like it

👍: 0 ⏩: 1

MediaDesign In reply to carrybag93 [2010-08-28 14:04:27 +0000 UTC]

Hehe thankyou... glad to know three years on people still get amusement out of it

👍: 0 ⏩: 1

carrybag93 In reply to MediaDesign [2010-08-29 00:57:17 +0000 UTC]

lol

👍: 0 ⏩: 0

degree [2008-04-03 23:54:02 +0000 UTC]

good effect

👍: 0 ⏩: 0

ablackdeath [2007-08-22 10:18:51 +0000 UTC]

That is so cool
How come your so smart with these things?
Show off

👍: 0 ⏩: 0

angelzofdeath [2007-08-21 09:14:15 +0000 UTC]

lmao i culd play with this 4eva

👍: 0 ⏩: 0

Bugx0r [2007-08-21 09:13:22 +0000 UTC]

Wow! Very cool!! I love the focal length... hehe, it's funny! Especially at 80

👍: 0 ⏩: 0

shurikmx [2007-08-21 09:02:15 +0000 UTC]

very interesting

👍: 0 ⏩: 0