shine world - 2019-04-19

Hi to all,
it's first time that I try to use directly OpenGL to draw a line and I've some questions.

Every object has ShowAxes which show XYZ vectors of any object, taking care of rotations (pitch/roll/turn) and position in space. This is a great feature but I need to show one or two axis only depending by use.

I've tried to use a DirectOpenGLRender event to draw manually that axes lines using native DrawAxes code found in base classes:

procedure TGLSceneFrame.GLDirectOpenGLRender(Sender: TObject; var rci: TRenderContextInfo);
begin
  if RotaryGuideMA.Visible then GLSceneDrawAxis(RotaryGuideM, 0, rci, $CCCC, Camera.DepthOfView);
  if RotaryGuideMB.Visible then GLSceneDrawAxis(RotaryGuideM, 1, rci, $CCCC, Camera.DepthOfView);
  if RotaryGuideMC.Visible then GLSceneDrawAxis(RotaryGuideM, 2, rci, $CCCC, Camera.DepthOfView);
  if RotaryGuideSA.Visible then GLSceneDrawAxis(RotaryGuideS, 0, rci, $CCCC, Camera.DepthOfView);
  if RotaryGuideSB.Visible then GLSceneDrawAxis(RotaryGuideS, 1, rci, $CCCC, Camera.DepthOfView);
  if RotaryGuideSC.Visible then GLSceneDrawAxis(RotaryGuideS, 2, rci, $CCCC, Camera.DepthOfView);
end;

procedure GLSceneDrawAxis(Target: TGLImmaterialSceneObject; Axis: Integer; var rci : TRenderContextInfo; Pattern: Word; AxisLen: Single);
var
  V: TVector;
begin
  V := Target.AbsolutePosition;

  // @@@ WHAT trasformations to get righ position rotations like ShowAxes feature ?

  glPushAttrib(GL_ENABLE_BIT or GL_LIGHTING_BIT or GL_LINE_BIT);
  glDisable(GL_LIGHTING);
  glEnable(GL_LINE_STIPPLE);
  if not rci.ignoreBlendingRequests then begin
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  end;
  glLineWidth(1);
  glLineStipple(1, $CCCC);
  glBegin(GL_LINES);
  case Axis of
    0:
    begin
      glColor3f(0.5, 0.0, 0.0); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0] - AxisLen, V[1], V[2]);
      glColor3f(1.0, 0.0, 0.0); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0] + AxisLen, V[1], V[2]);
    end;
    1:
    begin
      glColor3f(0.0, 0.5, 0.0); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0], V[1] - AxisLen, V[2]);
      glColor3f(0.0, 1.0, 0.0); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0], V[1] + AxisLen, V[2]);
    end;
    2:
    begin
      glColor3f(0.0, 0.0, 0.5); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0], V[1], V[2] - AxisLen);
      glColor3f(0.0, 0.0, 1.0); glVertex3f(V[0], V[1], V[2]); glVertex3f(V[0], V[1], V[2] + AxisLen);
    end;
  end;
  glEnd;
  glPopAttrib;

  // clear fpu exception flag (sometime raised by the call to glEnd)
  asm fclex end;
end;

How you can see in image the XYZ are fine but I don't know how to inform OpenGL that vectors are rotated..

Thank you in advance for any suggestion
Besh Regards
Silverio