AL_Graph3d

Top  Previous  Next

unit AL_Graph3d;

 

interface

 

uses

   Windows, Graphics, SysUtils, Classes, Controls, ExtCtrls, OpenGL1,

   Math, NewGeom, ClipBrd;

 

const

 

//Standards for Licht, Material, etc.

light_position : array[0..3] of GLfloat = (10.0, 10.0, 100.0, 0.0);

light_diffuse : array[0..3] of GLfloat = (0.8, 0.8, 0.8, 0.0);

light_ambient : array[0..3] of GLfloat = (0.3, 0.3, 0.3, 0.0);

mat_specular  : array[0..3] of GLfloat = (0.1, 0.1, 0.1, 1.0);

mat_shininess : array[0..0] of GLfloat = (0.0);

 

mat_ambient : array[0..3] of GLfloat = (0.0, 0.5, 0.0, 0.0);

mat_diffuse : array[0..3] of GLfloat = (0.5, 0.9, 0.5, 0.0);

 

Type

 

   TALAxis3d = class(TPersistent)

   private

       FVisible: Boolean;

       FLength: Integer;

       FColorY: TColor;

       FColorX: TColor;

       FColorZ: TColor;

       FOnChange: TNotifyEvent;

       procedure SetColorX(const Value: TColor);

       procedure SetColorY(const Value: TColor);

       procedure SetLength(const Value: Integer);

       procedure SetVisible(const Value: Boolean);

       procedure Changed;

   procedure SetColorZ(const Value: TColor);

   public

       constructor Create;

   published

       property Visible  : Boolean read FVisible write SetVisible;

       property Length   : Integer read FLength  write SetLength;

       property ColorX   : TColor  read FColorX  write SetColorX;

       property ColorY   : TColor  read FColorY  write SetColorY;

       property ColorZ   : TColor  read FColorZ  write SetColorZ;

       property OnChange : TNotifyEvent read FOnChange write FOnChange;

   end;

 

   TALCustomGraph3D = class (TCustomControl)

   private

          Color: array[0..3]of TColor;

          FActive: Boolean;

          FCentralCross: boolean;

          FWireFrame: boolean;

          FZoom: double;

       FBackgroundColor: TColor;

       FAxis: TALAxis3d;

       FOnBeginPaint: TNotifyEvent;

       FOnPaint: TNotifyEvent;

       Procedure CMChildkey( Var msg: TCMChildKey ); message CM_CHILDKEY;

          procedure SetActive(const Value: Boolean);

          procedure SetCentralCross(const Value: boolean);

          procedure SetWireFrame(const Value: boolean);

          procedure SetZoom(const Value: double);

       procedure OnChange(Sender: TObject);

   procedure SetBackgroundColor(const Value: TColor);

   protected

       XInc: extended;

       XMax: extended;

       XMin: extended;

       YInc: extended;

       YMax: extended;

       YMin: extended;

       ZMax: extended;

       ZMin: extended;

       Origin,Movept: TPoint;

       tr_x,tr_y,tr_z : double;

       IsMouseDown: Boolean;

       MouseDownX: Integer;

       MouseDownY: Integer;

          procedure Paint; override;

       procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

       procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;

       procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;

          function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;

                            MousePos: TPoint): Boolean; override;

          function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;

          function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;

          procedure KeyDown(var Key: Word;Shift: TShiftState); override;

          procedure KeyPress(var Key: Char); override;

   public

       dc: HDC;

       rc : HGLRC;

       Count: Integer;

       PVX0: extended;

       PVX1: extended;

       PVX2: extended;

       PVXOld: extended;

       PVY0: extended;

       PVY1: extended;

       PVY2: extended;

       PVYOld: extended;

       PVZ0: extended;

       PVZ1: extended;

       PVZ2: extended;

       PVZOld: extended;

          constructor Create(AOwner: TComponent); override;

          destructor Destroy; override;

 

       procedure ConvertV3ToS(X,Y,Z:extended;var r,a,b:extended);

       procedure ConvertSToV3(R,A,B:extended;var X,Y,Z:extended);

 

       procedure Render;

       procedure ZoomIn;

       procedure ZoomOut;

       procedure Rotate(dx,dy:extended);

       procedure Translate3d(dx,dy,dz:extended);

 

       // Camera

       procedure CamFront;

       procedure CamBack;

       procedure CamTop;

       procedure CamBottom;

       procedure CamLeft;

       procedure CamRight;

 

       //Draw method

       procedure SetColor(Color:TColor);

       procedure DrawAxis;

       procedure Line(X0,Y0,Z0,X1,Y1,Z1:extended);

       procedure Plane(X0,Y0,Z0,X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3:extended);

       procedure Circle(u, v, r: double);

       procedure Polygon(p: array of TPoint3d);

       procedure PolygonFill(p: array of TPoint3d);

       procedure PolyLine(p: array of TPoint3d);

 

       procedure SaveBitmap(filename:string);

       procedure CopyToClipboard;

 

       property Active          : Boolean   read FActive write SetActive;

       property Axis            : TALAxis3d read FAxis write FAxis;

          property CentralCross    : boolean   read FCentralCross write SetCentralCross;

       property BackgroundColor : TColor    read FBackgroundColor write SetBackgroundColor;

       property WireFrame       : boolean   read FWireFrame write SetWireFrame;

       property Zoom            : double    read FZoom write SetZoom;

       property OnBeginPaint    : TNotifyEvent read FOnBeginPaint write FOnBeginPaint;

       property OnAfterPaint    : TNotifyEvent read FOnPaint write FOnPaint;

   end;

 

   TALGraph3D = class (TALCustomGraph3D)

   private

   protected

   public

   published

       property Active;

       property Axis;

          property CentralCross;

       property BackgroundColor;

       property WireFrame;

       property Zoom;

 

       property Align;

       property Enabled;

       property TabOrder;

       property TabStop;

       property OnDockDrop;

       property OnDockOver;

       property OnEnter;

       property OnExit;

       property OnGetSiteInfo;

       property OnKeyDown;

       property OnKeyPress;

       property OnKeyUp;

       property OnMouseDown;

       property OnMouseMove;

       property OnMouseUp;

       property OnMouseWheel;

       property OnMouseWheelDown;

       property OnMouseWheelUp;

       property OnResize;

       property OnUnDock;

       property OnBeginPaint;

       property OnAfterPaint;

//        property OnPaint;

   end;

 

procedure Register;

 

implementation

 

procedure Register;

begin

RegisterComponents('AL', [TALGraph3D]);

end;

 

{ TALAxis3d }

// ==========================================================================

 

procedure TALAxis3d.Changed;

begin

if Assigned(FOnChange) then FOnChange(Self);

end;

 

constructor TALAxis3d.Create;

begin

inherited;

FColorX   := clWhite;

FColorY   := clLime;

FColorZ   := clRed;

FLength   := 5;

Visible   := True;

end;

 

procedure TALAxis3d.SetColorX(const Value: TColor);

begin

FColorX := Value;

Changed;

end;

 

procedure TALAxis3d.SetColorY(const Value: TColor);

begin

FColorY := Value;

Changed;

end;

 

procedure TALAxis3d.SetColorZ(const Value: TColor);

begin

FColorZ := Value;

Changed;

end;

 

procedure TALAxis3d.SetLength(const Value: Integer);

begin

FLength := Value;

Changed;

end;

 

procedure TALAxis3d.SetVisible(const Value: Boolean);

begin

FVisible := Value;

Changed;

end;

 

 

{ TALCustomGraph3D }

// ==========================================================================

 

constructor TALCustomGraph3D.Create(AOwner: TComponent);

begin

   inherited;

   XMin:=-1;XMax:=1;YMin:=-1;YMax:=1;XInc:=0.1;YInc:=0.1;ZMin:=-1;ZMax:=1;

   Count:=0;

   PVX0:=0; PVY0:=0.1; PVZ0:=0;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

   Axis             := TALAxis3d.Create;

   Axis.OnChange    := OnChange;

   IsMouseDown      := false;

   FBackGroundColor := ClBlack;

   FWireframe       := false;

   TabStop          := True;

   PVX0:=5; PVY0:=5; PVZ0:=5;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

   Width  := 100;

   height := 100;

//    DoubleBuffered := True;

//    TabStop        := True;

   Active := False;

   Render;

   Zoom := 0.1;

end;

 

destructor TALCustomGraph3D.Destroy;

begin

Axis.Free;

wglMakeCurrent(0, 0);

wglDeleteContext(rc);

inherited Destroy;

end;

 

procedure TALCustomGraph3D.CMChildkey(var msg: TCMChildKey);

var dx,dy,dz: double;

   k:double;

begin

k:=0.01;

dx := 0; dy:=0;

msg.result := 1; // declares key as handled

Case msg.charcode of

(*

   VK_RETURN,190 : ZoomDrawing;

   VK_ESCAPE  : begin

                  STOP := True;

                  ActionMode := amNone;

                  DrawMode   := dmNone;

                  SelectAll(False);

                end;*)

   VK_ADD     : Zoom := FZoom*0.99999;

   VK_SUBTRACT,189: Zoom := FZoom*1.00001;

//    VK_F4      : ShowPoints := not ShowPoints;

   VK_LEFT    : dx:=k;

   VK_RIGHT   : dx:=-k;

   VK_UP      : dy:=-k;

   VK_DOWN    : dy:=k;

   VK_PRIOR   : dz:=-k;

   VK_NEXT    : dz:=k;

Else

   msg.result:= 0;

   inherited;

End;

if (dx<>0) or (dy<>0) or (dz<>0) then

    Translate3d(dx,dy,dz);

inherited;

end;

 

function TALCustomGraph3D.DoMouseWheel(Shift: TShiftState;

WheelDelta: Integer; MousePos: TPoint): Boolean;

begin

 

end;

 

function TALCustomGraph3D.DoMouseWheelDown(Shift: TShiftState;

MousePos: TPoint): Boolean;

begin

 

end;

 

function TALCustomGraph3D.DoMouseWheelUp(Shift: TShiftState;

MousePos: TPoint): Boolean;

begin

 

end;

 

procedure TALCustomGraph3D.KeyDown(var Key: Word; Shift: TShiftState);

begin

inherited;

 

end;

 

procedure TALCustomGraph3D.KeyPress(var Key: Char);

begin

inherited;

 

end;

 

procedure TALCustomGraph3D.MouseDown(Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

   IsMouseDown:=true;

   MouseDownX:=X;

   MouseDownY:=Y;

   PVXOld:=PVX0;

   PVYOld:=PVY0;

   PVZOld:=PVZ0;

   Origin := Point(x,y);

   Movept := Point(x,y);

inherited;

end;

 

procedure TALCustomGraph3D.MouseMove(Shift: TShiftState; X, Y: Integer);

var dy: double;

begin

   if(not IsMouseDown)then exit;

   if Shift=[ssLeft] then begin

      PVX0:=PVXOld;

      PVY0:=PVYOld;

      PVZ0:=PVZOld;

      Rotate(2*(X-MouseDownX)/Width,0);

      Rotate(0,5*(MouseDownY-Y)/Height);

      Render();

   end;

   if Shift=[ssRight] then begin

   dy := (Movept.y-y)/4;

   if dy>0 then ZoomIn;

   if dy<0 then ZoomOut;

   Movept := Point(x,y);

   end;

inherited;

end;

 

procedure TALCustomGraph3D.MouseUp(Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

IsMouseDown:=false;

inherited;

end;

 

procedure TALCustomGraph3D.Paint;

begin

Render;

//  inherited;

end;

 

procedure TALCustomGraph3D.SetActive(const Value: Boolean);

var pfd: TPixelFormatDescriptor;

begin

if FActive <> Value then begin

   FActive := Value;

   if FActive then begin

          //Initialize the OpenGL

          with pfd do begin

            nSize:=sizeof(pfd);

            nVersion:=1;

            dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER or 0;

            cColorBits:=16;

            iPixelType:=PFD_TYPE_RGBA;

       end;

       dc := GetDC(Handle);

       SetPixelFormat(dc, ChoosePixelFormat(dc, @pfd), @pfd);

       rc :=wglCreateContext(dc);

       wglMakeCurrent(dc,rc);

       glShadeModel(GL_SMOOTH);

       glEnable(GL_DEPTH_TEST);

       glClearDepth(1.0);

       glDepthFunc(GL_EQUAL);

       glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

       Render();

   end else begin

       wglMakeCurrent(0, 0);

       wglDeleteContext(rc);

   end;

end;

end;

 

procedure TALCustomGraph3D.SetCentralCross(const Value: boolean);

begin

FCentralCross := Value;

Render;

end;

 

procedure TALCustomGraph3D.SetWireFrame(const Value: boolean);

begin

FWireFrame := Value;

Render;

end;

 

procedure TALCustomGraph3D.CamBack;

begin

   PVX0:=0; PVY0:=-FZoom; PVZ0:=0;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

Render;

end;

 

procedure TALCustomGraph3D.CamBottom;

begin

   PVX0:=0; PVY0:=0; PVZ0:=-FZoom;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

Render;

end;

 

procedure TALCustomGraph3D.CamFront;

begin

   PVX0:=0; PVY0:=FZoom; PVZ0:=0;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

Render;

end;

 

procedure TALCustomGraph3D.CamLeft;

begin

   PVX0:=0; PVY0:=-FZoom; PVZ0:=0;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=0;

Render;

end;

 

procedure TALCustomGraph3D.CamRight;

begin

   PVX0:=0; PVY0:=FZoom; PVZ0:=0;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=1;

Render;

end;

 

procedure TALCustomGraph3D.CamTop;

begin

   PVX0:=0; PVY0:=1; PVZ0:=FZoom;

   PVX1:=0; PVY1:=0; PVZ1:=0;

   PVX2:=0; PVY2:=0; PVZ2:=-1;

Render;

end;

 

procedure TALCustomGraph3D.DrawAxis;

begin

if Axis.Visible then begin

   glBegin(GL_LINES);

   SetColor(Axis.ColorX);

   glVertex3f(-Axis.Length,0,0);

   glVertex3f(Axis.Length,0,0);

   SetColor(Axis.ColorY);

   glVertex3f(0,-Axis.Length,0);

   glVertex3f(0,Axis.Length,0);

   SetColor(Axis.ColorZ);

   glVertex3f(0,0,-Axis.Length);

   glVertex3f(0,0,Axis.Length);

   glEnd();

end;

end;

 

procedure TALCustomGraph3D.Line(X0, Y0, Z0, X1, Y1, Z1: extended);

begin

   glBegin(GL_LINES);

   glVertex3f(X0,Y0,Z0);

   glVertex3f(X1,Y1,Z1);

   glEnd();

end;

 

procedure TALCustomGraph3D.Plane(X0, Y0, Z0, X1, Y1, Z1, X2, Y2, Z2, X3,

Y3, Z3: extended);

begin

   glBegin(GL_QUADS);

   glVertex3f(X0,Y0,Z0);

   glVertex3f(X1,Y1,Z1);

   glVertex3f(X2,Y2,Z2);

   glVertex3f(X3,Y3,Z3);

   glEnd();

end;

 

procedure TALCustomGraph3D.Circle(u, v, r: double);

var i: integer;

begin

glBegin(GL_LINE_LOOP);

   For i:=0 to 360 do

       glVertex3f(u+r*cos(DegToRad(i)),v+r*sin(DegToRad(i)),0);

glEnd;

end;

 

procedure TALCustomGraph3D.Polygon(p: array of TPoint3d);

var i: integer;

begin

glBegin(GL_LINE_LOOP);

   For i:=0 to High(p) do

       glVertex3f(p[i].x,p[i].y,p[i].z);

glEnd;

end;

 

procedure TALCustomGraph3D.PolygonFill(p: array of TPoint3d);

var i: integer;

begin

///////////////////////////////////////////////////////////////////////////////

// draw a simple concave quad

///////////////////////////////////////////////////////////////////////////////

   // define concave quad data (vertices only)

   //  0    2

   //  \ \/ /

   //   \3 /

   //    \/

   //    1

 

   // We are going to do 2-pass draw: draw to stencil buffer first,

   // then draw to color buffer.

   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

   glDisabLe(GL_CULL_FACE);

   glEnable(GL_STENCIL_TEST);          // enable stencil test

 

   // PASS 1: draw to stencil buffer only

   // The reference value will be written to the stencil buffer plane if test passed

   // The stencil buffer is initially set to all 0s.

   glStencilFunc(GL_ALWAYS, 1, $ffff);

   glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // disable writing to color buffer

   glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);

 

   glBegin(GL_TRIANGLE_FAN);

   For i:=0 to High(p) do

       glVertex3f(p[i].x,p[i].y,p[i].z);

   glEnd();

 

 

   // PASS 2: draw color buffer

   // Draw again the exact same polygon to color buffer where the stencil

   // value is only odd number(1). The even(0) area will be descarded.

   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);    // enable writing to color buffer

   glStencilFunc(GL_EQUAL, 1, 1);                  // test if it is odd(1)

   glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

   glColor3f(1,1,1);

 

   glBegin(GL_TRIANGLE_FAN);

   For i:=0 to High(p) do

       glVertex3f(p[i].x,p[i].y,p[i].z);

   glEnd();

 

   glDisable(GL_STENCIL_TEST);

end;

 

procedure TALCustomGraph3D.PolyLine(p: array of TPoint3d);

var i: integer;

begin

glBegin(GL_LINE_STRIP);

   For i:=0 to High(p) do begin

       glVertex3f(p[i].x,p[i].y,p[i].z);

   end;

glEnd;

end;

 

procedure TALCustomGraph3D.Render;

begin

if Active then begin

   glViewport(0,0,Self.Width,Self.Height);

   glMatrixMode(GL_PROJECTION);

   glLoadIdentity();

   gluPerspective(45.0, Self.Width/Self.Height, 0.1, 5000.0);

//    glOrtho(0, Width, 0, Height, 0.1,5000);

   glMatrixMode(GL_MODELVIEW);

   //Clear and set PointView

   glClearColor((FBackgroundColor AND $000000FF) / 255,((FBackgroundColor AND $0000FF00) DIV 256) / 255,

                                  ((FBackgroundColor AND $00FF0000) DIV 65536) / 255, 1);

   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

   glLoadIdentity();

   if Assigned(FOnBeginPaint) then FOnBeginPaint(Self)

   else

      gluLookAt(PVX0,PVY0,PVZ0,PVX1,PVY1,PVZ1,PVX2,PVY2,PVZ2);

   if Wireframe then glPolygonmode(GL_FRONT_AND_BACK, GL_LINE)else glPolygonmode(GL_FRONT_AND_BACK, GL_FILL);

   //Draw

   glTranslatef(tr_x,tr_y,tr_z);

   DrawAxis();

   (*

   for i:=0 to Count-1 do begin

     //Set Color

     for j:=0 to 3 do Color[j]:=Items[i].Color[j];

     //Check Style

     with Items[i]do

         case Items[i].Style of

         OrdCone:DrawCone(X0,Y0,Z0,X1,Y1,Z1,R);

         OrdCube:DrawCube(X0,Y0,Z0,X1,Y1,Z1);

         OrdCylinder:DrawCylinder(X0,Y0,Z0,A,B,C);

         OrdLine:DrawLine(X0,Y0,Z0,X1,Y1,Z1);

         OrdPlane:DrawPlane(X0,Y0,Z0,X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3);

         OrdSphere:DrawSphere(X0,Y0,Z0,R);

         OrdTriangle:DrawTriangle(X0,Y0,Z0,X1,Y1,Z1,X2,Y2,Z2);

         OrdZYX:DrawZYX(Expression,VX0,VY0,VX1,VY1);

         end;

   end;*)

   if Assigned(FOnPaint) then FOnPaint(Self);

   SwapBuffers(DC);

end;

end;

 

procedure TALCustomGraph3D.Rotate(dx, dy: extended);

var

   r, a, b: extended;

begin

   ConvertV3ToS(PVX0,PVY0,PVZ0,r,a,b);

   a:=a+dx; b:=b+dy;

   if(b>=PI)then b:=0;

   ConvertSToV3(R,A,B,PVX0,PVY0,PVZ0);

end;

 

procedure TALCustomGraph3D.SaveBitmap(filename: string);

var bmp: TBitmap;

begin

   DC := GetDC (Handle);

   bmp:=TBitmap.Create;

   bmp.Width :=width;

   bmp.Height := Height;

   BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width,bmp.Height,dc, 0, 0, SRCCOPY);

   bmp.height:=bmp.height-5;

   bmp.width :=bmp.width -5;

   bmp.savetofile(filename);

   bmp.Free;

end;

 

procedure TALCustomGraph3D.CopyToClipboard;

var bmp: TBitmap;

begin

   DC := GetDC (Handle);

   bmp:=TBitmap.Create;

   bmp.Width :=width;

   bmp.Height := Height;

   BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width,bmp.Height,dc, 0, 0, SRCCOPY);

   bmp.height:=bmp.height-5;

   bmp.width :=bmp.width -5;

   Clipboard.Assign(BMP);

   bmp.Free;

end;

 

 

procedure TALCustomGraph3D.SetColor(Color: TColor);

begin

   glColor3ub((Color and $0000FF),(Color and $00FF00) shr 8,(Color and $FF0000) shr 16);

end;

 

procedure TALCustomGraph3D.ZoomIn;

var

   R, a, b: extended;

begin

Zoom := FZoom*0.97;

end;

 

procedure TALCustomGraph3D.ZoomOut;

var

   R, a, b: extended;

begin

Zoom := FZoom*1.03;

end;

 

procedure TALCustomGraph3D.SetZoom(const Value: double);

var

   R, a, b: extended;

begin

   FZoom := Value;

   ConvertV3ToS(PVX0,PVY0,PVZ0,R,a,b);

   R:=FZoom;

   ConvertSToV3(R,A,B,PVX0,PVY0,PVZ0);

   Render();

end;

 

procedure TALCustomGraph3D.ConvertSToV3(R, A, B: extended; var X, Y,

Z: extended);

begin

   Y:=r*Sin(b)*Cos(a);

   X:=r*Sin(b)*Sin(a);

   Z:=r*Cos(b);

end;

 

procedure TALCustomGraph3D.ConvertV3ToS(X, Y, Z: extended; var r, a,

b: extended);

begin

   if(X=0)and(Y=0)and(Z=0)then exit;

   R:=Sqrt(X*X+Y*Y+Z*Z);

   if(Y=0)then

       begin

           if(X>0)then a:=pi/2 else a:=-PI/2;

       end

   else

       begin

           a:=Arctan(X/Y);

           if(a*X<0)then a:=a+PI;

       end;

   b:=Arccos(Z/r);

end;

 

procedure TALCustomGraph3D.Translate3d(dx, dy, dz: extended);

begin

tr_x:=tr_x+FZoom*dx;

tr_y:=tr_y+FZoom*dy;

tr_z:=tr_z+FZoom*dz;

Render;

end;

 

procedure TALCustomGraph3D.OnChange(Sender: TObject);

begin

Render;

end;

 

procedure TALCustomGraph3D.SetBackgroundColor(const Value: TColor);

begin

FBackgroundColor := Value;

Render;

end;

 

end.