Advertisement
Guest User

Untitled

a guest
Dec 15th, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. for (int i = 0; i < axiom.length(); i++) {
  2. char c = axiom.charAt(i);
  3.  
  4. Matrix4f tempRotation = new Matrix4f();
  5. tempRotation.setIdentity();
  6.  
  7. switch (c) {
  8. case 'G':
  9. case 'F':
  10. // Tree trunk
  11. view.setBlock(posX + (int) position.x + 1, posY + (int) position.y, posZ + (int) position.z, barkType, view.getBlock(posX + (int) position.x + 1, posY + (int) position.y, posZ + (int) position.z));
  12. view.setBlock(posX + (int) position.x - 1, posY + (int) position.y, posZ + (int) position.z, barkType, view.getBlock(posX + (int) position.x - 1, posY + (int) position.y, posZ + (int) position.z));
  13. view.setBlock(posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z + 1, barkType, view.getBlock(posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z + 1));
  14. view.setBlock(posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z - 1, barkType, view.getBlock(posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z - 1));
  15.  
  16. // Generate leaves
  17. if (_stackOrientation.size() > 1) {
  18. int size = 1;
  19.  
  20. for (int x = -size; x <= size; x++) {
  21. for (int y = -size; y <= size; y++) {
  22. for (int z = -size; z <= size; z++) {
  23. if (Math.abs(x) == size && Math.abs(y) == size && Math.abs(z) == size)
  24. continue;
  25.  
  26. view.setBlock(posX + (int) position.x + x + 1, posY + (int) position.y + y, posZ + z + (int) position.z, leafType, air);
  27. view.setBlock(posX + (int) position.x + x - 1, posY + (int) position.y + y, posZ + z + (int) position.z, leafType, air);
  28. view.setBlock(posX + (int) position.x + x, posY + (int) position.y + y, posZ + z + (int) position.z + 1, leafType, air);
  29. view.setBlock(posX + (int) position.x + x, posY + (int) position.y + y, posZ + z + (int) position.z - 1, leafType, air);
  30. }
  31. }
  32. }
  33. }
  34.  
  35. Vector3f dir = new Vector3f(1, 0, 0);
  36. rotation.transform(dir);
  37.  
  38. position.add(dir);
  39. break;
  40. case '[':
  41. _stackOrientation.push(new Matrix4f(rotation));
  42. _stackPosition.push(new Vector3f(position));
  43. break;
  44. case ']':
  45. rotation = _stackOrientation.pop();
  46. position = _stackPosition.pop();
  47. break;
  48. case '+':
  49. tempRotation.setIdentity();
  50. tempRotation.setRotation(new AxisAngle4f(new Vector3f(0, 0, 1), (float) Math.toRadians(angleInDegree + angleOffset)));
  51. rotation.mul(tempRotation);
  52. break;
  53. case '-':
  54. tempRotation.setIdentity();
  55. tempRotation.setRotation(new AxisAngle4f(new Vector3f(0, 0, -1), (float) Math.toRadians(angleInDegree + angleOffset)));
  56. rotation.mul(tempRotation);
  57. break;
  58. case '&':
  59. tempRotation.setIdentity();
  60. tempRotation.setRotation(new AxisAngle4f(new Vector3f(0, 1, 0), (float) Math.toRadians(angleInDegree + angleOffset)));
  61. rotation.mul(tempRotation);
  62. break;
  63. case '^':
  64. tempRotation.setIdentity();
  65. tempRotation.setRotation(new AxisAngle4f(new Vector3f(0, -1, 0), (float) Math.toRadians(angleInDegree + angleOffset)));
  66. rotation.mul(tempRotation);
  67. break;
  68. case '*':
  69. tempRotation.setIdentity();
  70. tempRotation.setRotation(new AxisAngle4f(new Vector3f(1, 0, 0), (float) Math.toRadians(angleInDegree)));
  71. rotation.mul(tempRotation);
  72. break;
  73. case '/':
  74. tempRotation.setIdentity();
  75. tempRotation.setRotation(new AxisAngle4f(new Vector3f(-1, 0, 0), (float) Math.toRadians(angleInDegree)));
  76. rotation.mul(tempRotation);
  77. break;
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement