package mekstension; import gdl.MinimalCamera; import javax.media.opengl.GL; import javax.media.opengl.glu.GLU; import processing.core.PApplet; import processing.opengl.PGraphicsOpenGL; import shapes.ShapeManager; import shapes.ShapeRenderer; import toxi.geom.Vec3D; public class Mekstension extends PApplet { public static final String VERSION = "Mekstension v.0.1"; public static boolean FULLSCREEN = false; private boolean debug = false; private boolean hideCursor = false; public PGraphicsOpenGL pgl; public GL gl; public GLU glu; private ShapeManager shapeManager; private ShapeRenderer shapeRenderer; private Hud hud; private MinimalCamera cam; /** * setup */ public void setup() { if( FULLSCREEN ) size(screen.width, screen.height, OPENGL); else size(1200, 800, OPENGL); hint(ENABLE_OPENGL_4X_SMOOTH); frameRate(60); pgl = (PGraphicsOpenGL) g; gl = pgl.beginGL(); glu = new GLU(); shapeManager = new ShapeManager(this); shapeRenderer = new ShapeRenderer(this); hud = new Hud(this); hud.log( VERSION ); hud.toggle(); cam = new MinimalCamera(width, height); cam.farClip = 10; } /** * runner * * @param args java applet/application arguments */ public static void main(String[] args) { String className = "mekstension.Mekstension"; if(FULLSCREEN) { PApplet.main( new String[] { "--present", className } ); } else { PApplet.main( new String[] { className } ); } } /** * Draw loop */ public void draw() { cam.update(); cam.apply(g); background(0); shapeManager.update(); shapeRenderer.draw( shapeManager.getShapelist() ); hud.draw(); } /** * mouse button down and mouse moving */ public void mouseDragged() { shapeManager.mouseEdit(mouseX, mouseY, pmouseX, pmouseY); } /** * Key pressed */ public void keyPressed() { switch(keyCode) { // global controls case 81 : // q shapeManager.setEditMode(ShapeManager.GLOBAL_SET_ANGLE); hud.log("Angle: " + ((shapeManager.globalAngle * (2 * Math.PI) * 9))); break; case 87 : // w shapeManager.setEditMode(ShapeManager.GLOBAL_SET_FOCAL_LENGTH); hud.log("Focal Length: " + shapeManager.globalFocalLength); break; case 69 : // e shapeManager.setEditMode(ShapeManager.GLOBAL_SET_DEPTH); hud.log("Depth"); break; case 82 : // r shapeManager.setEditMode(ShapeManager.GLOBAL_SET_SEGMENTS); hud.log("Segments: " + shapeManager.globalSegments); break; case 84 : // t shapeManager.setEditMode(ShapeManager.GLOBAL_CYCLE_FG); hud.log("Cycle Foreground Color: " + parseInt(shapeManager.globalFG.red() * 255) + ", " + parseInt(shapeManager.globalFG.green() * 255) + ", " + parseInt(shapeManager.globalFG.blue() * 255)); break; case 89 : // y shapeManager.setEditMode(ShapeManager.GLOBAL_CYCLE_BG); hud.log("Cycle Background Color: " + parseInt(shapeManager.globalBG.red() * 255) + ", " + parseInt(shapeManager.globalBG.green() * 255) + ", " + parseInt(shapeManager.globalBG.blue() * 255)); break; case 85 : // u shapeManager.setEditMode(ShapeManager.GLOBAL_CYCLE_STROKE); hud.log("Cycle Stroke Color: " + parseInt(shapeManager.globalStroke.red() * 255) + ", " + parseInt(shapeManager.globalStroke.green() * 255) + ", " + parseInt(shapeManager.globalStroke.blue() * 255)); break; case 73 : // i shapeManager.setEditMode(ShapeManager.GLOBAL_SET_FG_ALPHA); hud.log("Set Foreground Alpha:" + shapeManager.globalFG.alpha); break; case 79 : // o shapeManager.setEditMode(ShapeManager.GLOBAL_SET_BG_ALPHA); hud.log("Set Background Alpha:" + shapeManager.globalBG.alpha); break; case 80 : // p shapeManager.setEditMode(ShapeManager.GLOBAL_SET_STROKE_ALPHA); hud.log("Set Stroke Alpha: " + shapeManager.globalStroke.alpha); break; // individual object controls case 65 : // a shapeManager.setEditMode(ShapeManager.OBJ_SET_POSITION); Vec3D pos = shapeManager.currentShape.getPos(); hud.log(shapeManager.currentShape.label + " position: " + pos.x + ", " + pos.y ); break; case 83 : // s shapeManager.setEditMode(ShapeManager.OBJ_SET_ROTATION); hud.log(shapeManager.currentShape.label + " rotation: " + shapeManager.currentShape.rot); break; case 68 : // d shapeManager.setEditMode(ShapeManager.OBJ_SET_SCALE); hud.log(shapeManager.currentShape.label + " scale: " + shapeManager.currentShape.scale); break; case 70 : // f shapeManager.setEditMode(ShapeManager.OBJ_SET_DEPTH); hud.log(shapeManager.currentShape.label + " depth: " + shapeManager.currentShape.depth); break; case 71 : // g shapeManager.setEditMode(ShapeManager.OBJ_SET_MODX_AMP); hud.log(shapeManager.currentShape.label + " modulation x amplitude: " + shapeManager.currentShape.ampx); break; case 72 : // h shapeManager.setEditMode(ShapeManager.OBJ_SET_MODX_FREQ); hud.log(shapeManager.currentShape.label + " modulation x freq: " + shapeManager.currentShape.modXFreq); break; case 74 : // j shapeManager.setEditMode(ShapeManager.OBJ_SET_MODY_AMP); hud.log(shapeManager.currentShape.label + " modulation y amplitude: " + shapeManager.currentShape.ampy); break; case 75 :// k shapeManager.setEditMode(ShapeManager.OBJ_SET_MODY_FREQ); hud.log(shapeManager.currentShape.label + " modulation y freq: " + shapeManager.currentShape.modYFreq); break; case 76 : // l shapeManager.setEditMode(ShapeManager.OBJ_SET_SEGMENTS); hud.log(shapeManager.currentShape.label + " segments: " + shapeManager.currentShape.numSegments); break; case 61 : // = (+) if(shapeManager.currentShape != null) { shapeManager.currentShape.addSide(); hud.log(shapeManager.currentShape.label + " sides: " + shapeManager.currentShape.sides); } break; case 45 : // - if(shapeManager.currentShape != null) { shapeManager.currentShape.subtractSide(); hud.log(shapeManager.currentShape.label + " sides: " + shapeManager.currentShape.sides); } break; case 47 : // "/" shapeManager.addShape(); hud.log("Added shape " + shapeManager.currentShape.getID()); break; case 9 : // TAB hud.toggle(); hideCursor = hideCursor ? false : true; if (hideCursor) noCursor(); else cursor(); break; case 93 : // ] shapeRenderer.nextBlendModeL(); hud.log("GL Blend Function:\n" + shapeRenderer.GLblendR.getCurrentName() + "\n" + shapeRenderer.GLblendL.getCurrentName()); break; case 91 : // [ shapeRenderer.nextBlendModeR(); hud.log("GL Blend Function:\n" + shapeRenderer.GLblendR.getCurrentName() + "\n" + shapeRenderer.GLblendL.getCurrentName()); break; case 92 : // \ shapeRenderer.toggleBlend(); String blendEnabled = shapeRenderer.enableBlend ? "ON" : "OFF"; hud.log("GL Blend Function: " + blendEnabled); break; case 38 : // UP shapeManager.mouseEdit(0, -10, 0, 0); break; case 40 : // DN shapeManager.mouseEdit(0, 10, 0, 0); break; case 39 : // RT shapeManager.mouseEdit(10, 0, 0, 0); break; case 37 : // LT shapeManager.mouseEdit(-10, 0, 0, 0); break; case 90 : // z shapeManager.toggleFGCycle(); String cycleFG = shapeManager.cycleFG ? "ON" : "OFF"; hud.log("Toggle Foreground Color Cycle : " + cycleFG); break; case 88 : // x shapeManager.toggleBGCycle(); String cycleBG = shapeManager.cycleBG ? "ON" : "OFF"; hud.log("Toggle Background Color Cycle : " + cycleBG); break; case 67 : // c shapeManager.toggleStrokeCycle(); String cycleStroke = shapeManager.cycleStroke ? "ON" : "OFF"; hud.log("Toggle Stroke Color Cycle : " + cycleStroke); break; case 86 : // v shapeManager.setEditMode(ShapeManager.GLOBAL_SET_COLORCYCLE_SPEED); hud.log("Color Cycle Speed:" + shapeManager.colorCycleSpeed); break; case 32 : // SPACEBAR if(shapeManager.currentShape != null) { hud.log("Edit shape " + shapeManager.currentShape.getID()); shapeManager.nextShape(); } break; default : if(debug) System.out.print("\n" + keyCode); break; } } }