12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- float rotx = PI/4;
- float roty = PI/4;
- ArrayList<Block> blocks;
- BlockTextures blockTextures;
- Character player = new Character();
- boolean[] input = new boolean[256];
- PVector eyePosition = new PVector();
- PVector lookAtPosition = new PVector();
- float lastTime = 0.0f;
- float time = 0.0f;
- PVector windowLocation;
- void setup() {
- size(640, 360, P3D);
- ((PGraphicsOpenGL)g).textureSampling(3);
- noSmooth();
- hint(DISABLE_TEXTURE_MIPMAPS);
- textureMode(NORMAL);
- blockTextures = new BlockTextures();
- buildWorld();
- spawnPlayer();
- float fov = PI/3.0;
- perspective(fov, float(width)/float(height), 1, 200);
- }
- void spawnPlayer() {
- player.setPosition(-5, 2, 0);
- player.look(width/2, 5*height/8);
- }
- void buildWorld() {
- blocks = new ArrayList<Block>();
- for (int z = 0; z < 4; z++) {
- for (int y = -10; y < 1; y++) {
- for (int x = 0; x < 4; x++) {
- blocks.add(new Block(16, x * 2, y* 2, z * 2));
- }
- }
- }
- for (int z = -10; z < 10; z++) {
- for (int x = -10; x < 10; x++) {
- blocks.add(new Block(2, x * 2, 2, z * 2));
- }
- }
- }
- void update() {
- time = millis();
- player.move(time - lastTime);
- lastTime = time;
- }
- void draw() {
- player.updateCamera();
- update();
- background(0);
- noStroke();
- for (Block block : blocks) {
- block.draw();
- }
- }
- void mouseMoved() {
- player.look(mouseX, mouseY);
- }
- void mouseDragged() {
- player.look(mouseX, mouseY);
- }
- void keyPressed() {
- input[keyCode] = true;
- }
- void keyReleased() {
- input[keyCode] = false;
- }
|