ackvonhuelioLvl 41
- Edited
edit: embed wasn't working so just click the link
edit: embed wasn't working so just click the link
ackvonhuelio I've been looking for a way to rotate the camera! How does it work?
Binary_Coder
pushMatrix & popMatrix (or push() and pop() for cdo) and rotate() to rotate a part of the screen.
as for how I did this exactly, it's a lot of trigonometry that I don't really feel like explaining bc i don't even really understand that well. something to do with getting angles and translating the player x-y movement plane to match those angles.
ok
Binary_Coder To be more specific, here's how I've done it in the past.
push()
will create a new "subsection" of the screen which you can manipulate as you wish.
pop()
ends that subsection.
Within that subsection, you can use translate(), rotate(), scale() to do those things, and then draw whatever you want. It will be translated, rotated, and scaled as you want. I suggest you consult the p5.JS documentation.
Ravage
adding on to this, be sure to put translate()s around rotate() to specify the point that you wish to rotate about.
this knowledge will save you a lot of confusion later on.
ackvonhuelio Further elaborating upon what you said, it is confusing to know exactly which values to use, and the positive/negative signs that go along. Here is some nice code to do that for you:
function rotateAround(theta, rotateX, rotateY, targetX, targetY){
window.translate(rotateX, rotateY)
window.rotate(theta)
window.translate(-targetX, -targetY)
}