📄 oxnewtonvehicle4wheels.pas
字号:
unit oxNewtonVehicle4Wheels;
(*==============================================================================
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is "oxNewton opengl-Dynamics-delphi-component".
The Initial Developer of the Original Code is
Dave Gravel, OrionX3D Opengl & Delphi Programming, dave.gravel@cgocable.ca.
http://www.Dave.ServeUsers.com
http://www.k00m.sexidude.com
Portions created by Dave Gravel are Copyright (C) 2004 - 2006.
Dave Gravel. All Rights Reserved.
Contributor(s): GLScene (http://www.glscene.org) -
Julio Jerez and Alain Suero (http://www.newtondynamics.com) -
Sascha Willems (www.delphigl.de)
================================================================================
oxNewton v1.55 by Dave Gravel.
PS: I request only one thing from the users of my oxNewton Component,
it is to put on your about or your help a comment saying you using the
oxNewton Component with my name Dave Gravel and my
e-mail: dave.gravel@cgocable.ca
Don't modify or remove any comment or information on my file
if you do some modification on my code please contact me.
Read the Newton license too, it is realy important.
{******************************************************************************}
// [15-9-2007]: oxNewtonVehicle4Wheels last change by Dave Gravel.
// It is not a good idea to use this object in a game to create trafic circulation.
// This vehicle object have a big set of options to make the simulation the more real possible.
// If you like to create trafic you can use custom joint, or create a new basic vehicle from vehicle joints.
// Or you can use the method called raycast vehicle to make trafic.
// It is a good idea to take a look about it in Newton forum.
// You can use oxNewton manager to build your custum newton stuff.
// This object is normaly create for my personal use, but I let's other use it.
// The vehicle object start to come complet I need to fix some little parts.
// And 2 or 3 more options can come but I don't think more of this.
//
// I have start to write a very basic vehicle object to use for create trafic or AI.
// I have start too a custom vehicle object to add the wheel number you like.
{******************************************************************************}
===============================================================================*)
interface
{******************************************************************************}
// [15-9-2007]: oxNewtonVehicle4Wheels last change by Dave Gravel. //
{******************************************************************************}
uses
// Windows
Forms, Windows, Classes, Messages, SysUtils, Graphics, Controls,
ExtCtrls, Dialogs, StdCtrls,
// GLScene
GLScene, GLMisc, GLObjects, VectorGeometry, GLVectorFileObjects, VectorLists,
GLTexture, VectorTypes, TGA, JPEG, GLFileSMD, GLFile3DS, GLFileLWO, GLFileOBJ,
GLFileSTL, GLFileMS3D, GLFileMD5, GLFileMD3, GLFileMD2,
Q3MD3,
// Newton, oxNewton
oxNewtonUtils, oxNewtonManager, oxNewtonJoint,
oxNewtonImport;
type
TOXWheel = TGLFreeForm;
TGoodbytes = array[1..8] of byte;
ECorruptFile = class(Exception);
const
Goodbytes: TGoodbytes = (1,2,3,4,5,6,7,8);
{******************************************************************************}
// [15-9-2007]: TOXNewtonVehicle last change by Dave Gravel. //
{******************************************************************************}
type
TOXVehicleStreams = class( TComponent )
private
FOnCorrupt: TNotifyEvent;
procedure WriteStr( S: String; Stream: TStream );
function ReadStr( Stream: TStream ): string;
Procedure LoadFromStreamNor( ms: TStream );
Procedure SaveToStreamNor( ms: TStream );
function CheckGood( ms: TStream ): boolean;
procedure FoundCorrupt;
public
StreamList : TStringList;
Constructor Create( AOWner: TComponent ); override;
Destructor Destroy; override;
Procedure LoadFromFile( const Filename: string );
Procedure SaveToFile( const Filename: string );
Procedure AddStream( const ID: string; Source: TStream );
Procedure RemoveStream( const ID: string );
Procedure LoadFromStream( ms: TStream );
Procedure SaveToStream( ms: TStream );
Procedure GetStream( const ID: string; Dest: TStream );
Procedure ClearStreams;
published
property OnCorrupt : TNotifyEvent read FOnCorrupt write FOnCorrupt;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonVehicle last change by Dave Gravel. //
{******************************************************************************}
type
TOXNewtonVehicle = class;
{******************************************************************************}
// [15-9-2007]: TOXVehicleTire last change by Dave Gravel. //
{******************************************************************************}
TOXVehicleTire = class( TObject )
FindId: integer;
ID: Integer;
WTag: integer;
Brake: Float;
TireBrakeForce: Float;
TireSideSleepCoeficient: Float;
TireMaxSideSleepSpeed: Float;
SteeringForce: Float;
Torque: Float;
Wheel: TOXWheel;
SteerAngle: Float;
constructor Create( Name: string; pVehicle: TOXNewtonVehicle;
pMatrix: TOXMatrix; pWidth, pRadius: Float );
Destructor Destroy; override;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonVehicle last change by Dave Gravel. //
{******************************************************************************}
TOXNewtonVehicle = class( TGLFreeForm )
private
FOrionX3D: byte;
FOXVisual: boolean;
FBody: PNewtonBody;
FTire: array[0..3] of TOXVehicleTire;
FJoint: PNewtonJoint;
FCollision: PNewtonCollision;
FCustomUpVector: boolean;
FPin: TGLCoordinates;
FUpDir: TGLCoordinates;
FMass: Float;
FWID: integer;
FAutoFreeze: boolean;
FActived: boolean;
FWheelDummy: TOXNewtonDummy;
FManager: TOXNewtonManager;
FTraction: TOXVehicleTraction;
FWheelaMeshName: string;
FWheelbMeshName: string;
FWheelcMeshName: string;
FWheeldMeshName: string;
FFrameModel: string;
FWheelaModel: string;
FWheelbModel: string;
FWheelcModel: string;
FWheeldModel: string;
FPath: string;
FFreezeSpeedMag2: Float;
FFreezeOmegaMag2: Float;
FFreezeFramesCount: integer;
FWheelPitchAngle: Float;
FWheelRollAngle: Float;
FWheelTurnAngle: Float;
FShockValue: Float;
FShockLength: Float;
FShockSpring: Float;
FWheelMass: Float;
FSpeedForce: Float;
FSpeedDivide: Float;
FSteeringForce: Float;
FSteeringDivide: Float;
FSteeringMultiply: Float;
FLinearDamping: Float;
FAngularDampingX: Float;
FAngularDampingY: Float;
FAngularDampingZ: Float;
FInertiaX: Float;
FInertiaY: Float;
FInertiaZ: Float;
FOriginX: Float;
FOriginY: Float;
FOriginZ: Float;
FConcretX: Float;
FConcretY: Float;
FConcretZ: Float;
FWheelaBrakeForce: Float;
FWheelbBrakeForce: Float;
FWheelcBrakeForce: Float;
FWheeldBrakeForce: Float;
FWheelaPos: TGLCoordinates;
FWheelbPos: TGLCoordinates;
FWheelcPos: TGLCoordinates;
FWheeldPos: TGLCoordinates;
FWheelaWidth: Float;
FWheelaRadius: Float;
FWheelbWidth: Float;
FWheelbRadius: Float;
FWheelcWidth: Float;
FWheelcRadius: Float;
FWheeldWidth: Float;
FWheeldRadius: Float;
FWheelaOmega: Float;
FWheelbOmega: Float;
FWheelcOmega: Float;
FWheeldOmega: Float;
FWheelaNormalLoad: Float;
FWheelbNormalLoad: Float;
FWheelcNormalLoad: Float;
FWheeldNormalLoad: Float;
FWheelaOnAir: boolean;
FWheelbOnAir: boolean;
FWheelcOnAir: boolean;
FWheeldOnAir: boolean;
FWheelaLostSideGrip: boolean;
FWheelbLostSideGrip: boolean;
FWheelcLostSideGrip: boolean;
FWheeldLostSideGrip: boolean;
FWheelaLostTraction: boolean;
FWheelbLostTraction: boolean;
FWheelcLostTraction: boolean;
FWheeldLostTraction: boolean;
FWheelSideSleepCoeficient: Float;
FWheelMaxSideSleepSpeed: Float;
FMassRegulation: Float;
FRollingFriction: Float;
FWheelMaxLongitudinalSlideSpeed: Float;
FContactID: integer;
FMeshModel: byte;
FWheelRotation: Float;
FMaterialSurfaceMode: TOXMaterialSurfaceMode;
FWheelsMaterialSurfaceMode: TOXMaterialSurfaceMode;
FMaterialCustom: boolean;
FWheelsMaterialCustom: boolean;
FMaterialSoftness: Float;
FMaterialElasticity: Float;
FMaterialStaticFriction: Float;
FMaterialKineticFriction: Float;
FWheelsMaterialSoftness: Float;
FWheelsMaterialElasticity: Float;
FWheelsMaterialStaticFriction: Float;
FWheelsMaterialKineticFriction: Float;
FWheelMaterialLibrary: TGLMaterialLibrary;
FCustomMassInertiaOrigin: boolean;
FContinuousCollisionMode: boolean;
FisSetMatrix: boolean;
FisAddImpulse: boolean;
FisAddTorque: boolean;
FisAddForce: boolean;
FisSetOmega: boolean;
FisSetVelocity: boolean;
FisSetForce: boolean;
FisSetTorque: boolean;
FAddImpulse: TOXVector3;
FAddImpulseVel: TOXVector3;
FAddForce: TOXVector3;
FAddTorque: TOXVector3;
FSetOmega: TOXVector3;
FSetVelocity: TOXVector3;
FSetForce: TOXVector3;
FSetTorque: TOXVector3;
FGetOmega: TOXVector3;
FGetVelocity: TOXVector3;
FGetForce: TOXVector3;
FGetTorque: TOXVector3;
FGetMatrix: TOXMatrix;
FSetMatrix: TOXMatrix;
FOnAir: boolean;
FInternalForceAndTorque: boolean;
FFrictionMotion1: boolean;
FFrictionMotion2: boolean;
FVehicleStreams: TOXVehicleStreams;
FOnContactBegin: TOXOnContactBegin;
FOnContactProcess: TOXOnContactProcess;
FOnContactEnd: TOXOnContactEnd;
FOnStepRender: TOXOnStepRender;
FOnCustomMass: TOXOnCustomMass;
procedure AddTire( Name: string; pMatrix: TOXMatrix; pWidth,
pRadius: Float );
procedure SetMaterialSurfaceMode( const Mode: TOXMaterialSurfaceMode );
procedure SetWheelsMaterialSurfaceMode( const Mode: TOXMaterialSurfaceMode );
procedure SetMass( const val: Float );
procedure SetPin( val: TGLCoordinates );
procedure SetConcretX( const val: Float );
procedure SetConcretY( const val: Float );
procedure SetConcretZ( const val: Float );
procedure SetInertiaX( const val: Float );
procedure SetInertiaY( const val: Float );
procedure SetInertiaZ( const val: Float );
procedure SetOriginX( const val: Float );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -