AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Objektrotation in Abhängigkeit

Ein Thema von -=ZGD=- · begonnen am 16. Mai 2014 · letzter Beitrag vom 16. Mai 2014
 
-=ZGD=-

Registriert seit: 25. Apr 2006
Ort: Bad Aibling
105 Beiträge
 
Delphi 10.1 Berlin Professional
 
#7

AW: Objektrotation in Abhängigkeit

  Alt 16. Mai 2014, 10:35
Richtig, die rote Markierung sollte dann rechts sein.
Ich habe den Rotationspunkt jetzt ins Zentrum des T-Stücks gelegt und lasse darum rotieren.


Das habe ich jetzt, aber es ist noch der Wurm drin.

Delphi-Quellcode:
unit unit_main;

interface

uses
   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
   System.Classes, Vcl.Graphics,
   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Imaging.jpeg, Vcl.ExtCtrls,
   Vcl.Imaging.pngimage, Vcl.StdCtrls, Generics.Collections, System.Math;

type
   RMarker = record
      Top: Integer;
      Left: Integer;
      Width: Integer;
      Height: Integer;
   end;

type
   TMarker = TDictionary<TImage, RMarker>;

type
   Tform_main = class(TForm)
      Image1: TImage;
      img1: TImage;
      Button1: TButton;
      Image2: TImage;
      shape_mittelpunkt: TShape;
      procedure Button1Click(Sender: TObject);
   private
      { Private-Deklarationen }
      fRotationCount: Integer;

      fMarker: TMarker;

      fMarker1Left, fMarker1Top, fMarker1Width, fMarker1Height: Integer;
   public
      { Public-Deklarationen }
   end;

var
   form_main: Tform_main;

implementation

{$R *.dfm}

procedure DreheBmp(Grad: Word; SourceBmp, DestBmp: TBitmap);
var
   Points: array [0 .. 2] of TPoint;
   Winkel: Double;
   X1, X2, Y1, Y2: Integer;
begin
   if Grad <= 360 then
   begin
      Winkel := (Grad - Grad div 90 * 90) / 180 * pi;
      X1 := Round(SourceBmp.Width * sin(Winkel));
      X2 := Round(SourceBmp.Width * cos(Winkel));
      Y2 := Round(SourceBmp.Height * sin(Winkel));
      Y1 := Round(SourceBmp.Height * cos(Winkel));
      Case Grad of
         0 .. 89, 360:
            begin
               Points[1] := Point(X2, 0); // rechts oben
               Points[0] := Point(0, X1); // links oben
               Points[2] := Point(Y2, Y1 + X1); // links unten
               DestBmp.Width := X2 + Y2;
               DestBmp.Height := Y1 + X1;
            end;
         90 .. 179:
            begin
               Points[1] := Point(0, Y2); // rechts oben
               Points[0] := Point(X1, Y2 + X2); // links oben
               Points[2] := Point(X1 + Y1, X2); // links unten
               DestBmp.Width := Y1 + X1;
               DestBmp.Height := X2 + Y2;
            end;
         180 .. 269:
            begin
               Points[1] := Point(Y2, X1 + Y1); // rechts oben
               Points[0] := Point(Y2 + X2, Y1); // links oben
               Points[2] := Point(X2, 0); // links unten
               DestBmp.Width := X2 + Y2;
               DestBmp.Height := Y1 + X1;
            end;
         270 .. 359:
            begin
               Points[1] := Point(X1 + Y1, X2); // rechts oben
               Points[0] := Point(Y1, 0); // links oben
               Points[2] := Point(0, Y2); // links unten
               DestBmp.Width := Y1 + X1;
               DestBmp.Height := X2 + Y2;
            end;
      end;
      PlgBlt(DestBmp.Canvas.Handle, Points, SourceBmp.Canvas.Handle, 0, 0,
         SourceBmp.Width, SourceBmp.Height, 0, 0, 0);
   end;
end;

procedure Tform_main.Button1Click(Sender: TObject);
var
   bmp1, bmp2: TBitmap;

   xp, yp: Integer;
   X1, Y1: Integer;
   X2, Y2: Integer;
   xh, yh: Integer;
begin
   bmp1 := TBitmap.Create;
   bmp1.Assign(Image1.Picture.Graphic);
   bmp2 := TBitmap.Create;

   inc(fRotationCount);

   // Mittelpunkt des T-Stücks
   xp := (Image1.Left + Image1.Width) - (Image1.Width div 2);
   yp := (Image1.Top + Image1.Height) - (Image1.Height div 2);

   // Drehpunkt TOP/LEFT T-Stück (DEBUG)
   // xp := Image1.Left;
   // yp := Image1.Top;

   // TOP/LEFT des Markers
   X1 := img1.Left;
   Y1 := img1.Top;

   // Differenz zum Mittelpunkt
   xh := X1 - xp;
   yh := Y1 - yp;

   X2 := +Round((xh * cos(DegToRad(90))) + (yh * sin(DegToRad(90))));
   Y2 := -Round((xh * sin(DegToRad(90))) + (yh * cos(DegToRad(90))));

   X1 := X2 + xp;
   Y1 := Y2 + yp;

   X2 := Y1 - xp;
   Y2 := -X1 + xp;
   X1 := X2 + xp;
   Y1 := Y2 + yp;

   // Zuweisung neuer Koordinaten
   img1.Left := X1;
   img1.Top := Y2;

   // Drehe T-Stück
   // DreheMarker(img1);
   DreheBmp(90, bmp1, bmp2);
   Image1.Picture.Assign(bmp2);

   // Mittelpunkt nach Drehung holen (DEBUG)
   xp := (Image1.Left + Image1.Width) - (Image1.Width div 2);
   yp := (Image1.Top + Image1.Height) - (Image1.Height div 2);

   // Objektmittelpunkt anzeigen (DEBUG)
   shape_mittelpunkt.Left := xp - shape_mittelpunkt.Width div 2;
   shape_mittelpunkt.Top := yp - shape_mittelpunkt.Height div 2;

end;

end.
Angehängte Dateien
Dateityp: zip MarkerRotation.zip (305,1 KB, 5x aufgerufen)
Stefan Michalk

Geändert von -=ZGD=- (16. Mai 2014 um 11:00 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:38 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz