Deviant Login Shop
 Join deviantART for FREE Take the Tour
×



Details

Submitted on
August 21, 2007
Image Size
1.4 KB
Resolution
550×400
Link
Thumb
Embed

Stats

Views
2,687
Favourites
22 (who?)
Comments
9
Downloads
114
×
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();
}
Add a Comment:
 
:iconkapo88:
KAPO88 Featured By Owner Jan 27, 2011  Hobbyist Digital Artist
Ive been playing with this for 2 hours
Reply
:iconcarrybag93:
carrybag93 Featured By Owner Aug 28, 2010  Student Filmographer
wow...it's screwing with my brain =P...
I like it
Reply
:iconmediadesign:
MediaDesign Featured By Owner Aug 28, 2010
Hehe thankyou... glad to know three years on people still get amusement out of it :P
Reply
:iconcarrybag93:
carrybag93 Featured By Owner Aug 28, 2010  Student Filmographer
lol
Reply
:icondegree:
degree Featured By Owner Apr 3, 2008   Interface Designer
good effect
Reply
:iconablackdeath:
ablackdeath Featured By Owner Aug 22, 2007
That is so cool
How come your so smart with these things?
Show off:p
Reply
:iconangelzofdeath:
angelzofdeath Featured By Owner Aug 21, 2007
lmao i culd play with this 4eva
Reply
:iconbugx0r:
Bugx0r Featured By Owner Aug 21, 2007  Professional Interface Designer
Wow! Very cool!! I love the focal length... hehe, it's funny! Especially at 80 :P
Reply
:iconshurikmx:
shurikmx Featured By Owner Aug 21, 2007  Professional General Artist
very interesting
Reply
Add a Comment: