📄 oxnewtonstaticobjects.pas
字号:
FCollision: PNewtonCollision;
FBody: PNewtonBody;
FContactID: integer;
FMaterialCustom: boolean;
FCollisionArray: TCollisionPrimitiveArray;
FObjects: TList;
FConvexHull: boolean;
FOnStepRender: TOXOnStepRender;
function GetGeom: PNewtonCollision;
function GetBody: PNewtonBody;
public
procedure AddCube( obj: TCompoundCube );
procedure AddSphere( obj: TCompoundSphere );
procedure AddCylinder( obj: TCompoundCylinder );
procedure AddCone( obj: TCompoundCone );
procedure AddCapsule( obj: TCompoundCapsule );
procedure AddChamferCylinder( obj: TCompoundChamferCylinder );
procedure AddMesh( obj: TCompoundMesh );
property Manager: TOXNewtonManager read FManager;
property Actived: boolean read FActived;
procedure UpdateTransformation;
procedure InitNewton; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure DoProgress( const progressTime: TProgressTimes ); override;
procedure BuildList( var rci: TRenderContextInfo ); override;
property Geom: PNewtonCollision read GetGeom write FCollision;
property Body: PNewtonBody read GetBody;
property ContactID: integer read FContactID write FContactID;
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property OXVisual: boolean read FOXVisual write FOXVisual;
property OnStepRender: TOXOnStepRender read FOnStepRender write FOnStepRender;
property ConvexHull: boolean read FConvexHull write FConvexHull;
end;
implementation
uses oxNewtondll;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
constructor TOXNewtonStaCube.Create( aOwner: TComponent );
begin
inherited create( aOwner );
FOrionX3D:= 100;
FActived:= False;
FMaterialCustom:= False;
FOXVisual:= True;
FContactID:= -1;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCube.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCube.UpdateTransformation;
begin
if FActived then oxPSetInitTransform( FBody, Self );
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCube.BuildList( var rci: TRenderContextInfo );
begin
if FOXVisual then
inherited else
exit;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaCube.GetGeom: PNewtonCollision;
begin
result:= FCollision;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaCube.GetBody: PNewtonBody;
begin
result:= FBody;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCube.InitNewton;
begin
FManager:= TOXNewtonManager( Scene );
if FActived or ( FManager = nil ) then Exit;
FCollision:= NewtonCreateBox( FManager.World, CubeWidth, CubeHeight, CubeDepth, nil );
FBody:= NewtonCreateBody( FManager.World, FCollision );
if FManager.WorldMatrialCustom then begin
FContactID:= FManager.WorldDefaultMaterialID;
oxSetObjectMaterial( FBody );
end;
NewtonBodySetUserData( FBody, Self );
oxPSetInitTransform( FBody, Self );
NewtonReleaseCollision( FManager.World, FCollision );
FManager.AddLog( 'Static Cube Name: '+Name, 1, ':Info Object' );
FManager.AddLog( Name + ' InitNewton.', 1, ':Info Object' );
FActived:= True;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCube.DoProgress( const progressTime: TProgressTimes );
begin
inherited;
if FActived then begin
if Assigned( FOnStepRender ) then
FOnStepRender( progressTime.deltaTime, progressTime.newTime );
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCube last change by Dave Gravel. //
{******************************************************************************}
destructor TOXNewtonStaCube.Destroy;
begin
if FActived and assigned( FBody ) then begin
if ( not ( csDesigning in ComponentState ) ) then
if Name = '' then FManager.AddLog( ClassName + ' destroyed.', 1, ':Info Object' )
else FManager.AddLog( Name + ' destroyed.', 1, ':Info Object' );
FActived:= False;
NewtonDestroyBody( FManager.World, FBody );
end;
inherited destroy;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
constructor TOXNewtonStaSphere.Create( aOwner: TComponent );
begin
inherited create( aOwner );
FOrionX3D:= 100;
FActived:= False;
FMaterialCustom:= False;
FOXVisual:= True;
FContactID:= -1;
FExtentScale:= false;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaSphere.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaSphere.UpdateTransformation;
begin
if FActived then
oxPSetInitTransform( FBody, Self );
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaSphere.BuildList( var rci: TRenderContextInfo );
begin
if FOXVisual then
inherited else
exit;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaSphere.GetGeom: PNewtonCollision;
begin
result:= FCollision;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaSphere.GetBody: PNewtonBody;
begin
result:= FBody;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaSphere.InitNewton;
begin
FManager:= TOXNewtonManager(Scene);
if FActived or ( FManager = nil ) then Exit;
if (not FExtentScale) then
FCollision:= NewtonCreateSphere( FManager.World, Radius, Radius, Radius, nil )
else
if (FExtentScale) then begin
Radius:= 0.5;
FCollision:= NewtonCreateSphere( FManager.World, Scale.X/2, Scale.Y/2, Scale.Z/2, nil );
end;
FBody:= NewtonCreateBody( FManager.World, FCollision );
if FManager.WorldMatrialCustom then begin
FContactID:= FManager.WorldDefaultMaterialID;
oxSetObjectMaterial( FBody );
end;
NewtonBodySetUserData( FBody, Self );
oxPSetInitTransform( FBody, Self );
NewtonReleaseCollision( FManager.World, FCollision );
FManager.AddLog( 'Static Sphere Name: '+Name, 1, ':Info Object' );
FManager.AddLog( Name + ' InitNewton.', 1, ':Info Object' );
FActived:= True;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaSphere.DoProgress( const progressTime: TProgressTimes );
begin
inherited;
if FActived then begin
if Assigned( FOnStepRender ) then
FOnStepRender( progressTime.deltaTime, progressTime.newTime );
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaSphere last change by Dave Gravel. //
{******************************************************************************}
destructor TOXNewtonStaSphere.Destroy;
begin
if FActived and assigned( FBody ) then begin
if ( not ( csDesigning in ComponentState ) ) then
if Name = '' then FManager.AddLog( ClassName + ' destroyed.', 1, ':Info Object' )
else FManager.AddLog( Name + ' destroyed.', 1, ':Info Object' );
FActived:= False;
NewtonDestroyBody( FManager.World, FBody );
end;
inherited destroy;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
constructor TOXNewtonStaCylinder.Create( aOwner: TComponent );
begin
inherited create( aOwner );
FOrionX3D:= 100;
FActived:= False;
FMaterialCustom:= False;
FOXVisual:= True;
FContactID:= -1;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCylinder.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCylinder.UpdateTransformation;
begin
if FActived then
oxPSetInitTransform( FBody, Self );
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaCylinder.GetGeom: PNewtonCollision;
begin
result:= FCollision;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonStaCylinder.GetBody: PNewtonBody;
begin
result:= FBody;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonStaCylinder last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonStaCylinder.InitNewton;
begin
FManager:= TOXNewtonManager(Scene);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -