📄 oxnewtonsmdragdoll.pas
字号:
unit oxNewtonSmdRagdoll;
{******************************************************************************}
// [15-9-2007]: oxNewtonSmdRagdoll last change by Dave Gravel. //
{******************************************************************************}
{===============================================================================
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)
Skinned part based on the Lucas Goraieb code.
This he have create the skinned part based on my old ode ragdoll box demo good work.
This work is unfinished in the moment I working on the bones editor.
The ragdoll is build with custom joints and in smd format file loaded from the
nice GLScene tools and Newton dynamics.
================================================================================
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.
================================================================================}
interface
{******************************************************************************}
// [15-9-2007]: oxNewtonSmdRagdoll last change by Dave Gravel. //
{******************************************************************************}
uses
Forms, Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls,
Dialogs, VectorGeometry, GLObjects, GLMisc, GLScene, GLVectorFileObjects,
VectorLists, GLTexture, GLGeomObjects, VectorTypes, TGA, GLFileSMD,
JPEG, StdCtrls,
//
oxNewtonImport, oxNewtonStaticObjects, oxNewtonDynamicObjects, oxNewtondll,
oxNewtonJoint, oxNewtonUtils, oxNewtonManager, oxNewtonCustomJoints,
oxNewtonBonesRagdoll;
{******************************************************************************}
// [15-9-2007]: TOXRagdollBoneGeomType last change by Dave Gravel. //
{******************************************************************************}
type
TOXRagdollBoneGeomType = ( mdBox, mdCylinder, mdSphere );
{******************************************************************************}
// [15-9-2007]: TOXNewtonSkinRagdoll last change by Dave Gravel. //
{******************************************************************************}
type
TOXNewtonSkinRagdoll = class( TGLActor )
private
FOrionX3D: byte;
FActived: boolean;
FOXVisual: boolean;
FDummyJoint: TGLDummyCube;
FRagEnabled: boolean;
FManager: TOXNewtonManager;
FMass: Float;
FAutoFreeze: boolean;
FFreezeSpeedMag2: Float;
FFreezeOmegaMag2: Float;
FFreezeFramesCount: integer;
FContactID: integer;
FMaterialSurfaceMode: TOXMaterialSurfaceMode;
FMaterialCustom: boolean;
FMaterialSoftness: Float;
FMaterialElasticity: Float;
FMaterialStaticFriction: Float;
FMaterialKineticFriction: Float;
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;
FOnContactBegin: TOXOnContactBegin;
FOnContactProcess: TOXOnContactProcess;
FOnContactEnd: TOXOnContactEnd;
FOnStartRagdoll: TOXOnStartRagdoll;
FOnStopRagdoll: TOXOnStopRagdoll;
FForceAndTorque: TOXPhysicsApplyForceAndTorque;
FDummyRoot: TNewtonRagdollDummyJoint;
FRag: TNewtonRagdoll;
procedure SetMaterialSurfaceMode( const Mode: TOXMaterialSurfaceMode );
public
property Manager: TOXNewtonManager read FManager;
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;
function bone
(oBone: TNewtonRagdollBone; id: String; j: TRagdollJoint): TNewtonRagdollBone;
property Collide: boolean read FOnAir write FOnAir;
procedure SetMaterialSurface( Custom: boolean; Softness, Elasticity, StaticFriction, KineticFriction: Float );
procedure InitNewton; virtual;
procedure StartRagdoll;
procedure StopRagdoll;
procedure UpdateRagdoll;
procedure DoProgress( const progressTime: TProgressTimes ); override;
constructor Create( aOwner: TComponent ); override;
destructor Destroy; override;
property ContactID: integer read FContactID write FContactID;
property DummyJoint: TGLDummyCube read FDummyJoint write FDummyJoint;
published
property RagdollEnabled: boolean read FRagEnabled;
property OXVisual: boolean read FOXVisual write FOXVisual;
property AutoFreeze: boolean read FAutoFreeze write FAutoFreeze;
property Mass: Float read FMass write FMass;
property MaterialSurfaceMode: TOXMaterialSurfaceMode read FMaterialSurfaceMode write SetMaterialSurfaceMode;
property MaterialCustom: boolean read FMaterialCustom write FMaterialCustom;
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 InternalForceAndTorque: boolean read FInternalForceAndTorque write FInternalForceAndTorque;
property FrictionMotion1: boolean read FFrictionMotion1 write FFrictionMotion1;
property FrictionMotion2: boolean read FFrictionMotion2 write FFrictionMotion2;
property ApplyForceAndTorque: TOXPhysicsApplyForceAndTorque read FForceAndTorque write FForceAndTorque;
property OnContactBegin: TOXOnContactBegin read FOnContactBegin write FOnContactBegin;
property OnContactProcess: TOXOnContactProcess read FOnContactProcess write FOnContactProcess;
property OnContactEnd: TOXOnContactEnd read FOnContactEnd write FOnContactEnd;
property OnStartRagdoll: TOXOnStartRagdoll read FOnStartRagdoll write FOnStartRagdoll;
property OnStopRagdoll: TOXOnStopRagdoll read FOnStopRagdoll write FOnStopRagdoll;
end;
{******************************************************************************}
// [2005-11-09]: TOXNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
TOXNewtonRagdollBone = class;
{******************************************************************************}
// [2005-11-09]: TOXNewtonRagdoll last change by Dave Gravel. //
{******************************************************************************}
TOXNewtonRagdoll = class( TOXNewtonDummy )
private
FActived: boolean;
FManager: TOXNewtonManager;
procedure SetManager( const val: TOXNewtonManager );
procedure BuildRagdoll( pRagdoll: PNewtonRagdoll; pParentdollBone: PNewtonRagdollBone;
pVelocity: TOXVector3; var pBone: TOXNewtonRagdollBone );
public
RagdollDummy: TOXNewtonDummy;
Ragdoll: PNewtonRagdoll;
spine0_Bone: TOXNewtonRagdollBone;
spine1_Bone: TOXNewtonRagdollBone;
head_Bone: TOXNewtonRagdollBone;
rUpperArm_Bone: TOXNewtonRagdollBone;
lUpperArm_Bone: TOXNewtonRagdollBone;
rLowerArm_Bone: TOXNewtonRagdollBone;
lLowerArm_Bone: TOXNewtonRagdollBone;
rUpperLeg_Bone: TOXNewtonRagdollBone;
rLowerLeg_Bone: TOXNewtonRagdollBone;
lUpperLeg_Bone: TOXNewtonRagdollBone;
lLowerLeg_Bone: TOXNewtonRagdollBone;
Bone: array of TOXNewtonRagdollBone;
procedure InitNewton; virtual;
procedure DoProgress( const progressTime: TProgressTimes ); override;
constructor Create( aOwner: TComponent ); override;
procedure AddChildren( var pParent: TOXNewtonRagdollBone; pChildren: TOXNewtonRagdollBone );
procedure CreateRagdoll( pPosition, pVelocity, pRotation: TOXVector3; pHangByHead: Boolean = False );
destructor Destroy; override;
procedure Render;
published
property Manager: TOXNewtonManager read FManager write SetManager;
end;
{******************************************************************************}
// [2005-11-09]: TOXNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
TOXNewtonRagdollBone = class( TObject )
Children: array of TOXNewtonRagdollBone;
GeomType: TOXRagdollBoneGeomType;
Box: TGLCube;
Cylinder: TOXNewtonBoneCylinder;
SPhere: TGLSphere;
Body: PNewtonBody;
Size: TOXVector3;
Matrix: TOXMatrix;
ID: Integer;
Name: String;
procedure CreateBone( pGeomType: TOXRagdollBoneGeomType );
procedure Render;
constructor create;
destructor Destroy; override;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonSkinRagdoll last change by Dave Gravel. //
{******************************************************************************}
implementation
{******************************************************************************}
// [15-9-2007]: TOXNewtonSkinRagdoll last change by Dave Gravel. //
{******************************************************************************}
constructor TOXNewtonSkinRagdoll.Create( aOwner: TComponent );
begin
inherited create( aOwner );
FOrionX3D:= 100;
FActived:= False;
FRagEnabled:= false;
FFreezeSpeedMag2:= 0.0;
FFreezeOmegaMag2:= 0.0;
FFreezeFramesCount:= 0;
FGetMatrix:= oxEmptyHmgM;
FSetMatrix:= oxEmptyHmgM;
FisSetMatrix:= False;
FisAddImpulse:= False;
FisAddTorque:= False;
FisAddForce:= False;
FisSetOmega:= False;
FisSetVelocity:= False;
FisSetForce:= False;
FisSetTorque:= False;
FAddImpulse:= oxV3Make(0,0,0);
FAddImpulseVel:= oxV3Make(0,0,0);
FAddForce:= oxV3Make(0,0,0);
FAddTorque:= oxV3Make(0,0,0);
FSetOmega:= oxV3Make(0,0,0);
FSetVelocity:= oxV3Make(0,0,0);
FSetForce:= oxV3Make(0,0,0);
FSetTorque:= oxV3Make(0,0,0);
FMass:= 1;
FContactID:= -1;
FAutoFreeze:= True;
FMaterialCustom:= False;
FOXVisual:= True;
FOnAir:= True;
FInternalForceAndTorque:= false;
FFrictionMotion1:= true;
FFrictionMotion2:= false;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonSkinRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonSkinRagdoll.SetMaterialSurface( Custom: boolean; Softness, Elasticity, StaticFriction, KineticFriction: Float );
begin
FMaterialCustom:= Custom;
FMaterialSoftness:= Softness;
FMaterialElasticity:= Elasticity;
FMaterialStaticFriction:= StaticFriction;
FMaterialKineticFriction:= KineticFriction;
end;
{******************************************************************************}
// [15-9-2007]: TOXNewtonSkinRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonSkinRagdoll.SetMaterialSurfaceMode( const Mode: TOXMaterialSurfaceMode );
begin
case Mode of
mdNone: SetMaterialSurface( True, 0.0, 0.0, 0.0, 0.0 );
mdDefault: SetMaterialSurface( True, 0.05, 0.4, 1.0, 0.5 );
mdHard: SetMaterialSurface( True, 1.0, 0.5, 1.0, 0.5 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -