0
\$\begingroup\$

I am currently making a physics engine in Rust.

The 2 main data structures concerning collision detection are:

  1. RigidBody: Physics-related aspects of the body. Contains a reference to a Collider structure.

  2. Collider: Shape and structural-related aspects

However, I am unsure as to which data structure should store the instance fields:

  1. mass (or inverse mass)
  2. inertia (or inverse inertia)
  3. angle of orientation
  4. restitution

The reason for this absolute segregation is that during collision detection, only references to the concerning Colliders will be passed.

Could someone please advise me on the matter?

\$\endgroup\$
0
\$\begingroup\$

The breakdown I'm most used to seeing is like this:

Rigid Body - responsible for the simulation dynamics of an object that can move:

  • Mass
  • Inertia
  • Position of the body as a whole
  • Orientation of the body as a whole

Static collision objects that don't move - like unbreakable walls - don't need these properties, so it makes sense to not reproduce them on the Collider type.

Collider - responsible for the shape & surface other physics interact with:

  • Shape & dimensions
  • Physics material
    • Restitution / elasticity / bounciness
    • Coefficients of friction
    • Rules for combining these values with those of the other colliding surface
  • Position of the collider (within the body)
  • Orientation of the collider (within the body)
  • Reference to the parent body, if any
  • Density (helps calculate mass & inertia of the body, if used)

The semi-duplication of position & orientation here helps if you ever want to allow bodies with compound collision representations, made up of several distinct colliders, where each can be precisely positioned & oriented to match the shape of the game object they represent.

\$\endgroup\$
0
\$\begingroup\$

Typically a Collider is repurposed for Triggers, if that helps you think about the separation. It would have a null or special physics material.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.