scala - World.QueryAABB giving incorrect results in libgdx -
I am trying to implement mouse selection for my game when I type QueryAABB
It seems that it actually treats a lot more things than objects.
What's going on in the image
- Blue box is an actor in which there is a body that I want to choose
- Setting the blue box on the blue box
Box2DDebugRenderer - The mouse selects a region (white box) on the screen, it is completely graphical
- AABB is converted to meters and
QueryAABB
- Callback was called blue balk And it turned red.
- The green outline is a separate body left, to see if my conversion was correct or not, it was used for the actual selection process. Strong> no
This is related to my meter size, big, results are wrong and more wrong. It works perfectly at 1 meter = 1 pixel.
meter conversion
val MetersToPixels = 160f val PixelsToMeters = 1 / MetersToPixels def toMeters (n: float) = N * pixelsToMeters def pixels (n: float ) = N * MetersToPixels
In the image I am using MetersToPixels = 160f
so that the inaccuracies appear more, but I actually do not have to MetersToPixels = 16f
.
want the relevant selection code
val x1 = selectPos.x val y1 = selectPos.y val x2 = getX val y2 = getY + getHeight val (L , R) = if (x2 and lt; x1) (x2, x1) other (x1, x2) val (b, t) = if (y2 and lt; y1) (y2, y1) other (y1, y2) world
This code is inside my cursor keys
class. The task
method and selectPos
indicates the starting point where usage presses the left mouse button and getX
and g Ety
are actor
methods giving the current position the next bit organizes them because they can be out of sequence, then they are converted into meters because they are in all pixel units.
Selectbackback: query callback
override def report phishing (stability: stability): boolean = {fixture.getBody.getUserData match {Case selection: Selectable = & gt; Selected + = Case of Selectable Truth _ = & gt; True}}
selectable
is a feature that internally sets a boolean flag that helps determine the color of the blue box. And selected
a is unselected. Hasheset [Selection]
Cursor Size
is defined inside.
Other things probably
Box2DDebugRenderer
MetersToPixels
Able to collect, QueryAABB
is inherently incorrect for optimization. However, I have hit a roadblock with Lidgidax because there is no publicly visible function like b2testOverlap
and whatever I think, there will be a time soon to be one There is no plan.
I think my best solution would probably be to use it and show that the implementation of the physics of libgdx is not present.
Or, as no one suggests, I can add it to libgdx itself.
UPDATE
I collect the corner from the shape of the fix and use com.badlogic.gdx.math.Intersector
I decided to go with a simple solution to do this work against the vertices of the selection I think
QueryAABB
.
Comments
Post a Comment