Hi! I like to use the QueasyCam library for 3D games I develop in this wonderful IDE, it’s useful for first-person camera control, and I basically completely understand its inner workings. However, it uses the camera() function, something I don’t understand at all. This language is open-source, so I scrounged around in the code, but found nothing.
PApplet:camera() uses PGraphics:camera(), which does nothing with the variables you give it, but rather uses PGraphics:showMissingWarning(), which AGAIN, does nothing with the variables the master function gave it. I assumed that every native function in your PDE files are passed onto PApplet, but this can not be true because camera() actually works…
I have no idea why camera() WORKS, but the code WOULDN’T. Perhaps I need more experience coding in Java… or maybe I got a bad version of the source code, or maybe I’m looking in the wrong files…
And I just wanted to learn how the camera() function worked. This is like when I tried to put a skydome in a LWJGL game. I did exactly what the video told me to do, but I got a NullPointerException, wheres in the video it worked first time. Any answers to THIS either?
- The download I got for the starting code was corrupted.
- There was some sort of addendum in the video description showing how to fix the problem, and I didn’t see it.
- Well, I AM a complete noob to normal Java programming, so that could be the problem here, could’ve been too ambitious…
Sorry for going off track so much at the end. Anyway, wanted to know how camera() worked so I could make my own 3D game from scratch in Eclipse, scrounged through the source code here, only found a dead function that did NOTHING… could someone help me with this little problem?
Hi MCCreeper8890,
The class PGraphics
is extend
ed by several sub- (or child) classes which may override
the super- (or parent) class’s camera
function. You can get greater control over your renderer by supplying an int
constant as the third argument to either size
or createGraphics
then casting the PGraphics
object to its child (g
when using the PApplet
's renderer after size
or the returned object of createGraphics
). For example,
import processing.awt.PGraphicsJava2D;
PGraphicsJava2D renderer;
void setup() {
size(128, 128, JAVA2D);
// Doesn't support camera.
renderer = (PGraphicsJava2D)g;
}
and
PGraphics3D renderer;
void setup() {
size(128, 128, P3D);
// Supports camera.
renderer = (PGraphics3D)g;
}
If the camera
function is appropriate for a given renderer, you’ll find it defined in the child class. I think you’re looking for the camera definition here. It constructs a 4x4 lookAt matrix, for which you can find various explanations on the web, one being here.
So, basically, … thinking in progress…
PGraphics is a bridge interface between PGraphics2D and PGraphics3D, correct?
And the child classes can override any and all functions in the PGraphics library, correct?
And so if I want to understand the camera() function, I’ll have to look in PGraphics3D.java, right?
Edit: wasn’t as straightforward as I thought… Looked in PGraphics3D, found no camera() function aside from “super.camera()”. Looked in PGraphicsOpenGL (its parent class) and found no mention of a camera() function, at least not in the tiny fraction of the 13,638 lines in that class. Besides, why reverse engineer part of the source code? Why not just use it? I’d say it’s GREAT to integrate libraries into the source, not so much to use simpler pieces of source code every way possible, that will just make your code extremely messy.