unit Vis3D_ViewSettings;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, TextEditor, Vcl.StdCtrls, rgl,
  UxPanel, Vcl.ExtCtrls, ColorContainer, ScrollBoxEx, Vis3D_GeoObjSettings;

type
  TVis3D_ViewSettingsFrm = class(TDrawableOptionsFrm3D)
    btnApply: TUxButton;
    ScrollBox1: TScrollBoxEx;
    lblR: TLabel;
    eR: TTextEditor;
    lblTheta: TLabel;
    eTheta: TTextEditor;
    lblPhi: TLabel;
    ePhi: TTextEditor;
    lblDegrees: TLabel;
    Label1: TLabel;
    lblCameraPos: TLabel;
    lblProjection: TLabel;
    rbPerspective: TRadioButton;
    rbOrthographic: TRadioButton;
    procedure btnApplyClick(Sender: TObject);
  strict private
  strict protected
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

procedure TVis3D_ViewSettingsFrm.btnApplyClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_ViewSettingsFrm.Initialize;
begin
  inherited;
  var Obj := FDrawable as TView3D;
  eR.PlainText := FormatFloat('0.###', Obj.r);
  eTheta.PlainText := FormatFloat('0.###', 180 * Obj.Theta / Pi);
  ePhi.PlainText := FormatFloat('0.###', 180 * Obj.Phi / Pi);
  if Assigned(Obj.Control) then
  begin
    rbPerspective.Checked := Obj.Control.Projection = Perspective;
    rbOrthographic.Checked := Obj.Control.Projection = Orthographic;
  end;
end;

procedure TVis3D_ViewSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Obj := FDrawable as TView3D;
  if Assigned(Obj.Control) then
    if rbPerspective.Checked then
      Obj.Control.Projection := Perspective
    else if rbOrthographic.Checked then
      Obj.Control.Projection := Orthographic;
  var coords: TSphericalCoordinates;
  coords.r := StrToFloat(eR.PlainText);
  coords.θ := Pi * StrToFloat(eTheta.PlainText) / 180;
  coords.φ := Pi * StrToFloat(ePhi.PlainText) / 180;
  Obj.AnimateTo(coords);
  inherited;
end;

end.
