// Simulated screen for view control by dragging points // Written by Jarek Rossignac June 2006. Modified Septmber 2007 import processing.opengl.*; // load OpenGL import javax.media.opengl.*; import javax.media.opengl.glu.*; import java.nio.*; GL gl; GLU glu; float a=0; float ax = 0; float az = 0; boolean pickS=false; Mobile mobile = new Mobile(); pt ptMouse3D = new pt(); boolean showCoord = true; int texnum = 4; PImage[] tex = new PImage[texnum]; // ** SETUP ** void setup() { size(800, 800, OPENGL); setColors(); sphereDetail(12); //smooth(); PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); // font for writing labels on screen //this.addMouseWheelListener(new CMouseWheelEvent());// wheel gl=((PGraphicsOpenGL)g).gl; glu=((PGraphicsOpenGL)g).glu; tex[0] = loadImage("1.jpg"); tex[1] = loadImage("2.jpg"); tex[2] = loadImage("3.jpg"); tex[3] = loadImage("4.jpg"); textureMode(NORMALIZED); } // ** DRAW ** void draw() { lights(); directionalLight(0,0,128,0,1,0); directionalLight(0,0,128,0,0,1); //ortho(0, width, 0, height, -10, 10); background(white); pushMatrix(); translate(width/2,height/2,-150); rotateX(-ax*PI/height/2.); rotateZ(-az*PI/width/4.); //translate(-width/2,-height/2,0); if ( mousePressed ) { if ( mouse_pressed ) { mobile.Select(); mouse_pressed = false; } else if ( mouse_released == false ) { if ( mobile.Drag() == false ) { ax+=mouseY-pmouseY; az+=mouseX-pmouseX; } } } if ( keyPressed && key_pressed) { if ( mobile.PressKey() == false ) { if (key == 'c') showCoord = !showCoord; else if (key == 's') mobile.Save(); else if (key == 'l') mobile.Load(); else if (key == 'r') mobile.Reset(); } key_pressed = false; } mobile.Draw(); ptMouse3D.pick(); if ( showCoord ) { stroke(red); line(0,0,0, 100,0,0); stroke(green); line(0,0,0, 0,100,0); stroke(blue); line(0,0,0, 0,0,100); } popMatrix(); pushMatrix(); translate(0, 20); fill(black); text("Click to select a node.",0,0); noFill(); translate(0, 20); if ( mobile.IsSelected() == false ) { fill(black); text("Press 'c' to show/hide the coordinate axis.",0,0); noFill(); translate(0, 20); fill(black); text("Press 's' to save mobile.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'l' to load mobile.",0,0); noFill(); translate(0, 20); fill(black); text("Press 'r' to reset mobile.",0,0); noFill(); translate(0, 20); } mobile.ShowMenu(); popMatrix(); } //*** KEY ACTIONS (details in keys tab) boolean key_pressed = false; void keyPressed() { key_pressed = true; // keys(); }; boolean mouse_pressed = false; boolean mouse_released = false; void mousePressed() { mouse_pressed = true; mouse_released = false; pick=true; } void mouseReleased() { mouse_released = true; picked=false; }