-
Making a 3D rendering engine, need a bit of help with camera rotation...
Code:
var zP;
var xP;
var yP;
var xC;
var yC;
var caX;
var caZ;
var size;
var map = new Array();
map.push(new Array());
map.push(new Array());
map.push(new Array());
map[0].push("1");
map[0].push("1");
map[0].push("1");
map[0].push("1");
map[1].push("1");
map[1].push("1");
map[1].push("1");
map[2].push("1");
map[2].push("1");
map[2].push("1");
map[2].push("1");
map[2].push("1");
trace(map);
trace(map[0][0]);
trace(map[0][1]);
trace(map[1][1]);
trace(map[2][4])
trace(map[2][5])
trace("---");
//s = size
//ca = camera
function onLoad() {
this.createEmptyMovieClip("cube",this.getNextHighestDepth());
this.createEmptyMovieClip("cube",this.getNextHighestDepth());
cube.lineStyle(1,0x00FF00,100,true,"none","round","miter",1);
moveX = 0;
moveZ = 0;
size = 32;
trace(map[0][1]);
}
function onEnterFrame() {
cube.clear();
cube.lineStyle(0.5,0x00FF00,100,true,"none","round","miter",1);
if (Key.isDown(Key.UP)) {
moveZ -= 1;
}
if (Key.isDown(Key.RIGHT)) {
moveX -= 1;
}
if (Key.isDown(Key.DOWN)) {
moveZ += 1;
}
if (Key.isDown(Key.LEFT)) {
moveX += 1;
}
j = -1;
while (j<map.length) {
trace(i);
j++
trace(map[1][i]);
i = 0
while (i<map[j].length) {
trace(i);
if ((map[j][i] == 1) && (50+(16*j)+moveZ>1)) {
xP = 0+(i*32)+moveX;
yP = 50;
zP = 50+(16*j)+moveZ;
xP -= size/2;
yP -= size/2;
convert();
cube.moveTo(xC,yC);
xP += size;
yP += 0;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP += 0;
yP += size;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP -= size;
yP += 0;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP += 0;
yP -= size;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP += 0;
yP += 0;
zP += size/2;
convert();
cube.lineTo(xC,yC);
//SECOND LAYER!
convert();
xP += size;
yP += 0;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP += 0;
yP += size;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP -= size;
yP += 0;
zP += 0;
convert();
cube.lineTo(xC,yC);
xP += 0;
yP -= size;
zP += 0;
convert();
cube.lineTo(xC,yC);
//*********************************************************
yP += size;
zP -= 0;
convert();
cube.moveTo(xC,yC);
yP += 0;
zP -= size/2;
convert();
cube.lineTo(xC,yC);
yP += 0;
xP += size;
zP -= -size/2;
convert();
cube.moveTo(xC,yC);
yP += 0;
zP -= size/2;
convert();
cube.lineTo(xC,yC);
yP -= size;
xP += 0;
zP -= -size/2;
convert();
cube.moveTo(xC,yC);
yP += 0;
zP -= size/2;
convert();
cube.lineTo(xC,yC);
/*first cube done
^.^"
*/
}
i++;
}
}
trace("done");
}
function convert() {
xC = (xP*(200/zP))-(-300);
yC = (yP*(200/zP))-(-200);
}
Well, there's all the code. What I want is to be able to change camera rotation, what would I use to do this? (change rendering according to a horizontal camera rotation variable and vertical, what would I change?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|