Ejemplo n.º 1
0
void DaoxCanvas_Rotate( int x, int y )
{
	DaoxMatrix3D rotate = {1.0,0.0,0.0,0.0,1.0,0.0};
	DaoxAABBox2D box = daox_current_canvas->viewport;
	DaoxVector2D start, end, center = {0.0,0.0};
	double W2 = 0.5 * window_width;
	double H2 = 0.5 * window_height;
	double area, cosine, sine;

	start.x = last_x - W2;
	start.y = last_y - H2;
	end.x = x - W2;
	end.y = y - H2;

	area = DaoxTriangle_Area( center, start, end );
	cosine = DaoxTriangle_AngleCosine( center, start, end );
	sine = sqrt( 1.0 - cosine * cosine );


	rotate.A11 = rotate.A22 = cosine;
	if( area < 0.0 ){
		rotate.A12 = - sine;
		rotate.A21 =   sine;
	}else{
		rotate.A12 =   sine;
		rotate.A21 = - sine;
	}
	DaoxMatrix3D_Multiply( & daox_current_canvas->transform, rotate );

Done:
	last_x = x;
	last_y = y;
}
Ejemplo n.º 2
0
void DaoxWindow_RotateCanvas( DaoxWindow *self, DaoxCanvas *canvas, int x, int y )
{
	DaoxMatrix3D rotate = {1.0,0.0,0.0,0.0,1.0,0.0};
	DaoxVector2D start, end, center = {0.0,0.0};
	double W2 = 0.5 * self->width;
	double H2 = 0.5 * self->height;
	double area, cosine, sine;

	start.x = self->cursorPosX - W2;
	start.y = self->cursorPosY - H2;
	end.x = x - W2;
	end.y = y - H2;

	area = DaoxTriangle_Area( center, start, end );
	cosine = DaoxTriangle_AngleCosine( center, start, end );
	sine = sqrt( 1.0 - cosine * cosine );


	rotate.A11 = rotate.A22 = cosine;
	if( area < 0.0 ){
		rotate.A12 = - sine;
		rotate.A21 =   sine;
	}else{
		rotate.A12 =   sine;
		rotate.A21 = - sine;
	}
	DaoxMatrix3D_Multiply( & canvas->transform, rotate );
}