home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / TeeChartPro / TeeChart5Delphi5Eval.exe / %MAINDIR% / Examples / Features / OpenGL_Canvas.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-10  |  6.5 KB  |  263 lines

  1. unit OpenGL_Canvas;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   TeeComma, ExtCtrls, TeeProcs, TeEngine, Chart, TeeOpenGL, TeeGLCanvas,
  8.   StdCtrls, TeeSurfa, TeeEditPro, OpenGL2;
  9.  
  10. type
  11.   TOpenGLCanvas = class(TForm)
  12.     Chart1: TChart;
  13.     TeeCommander1: TTeeCommander;
  14.     TeeOpenGL1: TTeeOpenGL;
  15.     Panel1: TPanel;
  16.     Label1: TLabel;
  17.     ScrollBar1: TScrollBar;
  18.     ScrollBar2: TScrollBar;
  19.     ScrollBar3: TScrollBar;
  20.     ScrollBar4: TScrollBar;
  21.     ScrollBar5: TScrollBar;
  22.     ScrollBar6: TScrollBar;
  23.     Label2: TLabel;
  24.     Label3: TLabel;
  25.     ScrollBar7: TScrollBar;
  26.     ScrollBar8: TScrollBar;
  27.     ScrollBar9: TScrollBar;
  28.     Timer1: TTimer;
  29.     Series1: TSurfaceSeries;
  30.     CheckBox3: TCheckBox;
  31.     CheckBox1: TCheckBox;
  32.     CheckBox2: TCheckBox;
  33.     Image2: TImage;
  34.     Image3: TImage;
  35.     Image4: TImage;
  36.     Image5: TImage;
  37.     procedure Chart1AfterDraw(Sender: TObject);
  38.     procedure FormCreate(Sender: TObject);
  39.     procedure ScrollBar3Change(Sender: TObject);
  40.     procedure ScrollBar7Change(Sender: TObject);
  41.     procedure ScrollBar8Change(Sender: TObject);
  42.     procedure ScrollBar9Change(Sender: TObject);
  43.     procedure CheckBox3Click(Sender: TObject);
  44.     procedure Timer1Timer(Sender: TObject);
  45.     procedure CheckBox1Click(Sender: TObject);
  46.   private
  47.     { Private declarations }
  48.   public
  49.     { Public declarations }
  50.     MyBitmap0,
  51.     MyBitmap1,
  52.     MyBitmap2,
  53.     MyBitmap3     : TBitmap;
  54.     ConeColor     : TColor;
  55.     ConeRotation,
  56.     DeltaZ        : Integer;
  57.   end;
  58.  
  59. implementation
  60.  
  61. {$R *.DFM}
  62.  
  63. { Draw the 3D objects at the AfterDraw event of the Chart1 }
  64. procedure TOpenGLCanvas.Chart1AfterDraw(Sender: TObject);
  65. var x : Integer;
  66. begin
  67.   With Chart1,Canvas do
  68.   begin
  69.     Brush.Style:=bsSolid;
  70.     Pen.Style:=psClear;
  71.  
  72.     if CheckBox1.Checked then Pen.Style:=psSolid;
  73.  
  74.     Pen.Color:=clBlack;
  75.     x:=ChartXCenter;
  76.     if CheckBox2.Checked then Brush.Bitmap:=MyBitmap1;
  77.     Cube(x-500,x+500,500,550,-500,500,True);
  78.  
  79.     if CheckBox2.Checked then Brush.Bitmap:=MyBitmap0;
  80.     Cube(x-500,x-450,0,500,-500,500,True);
  81.     Cube(x-450,x-100,0,500,-500,-400,True);
  82.     Cube(x-450,x-100,0,500,400,500,True);
  83.  
  84.     Brush.Bitmap:=nil;
  85.  
  86.     Brush.Color:=RGB(200,200,250);
  87.     if CheckBox2.Checked then Brush.Bitmap:=MyBitmap2;
  88.     Cube(x-500,x+500,-100,0,-500,500,True);
  89.     Brush.Bitmap:=nil;
  90.  
  91.     Brush.Color:=clYellow;
  92.     Sphere(x-450,-150,-450,50);
  93.     Sphere(x-450,-150,450,50);
  94.     Sphere(x+450,-150,450,50);
  95.     Sphere(x+450,-150,-450,50);
  96.  
  97.     Brush.Color:=RGB(20,100,220);
  98.     Pyramid(True,x-500,-400,x+500,-200,-500,500,True);
  99.  
  100.     Brush.Color:=RGB(40,250,120);
  101.     Pen.Style:=psClear;
  102.     Cylinder(True,x+450,0,x+500,500,-500,-450,True);
  103.     Cylinder(True,x+450,0,x+500,500,450,500,True);
  104.  
  105.     if CheckBox2.Checked then Brush.Bitmap:=MyBitmap3;
  106.     RectangleZ(x-375,100,400,-350,350);
  107.  
  108.     Brush.Bitmap:=nil;
  109.  
  110.     if CheckBox1.Checked then Pen.Style:=psSolid;
  111.  
  112.     Pen.Color:=clBlack;
  113.     MoveTo3D(x-375,100,-250);
  114.     LineTo3D(x-375,50,0);
  115.     LineTo3D(x-375,100,250);
  116.  
  117.     Brush.Color:=RGB(255,215,196);
  118.     Cube(x-100,x,400,500,-200,200,True);
  119.  
  120.     Brush.Color:=clRed;
  121.     if CheckBox2.Checked then Brush.Bitmap:=MyBitmap0;
  122.     Sphere(x-50,350,-175,50);
  123.     Brush.Bitmap:=nil;
  124.  
  125.     Brush.Color:=clBlue;
  126.     Sphere(x-50,350,0,50);
  127.  
  128.     Brush.Color:=clGreen;
  129.     Sphere(x-50,350,175,50);
  130.  
  131.     Brush.Color:=RGB(234,106,218);
  132.     if CheckBox1.Checked then Pen.Style:=psSolid;
  133.  
  134.     Pen.Color:=clRed;
  135.     Cone(True,300,250,500,500,0,300,True,0);
  136.  
  137.     Font.Size:=60;
  138.     Font.Color:=clBlue;
  139.     TextOut3D(200,430,-400,'teeChart Pro');
  140.  
  141.     Font.Color:=clLime;
  142.     TeeTextAngleY:=ScrollBar1.Position;
  143.     TeeTextAngleZ:=ScrollBar2.Position;
  144.     RotateLabel3D(ScrollBar4.Position,ScrollBar5.Position,
  145.       ScrollBar6.Position,'100% Native Delphi',ScrollBar3.Position);
  146.     TeeTextAngleY:=0;
  147.     TeeTextAngleZ:=0;
  148.   end;
  149. end;
  150.  
  151. procedure TOpenGLCanvas.FormCreate(Sender: TObject);
  152. begin
  153.   { Set the OpenGL Font parameter }
  154.   TeeOpenGLFontExtrusion :=12;
  155.  
  156.   { Start OpenGL }
  157.   TeeOpenGL1.Active:=True;
  158.  
  159.   { this variable is for the animation only }
  160.   DeltaZ:=2;
  161.  
  162.   { Get the bitmaps from the Image components }
  163.   MyBitmap0:=TBitmap.Create;
  164.   MyBitmap0.Assign(Image2.Picture);
  165.  
  166.   MyBitmap1:=TBitmap.Create;
  167.   MyBitmap1.Assign(Image3.Picture);
  168.  
  169.   MyBitmap2:=TBitmap.Create;
  170.   MyBitmap2.Assign(Image4.Picture);
  171.  
  172.   MyBitmap3:=TBitmap.Create;
  173.   MyBitmap3.Assign(Image5.Picture);
  174.  
  175.   { setup the 3D parameters }
  176.   With Chart1.View3DOptions do
  177.   begin
  178.     Perspective:=70;
  179.     Zoom:=27;
  180.     Rotation:=348;
  181.     Elevation:=360;
  182.     HorizOffset:=-38;
  183.     VertOffset:=-130;
  184.   end;
  185.  
  186.   { set colors }
  187.   Chart1.Color:=clDkGray;
  188.   ConeColor:=clYellow;
  189.  
  190.   { add random values to Series1 }
  191.   Series1.FillSampleValues(20);
  192.  
  193.   { some more parameters }
  194.   Chart1.Legend.Visible:=False;
  195.   Chart1.Title.Visible:=False;
  196.   Chart1.Chart3DPercent:=100;
  197.   ConeRotation:=0;
  198.  
  199.   { set the default toolbar button }
  200.   TeeCommander1.ButtonRotate.Down:=True;
  201. end;
  202.  
  203. procedure TOpenGLCanvas.ScrollBar3Change(Sender: TObject);
  204. begin
  205.   Chart1.Repaint;
  206. end;
  207.  
  208. { move the Light X }
  209. procedure TOpenGLCanvas.ScrollBar7Change(Sender: TObject);
  210. begin
  211.   TeeOpenGL1.Light.Position.X:=ScrollBar7.Position;
  212. end;
  213.  
  214. { move the Light Y }
  215. procedure TOpenGLCanvas.ScrollBar8Change(Sender: TObject);
  216. begin
  217.   TeeOpenGL1.Light.Position.Y:=ScrollBar8.Position;
  218. end;
  219.  
  220. { move the Light Z }
  221. procedure TOpenGLCanvas.ScrollBar9Change(Sender: TObject);
  222. begin
  223.   TeeOpenGL1.Light.Position.Z:=ScrollBar9.Position;
  224. end;
  225.  
  226. { start / stop the animation }
  227. procedure TOpenGLCanvas.CheckBox3Click(Sender: TObject);
  228. begin
  229.   Timer1.Enabled:=CheckBox3.Checked;
  230. end;
  231.  
  232. { rotation animation }
  233. procedure TOpenGLCanvas.Timer1Timer(Sender: TObject);
  234. begin
  235.   With Chart1.View3DOptions do
  236.   begin
  237.     if Zoom>35 then Rotation:=Rotation+2
  238.                else Rotation:=Rotation+1;
  239.     if Rotation>=360 then Rotation:=0;
  240.     Zoom:=Zoom+DeltaZ;
  241.     if (Zoom>50) or (Zoom<25) then DeltaZ:=-DeltaZ;
  242.     if Random(100)=1 then
  243.        Case Random(5) of
  244.        0: ConeColor:=clBlue;
  245.        1: ConeColor:=clRed;
  246.        2: ConeColor:=clLime;
  247.        3: ConeColor:=clYellow;
  248.        4: ConeColor:=clWhite;
  249.        end;
  250.   end;
  251.   Inc(ConeRotation);
  252.   if ConeRotation>360 then ConeRotation:=0;
  253. end;
  254.  
  255. procedure TOpenGLCanvas.CheckBox1Click(Sender: TObject);
  256. begin
  257.   Series1.Pen.Visible:=CheckBox1.Checked;
  258. end;
  259.  
  260. initialization
  261.   RegisterClass(TOpenGLCanvas);
  262. end.
  263.