Hey,
I've been trying to rotate a polygon with 3 Points, which is actually a triangle, but I guess it doen't make a difference, since they both don't have a parameter for an angle. So is there a good way, that's easy to use? I've seen one with a canvas, but that seemed rather too complicated for such a simple cause. or would you recommend an image?
Rotating a polygon
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Rotating a polygon
As you said, you can draw the polygon to a canvas and draw that canvas rotated by a certain angle. This is a simple way, but probably not too fast.
A better way would be to do some rotation maths on every point - the relevant equations under the heading "Matrix Algebra" should work, but they will rotate about the origin (0;0). To get them to rotate around a different point, you will first have to translate the polygon to more-or-less above the origin before doing the rotation, then translate it back.
On the other hand using an image would be much easier, and allow for textures or coloured polygons to be used, but may suffer a slight loss of quality and speed.
A better way would be to do some rotation maths on every point - the relevant equations under the heading "Matrix Algebra" should work, but they will rotate about the origin (0;0). To get them to rotate around a different point, you will first have to translate the polygon to more-or-less above the origin before doing the rotation, then translate it back.
On the other hand using an image would be much easier, and allow for textures or coloured polygons to be used, but may suffer a slight loss of quality and speed.
Re: Rotating a polygon
Is there a good matrix library that can be used with LÖVE? Because that would've been really helpful in this situation.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Rotating a polygon
Wat?canvas
Code: Select all
local t = 0
function love.update(dt)
t = t + dt
end
function love.draw()
love.graphics.push()
love.graphics.translate(150,150) -- rotation center
love.graphics.rotate(-t/2) -- rotate
love.graphics.translate(-150,-150) -- move back
love.graphics.polygon('fill', 100, 100, 200, 100, 150, 200)
love.graphics.pop()
love.graphics.polygon('fill', 200, 200, 300, 200, 250, 300)
end
hump.vector might be what you're looking for. But if you just want to draw the polygon, you don't need it. At all.T-Bone wrote:Is there a good matrix library that can be used with LÖVE? Because that would've been really helpful in this situation.
Re: Rotating a polygon
Oh dang, I forgot about love's transformation functions. I guess that's the simple way of doing it.
Question though: is it faster to use built-in transformation functions than the pure maths for such things?
Question though: is it faster to use built-in transformation functions than the pure maths for such things?
Re: Rotating a polygon
Counter question: Does it matter?
Because it sure is faster to write...
Because it sure is faster to write...
Who is online
Users browsing this forum: No registered users and 1 guest