Home > Blockchain >  In delphi how do i add basic mouse controls to a sphere?
In delphi how do i add basic mouse controls to a sphere?

Time:09-12

In delphi im trying to zoom in and out and click to rotate but im not sure on what to do

begin

end;

procedure TForm1.GlobeMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; var Handled: Boolean);
begin

end;
procedure TForm1.GlobeClick(Sender: TObject);
begin

end;

CodePudding user response:

Another way to do this might be to add your own camera instead of the default design camera.

Drop a TDummy component on your form and add the camera to that TDummy. Then use the Viewport3D's MouseMove and MouseWheel events to rotate the TDummy and adjust the camera's Z position respectively.

// ----------------------------------------------------------------------------
procedure TfrmMain.Viewport3D1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  FMouseDown := PointF(X, Y);
end;

// ----------------------------------------------------------------------------
procedure TfrmMain.Viewport3D1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Single);
begin
  if ssLeft in Shift then
  begin
    Dummy1.RotationAngle.X := Dummy1.RotationAngle.X -
      ((Y - FMouseDown.Y) * 0.3);
    Dummy1.RotationAngle.Y := Dummy1.RotationAngle.Y  
      ((X - FMouseDown.X) * 0.3);
    FMouseDown := PointF(X, Y);
  end;
end;

// ----------------------------------------------------------------------------
procedure TfrmMain.Viewport3D1MouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; var Handled: Boolean);
begin
  Camera1.Position.Z := Camera1.Position.Z   WheelDelta / 40;
end;

There's a more complete example in this Simple FireMonkey 3D blog post. See the section titled "Manipulate the Scene".

CodePudding user response:

@Bruce McGee i keep getting these errors E2035 Not enough actual parameter at line 93 E3037 Declaration of "MouseMove" differs from previous declaration at line 103 E2066 Missing operator line at 107 this error shows up three times E2003 Undeclared identifier 'FMmouseDown' at line 108 E2029 ')' expected but identifier 'Y' found at line 108 E2065 Unsatisfied forward or external declaration 'Tform1.MouseDown' at line 73 E2065 Unsatisfied forward or external declaration 'Tform1.ScrollZoom' at line 73 Here is a screenshot

  • Related