Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Asignar valor double a movimiento del mouse (https://www.clubdelphi.com/foros/showthread.php?t=81732)

radenf 12-12-2012 19:28:16

Asignar valor double a movimiento del mouse
 
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:
Cita:

How to convert mouse movements to rotation of an element:
http://stackoverflow.com/questions/4...-of-an-element

What are atan and atan2 used for in games?:
http://gamedev.stackexchange.com/que...d-for-in-games

ArcTan:
http://www.delphibasics.co.uk/RTL.asp?Name=ArcTan

Angle and Coordinates:
http://www.zahniser.net/~russell/com...%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:
Revisa este código:
Código Delphi [-]
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


La franja horaria es GMT +2. Ahora son las 04:51:20.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi