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: 24
Joined: Sun Dec 30, 2012 7:22 pm

Texture Mapping To Collision Detection Objects?

Post 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?
Check out my Github: https://github.com/jordan4ibanez/
It's a dumpster
User avatar
jojomickymack
Prole
Posts: 45
Joined: Tue Dec 26, 2017 4:52 pm

Re: Texture Mapping To Collision Detection Objects?

Post 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 2244 times
Attachments
polygon001.love
(149.05 KiB) Downloaded 135 times
Post Reply

Who is online

Users browsing this forum: No registered users and 151 guests