Cameras in PGraphics? (for 2.0a7)
in
Core Library Questions
•
1 year ago
Hello,
And met some problems with the cameras between parent PApplet and the PGraphics canvas
I expected the function camera(nine floats) works separately, but it did not.
when i used below,
PGraphics canvas = createCanvas(P3D); // in the setup()
canvas.beginDraw();
canvas.camera(float values);
canvas.endDraw();
In this case, it did not work. In other words, the effect of camera weren't applied to the PGraphics Instance.
And when i just use like below,
canvas.beginDraw();
camera(float values); // not canvas.camera()
canvas.endDraw();
the camera worked both PGraphics canvas and the normal (parent) canvas.
<Codes>
- PGraphics canvas;
- MyModel mMyModel;
- void setup() {
- size(300, 300, P3D);
- canvas = createGraphics(300, 300, P3D);
- mMyModel = new MyModel();
- mMyModel.init();
- }
- void draw() {
- background(204);
- canvas.beginDraw();
- canvas.background(0, 0, 0, 100);
- canvas.camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0); // <<< or just canvas()
- mMyModel.draw();
- canvas.endDraw();
- image(canvas, 0, 0);
- }
Any help?
Thanks.
// updated
ok, i figured out that the camera function works just fine with the primitives like sphere() by callling
canvas.sphere(20); //
instead of mMyModel.draw();
however, the problem occurs when i define a PShape and draw them by calling shape(PShape)
Inside the mMyModel,
I defined:
PShape instance with some vertices and normal definitions for a cube, and,
void draw() {
shape(model);
}
in it.
1