import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import processing.opengl.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; //MODIFIED VERSION OF: /**Copyright (c) 2009, Ioannis (Yiannis) Chatzikonstantinou, All rights reserved. **http://prototy.blogspot.com * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ //This software uses code portions of Daniel Shiffman's Flocking example, included //as an example in the original distribution of Processing //http://www.shiffman.net/ //http://www.processing.org ArrayList boids = new ArrayList(); // An arraylist for all the boids ArrayList nodes = new ArrayList(); // An arraylist for all the nodes PeasyCam cam; // Camera GL gl; GLU glu; float maxCourses = 150; void setup() { size(600,600, OPENGL); frameRate(25); cam = new PeasyCam(this, 0,0,0,750); gl=((PGraphicsOpenGL)g).gl; glu=((PGraphicsOpenGL)g).glu; } void draw() { background(0,0,50); runBoids(); runNodes(); showBoids(); } void mousePressed() { if (mouseButton==RIGHT) { pushMatrix(); float[] m=getMouse3D(); popMatrix(); nodes.add(new node3(new PVector(m[0],m[1],m[2]))); } } float[] getMouse3D() { ((PGraphicsOpenGL)g).beginGL(); int viewport[] = new int[4]; double[] proj=new double[16]; double[] model=new double[16]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX,proj,0); gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX,model,0); java.nio.FloatBuffer fb = java.nio.ByteBuffer.allocateDirect(4).order(java.nio.ByteOrder.nativeOrder()).asFloatBuffer(); gl.glReadPixels(mouseX, height-mouseY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, fb); fb.rewind(); double[] mousePosArr=new double[4]; glu.gluUnProject((double)mouseX,height-(double)mouseY,(double).95,model,0,proj,0,viewport,0,mousePosArr,0); ((PGraphicsOpenGL)g).endGL(); return new float[] { (float)mousePosArr[0],(float)mousePosArr[1],(float)mousePosArr[2] }; }