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

Viewed 118

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;
1 Answers

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".

Related