- #1
dot_binary
- 6
- 0
I'm making a 3D rotation of a poligon.The problem is when I rotate some points in 2D, it works, but if I use the same function to rotate the same points in a 3D perspective , while rotating the vertices move to the center of the object and remain there.
I also wrote the 3D rendering part.At first I thought that my rotation function is not precise, I made it more precise and still it it doesn't work.The 3D rendering function only takes the values stored in the objects array and puts vertices on screen.
The values stored in o[0][0] and o[0][1] represent the X and Y coordonates of the origin
and the ones stored in o[1][0] and o[1][1] are the coordonates of a point.
For now I'm only rotating on X and Y axis.
This is the rotation function:
int rotate(int t,double Ox, double Oy , double Ox2, double Oy2 , double Ub ){
double pi = 3.14159265 ;
if( Ub > 359 ){ Ub = Ub-360; }
if( Ub < 0 ){ Ub = 360-abs(int(Ub)); }
double U = (Ub*pi)/180 ;
double Tx = Ox2 - Ox ;
double Ty = Oy2 - Oy ;
double x = ( Tx *cos( U ) ) - ( Ty *sin( U ) );
double y = ( Ty *cos( U ) ) + ( Tx *sin( U ) );
Ox2 = floor( (Ox + x) + 0.5 ) ;
Oy2 = floor( (Oy + y) + 0.5 ) ;
if ( t == 1 ){
return int(Ox2) ;
}else{
return int(Oy2) ;
}
}
This is how I'm doing the rotation of one point around another point:
o[1][0] = rotate(1,o[0][0],o[0][1],o[1][0],o[1][1],Ub2);
o[1][1] = rotate(2,o[0][0],o[0][1],o[1][0],o[1][1],Ub2);
where Ub2 is the angle of rotation.
I also wrote the 3D rendering part.At first I thought that my rotation function is not precise, I made it more precise and still it it doesn't work.The 3D rendering function only takes the values stored in the objects array and puts vertices on screen.
The values stored in o[0][0] and o[0][1] represent the X and Y coordonates of the origin
and the ones stored in o[1][0] and o[1][1] are the coordonates of a point.
For now I'm only rotating on X and Y axis.
This is the rotation function:
int rotate(int t,double Ox, double Oy , double Ox2, double Oy2 , double Ub ){
double pi = 3.14159265 ;
if( Ub > 359 ){ Ub = Ub-360; }
if( Ub < 0 ){ Ub = 360-abs(int(Ub)); }
double U = (Ub*pi)/180 ;
double Tx = Ox2 - Ox ;
double Ty = Oy2 - Oy ;
double x = ( Tx *cos( U ) ) - ( Ty *sin( U ) );
double y = ( Ty *cos( U ) ) + ( Tx *sin( U ) );
Ox2 = floor( (Ox + x) + 0.5 ) ;
Oy2 = floor( (Oy + y) + 0.5 ) ;
if ( t == 1 ){
return int(Ox2) ;
}else{
return int(Oy2) ;
}
}
This is how I'm doing the rotation of one point around another point:
o[1][0] = rotate(1,o[0][0],o[0][1],o[1][0],o[1][1],Ub2);
o[1][1] = rotate(2,o[0][0],o[0][1],o[1][0],o[1][1],Ub2);
where Ub2 is the angle of rotation.