/** * this demo shows how to use a gestalt camera and apply it to the processing view. */ import gestalt.Gestalt; import gestalt.p5.GestaltPlugIn; import gestalt.shape.Line; import mathematik.Vector3f; import processing.opengl.*; GestaltPlugIn gestalt; Line _myLine; int _myCurrentPosition; Vector3f[] _myPoints; void setup() { size(640, 480, OPENGL); smooth(); /* gestalt */ gestalt = new GestaltPlugIn(this); /* camera */ gestalt.camera().setMode(Gestalt.CAMERA_MODE_LOOK_AT); gestalt.camera().position().set(width / 2, height * 0.05f, height * 0.25f); gestalt.camera().lookat.set(width / 2, height / 2, 0); gestalt.camera().upvector.set(0, 0, 1); /* create path storage */ _myPoints = new Vector3f[50]; for (int i = 0; i < _myPoints.length; i++) { _myPoints[i] = new Vector3f(); } /* create path view */ _myLine = gestalt.drawablefactory().line(); _myLine.material().getColor().set(1, 0.5f, 0, 0.25f); _myLine.material().depthmask = false; /* leave no trace in the depthbuffer */ _myLine.linewidth = 5; _myLine.setPrimitive(Gestalt.LINE_PRIMITIVE_TYPE_LINE_LOOP); gestalt.bin(Gestalt.BIN_3D).add(_myLine); /* share points */ _myLine.points = _myPoints; } void draw() { /* move camera */ gestalt.camera().side(0.5f); /* collect points */ _myCurrentPosition++; _myCurrentPosition %= _myPoints.length; _myPoints[_myCurrentPosition].set(mouseX, mouseY, 0); /* draw */ background(50); if (!mousePressed) { /* set the state of the processing view to match the gestalt camera. */ gestalt.applyCamera(gestalt.camera()); } connectCollectedPoints(); } void connectCollectedPoints() { for (int i = 0; i < _myPoints.length - 1; i++) { /* get current id */ int myID = i + _myCurrentPosition; myID %= _myPoints.length; /* get next id */ int myNextID = myID + 1; myNextID %= _myPoints.length; /* connect both points */ stroke(255); line(_myPoints[myID].x, _myPoints[myID].y, _myPoints[myID].z, _myPoints[myNextID].x, _myPoints[myNextID].y, _myPoints[myNextID].z ); } }