// 3d routines by Michaël (_SoLO_) THOMAS -  21/07/99 - MikeJ51@hotmail.com
// Optimized by Shazz - 6/07/2004

var fixr = Math.PI/180

roty1=0
rotz1=0
rotx2=0
//rotz2=0
//rotx3=0
//roty3=0
angle_a=0
angle_b=0
angle_c=0

// PROFILER
//var countloopR3D = 5000;
//var totalTimeRotateR3D = 0;
//var avgTimeR3D =0;
//var avgTotalR3D = 0;
//  END PROFILER


function rotation3d(rotx, roty, rotz, angle_a, angle_b, angle_c) {

	// PROFILER
	//startTimeRotateR3D = new Date();
	// END PROFILE	

	angleA = angle_a*fixr;
	cos_angleA = Math.cos(angleA);
	sin_angleA = Math.sin(angleA);
	angleB = angle_b*fixr;
	cos_angleB = Math.cos(angleB);
	sin_angleB = Math.sin(angleB);
	angleC = angle_c*fixr;
	cos_angleC = Math.cos(angleC);
	sin_angleC = Math.sin(angleC);
	
	
	roty1 = roty*cos_angleA - rotz*sin_angleA;
	rotz1 = roty*sin_angleA + rotz*cos_angleA;
	rotx2 = rotx*cos_angleB + rotz1*sin_angleB;
	rotzz = -rotx*sin_angleB + rotz1*cos_angleB;
	rotxx = rotx2*cos_angleC - roty1*sin_angleC;
	rotyy = rotx2*sin_angleC + roty1*cos_angleC;
	//rotxx=rotx3;
	//rotyy=roty3;
	//rotzz=rotz2;
	
	// PROFILER
	//countloopR3D--;
	//endTimeRotateR3D = new Date();
	
	//totalTimeRotateR3D = totalTimeRotateR3D + (endTimeRotateR3D-startTimeRotateR3D);
	//if(countloopR3D == 0){
	//	avgTimeR3D = avgTimeR3D + totalTimeRotateR3D;
	//	avgTotalR3D++;
	//	countloopR3D = 1000;
	//	window.status = "Temps d'execution " + countloopR3D + " Rotation3d() = " + totalTimeRotateR3D + " ms (avg = " + Math.floor(avgTimeR3D/avgTotalR3D) + " ms)";
	//	totalTimeRotateR3D = 0;
	//}
	// END PROFILE		
}


function projection() {

	// PROFILER
	//startTimeRotateR3D = new Date();
	// END PROFILE	
	rotxx=(rotxx << 8)/(per-rotzz);
	rotyy=(rotyy << 8)/(per-rotzz);
	
	
	// PROFILER
	//countloopR3D--;
	//endTimeRotateR3D = new Date();
	
	//totalTimeRotateR3D = totalTimeRotateR3D + (endTimeRotateR3D-startTimeRotateR3D);
	//if(countloopR3D == 0){
	//	avgTimeR3D = avgTimeR3D + totalTimeRotateR3D;
	//	avgTotalR3D++;
	//	countloopR3D = 5000;
	//	window.status = "Temps d'execution " + countloopR3D + " projection() = " + totalTimeRotateR3D + " ms (avg = " + Math.floor(avgTimeR3D/avgTotalR3D) + " ms)";
	//	totalTimeRotateR3D = 0;
	//}
	// END PROFILE		
}