Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upDebugDrawer improved. #2249
DebugDrawer improved. #2249
Conversation
|
Note that the ShapeRenderer, BitmapFont and SpriteBatch have to be disposed when no longer needed. Could you make them private with setters and getters, along with a private boolean |
|
Good spot @xoppa! I've implemented it the way you described it. |
| } | ||
|
|
||
| private static final Vector3 tmp = new Vector3(); |
This comment has been minimized.
This comment has been minimized.
| shapeRenderer.point(pointOnB.x, pointOnB.y, pointOnB.z); | ||
|
|
||
| to.set(pointOnB.x, pointOnB.y, pointOnB.z); | ||
| to.add(normalOnB.scl(distance)); |
This comment has been minimized.
This comment has been minimized.
|
I'm not sure about creating a font and spritebatch (and thus Mesh and ShaderProgram) by default. As we've seen the draw3dText method is by default only called for softbody simulation. So in most cases the font and spritebatch aren't even used. Perhaps lazy initialization would be a better approach. |
|
@xoppa: It seems like the libgdx projects are configured to not display warnings about unused fields? That's why I didn't notice it. I removed them and added the lazy initialization. |
| /** Switches the {@link SpriteBatch}. The given sprite batch won't be disposed when {@link #dispose()} is called. */ | ||
| public void setSpriteBatch (SpriteBatch spriteBatch) { | ||
| if (ownsSpriteBatch) { | ||
| this.spriteBatch.dispose(); |
This comment has been minimized.
This comment has been minimized.
|
Thanks! |

nooone commentedAug 20, 2014
I have added a few more implementations to the
DebugDrawer:reportErrorWarningdrawContactPointdrawTriangledraw3dTextThe
draw3dTextimplementation is probably the most interesting part as it's in need of the currentglViewportparameters, which is why I addedbegin(Viewport). Another alternative (@xoppa's idea) would be to keep track of the currentglViewportparamters in a static way, for example viaGdx.graphics.getGlViewport(). A more slow (but maybe for debugging purposes appropriate?) way would be to just read it like this:In both cases we could get rid of the
Viewportcompletely here.The way this PR draws 3D text is by projecting the destination position to the screen and then drawing it in 2D, centered on the position. This has the advantage of pixel perfection. However there are also some drawbacks:
I've tried to implement it following kalle_h's advice and draw it via the spritebatch with manipulated matrices to "real" 3D, however I could not make it work completely. Something must be wrong with the object matrix's rotation:
If we could get this to work, there's no need for the
glViewportparameters at all.