Ver la Versión Completa : Asignar valor double a movimiento del mouse
radenf
12-12-2012, 19:28:16
Hola amigos:
De nuevo con mis dudas complicadas.
Tengo un componente que me permite girar una imagen mediante la propiedad angle que posee un valor double.
Estas imagenes tienen formato .dcm y no pueden ser vistas en un TImage.
Quisiera poder rotar dicha imagen con el movimiento del mouse y pensé que podría hacerlo si logro asignar dicho valor double al desplazamiento del mouse sobre la imagen.
¿Es posible?
Agradezco de antemano cualquier ayuda
Salu2
nlsgarcia
12-12-2012, 21:13:35
radenf,
Revisa estos links:
How to convert mouse movements to rotation of an element:
http://stackoverflow.com/questions/4131252/how-to-convert-mouse-movements-to-rotation-of-an-element
What are atan and atan2 used for in games?:
http://gamedev.stackexchange.com/questions/14602/what-are-atan-and-atan2-used-for-in-games
ArcTan:
http://www.delphibasics.co.uk/RTL.asp?Name=ArcTan
Angle and Coordinates:
http://www.zahniser.net/~russell/computer/index.php?title=Angle%20and%20Coordinates
Espero sea útil :)
Nelson.
radenf
12-12-2012, 22:16:46
Muchas gracias nlsgarcia
Demasiado elevado para mi escaso nivel de conocimientos, ya que además no poseo ninguna noción de Java.
Gracias de todas maneras
Salu2
nlsgarcia
14-12-2012, 07:09:58
radenf,
Revisa este link:
Rotate Image Component: http://www.delphiarea.com/products/delphi-components/rotateimage/
Revisa este código:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
RotateImage1.Angle := Frac((RotateImage1.Angle + 1.0) / 360.0) * 360.0;
end;
procedure TForm1.RotateImage1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DraggingControl := nil;
if (Button = mbLeft) and not (ssDouble in Shift) then
DraggingControl := TRotateImage(Sender);
if Sender = DraggingControl then
begin
StartAngle := RotateImage1.Angle;
if X = DraggingControl.Width / 2 then
if Y < DraggingControl.Height / 2 then
StartTheta := Pi / 2
else
StartTheta := -Pi / 2
else
StartTheta := ArcTan2(Y - DraggingControl.Height / 2, X - DraggingControl.Width / 2);
end;
end;
procedure TForm1.RotateImage1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
Theta: Extended;
begin
if Sender = DraggingControl then
begin
if X = DraggingControl.Width / 2 then
if Y < DraggingControl.Height / 2 then
Theta := Pi / 2
else
Theta := -Pi / 2
else
Theta := ArcTan2(Y - DraggingControl.Height / 2, X - DraggingControl.Width / 2);
RotateImage1.Angle := StartAngle + 180 * (StartTheta - Theta) / Pi;
end;
end;
procedure TForm1.RotateImage1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DraggingControl := nil;
end;
El código anterior fue tomado del ejemplo que viene con el Componente TRotateImage mencionado en el link y muestra como calcular el angulo de rotación de una imagen, quizás puedas adaptar el ejemplo a tu aplicación de imágenes en formato .dcm
Espero sea útil :)
Nelson.
radenf
14-12-2012, 11:05:00
Muchas gracias.
Lo pruebo y te cuento.
Saludos
vBulletin v3.6.8, Derechos ©2000-2024, Jelsoft Enterprises Ltd.