| 1 |
{%MainUnit castletransform.pas} |
| 2 |
{ |
| 3 |
Copyright 2017-2022 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Physics joints - experimental, off by default. } |
| 18 |
|
| 19 |
{$ifdef CASTLE_EXPERIMENTAL_JOINTS} |
| 20 |
|
| 21 |
{$ifdef read_interface} |
| 22 |
{ Fixed joint creates a constant connection between two bodies. } |
| 23 |
TCastleFixedJoint = class(TCastleAbstractTwoBodiesJoint) |
| 24 |
private |
| 25 |
FKraftJointFixed: TKraftConstraintJointFixed; |
| 26 |
FAnchor: TVector3; |
| 27 |
FAnchorTransform: TCastleTransform; |
| 28 |
function GetAnchorForTool: TVector3; |
| 29 |
procedure SetAnchor(const AValue: TVector3); |
| 30 |
procedure InternalUpdateGizmosName; |
| 31 |
protected |
| 32 |
function GetKraftJoint: TKraftConstraintJoint; override; |
| 33 |
procedure CreateKraftJoint; override; |
| 34 |
procedure DeinitializeKraftJoint; override; |
| 35 |
procedure SetName(const Value: TComponentName); override; |
| 36 |
public |
| 37 |
constructor Create(AOwner: TComponent); override; |
| 38 |
destructor Destroy; override; |
| 39 |
|
| 40 |
procedure WorldBeforeDetach; override; |
| 41 |
procedure InternalCreateGizmos; override; |
| 42 |
procedure InternalDestroyGizmos; override; |
| 43 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 44 |
|
| 45 |
// TODO: This is local point should be world? |
| 46 |
property Anchor: TVector3 read FAnchor write SetAnchor; |
| 47 |
|
| 48 |
{$define read_interface_class} |
| 49 |
{$I auto_generated_persistent_vectors/tcastlefixedjoint_persistent_vectors.inc} |
| 50 |
{$undef read_interface_class} |
| 51 |
end; |
| 52 |
|
| 53 |
{ Pulley joint connects two bodies in such a way that the elevation of first |
| 54 |
rigid body lowers the second (connected) rigid body } |
| 55 |
TCastlePulleyJoint = class(TCastleAbstractTwoBodiesJoint) |
| 56 |
private |
| 57 |
FKraftJointPulley: TKraftConstraintJointPulley; |
| 58 |
FWorldAnchor: TVector3; |
| 59 |
FWorldGroundAnchor: TVector3; |
| 60 |
FConnectedWorldAnchor: TVector3; |
| 61 |
FConnectedWorldGroundAnchor: TVector3; |
| 62 |
FRatio: Single; |
| 63 |
FWorldAnchorTransform: TCastleTransform; |
| 64 |
FConnectedWorldAnchorTransform: TCastleTransform; |
| 65 |
FWorldGroundAnchorTransform: TCastleTransform; |
| 66 |
FConnectedWorldGroundAnchorTransform: TCastleTransform; |
| 67 |
procedure SetWorldAnchor(const AValue: TVector3); |
| 68 |
procedure SetConnectedWorldAnchor(const AValue: TVector3); |
| 69 |
procedure SetWorldGroundAnchor(const AValue: TVector3); |
| 70 |
procedure SetConnectedWorldGroundAnchor(const AValue: TVector3); |
| 71 |
procedure SetRatio(const AValue: Single); |
| 72 |
procedure InternalUpdateGizmosName; |
| 73 |
protected |
| 74 |
function GetKraftJoint: TKraftConstraintJoint; override; |
| 75 |
procedure CreateKraftJoint; override; |
| 76 |
procedure DeinitializeKraftJoint; override; |
| 77 |
procedure SetName(const Value: TComponentName); override; |
| 78 |
public |
| 79 |
constructor Create(AOwner: TComponent); override; |
| 80 |
destructor Destroy; override; |
| 81 |
|
| 82 |
procedure WorldBeforeDetach; override; |
| 83 |
procedure InternalCreateGizmos; override; |
| 84 |
procedure InternalDestroyGizmos; override; |
| 85 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 86 |
|
| 87 |
{ The point for parent transform in world coordinates. } |
| 88 |
property WorldAnchor: TVector3 read FWorldAnchor write SetWorldAnchor; |
| 89 |
|
| 90 |
{ The point for connected transform in world coordinates. } |
| 91 |
property ConnectedWorldAnchor: TVector3 read FConnectedWorldAnchor |
| 92 |
write SetConnectedWorldAnchor; |
| 93 |
|
| 94 |
{ Top point for parent transform. } |
| 95 |
property WorldGroundAnchor: TVector3 read FWorldGroundAnchor |
| 96 |
write SetWorldGroundAnchor; |
| 97 |
|
| 98 |
{ Top point for connected transform. } |
| 99 |
property ConnectedWorldGroundAnchor: TVector3 |
| 100 |
read FConnectedWorldGroundAnchor write SetConnectedWorldGroundAnchor; |
| 101 |
published |
| 102 |
{ Determines how elevating one body will lower the second, default 1 |
| 103 |
means the same distance. } |
| 104 |
property Ratio: Single read FRatio write SetRatio {$ifdef FPC}default 1.0{$endif}; |
| 105 |
|
| 106 |
{$define read_interface_class} |
| 107 |
{$I auto_generated_persistent_vectors/tcastlepulleyjoint_persistent_vectors.inc} |
| 108 |
{$undef read_interface_class} |
| 109 |
end; |
| 110 |
|
| 111 |
{ World Plane Distance Joint keeps rigid body at a certain distance from the plane. } |
| 112 |
TCastleWorldPlaneDistanceJoint = class (TCastleAbstractOneBodyJoint) |
| 113 |
private |
| 114 |
FKraftJointWorldPlaneDistance: TKraftConstraintJointWorldPlaneDistance; |
| 115 |
FAnchor: TVector3; |
| 116 |
FPlaneNormal: TVector3; |
| 117 |
FPlaneDistance: Single; |
| 118 |
FWorldDistance: Single; |
| 119 |
FDoubleSidedWorldPlane: Boolean; |
| 120 |
FFrequencyHz: Single; |
| 121 |
FDampingRatio: Single; |
| 122 |
FAnchorTransform: TCastleTransform; |
| 123 |
function GetAnchorForTool: TVector3; |
| 124 |
procedure SetAnchor(const AValue: TVector3); |
| 125 |
procedure SetPlaneNormal(const AValue: TVector3); |
| 126 |
procedure SetPlaneDistance(const AValue: Single); |
| 127 |
procedure SetWorldDistance(const AValue: Single); |
| 128 |
procedure SetFrequencyHz(const AValue: Single); |
| 129 |
procedure SetDampingRatio(const AValue: Single); |
| 130 |
procedure DoubleSidedWorldPlane(const AValue: Boolean); |
| 131 |
procedure InternalUpdateGizmosName; |
| 132 |
protected |
| 133 |
function GetKraftJoint: TKraftConstraintJoint; override; |
| 134 |
procedure CreateKraftJoint; override; |
| 135 |
procedure DeinitializeKraftJoint; override; |
| 136 |
protected |
| 137 |
procedure SetName(const Value: TComponentName); override; |
| 138 |
public |
| 139 |
constructor Create(AOwner: TComponent); override; |
| 140 |
destructor Destroy; override; |
| 141 |
|
| 142 |
procedure WorldBeforeDetach; override; |
| 143 |
procedure InternalCreateGizmos; override; |
| 144 |
procedure InternalDestroyGizmos; override; |
| 145 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 146 |
|
| 147 |
property Anchor: TVector3 read FAnchor write SetAnchor; |
| 148 |
property PlaneNormal: TVector3 read FPlaneNormal write SetPlaneNormal; |
| 149 |
published |
| 150 |
property PlaneDistance: Single read FPlaneDistance write SetPlaneDistance; |
| 151 |
property WorldDistance: Single read FWorldDistance write SetWorldDistance; |
| 152 |
property FrequencyHz: Single read FFrequencyHz write SetFrequencyHz; |
| 153 |
property DampingRatio: Single read FDampingRatio write SetDampingRatio; |
| 154 |
|
| 155 |
{$define read_interface_class} |
| 156 |
{$I auto_generated_persistent_vectors/tcastleworldplanedistancejoint_persistent_vectors.inc} |
| 157 |
{$undef read_interface_class} |
| 158 |
end; |
| 159 |
|
| 160 |
{ Slider Joint allows to move bodies along a specific axis } |
| 161 |
TCastleSliderJoint = class (TCastleAbstractTwoBodiesJoint) |
| 162 |
private |
| 163 |
FKraftJointSlider: TKraftConstraintJointSlider; |
| 164 |
FWorldSliderAxis: TVector3; |
| 165 |
FWorldAnchor: TVector3; |
| 166 |
FWorldAnchorTransform: TCastleTransform; |
| 167 |
FEnableLimits: Boolean; |
| 168 |
FMinTranslationLimit: Single; |
| 169 |
FMaxTranslationLimit: Single; |
| 170 |
FEnableMotor: Boolean; |
| 171 |
FMaxMotorForce: Single; |
| 172 |
FMotorSpeed: Single; |
| 173 |
procedure SetWorldAnchor(const AValue: TVector3); |
| 174 |
procedure SetWorldSliderAxis(const AValue: TVector3); |
| 175 |
procedure SetEnableLimits(const AValue: Boolean); |
| 176 |
procedure SetMinTranslationLimit(const AValue: Single); |
| 177 |
procedure SetMaxTranslationLimit(const AValue: Single); |
| 178 |
procedure InternalUpdateGizmosName; |
| 179 |
protected |
| 180 |
function GetKraftJoint: TKraftConstraintJoint; override; |
| 181 |
procedure CreateKraftJoint; override; |
| 182 |
procedure DeinitializeKraftJoint; override; |
| 183 |
procedure SetName(const Value: TComponentName); override; |
| 184 |
public |
| 185 |
constructor Create(AOwner: TComponent); override; |
| 186 |
destructor Destroy; override; |
| 187 |
|
| 188 |
procedure WorldBeforeDetach; override; |
| 189 |
procedure InternalCreateGizmos; override; |
| 190 |
procedure InternalDestroyGizmos; override; |
| 191 |
function PropertySections(const PropertyName: String): TPropertySections; override; |
| 192 |
|
| 193 |
property WorldAnchor: TVector3 read FWorldAnchor write SetWorldAnchor; |
| 194 |
property WorldSliderAxis: TVector3 read FWorldSliderAxis write SetWorldSliderAxis; |
| 195 |
published |
| 196 |
property EnableLimits: Boolean read FEnableLimits write SetEnableLimits; |
| 197 |
property MinTranslationLimit: Single read FMinTranslationLimit write SetMinTranslationLimit; |
| 198 |
property MaxTranslationLimit: Single read FMaxTranslationLimit write SetMaxTranslationLimit; |
| 199 |
|
| 200 |
{$define read_interface_class} |
| 201 |
{$I auto_generated_persistent_vectors/tcastlesliderjoint_persistent_vectors.inc} |
| 202 |
{$undef read_interface_class} |
| 203 |
end; |
| 204 |
|
| 205 |
{$endif read_interface} |
| 206 |
|
| 207 |
{$ifdef read_implementation} |
| 208 |
|
| 209 |
{ TCastleFixedJoint --------------------------------------------------------------- } |
| 210 |
|
| 211 |
constructor TCastleFixedJoint.Create(AOwner: TComponent); |
| 212 |
begin |
| 213 |
inherited Create(AOwner); |
| 214 |
NeedWorldChangeNotification := true; |
| 215 |
FAnchor := TVector3.Zero; |
| 216 |
{$define read_implementation_constructor} |
| 217 |
{$I auto_generated_persistent_vectors/tcastlefixedjoint_persistent_vectors.inc} |
| 218 |
{$undef read_implementation_constructor} |
| 219 |
end; |
| 220 |
|
| 221 |
destructor TCastleFixedJoint.Destroy; |
| 222 |
begin |
| 223 |
{$define read_implementation_destructor} |
| 224 |
{$I auto_generated_persistent_vectors/tcastlefixedjoint_persistent_vectors.inc} |
| 225 |
{$undef read_implementation_destructor} |
| 226 |
|
| 227 |
inherited Destroy; |
| 228 |
end; |
| 229 |
|
| 230 |
procedure TCastleFixedJoint.WorldBeforeDetach; |
| 231 |
begin |
| 232 |
FreeAndNil(FAnchorTransform); |
| 233 |
inherited WorldBeforeDetach; |
| 234 |
end; |
| 235 |
|
| 236 |
procedure TCastleFixedJoint.InternalCreateGizmos; |
| 237 |
begin |
| 238 |
inherited; |
| 239 |
if FAnchorTransform = nil then |
| 240 |
begin |
| 241 |
FAnchorTransform := TDesignJointAnchor.Create(nil); |
| 242 |
FAnchorTransform.Joint := Self; |
| 243 |
FAnchorTransform.OnGetValue := {$ifdef FPC}@{$endif} GetAnchorForTool; |
| 244 |
FAnchorTransform.OnSetValue := {$ifdef FPC}@{$endif} SetAnchor; |
| 245 |
InternalUpdateGizmosName; |
| 246 |
Parent.Add(FAnchorTransform); |
| 247 |
TDesignJointAnchor(FAnchorTransform).Value := Anchor; |
| 248 |
InternalCastleDesignInvalidate := true; |
| 249 |
end; |
| 250 |
end; |
| 251 |
|
| 252 |
procedure TCastleFixedJoint.InternalDestroyGizmos; |
| 253 |
begin |
| 254 |
FreeAndNil(FAnchorTransform); |
| 255 |
InternalCastleDesignInvalidate := true; |
| 256 |
inherited; |
| 257 |
end; |
| 258 |
|
| 259 |
function TCastleFixedJoint.PropertySections(const PropertyName: String |
| 260 |
): TPropertySections; |
| 261 |
begin |
| 262 |
if (PropertyName = 'AnchorPersistent') then |
| 263 |
Result := [psBasic] |
| 264 |
else |
| 265 |
Result := inherited PropertySections(PropertyName); |
| 266 |
end; |
| 267 |
|
| 268 |
procedure TCastleFixedJoint.SetAnchor(const AValue: TVector3); |
| 269 |
begin |
| 270 |
if not TVector3.PerfectlyEquals(FAnchor, AValue) then |
| 271 |
begin |
| 272 |
FAnchor := AValue; |
| 273 |
if FAnchorTransform <> nil then |
| 274 |
TDesignJointAnchor(FAnchorTransform).Value := FAnchor; |
| 275 |
RecreateKraftJoint; |
| 276 |
end; |
| 277 |
end; |
| 278 |
|
| 279 |
procedure TCastleFixedJoint.InternalUpdateGizmosName; |
| 280 |
begin |
| 281 |
if (FAnchorTransform <> nil) and (FAnchorTransform.Name <> Name + '_Anchor') then |
| 282 |
begin |
| 283 |
FAnchorTransform.Name := Name + '_Anchor'; |
| 284 |
InternalCastleDesignInvalidate := true; |
| 285 |
end; |
| 286 |
end; |
| 287 |
|
| 288 |
function TCastleFixedJoint.GetKraftJoint: TKraftConstraintJoint; |
| 289 |
begin |
| 290 |
Result := FKraftJointFixed; |
| 291 |
end; |
| 292 |
|
| 293 |
procedure TCastleFixedJoint.CreateKraftJoint; |
| 294 |
begin |
| 295 |
FKraftJointFixed := TKraftConstraintJointFixed.Create( |
| 296 |
World.FKraftEngine, |
| 297 |
FParentRigidBody.FKraftBody, |
| 298 |
FConnectedRigidBody.FKraftBody, |
| 299 |
VectorToKraft(Parent.LocalToWorld(FAnchor)), |
| 300 |
ConnectedCollide |
| 301 |
); |
| 302 |
end; |
| 303 |
|
| 304 |
procedure TCastleFixedJoint.DeinitializeKraftJoint; |
| 305 |
begin |
| 306 |
FreeAndNil(FKraftJointFixed); |
| 307 |
end; |
| 308 |
|
| 309 |
procedure TCastleFixedJoint.SetName(const Value: TComponentName); |
| 310 |
begin |
| 311 |
inherited SetName(Value); |
| 312 |
InternalUpdateGizmosName; |
| 313 |
end; |
| 314 |
|
| 315 |
{$define read_implementation_methods} |
| 316 |
{$I auto_generated_persistent_vectors/tcastlefixedjoint_persistent_vectors.inc} |
| 317 |
{$undef read_implementation_methods} |
| 318 |
|
| 319 |
{ TCastlePulleyJoint ---------------------------------------------------------------- } |
| 320 |
|
| 321 |
constructor TCastlePulleyJoint.Create(AOwner: TComponent); |
| 322 |
begin |
| 323 |
inherited Create(AOwner); |
| 324 |
NeedWorldChangeNotification := true; |
| 325 |
|
| 326 |
{FWorldAnchor := TVector3.Zero; |
| 327 |
FWorldGroundAnchor := TVector3.Zero; |
| 328 |
FConnectedWorldAnchor := TVector3.Zero; |
| 329 |
FConnectedWorldGroundAnchor := TVector3.Zero;} |
| 330 |
|
| 331 |
FWorldAnchor := CastleVectors.Vector3(-1, -1, 0); |
| 332 |
FWorldGroundAnchor := CastleVectors.Vector3(-1, 0, 0); |
| 333 |
FConnectedWorldAnchor := CastleVectors.Vector3(1, -1, 0); |
| 334 |
FConnectedWorldGroundAnchor := CastleVectors.Vector3(1, 0, 0); |
| 335 |
|
| 336 |
FRatio := 1.0; |
| 337 |
|
| 338 |
{$define read_implementation_constructor} |
| 339 |
{$I auto_generated_persistent_vectors/tcastlepulleyjoint_persistent_vectors.inc} |
| 340 |
{$undef read_implementation_constructor} |
| 341 |
end; |
| 342 |
|
| 343 |
destructor TCastlePulleyJoint.Destroy; |
| 344 |
begin |
| 345 |
{$define read_implementation_destructor} |
| 346 |
{$I auto_generated_persistent_vectors/tcastlepulleyjoint_persistent_vectors.inc} |
| 347 |
{$undef read_implementation_destructor} |
| 348 |
|
| 349 |
inherited Destroy; |
| 350 |
end; |
| 351 |
|
| 352 |
procedure TCastlePulleyJoint.WorldBeforeDetach; |
| 353 |
begin |
| 354 |
FreeAndNil(FWorldAnchorTransform); |
| 355 |
FreeAndNil(FConnectedWorldAnchorTransform); |
| 356 |
FreeAndNil(FWorldGroundAnchorTransform); |
| 357 |
FreeAndNil(FConnectedWorldGroundAnchorTransform); |
| 358 |
inherited WorldBeforeDetach; |
| 359 |
end; |
| 360 |
|
| 361 |
procedure TCastlePulleyJoint.InternalCreateGizmos; |
| 362 |
begin |
| 363 |
inherited; |
| 364 |
if FWorldAnchorTransform = nil then |
| 365 |
begin |
| 366 |
FWorldAnchorTransform := TDesignJointWorldAnchor.Create(nil); |
| 367 |
FWorldAnchorTransform.Joint := Self; |
| 368 |
....OnGetValue := {$ifdef FPC}@{$endif} ...; |
| 369 |
....OnSetValue := {$ifdef FPC}@{$endif} ...; |
| 370 |
InternalUpdateGizmosName; |
| 371 |
Parent.World.Add(FWorldAnchorTransform); |
| 372 |
FWorldAnchorTransform.Translation := WorldAnchor; |
| 373 |
InternalCastleDesignInvalidate := true; |
| 374 |
end; |
| 375 |
|
| 376 |
if FConnectedWorldAnchorTransform = nil then |
| 377 |
begin |
| 378 |
FConnectedWorldAnchorTransform := TDesignJointConnectedWorldAnchor.Create(nil); |
| 379 |
FConnectedWorldAnchorTransform.Joint := Self; |
| 380 |
....OnGetValue := {$ifdef FPC}@{$endif} ...; |
| 381 |
....OnSetValue := {$ifdef FPC}@{$endif} ...; |
| 382 |
InternalUpdateGizmosName; |
| 383 |
Parent.World.Add(FConnectedWorldAnchorTransform); |
| 384 |
FConnectedWorldAnchorTransform.Translation := ConnectedWorldAnchor; |
| 385 |
InternalCastleDesignInvalidate := true; |
| 386 |
end; |
| 387 |
|
| 388 |
if FWorldGroundAnchorTransform = nil then |
| 389 |
begin |
| 390 |
FWorldGroundAnchorTransform := TDesignJointWorldGroundAnchor.Create(nil); |
| 391 |
FWorldGroundAnchorTransform.Joint := Self; |
| 392 |
....OnGetValue := {$ifdef FPC}@{$endif} ...; |
| 393 |
....OnSetValue := {$ifdef FPC}@{$endif} ...; |
| 394 |
InternalUpdateGizmosName; |
| 395 |
Parent.World.Add(FWorldGroundAnchorTransform); |
| 396 |
FWorldGroundAnchorTransform.Translation := WorldGroundAnchor; |
| 397 |
InternalCastleDesignInvalidate := true; |
| 398 |
end; |
| 399 |
|
| 400 |
if FConnectedWorldGroundAnchorTransform = nil then |
| 401 |
begin |
| 402 |
FConnectedWorldGroundAnchorTransform := TDesignJointConnectedWorldGroundAnchor.Create(nil); |
| 403 |
FConnectedWorldGroundAnchorTransform.Joint := Self; |
| 404 |
....OnGetValue := {$ifdef FPC}@{$endif} ...; |
| 405 |
....OnSetValue := {$ifdef FPC}@{$endif} ...; |
| 406 |
InternalUpdateGizmosName; |
| 407 |
Parent.World.Add(FConnectedWorldGroundAnchorTransform); |
| 408 |
FConnectedWorldGroundAnchorTransform.Translation := ConnectedWorldGroundAnchor; |
| 409 |
InternalCastleDesignInvalidate := true; |
| 410 |
end; |
| 411 |
end; |
| 412 |
|
| 413 |
procedure TCastlePulleyJoint.InternalDestroyGizmos; |
| 414 |
begin |
| 415 |
FreeAndNil(FWorldAnchorTransform); |
| 416 |
FreeAndNil(FConnectedWorldAnchorTransform); |
| 417 |
FreeAndNil(FWorldGroundAnchorTransform); |
| 418 |
FreeAndNil(FConnectedWorldGroundAnchorTransform); |
| 419 |
InternalCastleDesignInvalidate := true; |
| 420 |
inherited; |
| 421 |
end; |
| 422 |
|
| 423 |
function TCastlePulleyJoint.PropertySections(const PropertyName: String |
| 424 |
): TPropertySections; |
| 425 |
begin |
| 426 |
if ArrayContainsString(PropertyName, [ |
| 427 |
'WorldAnchorPersistent', 'ConnectedWorldAnchorPersistent', |
| 428 |
'WorldGroundAnchorPersistent', 'ConnectedWorldGroundAnchorPersistent', |
| 429 |
'Ratio' |
| 430 |
]) then |
| 431 |
Result := [psBasic] |
| 432 |
else |
| 433 |
Result := inherited PropertySections(PropertyName); |
| 434 |
end; |
| 435 |
|
| 436 |
procedure TCastlePulleyJoint.SetWorldAnchor(const AValue: TVector3); |
| 437 |
begin |
| 438 |
if not TVector3.PerfectlyEquals(FWorldAnchor, AValue) then |
| 439 |
begin |
| 440 |
FWorldAnchor := AValue; |
| 441 |
if FWorldAnchorTransform <> nil then |
| 442 |
TDesignJointWorldAnchor(FWorldAnchorTransform).Value := AValue; |
| 443 |
RecreateKraftJoint; |
| 444 |
end; |
| 445 |
end; |
| 446 |
|
| 447 |
procedure TCastlePulleyJoint.SetConnectedWorldAnchor(const AValue: TVector3); |
| 448 |
begin |
| 449 |
if not TVector3.PerfectlyEquals(FConnectedWorldAnchor, AValue) then |
| 450 |
begin |
| 451 |
FConnectedWorldAnchor := AValue; |
| 452 |
if FConnectedWorldAnchorTransform <> nil then |
| 453 |
TDesignJointConnectedWorldAnchor(FConnectedWorldAnchorTransform).Value := AValue; |
| 454 |
RecreateKraftJoint; |
| 455 |
end; |
| 456 |
end; |
| 457 |
|
| 458 |
procedure TCastlePulleyJoint.SetWorldGroundAnchor(const AValue: TVector3); |
| 459 |
begin |
| 460 |
if not TVector3.PerfectlyEquals(FWorldGroundAnchor, AValue) then |
| 461 |
begin |
| 462 |
FWorldGroundAnchor := AValue; |
| 463 |
if FWorldGroundAnchorTransform <> nil then |
| 464 |
TDesignJointWorldGroundAnchor(FWorldGroundAnchorTransform).Value := AValue; |
| 465 |
RecreateKraftJoint; |
| 466 |
end; |
| 467 |
end; |
| 468 |
|
| 469 |
procedure TCastlePulleyJoint.SetConnectedWorldGroundAnchor(const AValue: TVector3 |
| 470 |
); |
| 471 |
begin |
| 472 |
if not TVector3.PerfectlyEquals(FConnectedWorldGroundAnchor, AValue) then |
| 473 |
begin |
| 474 |
FConnectedWorldGroundAnchor := AValue; |
| 475 |
if FConnectedWorldGroundAnchorTransform <> nil then |
| 476 |
TDesignJointConnectedWorldGroundAnchor(FConnectedWorldGroundAnchorTransform).Value := AValue; |
| 477 |
RecreateKraftJoint; |
| 478 |
end; |
| 479 |
end; |
| 480 |
|
| 481 |
procedure TCastlePulleyJoint.SetRatio(const AValue: Single); |
| 482 |
begin |
| 483 |
if not SameValue(FRatio, AValue) then |
| 484 |
begin |
| 485 |
FRatio := AValue; |
| 486 |
RecreateKraftJoint; |
| 487 |
end; |
| 488 |
end; |
| 489 |
|
| 490 |
procedure TCastlePulleyJoint.InternalUpdateGizmosName; |
| 491 |
begin |
| 492 |
if (FWorldAnchorTransform <> nil) and |
| 493 |
(FWorldAnchorTransform.Name <> Name + '_WorldAnchor') then |
| 494 |
begin |
| 495 |
FWorldAnchorTransform.Name := Name + '_WorldAnchor'; |
| 496 |
InternalCastleDesignInvalidate := true; |
| 497 |
end; |
| 498 |
|
| 499 |
if (FConnectedWorldAnchorTransform <> nil) and |
| 500 |
(FConnectedWorldAnchorTransform.Name <> Name + '_ConnectedWorldAnchor') then |
| 501 |
begin |
| 502 |
FConnectedWorldAnchorTransform.Name := Name + '_ConnectedWorldAnchor'; |
| 503 |
InternalCastleDesignInvalidate := true; |
| 504 |
end; |
| 505 |
|
| 506 |
if (FWorldGroundAnchorTransform <> nil) and |
| 507 |
(FWorldGroundAnchorTransform.Name <> Name + '_WorldGroundAnchor') then |
| 508 |
begin |
| 509 |
FWorldGroundAnchorTransform.Name := Name + '_WorldGroundAnchor'; |
| 510 |
InternalCastleDesignInvalidate := true; |
| 511 |
end; |
| 512 |
|
| 513 |
if (FConnectedWorldGroundAnchorTransform <> nil) and |
| 514 |
(FConnectedWorldGroundAnchorTransform.Name <> Name + '_ConnectedWorldGroundAnchor') then |
| 515 |
begin |
| 516 |
FConnectedWorldGroundAnchorTransform.Name := Name + '_ConnectedWorldGroundAnchor'; |
| 517 |
InternalCastleDesignInvalidate := true; |
| 518 |
end; |
| 519 |
end; |
| 520 |
|
| 521 |
function TCastlePulleyJoint.GetKraftJoint: TKraftConstraintJoint; |
| 522 |
begin |
| 523 |
Result := FKraftJointPulley; |
| 524 |
end; |
| 525 |
|
| 526 |
procedure TCastlePulleyJoint.CreateKraftJoint; |
| 527 |
begin |
| 528 |
Assert(FKraftJointPulley = nil, 'Second joint initialization'); |
| 529 |
FKraftJointPulley := TKraftConstraintJointPulley.Create( |
| 530 |
World.FKraftEngine, |
| 531 |
FParentRigidBody.FKraftBody, |
| 532 |
FConnectedRigidBody.FKraftBody, |
| 533 |
VectorToKraft(FWorldGroundAnchor), |
| 534 |
VectorToKraft(FConnectedWorldGroundAnchor), |
| 535 |
VectorToKraft(FWorldAnchor), |
| 536 |
VectorToKraft(FConnectedWorldAnchor), |
| 537 |
FRatio, |
| 538 |
ConnectedCollide |
| 539 |
); |
| 540 |
end; |
| 541 |
|
| 542 |
procedure TCastlePulleyJoint.DeinitializeKraftJoint; |
| 543 |
begin |
| 544 |
FreeAndNil(FKraftJointPulley); |
| 545 |
end; |
| 546 |
|
| 547 |
procedure TCastlePulleyJoint.SetName(const Value: TComponentName); |
| 548 |
begin |
| 549 |
inherited SetName(Value); |
| 550 |
InternalUpdateGizmosName; |
| 551 |
end; |
| 552 |
|
| 553 |
{$define read_implementation_methods} |
| 554 |
{$I auto_generated_persistent_vectors/tcastlepulleyjoint_persistent_vectors.inc} |
| 555 |
{$undef read_implementation_methods} |
| 556 |
|
| 557 |
{ TCastleWorldPlaneDistanceJoint --------------------------------------------------- } |
| 558 |
|
| 559 |
constructor TCastleWorldPlaneDistanceJoint.Create(AOwner: TComponent); |
| 560 |
begin |
| 561 |
inherited Create(AOwner); |
| 562 |
FAnchor := TVector3.Zero; |
| 563 |
FPlaneNormal := CastleVectors.Vector3(0, 1, 0); |
| 564 |
NeedWorldChangeNotification := true; |
| 565 |
|
| 566 |
{$define read_implementation_constructor} |
| 567 |
{$I auto_generated_persistent_vectors/tcastleworldplanedistancejoint_persistent_vectors.inc} |
| 568 |
{$undef read_implementation_constructor} |
| 569 |
end; |
| 570 |
|
| 571 |
destructor TCastleWorldPlaneDistanceJoint.Destroy; |
| 572 |
begin |
| 573 |
{$define read_implementation_destructor} |
| 574 |
{$I auto_generated_persistent_vectors/tcastleworldplanedistancejoint_persistent_vectors.inc} |
| 575 |
{$undef read_implementation_destructor} |
| 576 |
|
| 577 |
inherited Destroy; |
| 578 |
end; |
| 579 |
|
| 580 |
procedure TCastleWorldPlaneDistanceJoint.WorldBeforeDetach; |
| 581 |
begin |
| 582 |
FreeAndNil(FAnchorTransform); |
| 583 |
inherited WorldBeforeDetach; |
| 584 |
end; |
| 585 |
|
| 586 |
procedure TCastleWorldPlaneDistanceJoint.InternalCreateGizmos; |
| 587 |
begin |
| 588 |
inherited; |
| 589 |
if FAnchorTransform = nil then |
| 590 |
begin |
| 591 |
FAnchorTransform := TDesignJointAnchor.Create(nil); |
| 592 |
FAnchorTransform.Joint := Self; |
| 593 |
FAnchorTransform.OnGetValue := {$ifdef FPC}@{$endif} GetAnchorForTool; |
| 594 |
FAnchorTransform.OnSetValue := {$ifdef FPC}@{$endif} SetAnchor; |
| 595 |
InternalUpdateGizmosName; |
| 596 |
Parent.Add(FAnchorTransform); |
| 597 |
TDesignJointAnchor(FAnchorTransform).Value := Anchor; |
| 598 |
InternalCastleDesignInvalidate := true; |
| 599 |
end; |
| 600 |
end; |
| 601 |
|
| 602 |
procedure TCastleWorldPlaneDistanceJoint.InternalDestroyGizmos; |
| 603 |
begin |
| 604 |
FreeAndNil(FAnchorTransform); |
| 605 |
inherited; |
| 606 |
end; |
| 607 |
|
| 608 |
function TCastleWorldPlaneDistanceJoint.PropertySections( |
| 609 |
const PropertyName: String): TPropertySections; |
| 610 |
begin |
| 611 |
if ArrayContainsString(PropertyName, [ |
| 612 |
'AnchorPersistent', 'PlaneNormalPersistent', 'PlaneDistance', |
| 613 |
'WorldDistance', 'FrequencyHz', 'DampingRatio' |
| 614 |
]) then |
| 615 |
Result := [psBasic] |
| 616 |
else |
| 617 |
Result := inherited PropertySections(PropertyName); |
| 618 |
end; |
| 619 |
|
| 620 |
procedure TCastleWorldPlaneDistanceJoint.SetAnchor(const AValue: TVector3); |
| 621 |
begin |
| 622 |
if not TVector3.PerfectlyEquals(FAnchor, AValue) then |
| 623 |
begin |
| 624 |
FAnchor := AValue; |
| 625 |
RecreateKraftJoint; |
| 626 |
end; |
| 627 |
end; |
| 628 |
|
| 629 |
procedure TCastleWorldPlaneDistanceJoint.SetPlaneNormal(const AValue: TVector3); |
| 630 |
begin |
| 631 |
if not TVector3.PerfectlyEquals(FPlaneNormal, AValue) then |
| 632 |
begin |
| 633 |
FPlaneNormal := AValue; |
| 634 |
RecreateKraftJoint; |
| 635 |
end; |
| 636 |
end; |
| 637 |
|
| 638 |
procedure TCastleWorldPlaneDistanceJoint.SetPlaneDistance(const AValue: Single); |
| 639 |
begin |
| 640 |
if not SameValue(FPlaneDistance, AValue) then |
| 641 |
begin |
| 642 |
FPlaneDistance := AValue; |
| 643 |
RecreateKraftJoint; |
| 644 |
end; |
| 645 |
end; |
| 646 |
|
| 647 |
procedure TCastleWorldPlaneDistanceJoint.SetWorldDistance(const AValue: Single); |
| 648 |
begin |
| 649 |
if FWorldDistance <> AValue then |
| 650 |
begin |
| 651 |
FWorldDistance := AValue; |
| 652 |
if FKraftJointWorldPlaneDistance <> nil then |
| 653 |
FKraftJointWorldPlaneDistance.SetWorldDistance(FWorldDistance); |
| 654 |
end; |
| 655 |
end; |
| 656 |
|
| 657 |
procedure TCastleWorldPlaneDistanceJoint.SetFrequencyHz(const AValue: Single); |
| 658 |
begin |
| 659 |
if not SameValue(FFrequencyHz, AValue) then |
| 660 |
begin |
| 661 |
FFrequencyHz := AValue; |
| 662 |
RecreateKraftJoint; |
| 663 |
end; |
| 664 |
end; |
| 665 |
|
| 666 |
procedure TCastleWorldPlaneDistanceJoint.SetDampingRatio(const AValue: Single); |
| 667 |
begin |
| 668 |
if not SameValue(FDampingRatio, AValue) then |
| 669 |
begin |
| 670 |
FDampingRatio := AValue; |
| 671 |
RecreateKraftJoint; |
| 672 |
end; |
| 673 |
end; |
| 674 |
|
| 675 |
procedure TCastleWorldPlaneDistanceJoint.DoubleSidedWorldPlane(const AValue: Boolean); |
| 676 |
begin |
| 677 |
if FDoubleSidedWorldPlane <> AValue then |
| 678 |
begin |
| 679 |
FDoubleSidedWorldPlane := AValue; |
| 680 |
RecreateKraftJoint; |
| 681 |
end; |
| 682 |
end; |
| 683 |
|
| 684 |
procedure TCastleWorldPlaneDistanceJoint.InternalUpdateGizmosName; |
| 685 |
begin |
| 686 |
if (FAnchorTransform <> nil) and |
| 687 |
(FAnchorTransform.Name <> Name + '_Anchor') then |
| 688 |
begin |
| 689 |
FAnchorTransform.Name := Name + '_Anchor'; |
| 690 |
InternalCastleDesignInvalidate := true; |
| 691 |
end; |
| 692 |
end; |
| 693 |
|
| 694 |
function TCastleWorldPlaneDistanceJoint.GetKraftJoint: TKraftConstraintJoint; |
| 695 |
begin |
| 696 |
Result := FKraftJointWorldPlaneDistance; |
| 697 |
end; |
| 698 |
|
| 699 |
procedure TCastleWorldPlaneDistanceJoint.CreateKraftJoint; |
| 700 |
begin |
| 701 |
Assert(FKraftJointWorldPlaneDistance = nil, 'Second joint initialization'); |
| 702 |
FKraftJointWorldPlaneDistance := TKraftConstraintJointWorldPlaneDistance.Create( |
| 703 |
World.FKraftEngine, |
| 704 |
FParentRigidBody.FKraftBody, |
| 705 |
VectorToKraft(FAnchor), |
| 706 |
Plane(Vector3Norm(VectorToKraft(FPlaneNormal)), FPlaneDistance), |
| 707 |
FDoubleSidedWorldPlane, |
| 708 |
FWorldDistance, |
| 709 |
kclbLimitDistance, |
| 710 |
//kclbLimitMinimumDistance, |
| 711 |
//kclbLimitMaximumDistance, |
| 712 |
FFrequencyHz, |
| 713 |
FDampingRatio |
| 714 |
); |
| 715 |
end; |
| 716 |
|
| 717 |
procedure TCastleWorldPlaneDistanceJoint.DeinitializeKraftJoint; |
| 718 |
begin |
| 719 |
FreeAndNil(FKraftJointWorldPlaneDistance); |
| 720 |
end; |
| 721 |
|
| 722 |
procedure TCastleWorldPlaneDistanceJoint.SetName(const Value: TComponentName); |
| 723 |
begin |
| 724 |
inherited SetName(Value); |
| 725 |
InternalUpdateGizmosName; |
| 726 |
end; |
| 727 |
|
| 728 |
{$define read_implementation_methods} |
| 729 |
{$I auto_generated_persistent_vectors/tcastleworldplanedistancejoint_persistent_vectors.inc} |
| 730 |
{$undef read_implementation_methods} |
| 731 |
|
| 732 |
{ TCastleSliderJoint --------------------------------------------------------- } |
| 733 |
|
| 734 |
constructor TCastleSliderJoint.Create(AOwner: TComponent); |
| 735 |
begin |
| 736 |
inherited Create(AOwner); |
| 737 |
NeedWorldChangeNotification := true; |
| 738 |
FWorldSliderAxis := CastleVectors.Vector3(0, 1, 0); |
| 739 |
FWorldAnchor := TVector3.Zero; |
| 740 |
|
| 741 |
{$define read_implementation_constructor} |
| 742 |
{$I auto_generated_persistent_vectors/tcastlesliderjoint_persistent_vectors.inc} |
| 743 |
{$undef read_implementation_constructor} |
| 744 |
end; |
| 745 |
|
| 746 |
destructor TCastleSliderJoint.Destroy; |
| 747 |
begin |
| 748 |
{$define read_implementation_destructor} |
| 749 |
{$I auto_generated_persistent_vectors/tcastlesliderjoint_persistent_vectors.inc} |
| 750 |
{$undef read_implementation_destructor} |
| 751 |
|
| 752 |
inherited Destroy; |
| 753 |
end; |
| 754 |
|
| 755 |
procedure TCastleSliderJoint.WorldBeforeDetach; |
| 756 |
begin |
| 757 |
FreeAndNil(FWorldAnchorTransform); |
| 758 |
inherited WorldBeforeDetach; |
| 759 |
end; |
| 760 |
|
| 761 |
procedure TCastleSliderJoint.InternalCreateGizmos; |
| 762 |
begin |
| 763 |
inherited; |
| 764 |
if FWorldAnchorTransform = nil then |
| 765 |
begin |
| 766 |
FWorldAnchorTransform := TDesignJointWorldAnchor.Create(nil); |
| 767 |
FWorldAnchorTransform.Joint := Self; |
| 768 |
....OnGetValue := {$ifdef FPC}@{$endif} ...; |
| 769 |
....OnSetValue := {$ifdef FPC}@{$endif} ...; |
| 770 |
InternalUpdateGizmosName; |
| 771 |
Parent.World.Add(FWorldAnchorTransform); |
| 772 |
TDesignJointWorldAnchor(FWorldAnchorTransform).Value := WorldAnchor; |
| 773 |
InternalCastleDesignInvalidate := true; |
| 774 |
end; |
| 775 |
end; |
| 776 |
|
| 777 |
procedure TCastleSliderJoint.InternalDestroyGizmos; |
| 778 |
begin |
| 779 |
FreeAndNil(FWorldAnchorTransform); |
| 780 |
inherited; |
| 781 |
end; |
| 782 |
|
| 783 |
function TCastleSliderJoint.PropertySections(const PropertyName: String |
| 784 |
): TPropertySections; |
| 785 |
begin |
| 786 |
if ArrayContainsString(PropertyName, [ |
| 787 |
'WorldAnchorPersistent', 'EnableLimits', 'MinTranslationLimit', |
| 788 |
'MaxTranslationLimit', 'EnableMotor', 'MotorSpeed', 'MaxMotorForce', |
| 789 |
'WorldSliderAxisPersistent' |
| 790 |
]) then |
| 791 |
Result := [psBasic] |
| 792 |
else |
| 793 |
Result := inherited PropertySections(PropertyName); |
| 794 |
end; |
| 795 |
|
| 796 |
procedure TCastleSliderJoint.SetWorldAnchor(const AValue: TVector3); |
| 797 |
begin |
| 798 |
if TVector3.PerfectlyEquals(FWorldAnchor, AValue) then |
| 799 |
Exit; |
| 800 |
|
| 801 |
FWorldAnchor := AValue; |
| 802 |
if FWorldAnchorTransform <> nil then |
| 803 |
TDesignJointWorldAnchor(FWorldAnchorTransform).Value := FWorldAnchor; |
| 804 |
RecreateKraftJoint; |
| 805 |
end; |
| 806 |
|
| 807 |
procedure TCastleSliderJoint.SetWorldSliderAxis(const AValue: TVector3); |
| 808 |
begin |
| 809 |
if TVector3.PerfectlyEquals(FWorldSliderAxis, AValue) then |
| 810 |
Exit; |
| 811 |
|
| 812 |
FWorldSliderAxis := AValue; |
| 813 |
RecreateKraftJoint; |
| 814 |
end; |
| 815 |
|
| 816 |
procedure TCastleSliderJoint.SetEnableLimits(const AValue: Boolean); |
| 817 |
begin |
| 818 |
if FEnableLimits = AValue then |
| 819 |
Exit; |
| 820 |
|
| 821 |
FEnableLimits := AValue; |
| 822 |
|
| 823 |
if FKraftJointSlider <> nil then |
| 824 |
FKraftJointSlider.EnableLimit(AValue); |
| 825 |
end; |
| 826 |
|
| 827 |
procedure TCastleSliderJoint.SetMinTranslationLimit(const AValue: Single); |
| 828 |
begin |
| 829 |
FMinTranslationLimit := AValue; |
| 830 |
if FKraftJointSlider <> nil then |
| 831 |
FKraftJointSlider.SetMinimumTranslationLimit(FMinTranslationLimit); |
| 832 |
end; |
| 833 |
|
| 834 |
procedure TCastleSliderJoint.SetMaxTranslationLimit(const AValue: Single); |
| 835 |
begin |
| 836 |
FMaxTranslationLimit := AValue; |
| 837 |
if FKraftJointSlider <> nil then |
| 838 |
FKraftJointSlider.SetMaximumTranslationLimit(FMaxTranslationLimit); |
| 839 |
end; |
| 840 |
|
| 841 |
procedure TCastleSliderJoint.InternalUpdateGizmosName; |
| 842 |
begin |
| 843 |
if (FWorldAnchorTransform <> nil) and |
| 844 |
(FWorldAnchorTransform.Name <> Name + '_WorldAnchor') then |
| 845 |
begin |
| 846 |
FWorldAnchorTransform.Name := Name + '_WorldAnchor'; |
| 847 |
InternalCastleDesignInvalidate := true; |
| 848 |
end; |
| 849 |
end; |
| 850 |
|
| 851 |
function TCastleSliderJoint.GetKraftJoint: TKraftConstraintJoint; |
| 852 |
begin |
| 853 |
Result := FKraftJointSlider; |
| 854 |
end; |
| 855 |
|
| 856 |
procedure TCastleSliderJoint.CreateKraftJoint; |
| 857 |
begin |
| 858 |
FKraftJointSlider := TKraftConstraintJointSlider.Create( |
| 859 |
World.FKraftEngine, |
| 860 |
FParentRigidBody.FKraftBody, |
| 861 |
FConnectedRigidBody.FKraftBody, |
| 862 |
VectorToKraft(FWorldAnchor), |
| 863 |
VectorToKraft(FWorldSliderAxis), |
| 864 |
FEnableLimits, |
| 865 |
false, |
| 866 |
FMinTranslationLimit, |
| 867 |
FMaxTranslationLimit, |
| 868 |
0.0, |
| 869 |
0.0, |
| 870 |
ConnectedCollide |
| 871 |
); |
| 872 |
end; |
| 873 |
|
| 874 |
procedure TCastleSliderJoint.DeinitializeKraftJoint; |
| 875 |
begin |
| 876 |
FreeAndNil(FKraftJointSlider); |
| 877 |
end; |
| 878 |
|
| 879 |
procedure TCastleSliderJoint.SetName(const Value: TComponentName); |
| 880 |
begin |
| 881 |
inherited SetName(Value); |
| 882 |
InternalUpdateGizmosName; |
| 883 |
end; |
| 884 |
|
| 885 |
{$define read_implementation_methods} |
| 886 |
{$I auto_generated_persistent_vectors/tcastlesliderjoint_persistent_vectors.inc} |
| 887 |
{$undef read_implementation_methods} |
| 888 |
|
| 889 |
{$endif read_implementation} |
| 890 |
|
| 891 |
{$endif CASTLE_EXPERIMENTAL_JOINTS} |