[as3] Trigonometry is confusing

Started by
19 comments, last by Mathimetric 11 years, 2 months ago

//maybe this trig example could help you in some way

//example of model matrix rotation

Obj3d::RotateModel(int index, float x,float y,float z)
{


if(index >= 0 && index <= Facesets){

xyz__ center;
center = GetCenter(&Model_[index]);

#ifdef stub
cout<<"center x: "<<center.x<<" y: "<<center.y<<" z: "<<center.z<<endl;
system("pause");
#endif

xyz__ matrix;
xyz__ hyp;
xyz__ Angle;

for(int i = 0; i < Model_[index].nFaces;++i){
for(int w = 0;w<3;++w){

//a/b = atan(A)
//length a b
matrix.x = Model_[index].Object[VERTEX][w][0] - center.x;
matrix.y = Model_[index].Object[VERTEX][w][1] - center.y;
matrix.z = Model_[index].Object[VERTEX][w][2] - center.z;


if(matrix.z != 0) Angle.x = ( atan( (matrix.y / matrix.z)) / (0.017453292) );else Angle.x = 0;
if(matrix.x != 0) Angle.y = ( atan( (matrix.z / matrix.x)) / (0.017453292) );else Angle.y = 0;
if(matrix.x != 0) Angle.z = ( atan( (matrix.y / matrix.x)) / (0.017453292) );else Angle.z = 0;

if(Angle.x)
hyp.x = matrix.y / sin(Angle.x *0.017453292);
if(Angle.y)
hyp.y = matrix.z / sin(Angle.y *0.017453292);
if(Angle.z)
hyp.z = matrix.y / sin(Angle.z *0.017453292);


#ifdef stub
cout<<"atan("<<matrix.y<<"/"<<matrix.z<<") = " <<Angle.x<<endl;
system("pause");
#endif


//x rotation
if(x != 0 && Angle.x != 0 ){
Model_[index].Object[VERTEX][w][1] = (hyp.x * sin( (x + Angle.x) * 0.017453292 ) + center.y);
Model_[index].Object[VERTEX][w][2] = (hyp.x * cos( (x + Angle.x) * 0.017453292 ) + center.z);
}
//y rotation
if(y != 0 && Angle.y != 0 ){
Model_[index].Object[VERTEX][w][2] = (hyp.y * sin( (y + Angle.y) * 0.017453292 ) + center.z);
Model_[index].Object[VERTEX][w][0] = (hyp.y * cos( (y + Angle.y) * 0.017453292 ) + center.x);

}
//z rotation
if(z != 0 && Angle.z != 0){
Model_[index].Object[VERTEX][w][1] = (hyp.z * sin( (z + Angle.z) * 0.017453292 ) + center.y);
Model_[index].Object[VERTEX][w][0] = (hyp.z * cos( (z + Angle.z) * 0.017453292 ) + center.x);
}
}}
return 1;
}else

return 0;
}

its math do it

This topic is closed to new replies.

Advertisement