Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to draw debug for world:queryAABB, problem with world:queryAABB — Gideros Forum

How to draw debug for world:queryAABB, problem with world:queryAABB

DungDajHjepDungDajHjep Member
edited November 2014 in General questions
problem again

i used shape to draw area of querry, but I found querry not work correctly, it only works when the object in the center area and querry not work with objects at the edge, sometime all is nothing

Comments

  • In debug draw you can set different flasg what you want to display, one of them being AABB_bit, maybe it will help
    http://docs.giderosmobile.com/reference/physics/b2DebugDraw#b2.DebugDraw
  • DungDajHjepDungDajHjep Member
    edited November 2014
    @ar2rsawseen
    I tried to create a body in within the area querry and I do not get it in the fixtures list. Seems querryAABB works very unstable.

    When area of querying is larger more I get number of fixture less or nothing.
  • I once also got some unstable results with it, but it turned out I mixed the numbers and instead of checking bounding box, I was checking like a sand clock figure like, using switched values for one axis
    So recheck your number, queryAABB usually works quite decently, can't tell the same about RayCasting though :)
  • DungDajHjepDungDajHjep Member
    edited November 2014
    i draw querryAABB by shape and i can see where is area i check, here is my code:

    combo1 = {attackOffsetX = 10, attackOffsetY = 8, attackWidth = 60, attackHeight = 70} ,
    combo2 = {attackOffsetX = 10, attackOffsetY = 8, attackWidth = 38, attackHeight = 36}

    attackRect = combo1

    local startX = self.posX + attackRect.attackOffsetX
    local startY = self.posY + attackRect.attackOffsetY

    if self.attackDir == -1 then
    startX = self.posX- attackRect.attackOffsetX - attackRect.attackWidth
    end

    local fixtures = self.map.b2world:queryAABB(startX, startY, startX + attackRect.attackWidth, startY - attackRect.attackHeight)

    --print(self.posX,self.posY,startX, startY, startX + attackRect.attackWidth, startY - attackRect.attackHeight)

    --------------------
    local shape = Shape.new()

    shape:clear()
    shape:beginPath()

    shape:setFillStyle(Shape.SOLID, 0x9a5c78)

    shape:moveTo(startX,startY)
    shape:lineTo(startX + attackRect.attackWidth,startY)
    shape:lineTo(startX + attackRect.attackWidth, startY - attackRect.attackHeight)
    shape:lineTo(startX, startY - attackRect.attackHeight)

    shape:endPath()
    self.map:addChild(shape)
    Timer.delayedCall(500,function()
    shape:removeFromParent()
    shape:clear()
    shape = nil
    end)
  • @DungDajHjep why there is a subtraction for:
    startY - attackRect.attackHeight ?
    if it makes it lower than startY then you have the same problem as me.
  • DungDajHjepDungDajHjep Member
    edited November 2014
    @ar2rsawseen default, coordinate origin of gideros is top left, so positionY little is higher

    in Gideros Documentation:

    (table) = b2.World:queryAABB(lowerx, lowery, upperx, uppery)
    Parameters:
    lowerx: (number) the lower x coordinate of the query box
    lowery: (number) the lower y coordinate of the query box
    upperx: (number) the upper x coordinate of the query box
    uppery: (number) the upper y coordinate of the query box

    and in case it is same sand clock, shape will draw shapes such.image
    Untitled.png
    614 x 460 - 8K
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @DungDajHjep I think it it a language problem, lower means small, minimal and upper means, greater, maximal.
    As in lower bound and upper bound

    So you can read it as:

    minx: (number) the minimal x coordinate of the query box
    miny: (number) the minimal y coordinate of the query box
    maxx: (number) the maximal x coordinate of the query box
    maxy: (number) the maximal y coordinate of the query box

    Just try changing it and see if there is any differences

    Likes: DungDajHjep

    +1 -1 (+1 / -0 )Share on Facebook
  • @ar2rsawseen amazing, it's work perfect, thanks you very much !

    image
    Untitled.png
    344 x 232 - 5K
  • Fixed the docs to avoid future confusion ;)

    Likes: DungDajHjep

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.