Texture Mapping To Collision Detection Objects?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
jordan4ibanez
Prole
Posts: 14
Joined: Sun Dec 30, 2012 7:22 pm

Texture Mapping To Collision Detection Objects?

Post by jordan4ibanez » Tue Dec 12, 2017 4:39 pm

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?

User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: Texture Mapping To Collision Detection Objects?

Post by jojomickymack » Sun Dec 31, 2017 5:03 am

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 551 times
Attachments
polygon001.love
(149.05 KiB) Downloaded 27 times

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 11 guests