Page 1 of 1

Multiple fixtures per body (love.physics)

Posted: Fri Sep 18, 2015 6:36 pm
by christian-pfeifer
Hello everybody,

i have a problem with love.physics. I have created a little test-game. In this game i create one body and attach multiple fixtures (+shapes). At the update-method i rotate the body. All works fine, but the graphical result is not what i expected. Here is the code and a graphic explain what i expect and what i get.

What i'm doing wrong?

https://love2d.org/imgmirrur/zmzGppo.png

Code: Select all

Test = Class('Test');

function Test:initialize()
    local size = 25;
    local x, y = 0, 0;
    
    self.body = love.physics.newBody(World, 350, 250, "dynamic");
    
    for i=0, 2, 1 do
        local shape = love.physics.newRectangleShape(x, y, size, size, 0);
        local fixture = love.physics.newFixture(self.body, shape, 1);
    
        x = x + size;
    end
end

function Test:draw()
    local fixtures = self.body:getFixtureList();
    
    for idx, fixture in pairs(fixtures) do
        local shape = fixture:getShape();
        
        local x, y = self.body:getWorldPoints(shape:getPoints());
        
        love.graphics.setColor(255, 0, 0, 255);
        love.graphics.rectangle("line", x, x, 25, 25);
        
        love.graphics.setColor(255, 0, 0, 50);
        love.graphics.rectangle("fill", y, y, 25, 25);
    end    
end

function Test:update(dt)
    self.body:applyTorque(100);
end
Thanks for your help.
Christian

Re: Multiple fixtures per body (love.physics)

Posted: Fri Sep 18, 2015 10:05 pm
by adnzzzzZ
getWorldPoints(shape:getPoints()) will return you multiple points, not only x, y. You should draw those points using love.graphics.polygon.

Here's some code I wrote that does the same for all types of different shapes: https://github.com/adonaac/hxdx/blob/ma ... it.lua#L70

Re: Multiple fixtures per body (love.physics)

Posted: Sat Sep 19, 2015 3:25 am
by christian-pfeifer
Thank you very much adnzzzzZ,
is was that simble :megagrin: