Sorry if the subject name sucks, I couldn't think of anything better ^^;;
Anyway, one of my teachers asked me if I wanted to make a 3d 'walkthrough' of our new building. I accepted so I could have something to do, and for the challange. I have been reading my brains out and trying to do the best I can to wrap it around this concept of using actionscript for it. I have a code that I feel will work for what I want to do, but there are points I could use some help with from people who better understand how the code works.
The code I have for now is as follows:
origin = new Object();
origin.x = 200;
origin.y = 200;
focalLength = 100;
MakeA3DPoint = function(x,y,z){
var point = new Object();
point.x = x;
point.y = y;
point.z = z;
return point;
};
ConvertPointIn3DToPointIn2D = function(pointIn3D){
var pointIn2D = new Object();
var scaleRatio = focalLength/(focalLength + pointIn3D.z);
pointIn2D.x = pointIn3D.x * scaleRatio;
pointIn2D.y = pointIn3D.y * scaleRatio;
return pointIn2D;
};
pointsArray = [
MakeA3DPoint(-40, -40, -5),
MakeA3DPoint(40, -40, -5),
MakeA3DPoint(40, -40, 20),
MakeA3DPoint(-40, -40, 20),
MakeA3DPoint(-40, 80, -5),
MakeA3DPoint(40, 80, -5),
MakeA3DPoint(40, 80, 20),
MakeA3DPoint(-40, 80, 20)
];
this.createEmptyMovieClip("box",1);
direction = "left";
speed = 10;
backAndForthAndSideToSide = function(){
var screenPoints = new Array();
for (var i=0; i < pointsArray.length; i++){
var thisPoint = pointsArray[i];
if (direction == "left"){
thisPoint.x -= speed;
if (i == pointsArray.length-1 && thisPoint.x <= -100) direction = "backward";
}else if (direction == "backward"){
thisPoint.y += speed;
if (i == pointsArray.length-1 && thisPoint.y >= 150) direction = "right";
}else if (direction == "right"){
thisPoint.x += speed;
if (i == pointsArray.length-1 && thisPoint.x >= 60) direction = "forward";
}else if (direction == "forward"){
thisPoint.y -= speed;
if (i == pointsArray.length-1 && thisPoint.y <= 0) direction = "left";
}
screenPoints[i] = ConvertPointIn3DToPointIn2D(thisPoint);
screenPoints[i].x += origin.x;
screenPoints[i].y += origin.y;
}
// to be continued ...
// continued ...
this.clear();
this.lineStyle(2,0x000000,100);
// top
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);
// bottom
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);
// connecting bottom and top
this.moveTo(screenPoints[0].x, screenPoints[0].y);
this.lineTo(screenPoints[4].x, screenPoints[4].y);
this.moveTo(screenPoints[1].x, screenPoints[1].y);
this.lineTo(screenPoints[5].x, screenPoints[5].y);
this.moveTo(screenPoints[2].x, screenPoints[2].y);
this.lineTo(screenPoints[6].x, screenPoints[6].y);
this.moveTo(screenPoints[3].x, screenPoints[3].y);
this.lineTo(screenPoints[7].x, screenPoints[7].y);
};
box.onEnterFrame = backAndForthAndSideToSide;
What I would like to do (at least at this point) is to take out the automatic camera/object movement and replace it with movement with the arrow keys, which as I understand it takes a key listener and such coding. I also would like to 'paint the walls' as it were, or in other words, color in the space between 4 or more points. I know there is a way, I've seen it.. I just don't know how to code it.
Any help that would get me closer to this goal would be very much appreciated,
Thanks.