title: Delphi Firemonkey 3D: How can I change the origin from which a 3D object rotates?
body: <p>The cube rotates when the user holds down the LMB and moves the mouse.I am using a dummy as a kind of "anchor", so that the camera stays in the same place, but the object rotates, so all sides can be seen by rotating the object (which is a cube). The problem is that after rotating the object, its x and y remain constant, so that the same motion causes a different effect from the camera's perspective. e.g. If I rotate 180 degrees up(y), the x axis' rotation is mirrored, in that moving the mouse left rotates in th opposite direction as it would before the 180 degree rotation</p>
  
  <p>Here is my code: </p>
  
  <p>Form Create:</p>
  
  <pre><code>procedure TForm2.Form3DCreate(Sender: TObject);
  begin
  Xf := 0;
  Yf := 0;
  Xi := 0;
  Yi := 0;
  Xd := 0;
  Yd := 0;
  end;
  </code></pre>
  
  <p>Start Button:</p>
  
  <pre><code>procedure TForm2.btnStartClick(Sender: TObject);    
  begin
  layerStart.Visible := False;
  Controller := TController.create(Form2,10);
  Camera1 := TCamera.Create(Controller.getAnchor);
  Camera1.Parent := Controller.getAnchor;
  Anchor := Controller.getAnchor;
  Timer1.Enabled := True;
  
  end;
  </code></pre>
  
  <p>Creation of Object and 'Anchor':</p>
  
  <pre><code>Type
   tController = class
     private
       cubeArray : Array[1..10,1..10,1..10]  of TCube;
       fCubeCount, fHalf : integer;
       fForm : TForm3D;
       bigCube : tDummy;
     public
      constructor create(Form : TForm3D; cubeCount :integer);
      function getAnchor : tDummy;
  
   end;
  
  implementation
  
  { tController }
  
  constructor tController.create(Form: TForm3D; cubeCount: integer); //cubeCount Max 10, min 1
  var
    x, y, z : Integer;
  begin
  fCubeCount := cubeCount;
  fForm := Form;
  fHalf := cubeCount div 2;
  bigCube := TDummy.Create(Form);
  With bigCube do
           begin
             Visible := True;
             Position.X := 0;
             Position.Y := 0;
             Position.Z := 0;
             Parent := Form;
           end;
  
  for x := 1 to fCubeCount do
   begin
    for y := 1 to fCubeCount do
     begin
      for z := 1 to fCubeCount do
       begin
         CubeArray[x,y,z] := TCube.Create(bigCube);
          With CubeArray[x,y,z] do
           begin
             Visible := True;
             Width := 0.5;
             Height := 0.5;
             Depth := 0.5;
             Position.X := x - 0.5 - fHalf;
             Position.Y := y - 0.5 - fHalf;
             Position.Z := z - 0.5 - fHalf;
             Parent := bigCube;
           end;
          end;
      end;
     end;
  
   end;
  
  function tController.getAnchor: TDummy;
  begin
  result := bigCube;
  end;
  
  
  
  end.
  </code></pre>
  
  <p>Timer:</p>
  
  <pre><code>procedure TForm2.Timer1Timer(Sender: TObject);
  begin
  
  // X on Form to Left = 60; X on form to right = 1280
    while GetAsyncKeyState(VK_LBUTTON) = -32768  do
     begin
      Xi := Screen.MousePos.X;
      Yi := Screen.MousePos.Y;
      Sleep(1);
      Xf := Screen.MousePos.X;
      Yf := Screen.MousePos.Y;
  
      Xd := (Xi-Xf);
      Yd := (Yi-Yf)*-1;// *-1 for compliance with Cartesian plane logic
  
      Xd := (Xd / 1220)*360*10; //COnverting from X units to degrees, *10 for more rotation per amount moved by mouse
      Yd := (Yd / 1220)*360*10;
  
  
  Anchor.RotationAngle.Y := Anchor.RotationAngle.Y + Xd;
  Anchor.RotationAngle.X := Anchor.RotationAngle.X + Yd;
  Application.ProcessMessages;
  
     end;
  
  
     end;
  </code></pre>
  
  <p>The object I want to rotate is the cube which is made up of all the smaller cubes. As far as I know, this issue stems from the fact the the anchor remains the same relative to the cube after rotation i.e. the origin of rotation moves with the object which rotates. 
  How would I fix this?</p>