📄 oxnewtonmanager.pas
字号:
procedure TOXNewtonManager.SetWorldSolver( const val: TOXWorldSolver );
begin
if ( val <> FWorldSolver ) then begin
FWorldSolver:= val;
if FActived then begin
case FWorldSolver of
mdSolverExact: NewtonSetSolverModel( FWorld, 0 );
mdSolverAdaptive: NewtonSetSolverModel( FWorld, 1 );
mdSolverLinear: NewtonSetSolverModel( FWorld, 2 );
end;
end;
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetWorldFriction( const val: TOXWorldFriction );
begin
if ( val <> FWorldFriction ) then begin
FWorldFriction:= val;
if FActived then begin
case FWorldFriction of
mdFrictionExact: NewtonSetFrictionModel( FWorld, 0 );
mdFrictionAdaptive: NewtonSetFrictionModel( FWorld, 1 );
end;
end;
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonManager.GetWorldSolver: TOXWorldSolver;
begin
result:= FWorldSolver;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonManager.GetWorldFriction: TOXWorldFriction;
begin
result:= FWorldFriction;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetWorldStepMode( const val: TOXWorldStep );
begin
if ( val <> FWorldStep ) then
FWorldStep:= val;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonManager.GetWorldStepMode: TOXWorldStep;
begin
result:= FWorldStep;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetGravity( const val: TGLCoordinates );
begin
FGravity.SetPoint( val.DirectX, val.DirectY, val.DirectZ );
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetWorldSize( const val: TGLCoordinates );
begin
FWorldSize.SetPoint( val.DirectX, val.DirectY, val.DirectZ );
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetMinimumFrameRate( const val: boolean );
begin
if ( val <> FMinimumFrameRate ) then
FMinimumFrameRate:= val;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetMinimumFrameRateValue( const val: Float );
begin
if ( val <> FMinimumFrameRateValue ) then begin
FMinimumFrameRateValue:= val;
if FActived then begin
if FMinimumFrameRate then
NewtonSetMinimumFrameRate( FWorld, FMinimumFrameRateValue );
end;
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.SetWorldLimitation( const val: boolean );
begin
if ( val <> FWorldWallLimitation ) then
FWorldWallLimitation:= val;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
function TOXNewtonManager.GetWorldLimitation: boolean;
begin
result:= FWorldWallLimitation;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.InitNewton;
var
i: integer;
WorldLimiteWall: TOXNewtonStaCube;
cMin, cMax: TOXVector3;
aMem: NewtonAllocMemory;
fMem: NewtonFreeMemory;
begin
if FActived then exit;
oxSetManagerDll( self, FDebugLog );
oxSplashCredit;
oxSetProtectionDll;
aMem:= nil;
fMem:= nil;
FRenderer:= TGLDirectOpenGL( Objects.AddNewChild( TGLDirectOpenGL ) );
AddLog( Name + ' create.', 1, ':Info Object' );
FWorld:= NewtonCreate( aMem, fMem );
NewtonSetPlatformArchitecture( FWorld, 0 );
cMin[0]:= -FWorldSize.X; cMin[1]:= -FWorldSize.Y; cMin[2]:= -FWorldSize.Z;
cMax[0]:= FWorldSize.X; cMax[1]:= FWorldSize.Y; cMax[2]:= FWorldSize.Z;
NewtonSetWorldSize( FWorld, @cMin[0], @cMax[0] );
AddLog( 'WorldSizeMin:[ ' + FloatToStr( cMin[0] ) +
' ]=[ ' + FloatToStr( cMin[1] ) +
' ]=[ ' + FloatToStr( cMin[2] ) +' ]', 1, ':Info Newton' );
AddLog( 'WorldSizeMax:[ ' + FloatToStr( cMax[0] ) +
' ]=[ ' + FloatToStr( cMax[1] ) +
' ]=[ ' + FloatToStr( cMax[2] ) +' ]', 1, ':Info Newton' );
if FMatrialCustom then oxSetWorldDefaultMaterial( WorldMaterialSoftness,
WorldMaterialElasticity,
WorldMaterialStaticFriction,
WorldMaterialKineticFriction );
FNewtonVersion:= NewtonWorldGetVersion( FWorld );
AddLog( 'Newton version: ' + IntToStr( FNewtonVersion ) + ' ' +InfoDllMode, 1, ':Info Version' );
AddLog( 'oxNewtonManager Name: ' + Name, 1, ':Info Object' );
AddLog( Name + ' InitNewton.', 1, ':Info Object' );
if FWorldWallLimitation then begin
for i:= 0 to 5 do begin
WorldLimiteWall:= TOXNewtonStaCube( Objects.AddNewChild( TOXNewtonStaCube ) );
WorldLimiteWall.Name:= 'WorldLimiteWall' + IntToStr( i );
WorldLimiteWall.Visible:= False;
oxLimitationWallCollision( WorldLimiteWall, i );
WorldLimiteWall.InitNewton;
end;
AddLog( 'World limite wall''s set to the worldsize enabled.', 1, ':Info Newton' );
end else begin
AddLog( 'Limite wall''s set to the worldsize disabled.', 1, ':Info Newton' );
end;
case FWorldSolver of
mdSolverExact: NewtonSetSolverModel( FWorld, 0 );
mdSolverAdaptive: NewtonSetSolverModel( FWorld, 1 );
mdSolverLinear: NewtonSetSolverModel( FWorld, 2 );
end;
case FWorldFriction of
mdFrictionExact: NewtonSetFrictionModel( FWorld, 0 );
mdFrictionAdaptive: NewtonSetFrictionModel( FWorld, 1 );
end;
if FMinimumFrameRate then
NewtonSetMinimumFrameRate( FWorld, FMinimumFrameRateValue );
NewtonSetPlatformArchitecture( FWorld, FArchitecture );
FRenderer.OnRender:= BuildList;
FActived:= True;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.DoProgress(const progressTime : TProgressTimes);
var
dtime: double;
begin
if ( FActived ) then begin
case FWorldStep of
mdNormalStep: begin
NewtonUpdate( FWorld, FNewtonStepTime );
if Assigned( FOnStepRender ) then
FOnStepRender( progressTime.deltaTime, progressTime.newTime );
end;
mdCadencerStep: begin
NewtonUpdate( FWorld, progressTime.deltaTime );
if Assigned( FOnStepRender ) then
FOnStepRender( progressTime.deltaTime, progressTime.newTime );
end;
mdMultiplyStep: begin
dtime:= progressTime.deltaTime;
if FNewtonMultiplyTime <= 0 then FNewtonMultiplyTime:= 1;
FNewtonTime:= FNewtonTime + ( dtime * FNewtonMultiplyTime );
while ( FNewtonTime >= FWorldMultiplyLimit ) do begin
FNewtonTime:= FNewtonTime - FWorldMultiplySize;
NewtonUpdate( FWorld, FNewtonStepTime );
if Assigned( FOnMultiplyStepRender ) then
FOnMultiplyStepRender( progressTime.deltaTime, progressTime.newTime );
end;
end;
mdCustomStep: begin
if assigned( FOnCustomPhysicsStep ) then
OnCustomPhysicsStep( progressTime.deltaTime, progressTime.deltaTime );
end;
end;
end;
Inherited;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonManager.BuildList(Sender: TObject; var rci: TRenderContextInfo);
begin
if ( FActived ) and ( DebugView ) then begin
glPushMatrix;
glPushAttrib( GL_ENABLE_BIT or GL_CURRENT_BIT or GL_LIGHTING_BIT or
GL_LINE_BIT or GL_COLOR_BUFFER_BIT );
glDisable( GL_LIGHTING );
glEnable( GL_LINE_SMOOTH );
glLineWidth( FCollidableLineSize );
rci.GLStates.ResetGLMaterialColors;
glEnable( GL_COLOR_MATERIAL );
glColor4fv( FColor.AsAddress );
glColorMaterial( GL_FRONT, GL_EMISSION );
glBegin( GL_LINES );
NewtonWorldForEachBodyDo( FWorld, @oxDebugShowBodyCollision );
glEnd;
glDisable( GL_COLOR_MATERIAL );
glPopAttrib;
glPopMatrix;
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonManager last change by Dave Gravel. //
{******************************************************************************}
destructor TOXNewtonManager.Destroy;
var i: integer;
begin
for i:= 0 to FVehicleList.Count-1 do
TOXNewtonVehicle( FVehicleList.Items[i] ).Free;
Objects.DeleteChildren;
Cameras.DeleteChildren;
if ( FWorld <> nil ) and FActived then begin
NewtonMaterialDestroyAllGroupID( FWorld );
NewtonDestroyAllBodies( FWorld );
NewtonDestroy( FWorld );
if Name = '' then AddLog( ClassName + ' destroyed.', 1, ':Info Object' )
else AddLog( Name + ' destroyed.', 1, ':Info Object' );
end;
FActived:= False;
FLogEnable:= False;
FColor.Free;
FWorldSize.Free;
FGravity.Free;
FVehicleList.Free;
oxCloseProtectionDll;
inherited destroy;
end;
{******************************************************************************}
{$D '[15-9-2007]: TOXNewtonManager v1.55 by Dave Gravel under MPL-1.1 license.'}
{******************************************************************************}
initialization
RegisterClasses( [ TOXNewtonManager ] );
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -