Rotate Camera around it's own axis

I’d like to know if there is a way to rotate a 3D camera atound it’s own axis. I want to create a 3D game like Minecraft and for that I of course need to make the camera be rotatable I tried following code (unnecessary code excluded):

int x;
void draw()
{
  camera(0, 0, 300, x, 0, 0, 0, 1, 0);
  
  //Simplified
  if(mouseX < 0)
    x--;
  else if(mouseX > 0)
    x++;

  noStroke();
  
  translate(0, 0, 0);
  box(90);
  translate(400, 0, 0);
  box(90);
  translate(400, 0, 400);
  box(90);
}

But it only goes like a quarter of a circle and then stops. So, can I rotate the camera around it’s own axis?

1 Like

This is a great thing to want to do, and I first have a word of caution before you go down this path – 3D camera rotation is hard. How hard can it be? Surprisingly hard.

Instead, I would recommend using an existing library, like installing QuesyCam (“a super-simple FPS camera library for Processing”) through the PDE Contributions Manager. In particular, check out the MazeRunner demo, which shows you how to set up an FPS camera in a MineCraft-like block environment.

If you want to make that a third-person camera then you will have to do a bit more work, but once you learn how to use the library you are now 75% of the way there, instead of 5% of the way there.


I should also mention that you don’t use rotateX(), rotateY(), or rotateZ() in your example code – you only use translate(), which is for sliding things, not turning them. If you haven’t done so already, review the 2D tutorial and then read up on the 3D tutorial examples:

1 Like