Giter Site home page Giter Site logo

kraft's People

Contributors

bero1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kraft's Issues

TKraftShapeBox creates boxes with doubled sizes

Hello,
i am trying to get into the kraft physics engine and try to create some basic examples to be shared to the public ( https://github.com/PascalCorpsman/kraft_examples )

Doing this i found a behavior i did not expect.

When creating a TKraftShapeBox with the following command:

Shape := TKraftShapeBox.Create(KraftWorld, RigidBody, vector3(2, 1 2));

I expect to get a box with dimensions (2 / 1 / 2) but instead i get a box with dimensions (4 / 2 / 4)

To fix this i need to create the box with

Shape := TKraftShapeBox.Create(KraftWorld, RigidBody, vector3(2 / 2, 1 / 2, 2 / 2));

So is this a bug or is my english "bad" in the way of understanding "AExtents"

Centre of Mass not working with compound objects ..

Dear Benjamin,

i created this example: https://github.com/PascalCorpsman/kraft_examples/tree/main/001_Compound which creates a rigid body containing two "simple" shapes. Than i adjusted the center of mass and let it fall down on the floor. As soon the object touches the ground it completly freaks out and is shoot "away". If you look carefully you can see that it is rotation around the correct CG. But i expect it not to behave like this (i think it should fall down and then fall over to the side).
As following i post the important code parts:

Procedure TForm1.CreateWorld;
Var
  RigidBody: TKraftRigidBody;
  Shape: TKraftShape;
  Floor: TKraftRigidBody;
  FloorShape: TKraftShapePlane; // A Plane infinite in width
Begin
  (*
   * Each element in the Physiks Engine is a TKraftRigidBody
   * it can consists of multiple shapes.
   * A Shape is a container vor a hull and connects the Body with the hull ?
   *)
  // 1. Floor Creation
  Floor := TKraftRigidBody.Create(KraftWorld);
  Floor.SetRigidBodyType(krbtSTATIC);
  // Planes are defined by their normal vector and distance to the Origin.
  FloorShape := TKraftShapePlane.Create(KraftWorld, Floor, Plane(Vector3Norm(Vector3(0.0, 1.0, 0.0)), 0.0));
  FloorShape.Restitution := 0.3; // TODO: Why, it is static ?
  FloorShape.Density := 1.0; // TODO: Why, it is static ?
  Floor.ForcedMass := 0.01; // TODO: Why, it is static ?
  Floor.Finish;
  // Move the Floor plane to the Needed position ;)
  Floor.SetWorldTransformation(Matrix4x4Translate(0.0, 0.0, 0.0));
  (*
   * Create a box consisting of to convex hulls
   *)
  RigidBody := TKraftRigidBody.Create(KraftWorld);
  RigidBody.SetRigidBodyType(krbtSTATIC); // Init as static Object
  (*
   * Lets form a ****
   *                *
   *                *
   *                *
   *                * structure
   *)
  shape := TKraftShapeBox.Create(KraftWorld, RigidBody, Vector3(0.5, 2, 0.5));
  Shape.Restitution := 0.3;
  Shape.Density := 1.0;
  Shape.LocalTransform := Matrix4x4Translate(0, 2, 0);
  Shape.ForcedMass := 1;
  // Shape.SynchronizeTransform; -- is this needed ?
  Shape.Finish;
  shape := TKraftShapeBox.Create(KraftWorld, RigidBody, Vector3(2, 0.5, 0.5));
  Shape.Restitution := 0.3;
  Shape.Density := 1.0;
  Shape.LocalTransform := Matrix4x4Translate(1.5, 4.5, 0);
  Shape.ForcedMass := 1;
  // Shape.SynchronizeTransform; -- is this needed ?
  Shape.Finish;
  RigidBody.ForcedMass := 10;
  RigidBody.Finish;
  RigidBody.SetWorldPosition(MoveableBoxStartingPosition);

  CompoundBox := RigidBody;

  // Set the Centre of mass 
  CompoundBox.ForcedCenterOfMass.Vector := Vector3(-ScrollBar1.Position / 50 + 1.5, 2, 0);
  CompoundBox.BodyInertiaTensor := Matrix3x3Identity;
  // Set the Physics Engine to use the given Centre of Mass and do not auto calc it by the shapes !
  CompoundBox.Flags := CompoundBox.Flags + [krbfHasForcedCenterOfMass];
  CompoundBox.Finish; // Update the internal data structures


// and make the Body Moveable
  CompoundBox.SetRigidBodyType(krbtDynamic); // krbtKinematic ??
  CompoundBox.Finish; 

End; 

So the question is, is this a Bug in the engine ? Do i use it wrong ? (and if so how is it done correct ?) Do you need further informations (if so the code of the complete example is linked at the top)

sandbox gtk error

Although I do not think it's a problem with your kraft, I wanted to try the Sandbox in Linux.

MyConf: (He currently compiles all kinds of 3D things, Castle, Zengl, etc..)
Debian11, i3-wm, Laz 2.2, FPC 3.2.2

Error:

[FORMS.PP] ExceptionOccurred 
  Sender=Exception
  Exception=Could not find FB config
  Stack trace:
  $000000000090810D  GTK_GL_AREA_SHARE_NEW_USEFPGLX,  line 643 of glgtkglxcontext.pas
  $000000000090801C  GTK_GL_AREA_SHARE_NEW,  line 598 of glgtkglxcontext.pas
  $0000000000907FCA  GTK_GL_AREA_NEW,  line 575 of glgtkglxcontext.pas
  $00000000009088B3  LOPENGLCREATECONTEXTCORE,  line 890 of glgtkglxcontext.pas
  $0000000000908B71  LOPENGLCREATECONTEXT,  line 939 of glgtkglxcontext.pas
  $00000000008B075E  CREATEHANDLE,  line 724 of openglcontext.pas
  $0000000000641CD5  CREATEWND,  line 7545 of include/wincontrol.inc
  $0000000000641480  CREATEHANDLE,  line 7455 of include/wincontrol.inc
  $0000000000642C28  HANDLENEEDED,  line 7908 of include/wincontrol.inc
  $0000000000641F97  CREATEWND,  line 7590 of include/wincontrol.inc
  $0000000000641480  CREATEHANDLE,  line 7455 of include/wincontrol.inc
  $0000000000642C28  HANDLENEEDED,  line 7908 of include/wincontrol.inc
  $000000000063F609  GETHANDLE,  line 6517 of include/wincontrol.inc
  $000000000089C4A5  ADDPAGE,  line 370 of gtk2pagecontrol.inc
  $00000000007A7898  ADDREMOVEPAGEHANDLE,  line 720 of include/customnotebook.inc
  $00000000007A6647  CREATEWND,  line 286 of include/customnotebook.inc
  $0000000000641480  CREATEHANDLE,  line 7455 of include/wincontrol.inc

Compile but not execute.

Feature Request TKraftShapeCone, TKraftShapeCylinder

Looking at "TKraftShapeType" i am missing Cone and Cylinder.

Are you looking forward to implement these two ?

If not i can / will try to implement them in the way you did TKraftShapeBox using a ConvexHull and then use a Pull Request to share..

Feature request: Constrain position changes to particular axes (for 2D games)

In order to use Kraft for 2D games, I needed two things:

  1. constrain rotations to only happen around the Z axis. This is already straightforward using the krbfLockAxis* Flags.
  2. constrain translation to only happen along the X and Y axis. I'm right now doing it using a rather hacky method (more info below).

My feature request is to add flags like

krbfLockTranslationX
krbfLockTranslationY
krbfLockTranslationZ

to the TKraftRigidBodyFlag .

Once you constrain the rotations and positions like above, one can use Kraft for 2D games very comfortably :) Demo (where I constrain position using my hacky method below) is on https://www.youtube.com/watch?v=hIuEGnRm-yM , more information on https://castle-engine.sourceforge.io/wp/2017/09/13/castle-game-engine-2d-physics-using-kraft/ . The CGE manual on https://castle-engine.sourceforge.io/manual_physics.php also has a short section "2D games".

Right now, I constrain the position using this code:

    NewPos := Shape.GetCenter(Shape.InterpolatedWorldTransform);
    if LockPosition <> [] then
    begin
      // apply LockPosition to fix some NewPos coords
      if 0 in LockPosition then NewPos.X := Transform.Translation[0];
      if 1 in LockPosition then NewPos.Y := Transform.Translation[1];
      if 2 in LockPosition then NewPos.Z := Transform.Translation[2];
    end;
    Transform.Translation := VectorFromKraft(NewPos);
    if LockPosition <> [] then
      // fix also position at Kraft side after fixing by LockPosition
      Body.SetWorldTransformation(MatrixToKraft(Transform.Transform));

In other words, I implement the LockPosition by taking the position calculated by Kraft, reverting some of it's components (the locked components) to the previous position, and sending the "fixed" position back to Kraft. This actually works very well (as the demo shows), but it feels like a hack, as I'm reading + writing back the object position every frame, instead of "just reading" the position calculated by Kraft.

If Kraft would allow me to do something like

RigidBody.Flags := RigidBody.Flags + [krbfLockTranslationZ]

then the work would be done on the Kraft side, in a more cleaner way I think:)

some slowdown

Hi
in the brick wall demo , if i shot the first ball into the wall , the fps decreases to (1~2) for about 4 seconds , then it increases to 1200 . and thats the only issue i have .

my laptop is duel core 2.2 ghz , with nvidea Quadro gpu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.