import processing.opengl.*; static final float ENVRAD = 1000; Vec2 mp = new Vec2(); Vec2 pmp = new Vec2(); Vec2 cam = new Vec2(); Vec2 camTarget = new Vec2(); float zoom = 0; float zoomTarget = 0; MouseWheelEventDemo wheel; int wheelNotches = 0; float widthHalf = 150; float heightHalf = 150; void setup(){ size(300,300,OPENGL); widthHalf = width/2; heightHalf = height/2; ellipseMode(CENTER); wheel = new MouseWheelEventDemo(); } void draw(){ background(255); cam = lerp(cam,camTarget,.2); zoom = lerp(zoom,zoomTarget,.2); float absMouseX = screenX(mouseX - cam.x - widthHalf,mouseY - cam.y,zoom - heightHalf); float absMouseY = screenY(mouseX - cam.x - widthHalf,mouseY - cam.y,zoom - heightHalf); float abspMouseX = screenX(pmouseX - cam.x - widthHalf,pmouseY - cam.y,zoom - heightHalf); float abspMouseY = screenY(pmouseX - cam.x - widthHalf,pmouseY - cam.y,zoom - heightHalf); translate(widthHalf,heightHalf); translate(cam.x,cam.y,zoom); mp.nowEquals(absMouseX,absMouseY); pmp.nowEquals(abspMouseX,abspMouseY); if(mousePressed){ camTarget.add(new Vec2(pmp,mp)); } drawScreenZero(); drawOrigin(); drawEnvBounds(); drawMp(); } void drawScreenZero(){ float sxz = -widthHalf ; float syz = -heightHalf ; float scx = sxz + tan(radians(45)) * zoom; float scy = syz + tan(radians(45)) * zoom; println("sxzsyz: " + sxz + " , " + syz); println("scxscy: " + scx + " , " + scy); noFill(); stroke(0); strokeWeight(1); ellipse(scx,scy,40,40); } void drawEnvBounds(){ noFill(); stroke(180); strokeWeight(4); smooth(); ellipse(0,0,ENVRAD,ENVRAD); } void drawOrigin(){ noFill(); stroke(255,0,0); strokeWeight(1); noSmooth(); ellipse(0,0,10,10); } void drawMp(){ noFill(); stroke(0,0,255); strokeWeight(1); noSmooth(); ellipse(mp,30); } public class MouseWheelEventDemo implements MouseWheelListener { public MouseWheelEventDemo() { addMouseWheelListener(this); } public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); wheelNotches = abs(notches); if(notches<0){ mouseWheelUp(); }else{ mouseWheelDown(); } } } void mouseWheelUp(){ zoomTarget-=50; } void mouseWheelDown(){ zoomTarget+=50; }