Processing Camera Controller – Now you are in control!
Today I want to introduce you my new processing camera wrapper. Use it for your game character, object tracking or whatever you want. It is simple to use, flexible and open source. I appreciate any contribution and will add a tutorial, if there is a demand. But first, let’s talk about the camera in processing. The processing website also provides you good resources about using the camera in a 3d environment. You may check the basic 3d tutorial and the camera function documentation.
A brief introduction about the processing camera
Many graphics related functions in processing are wrapper functions. They usually have an implementation of OpenGL calls under the hood. The processing camera works similar this way. The camera function is part of PApplet which itself is the main container for many ‘globally’ accessible functions.
This PApplet contains a graphics objects from the PGraphics class, which is your current renderer. This PGrahics object itself is extended by the subclass PGraphicsOpenGl . All the important matrices and matrix operations are handled by this class. You can go to the code and search for
void camera(). You will be directed to the camera function.
The documentation of the function says the following:
camera() doesn't care whether or not it's inside a begin/end clause. Basically it's safe to use camera() or camera(ex, ey, ez, cx, cy, cz, ux, uy, uz) as naked calls because they do all the matrix resetting automatically.
Processing does all the matrix math for you already. Perfect! The documentation also says:
The actual call is like gluLookat.
If you want to know more about gluLookat check out this faq from the opengl website.
But why do i need a controller bundle for the camera?
Processing handles all the matrix operations for you. Camera position, translation and rotation remains to you. It is also your job to do the proper rotation around objects as well around an own axis. Then there are different popular types of perspectives to handle. Each has their own behavior. Do you really want to reinvent the wheel every time you need a camera to be controlled?
Of course you don’t. At least I want a ready-to-use camera control with an open code base and integrate it fast in my 3d game. I also wanted to be careless whether it is a first person or third person game. I want to say which perspective I am using, connect it to my controls and then start. Therefore, I implemented a camera class which has all important functionality for movement, view direction, rotation and zoom. The camera is then passed to four controllers which feed the camera with the corresponding values for the operations.
There is already a camera package available
I know there is already a camera package available for processing. No doubt, that it works great (although I did not try it yet). I just want to have my own approach of providing a camera control. My idea was to write the code in pure processing without any external tools. I deny to provide you a jar file because I want you to include the source as .pde file in your processing application and play with it, extend it and maybe improve it! If you still want it as a jar you can build it yourself. So you can learn how this is done either. Have you found ways to improve this tool? Do you suggest to upload it to the processing repo? Feel free to leave a comment or contact me.