Page 1 of 1

X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 1:17 pm
by melexm
Hello,
I would like to get an explanation (I couldn't find anything in the docs) about the x,y coordinates.
I want to create a line which will start from the mouse pressed x,y and end in the mouse released x,y.
Here is the code in the mouse released function event:

Code: Select all

walls[i].s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY)
It creates an odd line with no angle and only length is chaining.
Why isn't this working? (Link/answer are highly appreciated)

More code:

Code: Select all

function love.mousepressed(x, y, button)
	mStartX = x
	mStartY = y
end
function love.mousereleased(x, y, button)
	walls.count = walls.count + 1
	i = walls.count
	walls[i] = {}
	walls[i].b = love.physics.newBody(world, mStartX, mStartY, "static")
  	walls[i].s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here
  	walls[i].f = love.physics.newFixture(walls[i].b, walls[i].s, 1 )
  	walls[i].f:setFriction(0.1)
end

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 2:06 pm
by coffee
melexm wrote: walls.s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here


Shouldn't be instead walls.s = love.physics.newEdgeShape(mStartX, mStartY, mEndX, mEndY)?

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 2:51 pm
by melexm
coffee wrote:
melexm wrote: walls.s = love.physics.newEdgeShape(mStartX, mStartX, mEndX, mEndY) // here


Shouldn't be instead walls.s = love.physics.newEdgeShape(mStartX, mStartY, mEndX, mEndY)?


Still not working, it was mispeld because I was trying to play with it.
Any other ideas, I think this has to do with some dx,dy things...

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 3:15 pm
by vrld
You use mEndX and mEndY but never define them.

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 3:26 pm
by melexm
vrld wrote:You use mEndX and mEndY but never define them.
OK, it is better now:

Code: Select all

  	walls[i].s = love.physics.newEdgeShape(mStartX, mStartY, x, y)
But still it isn't created at the same point of the mouse.

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 5:48 pm
by Boolsheet
The coordinates you set on the shapes are relative to the body origin (also called local coordinates). That means if you create a body at mStartX and attach an EdgeShape that starts at mStartX, the line will start at mStartX*2. Create the body at (0, 0) and the line should be where you expect it to be. You also don't have to create a separate body for each line. It's possible to attach multiple fixtures to one body.

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 10:57 pm
by melexm
Boolsheet wrote:The coordinates you set on the shapes are relative to the body origin (also called local coordinates). That means if you create a body at mStartX and attach an EdgeShape that starts at mStartX, the line will start at mStartX*2. Create the body at (0, 0) and the line should be where you expect it to be. You also don't have to create a separate body for each line. It's possible to attach multiple fixtures to one body.

Thanks it works!
BTW: Wouldn't fixing shapes to one body makes the collisions not work?

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 11:21 pm
by Boolsheet
melexm wrote:BTW: Wouldn't fixing shapes to one body makes the collisions not work?
Uh. I think I don't understand what you are asking.

Re: X,Y Coordinates not working properly

Posted: Fri Dec 28, 2012 11:29 pm
by melexm
Boolsheet wrote:
melexm wrote:BTW: Wouldn't fixing shapes to one body makes the collisions not work?
Uh. I think I don't understand what you are asking.
I am creating multiple lines, attaching them to a single body object won't ruin the collisions with them?

Re: X,Y Coordinates not working properly

Posted: Sat Dec 29, 2012 12:31 am
by Boolsheet
No. That will all still work.