p5-matter-examples icon indicating copy to clipboard operation
p5-matter-examples copied to clipboard

Add example "matter camera"

Open b-g opened this issue 3 years ago • 2 comments

https://codepen.io/csims314/pen/goZQvG

b-g avatar Apr 20 '22 17:04 b-g

Some thoughts:

  1. Matter.js has something similar like a camera because in the Renderer you can set what the renderer should look at
    • But if I understand correctly we are using P5 as a renderer, so that functionality is not available to us
  2. If I understand the example @b-g posted correctly, they are just using translate and scale on the canvas context to simulate a camera
    • We could produce a similar result with push/pop as this apparently is what p5 is doing under the hood anyways
    • I don't know how well this would translate into a class though ... as the push would have to happen at the beginning of the draw and pop at the end
    • For the parallax example I now used push & pop without a camera class and it works fine (and is in line to what the folks have learned in the rest of the semester) ...
    • ... but I'd imagine that it would interfere with coordinates from mouse input, like in 6-add-remove-bodies (but I have not verified how mouseX/mouseY works in combination with push/pop/scale)
    • I think the fundamental problem is that p5 doesn't have the concept of viewports/cameras
      • It's quite sad, because in game engines like in Godot this is basic stuff

→ I am not sure how feasible it is to add a camera class with our P5 + Matter setup :( (At least one which doesn't interfere with mouse input and/or isn't super weird to use ... or am I missing something?)

stephanbogner avatar Jun 06 '22 14:06 stephanbogner

Nevertheless, ground work can be found in the new camera follow example.

stephanbogner avatar Jun 21 '22 10:06 stephanbogner