📄 oxnewtonbonesragdoll.pas
字号:
// [15-9-2007]: TOXRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXRagdoll.Start;
begin
if ( FEnabled ) then Exit;
FEnabled:= True;
RootBone.StartChild;
RootBone.AlignChild;
FOwner.Skeleton.StartRagDoll;
end;
{******************************************************************************}
// [15-9-2007]: TOXRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXRagdoll.Update;
begin
if ( FEnabled ) then begin
RootBone.UpdateChild;
FOwner.Skeleton.MorphMesh( true );
end;
end;
{******************************************************************************}
// [15-9-2007]: TOXRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXRagdoll.Stop;
begin
if not ( FEnabled ) then Exit;
FEnabled:= False;
RootBone.StopChild;
FOwner.Skeleton.StopRagDoll;
FOwner.Skeleton.MorphMesh( true );
end;
{******************************************************************************}
// [15-9-2007]: TOXRagdoll last change by Dave Gravel. //
{******************************************************************************}
procedure TOXRagdoll.BuildRagdoll;
begin
if assigned( RootBone ) then begin
RootBone.CreateBoundsChild;
FBuilt:= True;
end;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollHingeJoint last change by Dave Gravel. //
{******************************************************************************}
constructor TNewtonRagdollHingeJoint.Create( Axis: TOXVector3;
LimitationMin0, LimitationMax0: Float );
begin
inherited Create;
FAxis:= Axis;
FLimitationMin0:= LimitationMin0;
FLimitationMax0:= LimitationMax0;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollHingeJoint last change by Dave Gravel. //
{******************************************************************************}
constructor TNewtonRagdollUniversalJoint.Create( Axis: TOXVector3;
LimitationMin0, LimitationMax0: Float; Axis2: TOXVector3; LimitationMin1,
LimitationMax1: Float );
begin
inherited Create( Axis, LimitationMin0, LimitationMax0 );
FAxis2 := Axis2;
FLimitationMin0:= LimitationMin0;
FLimitationMax0:= LimitationMax0;
FLimitationMin1:= LimitationMin1;
FLimitationMax1:= LimitationMax1;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
constructor TNewtonRagdollBone.Create( Ragdoll: TNewtonRagdoll );
begin
inherited Create( Ragdoll );
FRagdoll:= Ragdoll;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
procedure TNewtonRagdollBone.Align;
begin
inherited;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
constructor TNewtonRagdollBone.CreateOwned( aOwner: TNewtonRagdollBone );
begin
inherited CreateOwned( aOwner );
FOwner:= aOwner;
FRagdoll:= aOwner.FRagdoll;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
procedure TNewtonRagdollBone.Start;
var
boneSize, vAxis, vAxis2 : TOXVector3;
world: PNewtonWorld;
JHinge: TOXCHingeJoint;
JUniver: TOXCUniversalJoint;
BoneDummy: TSkinBone;
function RotateAxis( Axis: TOXVector3 ): TOXVector3;
var absMat: TOXMatrix;
begin
absMat:= ReferenceMatrix;
absMat[3]:= oxNullV4;
Result:= oxVNormalize( oxVTransform( Axis, absMat ) );
end;
begin
World:= TOXNewtonSkinRagdoll( Ragdoll.Owner ).Manager.World;
boneSize[0]:= Size[0] * oxVLength( BoneMatrix[0] );
boneSize[1]:= Size[1] * oxVLength( BoneMatrix[1] );
boneSize[2]:= Size[2] * oxVLength( BoneMatrix[2] );
FGeom:= NewtonCreateBox( World, BoneSize[0], BoneSize[1], BoneSize[2], nil );
if not ( Joint is TNewtonRagdollDummyJoint ) then begin
FBody:= NewtonCreateBody( World, FGeom );
FRagdoll.FBodyList.Add(FBody);
//NewtonBodySetAutoFreeze( FBody, 0 );
//NewtonWorldUnfreezeBody( World, FBody );
//if TOXNewtonSkinRagdoll( Ragdoll.Owner ).AutoFreeze then
// NewtonBodySetAutoFreeze( FBody, 1 );
BoneDummy:= TSkinBone( TOXNewtonSkinRagdoll( Ragdoll.Owner ).
DummyJoint.AddNewChild( TSkinBone ) );
BoneDummy.FBone:= self;
BoneDummy.Matrix:= oxMDToMF( ReferenceMatrix );
oxPSetInitTransform( FBody, BoneDummy );
NewtonBodySetTransformCallback( FBody, @oxPSetTransform );
NewtonBodySetForceAndTorqueCallBack
( FBody, @oxObjectPhysicsApplyForceAndTorque );
if TOXNewtonSkinRagdoll( Ragdoll.Owner ).
Manager.WorldMatrialCustom then begin
TOXNewtonSkinRagdoll( Ragdoll.Owner ).ContactID:=
TOXNewtonSkinRagdoll( Ragdoll.Owner ).
Manager.WorldDefaultMaterialID;
oxSetObjectMaterial( FBody );
end;
if TOXNewtonSkinRagdoll( Ragdoll.Owner ).AutoFreeze then begin
NewtonBodySetAutoFreeze( FBody, 1 );
end else begin
NewtonBodySetAutoFreeze( FBody, 0 );
NewtonWorldUnfreezeBody( TOXNewtonSkinRagdoll( Ragdoll.Owner ).Manager.World, FBody );
end;
//oxSkinRagdoll(FGeom,FBody,
//VectorLength(VectorMake(BoneSize[0],BoneSize[1],BoneSize[2]))/10*TOXNewtonSkinRagdoll( Ragdoll.Owner ).Mass,
//0,0,0,0,0,0,0,0,0);
//NewtonBodySetContinuousCollisionMode( FBody, 1 );
// Need a fix here it can cause problem in some situation...
NewtonBodySetMassMatrix( FBody,
VectorLength( VectorMake( BoneSize[0], BoneSize[1], BoneSize[2]))/100*TOXNewtonSkinRagdoll( Ragdoll.Owner ).Mass,
VectorLength( VectorMake( BoneSize[0], BoneSize[1], BoneSize[2]))/100*TOXNewtonSkinRagdoll( Ragdoll.Owner ).Mass,
VectorLength( VectorMake( BoneSize[0], BoneSize[1], BoneSize[2]))/100*TOXNewtonSkinRagdoll( Ragdoll.Owner ).Mass,
VectorLength( VectorMake( BoneSize[0], BoneSize[1], BoneSize[2]))/100*TOXNewtonSkinRagdoll( Ragdoll.Owner ).Mass);
NewtonBodySetUserData( FBody, BoneDummy );
end;
NewtonReleaseCollision( World, FGeom );
if ( Joint is TNewtonRagdollDummyJoint ) then
FBody:= FOwner.Body;
if ( Owner <> nil ) then begin
if ( Joint is TNewtonRagdollHingeJoint ) then
with ( Joint as TNewtonRagdollHingeJoint ) do begin
vAxis := RotateAxis( Axis );
JHinge:= TOXCHingeJoint( TOXNewtonSkinRagdoll( Ragdoll.Owner ).
DummyJoint.AddNewChild( TOXCHingeJoint ) );
JHinge.JointCollisionState:= 0;
JHinge.JointStiffness:= 1;
JHinge.Scale.SetVector( 0.5, 0.5, 0.5 );
JHinge.JointLimitsOn:= True;
JHinge.JointChildPin.SetVector( vAxis[0], vAxis[1], vAxis[2] );
JHinge.Position.SetPoint( Anchor[0], Anchor[1], Anchor[2] );
JHinge.InitJoint( TNewtonRagdollBone(Owner).Body, FBody );
JHinge.JointMinAngle:= LimitationMin0;
JHinge.JointMaxAngle:= LimitationMax0;
end;
if ( Joint is TNewtonRagdollUniversalJoint ) then
with ( Joint as TNewtonRagdollUniversalJoint ) do begin
vAxis:= RotateAxis( Axis );
vAxis2:= RotateAxis( Axis2 );
JUniver:= TOXCUniversalJoint( TOXNewtonSkinRagdoll( Ragdoll.Owner ).
DummyJoint.AddNewChild( TOXCUniversalJoint ) );
JUniver.JointCollisionState:= 0;
JUniver.JointStiffness:= 1;
JUniver.Scale.SetVector( 0.5, 0.5, 0.5 );
JUniver.JointLimitOn0:= True;
JUniver.JointLimitOn1:= True;
JUniver.JointChildPin.SetVector( vAxis[0], vAxis[1], vAxis[2] );
JUniver.JointParentPin.SetVector( vAxis2[0], vAxis2[1], vAxis2[2] );
JUniver.Position.SetPoint( Anchor[0], Anchor[1], Anchor[2] );
JUniver.InitJoint( FBody, TNewtonRagdollBone( Owner ).Body );
JUniver.JointMinAngle0:= LimitationMin0;
JUniver.JointMaxAngle0:= LimitationMax0;
JUniver.JointMinAngle1:= LimitationMin1;
JUniver.JointMaxAngle1:= LimitationMax1;
end;
end;
with TOXNewtonBone( NewtonBodyGetUserData( FBody ) ) do begin
CubeWidth:= Size[0];
CubeHeight:= Size[1];
CubeDepth:= Size[2];
end;
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
procedure TNewtonRagdollBone.Stop;
begin
//
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdollBone last change by Dave Gravel. //
{******************************************************************************}
procedure TNewtonRagdollBone.Update;
begin
RagDoll.Owner.Skeleton.BoneByID( BoneID ).
SetGlobalMatrixForRagDoll( TGLBaseSceneObject( NewtonBodyGetUserData( FBody ) ).
AbsoluteMatrix );
end;
{******************************************************************************}
// [15-9-2007]: TNewtonRagdoll last change by Dave Gravel. //
{******************************************************************************}
constructor TNewtonRagdoll.Create( AOwner : TGLBaseMesh );
begin
inherited Create( AOwner );
FBodyList:= TList.Create;
end;
{******************************************************************************}
{$D '[15-9-2007]: TOXNewtonManager v1.55 by Dave Gravel under MPL-1.1 license.'}
{******************************************************************************}
initialization
RegisterClasses( [ TSkinBone ] );
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -