aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft/render/jogl/DefaultRenderer.java
blob: 12c12e057ec06393a18f25f38fa8568f6cef872d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ru.olamedia.olacraft.render.jogl;

import com.jogamp.newt.event.KeyEvent;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.glu.GLU;

import ru.olamedia.input.KeyListener;
import ru.olamedia.input.Keyboard;
import ru.olamedia.input.MouseJail;
import ru.olamedia.input.MouseListener;
import ru.olamedia.olacraft.game.Game;

public class DefaultRenderer implements IRenderer, KeyListener, MouseListener {
	private boolean isHUDEnabled = true;
	GLU glu = new GLU();
	// private static Color BLACK_TRANSPARENT = new Color(0, 0, 0, 0);
	long lastHUD = System.nanoTime();

	public DefaultRenderer() {
		Keyboard.attach(this);
		MouseJail.attach(this);
	}

	@Override
	public void render(GLAutoDrawable drawable) {
		Game.client.getScene().tick();
		Game.client.getScene().render(drawable);
	}

	@Override
	public void onKeyPressed(String name, KeyEvent e) {

	}

	@Override
	public void onKeyReleased(String name, KeyEvent e) {
		// System.out.println(name);
		if (name == "toggleHUD") {
			isHUDEnabled = !isHUDEnabled;
		}
		if (name == "captureMouse") {
			MouseJail.setActive(true);
		}
		if (name == "releaseMouse") {
			MouseJail.setActive(false);
		}
		if (name == "toggleFrustum") {
			Game.instance.camera.isFrustumVisible = !Game.instance.camera.isFrustumVisible;
		}
		if (name == "toggleRenderDistance") {
			int renderDistance = Game.client.getScene().getRenderDistance();
			renderDistance *= 2;
			if (renderDistance > 256) {
				renderDistance = 32;
			}
			Game.client.getScene().setRenderDistance(renderDistance);
		}
	}

	@Override
	public void onMouseMove(float dx, float dy) {
		Game.instance.camera.mouseMoved(dx, dy);
	}

	@Override
	public void onMouseClick() {
		Game.instance.player.onMouseClick();
	}

	@Override
	public void init(GLAutoDrawable drawable) {
		
	}
}