Advertisement
tahg

Untitled

Jul 23rd, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. double dist = e.distanceTo(x, y, z) / r;
  2. double sp = level.getSeenPercent(center, e.bb);
  3. double pow = (1 - dist) * sp;
  4. e.hurt(DamageSource.explosion, (int) ((pow * pow + pow) / 2 * 8 * r + 1));
  5.  
  6.  
  7. public float getSeenPercent(Vec3 center, AABB bb) {
  8. double xs = 1.0 / ((bb.x1 - bb.x0) * 2 + 1);
  9. double ys = 1.0 / ((bb.y1 - bb.y0) * 2 + 1);
  10. double zs = 1.0 / ((bb.z1 - bb.z0) * 2 + 1);
  11. int hits = 0;
  12. int count = 0;
  13. for (float xx = 0; xx <= 1; xx += xs)
  14. for (float yy = 0; yy <= 1; yy += ys)
  15. for (float zz = 0; zz <= 1; zz += zs) {
  16. double x = bb.x0 + (bb.x1 - bb.x0) * xx;
  17. double y = bb.y0 + (bb.y1 - bb.y0) * yy;
  18. double z = bb.z0 + (bb.z1 - bb.z0) * zz;
  19. if (clip(Vec3.getPool().allocate(x, y, z), center) == null) hits++;
  20. count++;
  21. }
  22.  
  23. return hits / (float) count;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement