Page 1 of 1

Texture Mapping To Collision Detection Objects?

Posted: Tue Dec 12, 2017 4:39 pm
by jordan4ibanez
You can draw a polygon using love.graphics.polygon("line", obj.b:getWorldPoints(obj.s:getPoints())).

But how does one go about mapping a texture to the world object?

Re: Texture Mapping To Collision Detection Objects?

Posted: Sun Dec 31, 2017 5:03 am
by jojomickymack
I was able to do this by using a mesh, and updating the mesh vertices by calling getPoints on the shape as an argument to Body:getWorldPoints(). Unfortunately, how the vertices are expected to be set on a mesh doesn't match up with how the points are returned, so I sort of hacked out a solution.

You can attach a polygon shape to a physics world body - there is limit to only 8 vertices and you're expected to attach multiple polygons together to create more interesting shapes.

Code: Select all

objects.triangle.shape = love.physics.newPolygonShape(vertices)
then you've got to create a mesh using the same vertices. I created this function to load them in

Code: Select all

function formatVertices(myVertices)
  return {
    {myVertices[1], myVertices[2], 0, 0, 255, 255, 255, 255},
    {myVertices[3], myVertices[4], 0, 1, 255, 255, 255, 255},
    {myVertices[5], myVertices[6], 1, 0, 255, 255, 255, 255}    
  }
end
given that there's a limit of 8, that's probably not horrible, but I think if you wanted to make a star shape or something it would be a unique challenge.

Nonetheless, there's a mesh with texture updated by a physics shape!
texture.gif
texture.gif (376.14 KiB) Viewed 2231 times