Hi,

I found some code at deconcept.com that produces a rotatable object in 3D. An x,y,x coordinate system is used and I am having trouble figuring out how the 3D coordinates are projected onto a 2D flash movie.

A series of points is created with a random x,y,z value between -100 and 100. The object rotates by moving the mouse in any direction. Here is the code that sits on each point:

Code:
// -- this is the 3d code - origional code from wireframe.co.za then rewritten to work in clip events
// -- and be more compatible with flash 5
onClipEvent (enterFrame) {
	// -- track mouse position, and rotate
	diffx = _root._xmouse-newX;
	diffy = _root._ymouse-newY;
	newX += diffx/5;
	newY += diffy/5;
	if (newX>0) {
		addX = int(newX/360)*-360;
	} else {
		addX = (int(newX/360)-1)*-360;
	}
	if (newY>0) {
		addY = int(newY/360)*-360;
	} else {
		addY = (int(newY/360)-1)*-360;
	}
	Yangle = (newX+addX);
	Xangle = (newY+addY);
	// ------ get x and y angle - apply to 3d coords
	Xang = Xangle*(math.PI/180);
	Yang = Yangle*(math.PI/180);
	// ---------------- convert x and y positions from 3d to 2d
	zpos = z*Math.cos(Yang)-x*Math.sin(Yang);
	xpos = z*Math.sin(Yang)+x*Math.cos(Yang);
	// ---------
	ypos = y*Math.cos(Xang)-zpos*Math.sin(Xang);
	zpos = y*Math.sin(Xang)+zpos*Math.cos(Xang);
	// ----------------- find depth
	depth = 1/((zpos/_root.perspective)+1);
	// ------------- apply 2d coords to the object
	_parent._x = xpos*depth+_root.centerRotationX;
	_parent._y = ypos*depth+_root.centerRotationY;
	// -- since the points are invisible for this, i commented out this part of the code
	 _parent._xscale = (depth/2)*300;
	 _parent._yscale = (depth/2)*300;
	 _parent._alpha = depth*100;
	// ---------- apply depth to object
	_parent.swapDepths(depth*13000);
}
The part I am having trouble understanding is the xpos, ypos, zpos calculations. If you can help explain that part, that would be great. Thanks!

Brandon