GLScene - Store/Playback an object

disclaimer

A list structure is used to store the position/rotation of a GLSceneObject including the camera. Objects including the camera can then be interactively positioned, stored and restored.
{
  implements capture/playback of GLSceneObject's position and rotation

  use :

   RotPosList:=TGLRotPosList.create;

   // get various objects / position / rotation
   
   RotPosList.LoadObj(Cube1);
   RotPosList.LoadObj(Cube1);  // at another position and/or rotation
   RotPosList.LoadObj(Cube1);  // at another position and/or rotation
   RotPosList.LoadObj(Cube1);  // at another position and/or rotation

   RotPosList.LoadObj(TGLSceneObject(GLCamera1));
   RotPosList.LoadObj(TGLSceneObject(GLCamera1));  // at another position and/or rotation
   RotPosList.LoadObj(TGLSceneObject(GLCamera1));  // at another position and/or rotation
   RotPosList.LoadObj(TGLSceneObject(GLCamera1));  // at another position and/or rotation

   // playback

   for i:=0 to RotPosList.count-1 do
     RotPosList.ToDisplay(i);

   RotPosList.destroy;

}
unit GLRotPosList;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Geometry,GLScene;

  

type
  TGLRotPosItem=class(TObject)
   private
    frot:TMatrix;  // defined in Geometry
    fpos:TVector;  // defined in Geometry
    fobj:TGLSceneObject;
   protected
    
   public
    constructor create(obj:TGLSceneObject);
    destructor destroy;
    procedure GetObj;           // get the pos&rot of object 
    procedure PutObj;           // put the pos&rot of object
    property rot:TMatrix read frot write frot;
    property pos:TVector read fpos write fpos;
   published
 
    property obj:TGLSceneObject read fobj write fobj;
  end;

  TGLRotPosList = class(TList)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
   constructor create; 
   destructor destroy; override; // destroy the contained items
   procedure clear; override;     // destroy the contained items
   procedure ToDisplay(i:integer);             // moves the data to the object
   function LoadObj(q:TGLSceneObject):integer; // get the data from the object
  published
    { Published declarations }
  end;

procedure Register;

implementation

//----  TGLRotPosItem ---------------------------------------------------
constructor TGLRotPosItem.create(obj:TGLSceneObject);
begin
 inherited create;
 fobj:=obj;
end;

destructor TGLRotPosItem.destroy;
begin
 inherited destroy;
end;

procedure TGLRotPosItem.GetObj; // get the pos&rot&object
begin
 fpos[0]:=fobj.position.x;
 fpos[1]:=fobj.position.y;
 fpos[2]:=fobj.position.z;
 frot:=fobj.matrix;
end; 

procedure TGLRotPosItem.PutObj; // put the pos&rot&object
begin
 fobj.beginupdate;
 fobj.position.x:=fpos[0];
 fobj.position.y:=fpos[1];
 fobj.position.z:=fpos[2];
 fobj.matrix:=frot;
 fobj.endupdate;
end;
//----  TGLRotPosList ---------------------------------------------------
constructor TGLRotPosList.create; 
begin
 inherited create;
end;

destructor TGLRotPosList.destroy; 
var q:TGLRotPosItem;
 i:integer;
begin
 clear;
 inherited destroy;
end;  

procedure TGLRotPosList.clear; 
var q:TGLRotPosItem;
 i:integer;
begin
 for i:=count-1 downto 0 do begin
  q:=items[i];
  delete(i);
  q.destroy;
  end;
end;

procedure TGLRotPosList.ToDisplay(i:integer);
var q:TGLRotPosItem;
begin
 if (i < = count) then begin
  q:=TGLRotPosItem(items[i]);
  q.PutObj;
 end;
end;

function TGLRotPosList.LoadObj(q:TGLSceneObject):integer;
var p:TGLRotPosItem;
begin
 if q < > nil then begin
  p:=TGLRotPosItem.create(q);
  p.getobj;
  result:=add(p);
 end;
end;
//----  end ---------------------------------------------------  
procedure Register;
begin
 // RegisterComponents('GLScene', [TGLRotPosList]);
end;

end.



OpenGL
home

last updated: 16.aug.00


Copyright (99,2000) Ing.Büro R.Tschaggelar