This is a physics simulation where a ball rolls down a bumpy hill, and the viewer can change the angle of the hill. But really the ground is level, and only a camera and gravity are rotating. So the ball just travels indefinitely towards a greater X and in a small range of Y.
I'm trying to center the scene rotation on the ball, but I can't manage it. I can only make it rotate from x=0,y=0 or from the top-left of the translated screen. In the former case the ground diverges away from the camera quickly.
The .love is attached. I am using a self-made camera module that just does some translation and rotation before the ball and current ground segments are drawn. Here is a snippet of that. What blows my mind is that it only kind-of works if rotate is first...I would think the translate (which keep in mind may stretch X towards infinity) would come before the rotation, then the second translate to shift the scene so the ball–which will be drawn at camera.x, camera.y–is a bit off-center. But that's when things get really messed up.
Code: Select all
camera = {
x = 0,
y = 0
}
local graphics = love.graphics
local push = graphics.push
local pop = graphics.pop
local translate = graphics.translate
local rotate = graphics.rotate
local scale = graphics.scale
local x_offset = graphics.getWidth() / 2 - 100
local y_offset = graphics.getHeight() / 2 - 100
function camera:set(angle)
push()
rotate(-(angle - (math.pi / 2)))
translate(-self.x, -self.y)
translate(x_offset,y_offset)
end
function camera:unset()
pop()
end
return camera