Hello, I’m trying to make a regular tetraeder in 3d with seoculars 3d engine. In this engine you have to use make3DPoint (x, y, z)
Now for this tetraeder I want to use a variable s that is the length of one rib. so this was the code I wrote with help from Voetsjoeba
[AS]focalLength = 300;
make3DPoint = function (x, y, z) {
var point = new Object();
point.x = x;
point.y = y;
point.z = z;
return point;
};
make2DPoint = function (x, y, scaleFactor) {
var point = new Object();
point.x = x;
point.y = y;
point.scaleFactor = scaleFactor;
return point;
};
ConvertTo2D = function (pointIn3D, scale) {
var pointIn2D = new Object();
pointIn2D.x = pointIn3D.xscale;
pointIn2D.y = pointIn3D.yscale;
return pointIn2D;
};
RotatePointsAndConvert = function (points, axisRotations) {
var TransformedPointsArray = [];
var sx = Math.sin(axisRotations.x);
var cx = Math.cos(axisRotations.x);
var sy = Math.sin(axisRotations.y);
var cy = Math.cos(axisRotations.y);
var sz = Math.sin(axisRotations.z);
var cz = Math.cos(axisRotations.z);
var x, y, z, xy, xz, yx, yz, zx, zy, scaleFactor;
var i = points.length;
while (i–) {
x = points*.x;
y = points*.y;
z = points*.z;
// rotation around x
xy = cxy-sxz;
xz = sxy+cxz;
// rotation around y
yz = cyxz-syx;
yx = syxz+cyx;
// rotation around z
zx = czyx-szxy;
zy = szyx+czxy;
scaleFactor = focalLength/(focalLength+yz);
x = zxscaleFactor;
y = zyscaleFactor;
z = yz;
TransformedPointsArray* = make2DPoint(x, y, scaleFactor);
}
return TransformedPointsArray;
};
var s = 200;
cube3D = [make3DPoint(0, -2/3Math.sqrt(s-1/2s1/2s), 0), make3DPoint(-1/2s, 1/3Math.sqrt(s-1/2s1/2s),1/2s), make3DPoint(1/2s, 1/3Math.sqrt(s-1/2s1/2s), 1/2s), make3DPoint(0, 1/3Math.sqrt(s-1/2s1/2s), -1/2s)];
cubeRotation = {x:0, y:0, z:0};
this.onEnterFrame = function() {
this.createEmptyMovieClip(“cube”, 1);
cube.lineStyle(0, 0x000000, 100);
if (Key.isDown(Key.LEFT)) {
cubeRotation.y += 0.05;
}
if (Key.isDown(Key.RIGHT)) {
cubeRotation.y -= 0.05;
}
if (Key.isDown(Key.UP)) {
cubeRotation.x += 0.05;
}
if (Key.isDown(Key.DOWN)) {
cubeRotation.x -= 0.05;
}
cube2D = RotatePointsAndConvert(cube3D, cubeRotation);
for (var i = 0; i<cube3D.length; i++) {
cube2D.x += 350;
cube2D*.y += 250;
}
cube.moveTo(cube2D[0].x, cube2D[0].y);
cube.beginFill(0x0000FF,20)
cube.lineTo(cube2D[1].x, cube2D[1].y);
cube.lineTo(cube2D[2].x, cube2D[2].y);
cube.lineTo(cube2D[0].x, cube2D[0].y);
cube.endFill()
//
cube.moveTo(cube2D[0].x,cube2D[0].y);
cube.lineTo(cube2D[3].x, cube2D[3].y);
cube.lineTo(cube2D[2].x, cube2D[2].y);
//
cube.lineTo(cube2D[3].x, cube2D[3].y)
cube.lineTo(cube2D[1].x, cube2D[1].y)
};
[/AS] I dunno why but there seems to be a problem with it cu nothing appears when I push test movie, not even an error.
Anyone have an idea what the problem is?
O and I’m very very noobish at AS so plz don’t laugh at me when it’s something stupid
Greetz and thanks.
EDIT: O and don’t worry about the names that state cube cuz that’s only because I edited some code by Voetsjoeba.