Advertisement
Zanzlanz

Game Math

Mar 12th, 2014
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is what I think of when I imagine math in game dev
  2. //It's the camera logic in one of my tests
  3.  
  4. camZoom = Math.max(.7, Math.min(1.5, w/Math.sqrt(Math.pow(minX-maxX, 2)+Math.pow(minY-maxY, 2))/2));
  5. camZoomSmooth += (camZoom-camZoomSmooth)/4;
  6. camRotSmooth += (camRot-camRotSmooth)/10;
  7. camX = (minX+maxX)/2;
  8. camY = (minY+maxY)/2;
  9. camXSmooth += (camX-camXSmooth)/4;
  10. camYSmooth += (camY-camYSmooth)/4;
  11. var zoomM:Matrix = new Matrix(1, 0, 0, 1, -camXSmooth+camOffsetX, -camYSmooth+camOffsetY);
  12. zoomM.scale(camZoomSmooth+Math.sin(tick/50)*.2-.2, camZoomSmooth+Math.sin(tick/50)*.2-.2);
  13. zoomM.rotate((camRotSmooth+Math.sin(tick/45)*10)/180*Math.PI);
  14. zoomM.translate(w/2, h/2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement