BeRo1985 / kraft

Kraft Physics Engine is an open source Object Pascal physics engine library that can be used in 3D games.
107 stars 21 forks source link

TKraftShapeBox creates boxes with doubled sizes #30

Closed PascalCorpsman closed 1 year ago

PascalCorpsman commented 1 year ago

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"

BeRo1985 commented 1 year ago

Hello @PascalCorpsman,

First of all, thank you for your interest in the KRAFT physics engine and for creating examples to share with the community. Your efforts are greatly appreciated!

Regarding your question about the behavior of TKraftShapeBox.Create, you're actually correct in your understanding. The AExtents parameter in the TKraftShapeBox.Create method refers to the "half-dimensions" of the box, also known as the extents. This is similar to the concept of a radius in a sphere, where the diameter (or full size) is twice the radius.

So, when you create a box with vector3(2, 1, 2), you're specifying the half-dimensions, and the full dimensions of the box will indeed be vector3(4, 2, 4). This is by design and not a bug in the physics engine.

To create a box with full dimensions of vector3(2, 1, 2), you should indeed use vector3(2 / 2, 1 / 2, 2 / 2) as you've discovered.

I also want to add that this approach is not unique to KRAFT. Many other physics engines (but not all) use the same concept of extents or half-dimensions for defining the size of shapes, relative to the center of these shapes. This is a common practice in the field of physics engines.

I hope this clears up any confusion. Please feel free to ask if you have any more questions or if there's anything else you'd like to discuss. Happy coding!

PascalCorpsman commented 1 year ago

Thanks for clearification.