jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.55k stars 425 forks source link

Annoying identical color #1097

Closed Snouf-ID closed 4 months ago

Snouf-ID commented 4 months ago

Hello :)

When I use DrawBodies functions for visual debug, my first dynamic object is the same color as the ground (static object). Kind of gray/white. After adding a second dynamic ball, which is indeed a different bright color, I conclude that it's just bad luck for this first color. This happens starting from the HelloWorld.cpp sample with the ground and the ball.

BodyManager::DrawSettings settings;   
settings.mDrawShapeColor = BodyManager::EShapeColor::MotionTypeColor;   
m_physics_system.DrawBodies(settings, &m_debug_renderer);   

I would expect to never have this color for dynamic, or at least not start with it. It's confusing in MotionTypeColor mode.

I'm using Jolt 5.0.

thanks in advance

jrouwe commented 4 months ago

The coloring rules for MotionTypeColor are very simple:

https://github.com/jrouwe/JoltPhysics/blob/4a08d8d4e1ce7e87fdb16b0708a54a15f9a5379e/Jolt/Physics/Body/BodyManager.cpp#L929-L943

The only reason why a body would be gray is if it is static. All sGetDistinctColor's differ from gray:

image

(note the first and last ball have the same color because sGetDistinctColor repeats after 36 colors)

So I don't understand how a dynamic object could be gray and it is also not something I see happening in the samples app.

Snouf-ID commented 4 months ago

an random drive bug, color is ok in code, sorry