Hi, all. I've been using Processing for ~1 year now, slowly taking steps into the wider Java world (e.g., using Eclipse now).
I'm trying to add some functionality to PGraphics, especially to PGraphics3D. My first thought was to simply subclass PGraphics. However, this seems to run afoul of createGraphics(), which (as far as I can tell) returns a PGraphics2D or PGraphics3D depending on your choice of renderer. If I try, e.g....
Code:class QPGraphics extends PGraphincs {
// blah blah blah
}
void setup() {
QPGraphics qpg = (QPGraphics) createGraphics(100, 100, P2D);
}
...I get a ClassCastException. Based on what I know of java so far, that makes sense to me: the compiler obviously can't guarantee that two subclasses of the same parent class are going to play well together.
But, the RawDXF library has no problem casting a createGraphics() to a subclass of PGraphics. I've looked through the source to RawDXF and I can't find what it is about RawDXF that makes it special. (And I've tried RawDXF myself and it works fine, so it's not some weird me-specific issue.)
So, what am I missing? Is there a way I can subclass PGraphics and have the subclass work happily with createGraphics()?