notgiven688 / jitterphysics2 Goto Github PK
View Code? Open in Web Editor NEWFast, simple, and dependency-free physics engine written in C# with a clear and user-friendly API.
License: MIT License
Fast, simple, and dependency-free physics engine written in C# with a clear and user-friendly API.
License: MIT License
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.
Greetings!
I'm eager to propose the inclusion of !=
and ==
operators within JMatrix. This addition would greatly benefit not only myself but potentially many others as well.
Transform all vertices and reconstruct the shape?
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());
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)
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.
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.
The system seems to be unstable when deal with very tiny shapes. Tested on the latest master branch.
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);
}
for (int i = 0; i < 10; i++)
{
ShootPrimitive();
}
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!
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
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.
Check out this setter:
The setter call first param angular
and second param linear
, but when setting the values it set linear
as first and angular
as second, flipping them.
Looks like a mistake.
Also please add individual setter / getter for damping types. Thanks!
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?
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 don't have the necessary knowledge to implement it, but in the future it would be awesome to get a voxel version of
the ghost collision triangle mesh filter
which prevents capsule shapes from snagging on internal edges of JBoxes placed adjacent to one another
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.
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?
There is JConvexHull.Build function in jitterphysics1 that can do it. How should it be done in jitterphysics2?
Check out the docs for IBroadPhaseFilter
:
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!
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?
Usually Mass = 0 means static objects.
If Mass of zero is not supported, its best to throw exception immediately upon setting it.
But IMO its better to support it and not generate NaNs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.