Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
physics [2020/05/24 13:30] – [Example] adminphysics [2020/06/06 15:37] – [Max Contacts] admin
Line 74: Line 74:
 Even if there is no object limit, this will limit your scene indirectly. 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 ===== ===== Colliders =====
  
Line 179: Line 186:
  
 **__CAUTION:__ By this methods you can influence physical mechanics so heavily, that overstep bounds / limits, which may lead to unexpected behaviour.** **__CAUTION:__ By this methods you can influence physical mechanics so heavily, that overstep bounds / limits, which may lead to unexpected behaviour.**
 +
 +
 +===== Example =====
 +For a working physics system you need a TGorillaPhysicsSystem component on your form.
 +
 +<file pascal Form1.pas>
 +type
 +  TForm1 = class(TForm)
 +    GorillaViewport1: TGorillaViewport;
 +    Light1: TLight;
 +    Dummy1: TDummy;
 +    Camera1: TCamera;
 +    GorillaPhysicsSystem1: TGorillaPhysicsSystem;
 +    Plane1: TPlane;
 +    GorillaCube1: TGorillaCube;
 +    PhysicsTimer1: TTimer;
 +    GorillaSphere1: TGorillaSphere;
 +    LightMaterialSource1: TLightMaterialSource;
 +    LightMaterialSource2: TLightMaterialSource;
 +    procedure FormCreate(Sender: TObject);
 +    procedure PhysicsTimer1Timer(Sender: TObject);
 +  private
 +    { Private-Deklarationen }
 +  public
 +    { Public-Deklarationen }
 +  end;
 +
 +var
 +  Form1: TForm1;
 +
 +implementation
 +
 +{$R *.fmx}
 +
 +uses
 +  Gorilla.Physics, Gorilla.Physics.Q3.Body;
 +  
 +procedure TForm1.FormCreate(Sender: TObject);
 +var LPrefab : TGorillaColliderSettings;
 +begin
 +  // the plane should be a static body, otherwise it will fall in to nothingness
 +  LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eStaticBody);
 +  GorillaPhysicsSystem1.AddBoxCollider(Plane1, LPrefab);
 +
 +  // the cube is a dynamic / moveable body which collides with the plane and sphere
 +  LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eDynamicBody);
 +  GorillaPhysicsSystem1.AddBoxCollider(GorillaCube1, LPrefab);
 +
 +  // the sphere is a dynamic / moveable body which collides with the plane and cube
 +  LPrefab := TGorillaColliderSettings.Create(TQ3BodyType.eDynamicBody);
 +  GorillaPhysicsSystem1.AddSphereCollider(GorillaSphere1, LPrefab);
 +
 +  // we activate the physics system
 +  GorillaPhysicsSystem1.Active := true;
 +  
 +  // and we need to activate the physics timer for constant updates
 +  PhysicsTimer1.Enabled := true;
 +end;
 +
 +procedure TForm1.PhysicsTimer1Timer(Sender: TObject);
 +var LDelta : Single;
 +begin
 +  // get the delta time => time since the last step() was called
 +  LDelta := GorillaPhysicsSystem1.GetDeltaTime();
 +  GorillaPhysicsSystem1.Step(LDelta);
 +  GorillaViewport1.Invalidate();
 +end;
 +</file>
 +
  
 Next step: [[fmodaudio|FMOD Audio]] Next step: [[fmodaudio|FMOD Audio]]