Coder Social home page Coder Social logo

notgiven688 / jitterphysics2 Goto Github PK

View Code? Open in Web Editor NEW
207.0 207.0 17.0 37.12 MB

Fast, simple, and dependency-free physics engine written in C# with a clear and user-friendly API.

License: MIT License

C# 99.13% Python 0.29% Shell 0.03% CMake 0.14% GLSL 0.27% HTML 0.11% JavaScript 0.04%
csharp dotnet physics-engine

jitterphysics2's People

Contributors

enkore avatar labbbirder avatar notgiven688 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

jitterphysics2's Issues

More information in tutorial

It would be nice if you could consider updating the tutorial to include additional information.

Unfortunately a lot of the concepts are unclear from the very brief tutorial that exists currently. Rather than a demo maybe you can just go over various concepts in the library and explain them? This would certainly help people trying to understand how to use it.

Also, in my particular case I'm finding it difficult to understand how to address the fact that I'm using Z-up and all of the game is build around it, but the Jitter uses Y-up it seems. So, I'm not sure how I can combine this together other than changing all of my code to also be Y-Up.

Also, when creating various shapes and adding them to a certain position it is unclear what is used as an origin. For example what part of the cube is positioned at the position point? Is it one of the sides or center? If it's a side then which one? How do world orientation affects which side of the cube is the origin? Etc. There are a lot of such nuances that are not explained anywhere that would be nice to know.

Sorry if my questions seem silly, but I've never used a 3D physics engine before and only have experience with 2D physics engine where everything is much simpler.

Converting XNA Matrix to JMatrix for TransformedShape

It seems my rotated models are appearing different than the collision shapes in Jitter. Here is how I'm converting them:

public static JMatrix ToJMatrix(this Matrix matrix) { return new JMatrix( matrix.M11, matrix.M12, matrix.M13, matrix.M21, matrix.M22, matrix.M23, matrix.M31, matrix.M32, matrix.M33 ); }

Is this correct?

I'm then creating a transformedshape:

TransformedShape tfs1 = new(boxShape, center,rotationMatrix.ToJMatrix());

Shapes passed to default narrow phase collision handler are not associated with a rigid body

I continuously spawning tiny size shapes, meanwhile, I remove the rigidbody in world randomly. Soon got a exception says Shapes passed to default narrow phase collision handler are not associated with a rigid body

System.InvalidOperationException
  HResult=0x80131509
  Message=Shapes passed to default narrow phase collision handler are not associated with a rigid body.
  Source=Jitter2
  StackTrace:
   at Jitter2.World.Detect(Shape sA, Shape sB) in E:\UnityProjects\jitter2\src\Jitter2\World.Detect.cs:line 289
   at Jitter2.World.DetectCollisionsCallback(Batch batch) in E:\UnityProjects\jitter2\src\Jitter2\World.Step.cs:line 451
   at Jitter2.World.DetectCollisions(Boolean multiThread) in E:\UnityProjects\jitter2\src\Jitter2\World.Step.cs:line 764
   at Jitter2.World.Step(Single dt, Boolean multiThread) in E:\UnityProjects\jitter2\src\Jitter2\World.Step.cs:line 144
   at JitterDemo.Playground.Draw() in E:\UnityProjects\jitter2\src\JitterDemo\Playground.cs:line 127
   at JitterDemo.Renderer.OpenGL.GLFWWindow.Sync() in E:\UnityProjects\jitter2\src\JitterDemo\Renderer\OpenGL\GLFWWindow.cs:line 291
   at JitterDemo.Renderer.OpenGL.GLFWWindow.Open(CreationSettings settings) in E:\UnityProjects\jitter2\src\JitterDemo\Renderer\OpenGL\GLFWWindow.cs:line 179
   at JitterDemo.Program.Main() in E:\UnityProjects\jitter2\src\JitterDemo\Program.cs:line 25

Maybe it'a problem caused by DynamicTree.

I want to known why the tiny shapes so different, and how to solve the problems.

Here is the additional modification:

...
        if (Keyboard.KeyPressBegin(Keyboard.Key.M))
        {
            multiThread = !multiThread;
        }

-        if (!GuiRenderer.WantsCaptureKeyboard && Keyboard.KeyPressBegin(Keyboard.Key.Space))
+        if (!GuiRenderer.WantsCaptureKeyboard && Keyboard.IsKeyDown(Keyboard.Key.Space))
        {
-            ShootPrimitive();
+            for (int i = 0; i < 2; i++)
+            {
+                ShootPrimitive();
+            }
        }
+        if (rand.Next(2) == 1)
+        {
+            var idx = rand.Next(world.RigidBodies.Count);
+            if (idx>4) world.Remove(world.RigidBodies[idx]);
+        }

         base.Draw();
...

Originally posted by @labbbirder in #141 (comment)

Orientation Becomes NaN When `dt = 0`

When using a HingeAngle constraint and 0 is passed in as dt in the World.Step method the orientation of the body the constraint is applied to becomes NaN.

Consider renaming World to JitterWorld or PhysicsWorld

Good day.

The word World is pretty standard way to call your actual game world or a namespace in a project, so I think it would be a good idea to consider renaming World to JitterWorld, JWorld or PhysicsWorld or something similar to avoid collisions.

Demo got stuck when emitting amount of shapes in tiny size at one

The system seems to be unstable when deal with very tiny shapes. Tested on the latest master branch.

Steps to Reproduce

  1. change the Shoot method to produce tiny shapes:
    Random rand = new(123);
    public void ShootPrimitive()
    {
        const float primitiveVelocity = 20.0f;

        var pos = Camera.Position;
        var dir = Camera.Direction;

        var sb = World.CreateRigidBody();
        sb.Position = Conversion.ToJitterVector(pos);
        sb.Velocity = Conversion.ToJitterVector(dir * primitiveVelocity);

        //var ss = new BoxShape(0.3f);
        var ss = new BoxShape(rand.Next(1, 4) / 1000f);
        sb.AddShape(ss);
    }
  1. change the Control method to shoot a alot at once:
    for (int i = 0; i < 10; i++)
    {
        ShootPrimitive();
    }
  1. Run the demo and press space.

Rigid Body damping is reversed

Hello,

Aside for this issue #53 , the damping values themselves are also seems to be reversed.

This means that damping value of 0 completely stop the objects from moving (what should happen with damping value of 1) while damping value of 1 actually let the objects move forever (what should happen with 0).

In other words, I need to set damping like this in order for it to behave like in other physics simulators:

rigidBody.Damping = (1f - actualLinearDamping, 1f - actualAngularDamping);

Is that intentional? I checked with few other engines and there seems to be a consensus that 0 = no damping, 1 = 100% damping, and sometimes negative value increase movement.

Thanks!

Callback function when entity transform changes.

When the transform of an entity changes, is it possible to provide a callback function so that the transform of the corresponding entity in the game can be modified?

What I do now is: traverse every entity in the physical world every frame, find the corresponding game entity through Tag, and then modify the transform

Issue debugging on linux (Ubuntu 22.04)

I have been implementing the JitterPhysics2 with my own game engine using MonoGame but for some reason I am having problems debugging my game now, going step by step on the initialization process the debugger gets stuck somewhere inside the "World.Step" somewhere on the line "ThreadPool.Instance.SignalWait()".
I tried running the step without multi thread but it seems that the issue persists, however running the game normally without debugger has no issues, maybe this is happening since I am using linux but I tried using the older version of Jitter 1 and it runs well.

Question about sweeping/casting shapes

This is what I've found for casting a box:

foreach ( var worldShape in PhysicsWorld.Shapes )
{
  var sweep = NarrowPhase.SweepTest( worldShape, shape, JQuaternion.Identity, JQuaternion.Identity, worldShape.RigidBody.Position, origin, JVector.Zero, direction, out var pointA, out var pointB, out var sweepNormal, out var sweepFraction );
  var dist = sweepFraction * direction.Length();
  if ( sweep && dist <= maxDistance )
  {
    var dirNormal = direction;
    dirNormal.Normalize();
    result.Hit = true;
    result.Normal = ToOpenTK( sweepNormal );
    result.Object = shape.RigidBody?.Tag as MapObject;
    result.Position = ToOpenTK( origin + (dirNormal * maxDistance) * sweepFraction );
    break;
  }
}

But it's not ideal. Is there something built-in to help with sweeps/shape casts?

How do I create a kinematic body?

To use jitter2 on the server
I want to receive the character's movement from the client.
So, on the server, I want to handle the character's rigid body as kinematic. How can I do this?

I hope the DebugDraw interface will be implemented soon.

I'm using JitterPhysics on my toy game engine, it is awesome.
When using rigidbody with shape and raycast, if I can see the position of rigidbody/shape or the path of raycast, you can troubleshoot errors more intuitively.
For rays, if the path can be seen, it can also be clear in what state (such as rotation) the shape is detected.

Unity & NetStandard support?

I really want to use this in Unity but targeting at .Net 7 with C# > 7 makes it impossible. Jitter physics v1 works perfectly, is there any way you could make it compatible too?

IBroadPhaseFilter works the opposite of the way it should

Check out the docs for IBroadPhaseFilter:

https://github.com/notgiven688/jitterphysics2/blob/e80205d51c3947efaf926d38c121800302be6ceb/src/Jitter2/Collision/CollisionFilter/IBroadPhaseFilter.cs#L38C1-L38C90

It says <returns>False if the collision should be filtered out; true otherwise.</returns>.

However, when setting a filter, if I return true it doesn't do collision, but if I return false, the objects do collide.

IMO the correct behavior is according to docs, ie true = collide, false = don't collide.
It makes more sense that way. But whatever you choose please make it consistent with the comment.

Thanks!

ConvexHullShape with flat meshes

Hi! I'm currently working on implementing this library into my engine when I noticed I get an error whilst loading collision meshes.

Strange, I thought, so I had a look and found out that the issue lied in the fact that one of my collision meshes was simply a completely flat plane.

This then led to the mass calculations resulting in a mass of 0(since it's infinitely thin). And since 0 mass is disallowed it throws an error.

I'm wondering if there might be a fix available for this?

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.