# What is wrong in this code? (3d)

**URL:** <https://forum.kirupa.com/t/what-is-wrong-in-this-code-3d/84338>\
**Category:** flash\
**Created:** [March 26, 2005, 3:21pm UTC](https://forum.kirupa.com/t/what-is-wrong-in-this-code-3d/84338 "2005-03-26T15:21:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chriz74](https://avatars.discourse-cdn.com/v4/letter/c/90db22/32.png) [@Chriz74](https://forum.kirupa.com/u/Chriz74)\
**Post date:** [March 26, 2005, 3:21pm UTC](https://forum.kirupa.com/t/what-is-wrong-in-this-code-3d/84338/1 "2005-03-26T15:21:45Z")

</div>

Ok… i found the bug in the 3d pyramids routine… anyway. Do you know what is wrong here? I have points for a 3d logo at z -20 and z +20 … I am using the ifvisiblebetween function for backface culling… the problem is the program shows only the last logo (black) and not the first one (red) … if you try to delete the last one (black) from the code you’ll notice the red shows up. So why it doesn’t show up when the black is under it? I really can’t understand.

* * *

this.createEmptyMovieClip(“theScene”, 1);  
theScene.\_x = 80;  
theScene.\_y = 150;

focalLength = 300;  
isVisibleBetween = function (a, b, c) {  
if (((b.y-a.y)/(b.x-a.x)-(c.y-a.y)/(c.x-a.x)\<0) ^ (a.x\<=b.x == a.x\>c.x)) {  
return true;  
} else {  
return false;  
}

};  
make3DPoint = function(x,y,z){  
var point = new Object();  
point.x = x;  
point.y = y;  
point.z = z;  
return point;  
};  
Transform3DPointsTo2DPoints = 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 = cx_y - sx_z;  
xz = sx_y + cx_z;  
// rotation around y  
yz = cy_xz - sy_x;  
yx = sy_xz + cy_x;  
// rotation around z  
zx = cz_yx - sz_xy;  
zy = sz_yx + cz_xy;

scaleFactor = focalLength/(focalLength + yz);  
x = zx_scaleFactor;  
y = zy_scaleFactor;  
z = -yz;  
TransformedPointsArray\* = make3DPoint(x, y, z);  
}  
return TransformedPointsArray;  
};  
pointsArray = [  
make3DPoint ( -120, -40, -20 ),  
make3DPoint ( -105, -55, -20 ),  
make3DPoint ( -40, -55, -20),  
make3DPoint ( -165, 60, -20 ),  
make3DPoint ( 170, 60, -20 ),  
make3DPoint ( 170, -40, -20 ),  
make3DPoint ( 130, -80, -20 ),  
make3DPoint ( 45, -80, -20 ),  
make3DPoint ( 20, -55, -20 ),  
make3DPoint ( 110, -55, -20 ),  
make3DPoint ( 135, -30, -20 ),  
make3DPoint ( 135, 30, -20 ),  
make3DPoint ( -90, 30, -20 ),  
make3DPoint ( 30, -80, -20 ),  
make3DPoint ( -150, -80, -20 ),  
make3DPoint ( -120, -40, 20 ),  
make3DPoint ( -105, -55, 20 ),  
make3DPoint ( -40, -55, 20 ),  
make3DPoint ( -165, 60, 20 ),  
make3DPoint ( 170, 60, 20 ),  
make3DPoint ( 170, -40, 20 ),  
make3DPoint ( 130, -80, 20 ),  
make3DPoint ( 45, -80, 20 ),  
make3DPoint ( 20, -55, 20 ),  
make3DPoint ( 110, -55, 20 ),  
make3DPoint ( 135, -30, 20 ),  
make3DPoint ( 135, 30, 20 ),  
make3DPoint ( -90, 30, 20 ),  
make3DPoint ( 30, -80, 20 ),  
make3DPoint ( -150, -80, 20 ),  
make3DPoint ( -120, -40, -20 ),  
make3DPoint ( -105, -55, -20 ),  
make3DPoint ( -40, -55, -20),  
make3DPoint ( -165, 60, -20 ),  
make3DPoint ( 170, 60, -20 ),  
make3DPoint ( 170, -40, -20 ),  
make3DPoint ( 130, -80, -20 ),  
make3DPoint ( 45, -80, -20 ),  
make3DPoint ( 20, -55, -20 ),  
make3DPoint ( 110, -55, -20 ),  
make3DPoint ( 135, -30, -20 ),  
make3DPoint ( 135, 30, -20 ),  
make3DPoint ( -90, 30, -20 ),  
make3DPoint ( 30, -80, -20 ),  
make3DPoint ( -150, -80, -20 ),  
make3DPoint ( -120, -40, 20 ),  
make3DPoint ( -105, -55, 20 ),  
make3DPoint ( -40, -55, 20 ),  
make3DPoint ( -165, 60, 20 ),  
make3DPoint ( 170, 60, 20 ),  
make3DPoint ( 170, -40, 20 ),  
make3DPoint ( 130, -80, 20 ),  
make3DPoint ( 45, -80, 20 ),  
make3DPoint ( 20, -55, 20 ),  
make3DPoint ( 110, -55, 20 ),  
make3DPoint ( 135, -30, 20 ),  
make3DPoint ( 135, 30, 20 ),  
make3DPoint ( -90, 30, 20 ),  
make3DPoint ( 30, -80, 20 ),  
make3DPoint ( -150, -80, 20 )

];  
theScene.AxisRotations = make3DPoint(0,0,0);  
rotate1 = function(){  
this.AxisRotations.x -= 0.0;  
this.AxisRotations.y += 0.08;  
this.AxisRotations.z += 0.00;  
var pts2D = Transform3DPointsTo2DPoints(pointsArray, this.AxisRotations);  
var mouseIsDown = Key.isDown(1);

this.clear();  
if (isVisibleBetween(pts2D[3], pts2D[4], pts2D[14] )){  
this.beginFill(0xFF0000, 100);  
this.moveTo(pts2D[0].x, pts2D[0].y);  
this.lineTo(pts2D[1].x, pts2D[1].y);  
this.lineTo(pts2D[2].x, pts2D[2].y);  
this.lineTo(pts2D[3].x, pts2D[3].y);  
this.lineTo(pts2D[4].x, pts2D[4].y);  
this.lineTo(pts2D[5].x, pts2D[5].y);  
this.lineTo(pts2D[6].x, pts2D[6].y);  
this.lineTo(pts2D[7].x, pts2D[7].y);  
this.lineTo(pts2D[8].x, pts2D[8].y);  
this.lineTo(pts2D[9].x, pts2D[9].y);  
this.lineTo(pts2D[10].x, pts2D[10].y);  
this.lineTo(pts2D[11].x, pts2D[11].y);  
this.lineTo(pts2D[12].x, pts2D[12].y);  
this.lineTo(pts2D[13].x, pts2D[13].y);  
this.lineTo(pts2D[14].x, pts2D[14].y);  
this.lineTo(pts2D[0].x, pts2D[0].y);  
this.endFill();

}  
this.clear();  
if (isVisibleBetween(pts2D[48], pts2D[44], pts2D[49] )){  
this.beginFill(0x000000, 100);  
this.moveTo(pts2D[45].x, pts2D[45].y);  
this.lineTo(pts2D[46].x, pts2D[46].y);  
this.lineTo(pts2D[47].x, pts2D[47].y);  
this.lineTo(pts2D[48].x, pts2D[48].y);  
this.lineTo(pts2D[49].x, pts2D[49].y);  
this.lineTo(pts2D[50].x, pts2D[50].y);  
this.lineTo(pts2D[51].x, pts2D[51].y);  
this.lineTo(pts2D[52].x, pts2D[52].y);  
this.lineTo(pts2D[53].x, pts2D[53].y);  
this.lineTo(pts2D[54].x, pts2D[54].y);  
this.lineTo(pts2D[55].x, pts2D[55].y);  
this.lineTo(pts2D[56].x, pts2D[56].y);  
this.lineTo(pts2D[57].x, pts2D[57].y);  
this.lineTo(pts2D[58].x, pts2D[58].y);  
this.lineTo(pts2D[59].x, pts2D[59].y);  
this.lineTo(pts2D[45].x, pts2D[45].y);  
this.endFill();

}

};  
theScene.onEnterFrame = rotate1;

* * *
