Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameScreen(ArcaneArts game){
- this.game = game;
- stage = new Stage();
- font = game.getFont(10, "FantaisieArtistique");
- label = new Label(" ", new Label.LabelStyle(font, Color.BLACK));
- stage.addActor(label);
- strBuilder = new StringBuilder();
- modelBatch = new ModelBatch();
- camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- camera.position.set(10f, 10f, 10f);
- camera.lookAt(0,0,0);
- camera.near = 1f;
- camera.far = 300f;
- camera.update();
- environment = new Environment();
- environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
- environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
- camController = new CameraInputController(camera);
- Gdx.input.setInputProcessor(camController);
- //Load 3d scene
- Model sceneModel = game.assetManager.get("3d/boxes.g3db", Model.class);
- for (int i = 0; i<sceneModel.nodes.size; i++){
- String id = sceneModel.nodes.get(i).id;
- GameObject instance = new GameObject(sceneModel, id, true);
- ColorAttribute attr = ColorAttribute.createDiffuse(MathUtils.random(), MathUtils.random(), MathUtils.random(), MathUtils.random());
- instance.materials.get(0).set(attr);
- instances.add(instance);
- }
- shader = new TestShader();
- shader.init();
- }
- private int visibleCount;
- @Override
- public void render(float delta) {
- camController.update();
- Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- Gdx.gl.glClearColor(.5f, .5f, .5f, 1f);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
- visibleCount = 0;
- modelBatch.begin(camera);
- for (GameObject instance : instances)
- if (isVisible(camera, instance)){
- modelBatch.render(instance, shader);
- visibleCount++;
- }
- modelBatch.end();
- if (running)
- gameLogic(delta);
- strBuilder.setLength(0);
- strBuilder.append(" FPS ").append(Gdx.graphics.getFramesPerSecond())
- .append(" Visible: ").append(visibleCount);
- label.setText(strBuilder);
- stage.draw();
- }
- private Vector3 position = new Vector3();
- private boolean isVisible(final Camera camera, final GameObject instance){
- instance.transform.getTranslation(position);
- position.add(instance.center);
- System.out.println(instance.radius);
- return camera.frustum.sphereInFrustum(position, instance.radius);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement