📄 oxnewtonvehicle4wheels.pas
字号:
procedure SetOriginY( const val: Float );
procedure SetOriginZ( const val: Float );
procedure SetAngularDampingX( const val: Float );
procedure SetAngularDampingY( const val: Float );
procedure SetAngularDampingZ( const val: Float );
procedure SetMassValues;
procedure SetWheelRotation( val: Float );
procedure SetSteeringForce( val: Float );
procedure SetSideSleepCoeficient( val: Float );
procedure SetSideSleepSpeed( val: Float );
procedure SetWheelaBrakeForce( val: Float );
procedure SetWheelbBrakeForce( val: Float );
procedure SetWheelcBrakeForce( val: Float );
procedure SetWheeldBrakeForce( val: Float );
procedure SetTraction( val: TOXVehicleTraction );
function GetTraction: TOXVehicleTraction;
function GetGeom: PNewtonCollision;
function GetBody: PNewtonBody;
function GetTire( Index: Integer ): TOXVehicleTire;
procedure SetLinearDamping( const val: Float );
procedure SetAutoFreeze( const val: boolean );
procedure SetContinuousCollision( const val: boolean );
procedure SetFreezeSpeedMag2( const val: Float );
procedure SetFreezeOmegaMag2( const val: Float );
procedure SetFreezeFramesCount( const val: Integer );
public
property Manager: TOXNewtonManager read FManager;
property Actived: boolean read FActived;
property VehicleStreams: TOXVehicleStreams read FVehicleStreams write FVehicleStreams;
property BodyGetOmega: TOXVector3 read FGetOmega write FGetOmega;
property BodyGetForce: TOXVector3 read FGetForce write FGetForce;
property BodyGetTorque: TOXVector3 read FGetTorque write FGetTorque;
property BodyGetVelocity: TOXVector3 read FGetVelocity write FGetVelocity;
property BodyGetMatrix: TOXMatrix read FGetMatrix write FGetMatrix;
property BodySetMatrix: TOXMatrix read FSetMatrix write FSetMatrix;
property BodyAddImpulse: TOXVector3 read FAddImpulse write FAddImpulse;
property BodyAddImpulseVelocity: TOXVector3 read FAddImpulseVel write FAddImpulseVel;
property BodyAddForce: TOXVector3 read FAddForce write FAddForce;
property BodyAddTorque: TOXVector3 read FAddTorque write FAddTorque;
property BodySetOmega: TOXVector3 read FSetOmega write FSetOmega;
property BodySetVelocity: TOXVector3 read FSetVelocity write FSetVelocity;
property BodySetForce: TOXVector3 read FSetForce write FSetForce;
property BodySetTorque: TOXVector3 read FSetTorque write FSetTorque;
property isSetMatrix: boolean read FisSetMatrix write FisSetMatrix;
property isAddImpulse: boolean read FisAddImpulse write FisAddImpulse;
property isAddTorque: boolean read FisAddTorque write FisAddTorque;
property isAddForce: boolean read FisAddForce write FisAddForce;
property isSetOmega: boolean read FisSetOmega write FisSetOmega;
property isSetVelocity: boolean read FisSetVelocity write FisSetVelocity;
property isSetForce: boolean read FisSetForce write FisSetForce;
property isSetTorque: boolean read FisSetTorque write FisSetTorque;
property Collide: boolean read FOnAir write FOnAir;
procedure SetMaterialSurface( Custom: boolean; Softness, Elasticity,
StaticFriction, KineticFriction: Float );
procedure SetWheelsMaterialSurface( Custom: boolean; Softness, Elasticity,
StaticFriction, KineticFriction: Float );
procedure UpdateTransformation( poweroff: boolean );
procedure InitNewton; virtual;
function GetSpeed: Float;
property WheelaOmega: Float read FWheelaOmega write FWheelaOmega;
property WheelbOmega: Float read FWheelbOmega write FWheelbOmega;
property WheelcOmega: Float read FWheelcOmega write FWheelcOmega;
property WheeldOmega: Float read FWheeldOmega write FWheeldOmega;
property WheelaOnAir: boolean read FWheelaOnAir write FWheelaOnAir;
property WheelbOnAir: boolean read FWheelbOnAir write FWheelbOnAir;
property WheelcOnAir: boolean read FWheelcOnAir write FWheelcOnAir;
property WheeldOnAir: boolean read FWheeldOnAir write FWheeldOnAir;
property WheelaNormalLoad: Float read FWheelaNormalLoad write FWheelaNormalLoad;
property WheelbNormalLoad: Float read FWheelbNormalLoad write FWheelbNormalLoad;
property WheelcNormalLoad: Float read FWheelcNormalLoad write FWheelcNormalLoad;
property WheeldNormalLoad: Float read FWheeldNormalLoad write FWheeldNormalLoad;
property WheelaLostSideGrip: boolean read FWheelaLostSideGrip write FWheelaLostSideGrip;
property WheelbLostSideGrip: boolean read FWheelbLostSideGrip write FWheelbLostSideGrip;
property WheelcLostSideGrip: boolean read FWheelcLostSideGrip write FWheelcLostSideGrip;
property WheeldLostSideGrip: boolean read FWheeldLostSideGrip write FWheeldLostSideGrip;
property WheelaLostTraction: boolean read FWheelaLostTraction write FWheelaLostTraction;
property WheelbLostTraction: boolean read FWheelbLostTraction write FWheelbLostTraction;
property WheelcLostTraction: boolean read FWheelcLostTraction write FWheelcLostTraction;
property WheeldLostTraction: boolean read FWheeldLostTraction write FWheeldLostTraction;
procedure FlipRight( fX, fY, fZ, aX, aY, aZ: Float; Angle: Float );
procedure SetTorque( pTorque: Float );
procedure SetBrake( pBrake: Float );
procedure SetHardBrake( pBrake: Float );
procedure VehicleLoadFrom3DS( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromSMD( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromLWO( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromOBJ( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromSTL( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromMS3D( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromMD5( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromMD3( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromMD2( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromMesh( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleLoadFromVHC( Vehicle: string;
Wheela,Wheelb,Wheelc,Wheeld: string );
procedure VehicleAutoConfig( const cName: ShortString; var Vhc: TOXNewtonVehicle );
procedure SetSteeringAngle( pSteeringAngle: Float );
procedure BuildList( var rci: TRenderContextInfo ); override;
procedure Notification( AComponent: TComponent; Operation: TOperation ); override;
procedure DoProgress( const progressTime: TProgressTimes ); override;
property Tire[Index: Integer]: TOXVehicleTire read GetTire;
property Geom: PNewtonCollision read GetGeom;
property Body: PNewtonBody read GetBody;
property Joint: PNewtonJoint read FJoint;
property ContactID: integer read FContactID write FContactID;
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property OXVisual: boolean read FOXVisual write FOXVisual;
property ContinuousCollisionMode: boolean read FContinuousCollisionMode write SetContinuousCollision;
property AutoFreeze: boolean read FAutoFreeze write SetAutoFreeze;
property Mass: Float read FMass write SetMass;
property WheelaBrakeForce: Float read FWheelaBrakeForce write SetWheelaBrakeForce;
property WheelbBrakeForce: Float read FWheelbBrakeForce write SetWheelbBrakeForce;
property WheelcBrakeForce: Float read FWheelcBrakeForce write SetWheelcBrakeForce;
property WheeldBrakeForce: Float read FWheeldBrakeForce write SetWheeldBrakeForce;
property WheelRotation: Float read FWheelRotation write SetWheelRotation;
property MassCenterX: Float read FConcretX write SetConcretX;
property MassCenterY: Float read FConcretY write SetConcretY;
property MassCenterZ: Float read FConcretZ write SetConcretZ;
property MassInertiaX: Float read FInertiaX write SetInertiaX;
property MassInertiaY: Float read FInertiaY write SetInertiaY;
property MassInertiaZ: Float read FInertiaZ write SetInertiaZ;
property MassOriginX: Float read FOriginX write SetOriginX;
property MassOriginY: Float read FOriginY write SetOriginY;
property MassOriginZ: Float read FOriginZ write SetOriginZ;
property WheelsMaterialSurfaceMode: TOXMaterialSurfaceMode read FWheelsMaterialSurfaceMode write SetWheelsMaterialSurfaceMode;
property MaterialSurfaceMode: TOXMaterialSurfaceMode read FMaterialSurfaceMode write SetMaterialSurfaceMode;
property MaterialCustom: boolean read FMaterialCustom write FMaterialCustom;
property WheelsMaterialCustom: boolean read FWheelsMaterialCustom write FWheelsMaterialCustom;
property MaterialSoftness: Float read FMaterialSoftness write FMaterialSoftness;
property MaterialElasticity: Float read FMaterialElasticity write FMaterialElasticity;
property MaterialStaticFriction: Float read FMaterialStaticFriction write FMaterialStaticFriction;
property MaterialKineticFriction: Float read FMaterialKineticFriction write FMaterialKineticFriction;
property WheelsMaterialSoftness: Float read FWheelsMaterialSoftness write FWheelsMaterialSoftness;
property WheelsMaterialElasticity: Float read FWheelsMaterialElasticity write FWheelsMaterialElasticity;
property WheelsMaterialStaticFriction: Float read FWheelsMaterialStaticFriction write FWheelsMaterialStaticFriction;
property WheelsMaterialKineticFriction: Float read FWheelsMaterialKineticFriction write FWheelsMaterialKineticFriction;
property MassRegulation: Float read FMassRegulation write FMassRegulation;
property ModelPath: string read FPath write FPath;
property RollingFriction: Float read FRollingFriction write FRollingFriction;
property ModelFrame: string read FFrameModel write FFrameModel;
property ModelWheela: string read FWheelaModel write FWheelaModel;
property ModelWheelb: string read FWheelbModel write FWheelbModel;
property ModelWheelc: string read FWheelcModel write FWheelcModel;
property ModelWheeld: string read FWheeldModel write FWheeldModel;
property Traction: TOXVehicleTraction read GetTraction write SetTraction;
property SpeedDivide: Float read FSpeedDivide write FSpeedDivide;
property SpeedForce: Float read FSpeedForce write FSpeedForce;
property SteeringDivide: Float read FSteeringDivide write FSteeringDivide;
property SteeringMultiply: Float read FSteeringMultiply write FSteeringMultiply;
property SteeringForce: Float read FSteeringForce write SetSteeringForce;
property LinearDamping: Float read FLinearDamping write SetLinearDamping;
property ShockLength: Float read FShockLength write FShockLength;
property ShockSpring: Float read FShockSpring write FShockSpring;
property ShockValue: Float read FShockValue write FShockValue;
property AngularDampingX: Float read FAngularDampingX write SetAngularDampingX;
property AngularDampingY: Float read FAngularDampingY write SetAngularDampingY;
property AngularDampingZ: Float read FAngularDampingZ write SetAngularDampingZ;
property UpVector: TGLCoordinates read FUpDir write FUpDir;
property CustomUpVector: boolean read FCustomUpVector write FCustomUpVector;
property WheelPin: TGLCoordinates read FPin write SetPin;
property WheelaPos: TGLCoordinates read FWheelaPos write FWheelaPos;
property WheelbPos: TGLCoordinates read FWheelbPos write FWheelbPos;
property WheelcPos: TGLCoordinates read FWheelcPos write FWheelcPos;
property WheeldPos: TGLCoordinates read FWheeldPos write FWheeldPos;
property WheelaWidth: Float read FWheelaWidth write FWheelaWidth;
property WheelaRadius: Float read FWheelaRadius write FWheelaRadius;
property WheelbWidth: Float read FWheelbWidth write FWheelbWidth;
property WheelbRadius: Float read FWheelbRadius write FWheelbRadius;
property WheelcWidth: Float read FWheelcWidth write FWheelcWidth;
property WheelcRadius: Float read FWheelcRadius write FWheelcRadius;
property WheeldWidth: Float read FWheeldWidth write FWheeldWidth;
property WheeldRadius: Float read FWheeldRadius write FWheeldRadius;
property WheelMass: Float read FWheelMass write FWheelMass;
property WheelPitchAngle: Float read FWheelPitchAngle write FWheelPitchAngle;
property WheelRollAngle: Float read FWheelRollAngle write FWheelRollAngle;
property WheelTurnAngle: Float read FWheelTurnAngle write FWheelTurnAngle;
property WheelMaterialLibrary: TGLMaterialLibrary read FWheelMaterialLibrary write FWheelMaterialLibrary;
property WheelMaxLongitudinalSlideSpeed: Float read FWheelMaxLongitudinalSlideSpeed write FWheelMaxLongitudinalSlideSpeed;
property WheelSideSleepCoeficient: Float read FWheelSideSleepCoeficient write SetSideSleepCoeficient;
property WheelMaxSideSleepSpeed: Float read FWheelMaxSideSleepSpeed write SetSideSleepSpeed;
property InternalForceAndTorque: boolean read FInternalForceAndTorque write FInternalForceAndTorque;
property FrictionMotion1: boolean read FFrictionMotion1 write FFrictionMotion1;
property FrictionMotion2: boolean read FFrictionMotion2 write FFrictionMotion2;
property CustomMassInertiaOrigin: boolean read FCustomMassInertiaOrigin write FCustomMassInertiaOrigin;
property FreezeSpeedMag2: Float read FFreezeSpeedMag2 write SetFreezeSpeedMag2;
property FreezeOmegaMag2: Float read FFreezeOmegaMag2 write SetFreezeOmegaMag2;
property FreezeFramesCount: integer read FFreezeFramesCount write SetFreezeFramesCount;
property OnContactBegin: TOXOnContactBegin read FOnContactBegin write FOnContactBegin;
property OnContactProcess: TOXOnContactProcess read FOnContactProcess write FOnContactProcess;
property OnContactEnd: TOXOnContactEnd read FOnContactEnd write FOnContactEnd;
property OnStepRender: TOXOnStepRender read FOnStepRender write FOnStepRender;
property OnCustomMass: TOXOnCustomMass read FOnCustomMass write FOnCustomMass;
end;
implementation
uses oxNewtondll;
{******************************************************************************}
// [15-9-2007]: TOXVehicleTire last change by Dave Gravel. //
{******************************************************************************}
constructor TOXVehicleTire.Create( Name: string; pVehicle: TOXNewtonVehicle;
pMatrix: TOXMatrix; pWidth, pRadius: Float );
begin
WTag:= 4;
if ( pVehicle.FMeshModel = 0 ) then exit;
if ( pVehicle.FMeshModel = 1 ) then begin
Wheel:= TOXWheel( pVehicle.FWheelDummy.AddNewChild( TOXWheel ) );
Wheel.MaterialLibrary:= pVehicle.WheelMaterialLibrary;
Wheel.LightmapLibrary:= pVehicle.WheelMaterialLibrary;
Wheel.LoadFromFile( Name );
Wheel.AutoCentering:=[ macCenterX, macCenterY, macCenterZ, macUseBarycenter ];
Wheel.Position.SetPoint( pMatrix[3, 0], pMatrix[3, 1], pMatrix[3, 2] );
Wheel.RollAngle:= pVehicle.WheelRollAngle;
Wheel.TurnAngle:= pVehicle.WheelTurnAngle;
Wheel.PitchAngle:= pVehicle.WheelPitchAngle;
end;
if ( pVehicle.FMeshModel = 2 ) then begin
Wheel:= TOXWheel( pVehicle.FWheelDummy.AddNewChild( TOXWheel ) );
Wheel.MaterialLibrary:= pVehicle.WheelMaterialLibrary;
Wheel.LightmapLibrary:= pVehicle.WheelMaterialLibrary;
Wheel.MeshObjects.LoadFromFile( Name );
Wheel.AutoCentering:=[ macCenterX, macCenterY, macCenterZ, macUseBarycenter ];
Wheel.Position.SetPoint( pMatrix[3, 0], pMatrix[3, 1], pMatrix[3, 2] );
Wheel.RollAngle:= pVehicle.WheelRollAngle;
Wheel.TurnAngle:= pVehicle.WheelTurnAngle;
Wheel.PitchAngle:= pVehicle.WheelPitchAngle;
end;
if ( pVehicle.FMeshModel = 3 ) then begin
Wheel:= TOXWheel( pVehicle.FWheelDummy.AddNewChild( TOXWheel ) );
pVehicle.WheelMaterialLibrary.Materials.Clear;
Wheel.MaterialLibrary:= pVehicle.WheelMaterialLibrary;
Wheel.LightmapLibrary:= pVehicle.WheelMaterialLibrary;
VehicleStreamDec(Wheel,Name,pVehicle.WheelMaterialLibrary);
Wheel.AutoCentering:=[ macCenterX, macCenterY, macCenterZ, macUseBarycenter ];
Wheel.Position.SetPoint( pMatrix[3, 0], pMatrix[3, 1], pMatrix[3, 2] );
Wheel.RollAngle:= pVehicle.WheelRollAngle;
Wheel.TurnAngle:= pVehicle.WheelTurnAngle;
Wheel.PitchAngle:= pVehicle.WheelPitchAngle;
end;
if ( pVehicle.FWheelDummy.Count = 1 ) then
TireBrakeForce:= pVehicle.WheelaBrakeForce;
if ( pVehicle.FWheelDummy.Count = 2 ) then
TireBrakeForce:= pVehicle.WheelbBrakeForce;
if ( pVehicle.FWheelDummy.Count = 3 ) then
TireBrakeForce:= pVehicle.WheelcBrakeForce;
if ( pVehicle.FWheelDummy.Count = 4 ) then
TireBrakeForce:= pVehicle.WheeldBrakeForce;
SteeringForce:= pVehicle.SteeringForce;
oxVehicleTireCreateShock( Wheel, pVehicle, pMatrix, self,
pVehicle.WheelMass, pWidth, pRadius, pVehicle.FShockLength,
pVehicle.FShockSpring, pVehicle.FShockValue, oxV3FToV3D( pVehicle.FPin.AsAffineVector ) );
end;
{******************************************************************************}
// [15-9-2007]: TOXVehicleTire last change by Dave Gravel. //
{******************************************************************************}
destructor TOXVehicleTire.destroy;
begin
if Assigned( Wheel ) then Wheel.free;
inherited destroy;
end;
{******************************************************************************}
// [15-9-2007]: TOXVehicleStreams last change by Dave Gravel. //
{******************************************************************************}
procedure TOXVehicleStreams.AddStream( const ID: string; Source: TStream );
var ms : TMemoryStream;
begin
if ( length( id ) > 0 ) and ( assigned( source ) ) then begin
ms:= TmemoryStream.Create;
ms.CopyFrom( source, 0 );
Streamlist.AddObject( ID, ms );
end;
end;
procedure TOXVehicleStreams.ClearStreams;
var a:integer;
begin
with StreamList do begin
for a:=0 to count -1 do
TMemoryStream( objects[a] ).free;
clear;
end;
end;
constructor TOXVehicleStreams.Create( AOWner: TComponent );
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -