Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
physics [2020/05/24 13:03] – [Iterations] admin | physics [2020/06/06 15:37] – [Max Contacts] admin | ||
---|---|---|---|
Line 2: | Line 2: | ||
Gorilla3D provides an integrated 3D physics engine for basic implementation. | Gorilla3D provides an integrated 3D physics engine for basic implementation. | ||
- | |||
- | It is possible to automatically check for collisions by the following shaped colliders: | ||
- | * Box-Collider | ||
- | * Sphere-Collider | ||
- | * Terrain-Collider | ||
- | * Particle-Collider | ||
- | * Capsule-Collider (up-coming) | ||
- | * Mesh-Collider (experimental) | ||
- | * Terrain-Collider (experimental) | ||
- | |||
- | The physics controller establishes a separated 3D world for collision detection. | ||
- | Even though you link visual components like TGorillaCube or TGorillaSphere, | ||
- | |||
- | You push starting transformation and body data by adding a collider: | ||
- | * AddBoxCollider | ||
- | * AddSphereCollider | ||
- | * AddCapsuleCollider | ||
- | * AddParticleCollider | ||
- | * AddTerrainCollider | ||
- | * AddMeshCollider | ||
- | |||
- | From there on the physics controller will compute transformation based on its own universe. | ||
- | Nevertheless, | ||
- | |||
- | But if you want to take influence vice versa, that means, manipulating physics transformation from the visual scene, you have to use helper functionality. | ||
- | |||
- | [[# | ||
- | |||
- | Derived components of TCustomMesh and TGorillaMesh are supported for colliders. | ||
===== Computation ===== | ===== Computation ===== | ||
Line 49: | Line 20: | ||
</ | </ | ||
+ | |||
+ | ==== Start ==== | ||
+ | |||
+ | To enable physics computation you have to enable the controller, by simply activating it. | ||
+ | |||
+ | <file pascal> | ||
+ | GorillaPhysicsSystem1.Active := true; | ||
+ | </ | ||
==== Iterations ==== | ==== Iterations ==== | ||
Line 71: | Line 50: | ||
So set up bounds that suit your scene. When objects reaching those boundaries, the will be laid down to sleep and will not affect performance. | So set up bounds that suit your scene. When objects reaching those boundaries, the will be laid down to sleep and will not affect performance. | ||
+ | <file pascal> | ||
+ | GorillaPhysicsSystem1.Engine.Bounds := TBoundingBox.Create(Point3D(0, | ||
+ | </ | ||
+ | |||
+ | ==== Gravity ==== | ||
+ | |||
+ | You can influence physics world gravity vector. The gravity vector is the direction objects falling. | ||
+ | <file pascal> | ||
+ | // falling upwards instead of downwards | ||
+ | GorillaPhysicsSystem1.Engine.Gravity := Point3D(0, -1, 0); | ||
+ | </ | ||
+ | ==== Max Contacts ==== | ||
+ | |||
+ | A builtin constant is the maximum contact count. It's currently set to 128. | ||
+ | This is important to keep in mind when setting up a scene with many objects close to each other. | ||
+ | |||
+ | //This limit is not configurable!// | ||
+ | |||
+ | The contact count is the number of contacts of one object to other objects. | ||
+ | When having huge scenes with hundreds of objects close together, this number will reach its limit very fast. | ||
+ | This will lead to unsolved collisions! So collisions between some objects will not be considered! | ||
+ | The contact count limit exists to keep performance at a high level. | ||
+ | Even if there is no object limit, this will limit your scene indirectly. | ||
+ | |||
+ | ==== Types of Body ==== | ||
+ | |||
+ | Q3 Physics Engine allows to decide between 3 different body types. | ||
+ | |||
+ | ^Type ^Description ^ | ||
+ | |TQ3BodyType.eStaticBody | Static bodies will not be move or influenced by mass and impulses. Use this type for defining a plane / floor.| | ||
+ | |TQ3BodyType.eDynamicBody|Dynamic bodies will move, handle forces influenced by mass and impulses. Use this type by default for any kind of physics-engine handled instances.| | ||
+ | |TQ3BodyType.eKinematicBody|Kinematic bodies will be moved, but will not be influenced by mass and impulses. Use this type as an alternative to dynamic bodies. | | ||
+ | ===== Colliders ===== | ||
+ | |||
+ | Collision detection in physics is based on so called colliders. Colliders depending on the shape of a visual component like a sphere, box or capsule. | ||
+ | For each shape there has to exist an individual collider type to handle intersection tests. | ||
+ | |||
+ | At the moment it is possible to automatically check for collisions by the following shapes: | ||
+ | * Box | ||
+ | * Sphere | ||
+ | * Terrain | ||
+ | * Particle | ||
+ | * Capsule | ||
+ | * Mesh (experimental) | ||
+ | * Terrain (experimental) | ||
+ | |||
+ | The physics controller establishes a separated 3D world for collision detection. | ||
+ | Even though you link visual components like TGorillaCube or TGorillaSphere, | ||
+ | |||
+ | On collider registration you push starting transformation information and shape data to the physics world: | ||
+ | * AddBoxCollider() | ||
+ | * AddSphereCollider() | ||
+ | * AddCapsuleCollider() | ||
+ | * AddParticleCollider() | ||
+ | * AddTerrainCollider() | ||
+ | * AddMeshCollider() | ||
+ | |||
+ | From there on the physics controller will compute transformation based on its own universe. | ||
+ | Nevertheless, | ||
+ | |||
+ | But if you want to take influence vice versa, that means, manipulating physics transformation from the visual scene, you have to use helper functionality. | ||
+ | |||
+ | [[# | ||
+ | |||
+ | Derived components of **TCustomMesh** and **TGorillaMesh** are supported for colliders. | ||
===== Threading ===== | ===== Threading ===== | ||
Line 94: | Line 138: | ||
</ | </ | ||
(available since v0.8.2.1600+) | (available since v0.8.2.1600+) | ||
+ | |||
+ | ===== Callbacks ===== | ||
+ | |||
+ | The physics controller provides 2 callback events to interact with the physics world. | ||
+ | * OnBeginContact | ||
+ | * OnEndContact | ||
+ | |||
+ | Those callbacks will give you the both colliding elements at this moment of TQ3Body type (Gorilla.Physics.Q3.Body). | ||
+ | Each body has an untyped pointer property " | ||
+ | |||
+ | <file pascal> | ||
+ | procedure TUIMainWin.doOnBeginContact(const ABodyA, ABodyB : TQ3Body); | ||
+ | begin | ||
+ | if not Assigned(ABodyA.UserDataType) then | ||
+ | Exit; | ||
+ | if not Assigned(ABodyB.UserDataType) then | ||
+ | Exit; | ||
+ | | ||
+ | if TComponent(ABodyA.UserData).Name.Equals(' | ||
+ | begin | ||
+ | FMX.Types.Log.D(' | ||
+ | [TComponent(ABodyA.UserData).Name, | ||
+ | end | ||
+ | else | ||
+ | begin | ||
+ | FMX.Types.Log.D('< | ||
+ | [ABodyA.UserDataType^.Name, | ||
+ | end; | ||
+ | end; | ||
+ | </ | ||
+ | ===== Remote-Control ===== | ||
+ | |||
+ | As you read above, the physics controller universe is separated from scene universe. | ||
+ | But sometimes you need to control elements in physics world. | ||
+ | Therefore we've implemented some helper methods. | ||
+ | * RemoteMeshTransform | ||
+ | * RemoteBodyTransform | ||
+ | * RemoteBodyImpulse | ||
+ | * RemoteBodyForce | ||
+ | |||
+ | <file pascal> | ||
+ | // move cube upwards by impulse | ||
+ | GorillaPhysicsSystem1.RemoteBodyImpulse(GorillaCube1, | ||
+ | </ | ||
+ | |||
+ | By the methods above you're able to set a position and/or rotation explicitly, or to apply a force / impulse on a specific element. | ||
+ | |||
+ | **__CAUTION: | ||
+ | |||
+ | |||
===== Example ===== | ===== Example ===== | ||
For a working physics system you need a TGorillaPhysicsSystem component on your form. | For a working physics system you need a TGorillaPhysicsSystem component on your form. | ||
Line 161: | Line 255: | ||
</ | </ | ||
- | ===== Callbacks ===== | ||
- | |||
- | The physics controller provides 2 callback events to interact with the physics world. | ||
- | * OnBeginContact | ||
- | * OnEndContact | ||
- | |||
- | Those callbacks will give you the both colliding elements at this moment of TQ3Body type (Gorilla.Physics.Q3.Body). | ||
- | Each body has an untyped pointer property " | ||
- | ===== Remote-Control ===== | ||
- | |||
- | As you read above, the physics controller universe is separated from scene universe. | ||
- | But sometimes you need to control elements in physics world. | ||
- | Therefore we've implemented some helper methods. | ||
- | * RemoteMeshTransform | ||
- | * RemoteBodyTransform | ||
- | * RemoteBodyImpulse | ||
- | * RemoteBodyForce | ||
- | |||
- | By this methods you're able to set a position or rotation explicitly or to apply a force / impulse on a specific element. | ||
- | |||
- | **__CAUTION: | ||
Next step: [[fmodaudio|FMOD Audio]] | Next step: [[fmodaudio|FMOD Audio]] |