texturecube.pde 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. float rotx = PI/4;
  2. float roty = PI/4;
  3. ArrayList<Block> blocks;
  4. BlockTextures blockTextures;
  5. Character player = new Character();
  6. boolean[] input = new boolean[256];
  7. PVector eyePosition = new PVector();
  8. PVector lookAtPosition = new PVector();
  9. float lastTime = 0.0f;
  10. float time = 0.0f;
  11. PVector windowLocation;
  12. void setup() {
  13. size(640, 360, P3D);
  14. ((PGraphicsOpenGL)g).textureSampling(3);
  15. noSmooth();
  16. hint(DISABLE_TEXTURE_MIPMAPS);
  17. textureMode(NORMAL);
  18. blockTextures = new BlockTextures();
  19. buildWorld();
  20. spawnPlayer();
  21. float fov = PI/3.0;
  22. perspective(fov, float(width)/float(height), 1, 200);
  23. }
  24. void spawnPlayer() {
  25. player.setPosition(-5, 2, 0);
  26. player.look(width/2, 5*height/8);
  27. }
  28. void buildWorld() {
  29. blocks = new ArrayList<Block>();
  30. for (int z = 0; z < 4; z++) {
  31. for (int y = -10; y < 1; y++) {
  32. for (int x = 0; x < 4; x++) {
  33. blocks.add(new Block(16, x * 2, y* 2, z * 2));
  34. }
  35. }
  36. }
  37. for (int z = -10; z < 10; z++) {
  38. for (int x = -10; x < 10; x++) {
  39. blocks.add(new Block(2, x * 2, 2, z * 2));
  40. }
  41. }
  42. }
  43. void update() {
  44. time = millis();
  45. player.move(time - lastTime);
  46. lastTime = time;
  47. }
  48. void draw() {
  49. player.updateCamera();
  50. update();
  51. background(0);
  52. noStroke();
  53. for (Block block : blocks) {
  54. block.draw();
  55. }
  56. }
  57. void mouseMoved() {
  58. player.look(mouseX, mouseY);
  59. }
  60. void mouseDragged() {
  61. player.look(mouseX, mouseY);
  62. }
  63. void keyPressed() {
  64. input[keyCode] = true;
  65. }
  66. void keyReleased() {
  67. input[keyCode] = false;
  68. }