<html>
<head>
<title>Cube3D Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9">
</head>
<body bgcolor="#000000" text="#FF0000" onResize="return false" onContextMenu="return false" onSelectStart="return false" onScroll="return false">
<script>
// prepare layers
for(i = 0; i < 8; i++)
document.write("<div id='v" + i + "' style='position:absolute; left:0px; top:0px; width:30px; height:30px; z-index:1'><b style='font-size: 30px'>•</b></div>");
// define global variables
var firstCoorX = new Array(100, 100, 100, 100, -100, -100, -100, -100);
var firstCoorY = new Array(100, 100, -100, -100, 100, 100, -100, -100);
var firstCoorZ = new Array(100, -100, 100, -100, 100, -100, 100, -100);
var coorX = new Array();
var coorY = new Array();
var coorZ = new Array();
var zoom = 300, dist = 350;
var midX = 200, midY = 200;
var PI = 3.1415926535;
var angleXaxis = 0, angleYaxis = 0, angleZaxis = 0;
// rotate cube function
function rotateCube()
{
for(i = 0; i < 8; i++)
{
// rotate on x axis
coorY[i] = firstCoorY[i] * Math.cos(angleXaxis / 180.0 * PI) + firstCoorZ[i] * Math.sin(angleXaxis / 180.0 * PI);
coorZ[i] = firstCoorY[i] * Math.sin(angleXaxis / 180.0 * PI) - firstCoorZ[i] * Math.cos(angleXaxis / 180.0 * PI);
// rotate on y axis
coorX[i] = coorZ[i] * Math.cos(angleYaxis / 180.0 * PI) + firstCoorX[i] * Math.sin(angleYaxis / 180.0 * PI);
coorZ[i] = coorZ[i] * Math.sin(angleYaxis / 180.0 * PI) - firstCoorX[i] * Math.cos(angleYaxis / 180.0 * PI);
// rotate on z axis
temp = coorX[i];
coorX[i] = coorX[i] * Math.cos(angleZaxis / 180.0 * PI) + coorY[i] * Math.sin(angleZaxis / 180.0 * PI);
coorY[i] = temp * Math.sin(angleZaxis / 180.0 * PI) - coorY[i] * Math.cos(angleZaxis / 180.0 * PI);
}
// increase angles
angleXaxis = (angleXaxis + 1) % 360;
angleYaxis = (angleYaxis + 2) % 360;
angleZaxis = (angleZaxis + 3) % 360;
}
// projection and plot function
function setCube()
{
for(i = 0; i < 8; i++) // for every 8 vertex
{
if(coorZ[i] + dist > 0) // if it is visible
{
px = coorX[i] / (coorZ[i] + dist) * zoom; // FORMULA: projection_x = x / (z + distance) * zoom
py = coorY[i] / (coorZ[i] + dist) * zoom; // FORMULA: projection_y = y / (z + distance) * zoom
document.all("v" + i).style.left = midX + px; // FORMULA: vertex_position_x = center_of_the_area + projection_x
document.all("v" + i).style.top = midY + py; // FORMULA: vertex_position_y = middle_of_the_area + projection_y
}
}
}
function cubeAnim()
{
rotateCube(); // rotate the cube
setCube(); // project and draw
setTimeout("cubeAnim()", 20); // call next frame after 20 miliseconds
}
cubeAnim(); // call the first frame
</script>
</body>
</html>Umarım bu size yardımcı olur.