From 5636643595e36f42bae49a2f15493c7538d69138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Mon, 9 May 2022 22:50:43 +0200 Subject: [PATCH] feat: some changes from before vac --- DepthBuffer.java | 6 ++++++ GraphicsWrapper.java | 2 +- Renderer.java | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/DepthBuffer.java b/DepthBuffer.java index ed022a7..1a12d52 100644 --- a/DepthBuffer.java +++ b/DepthBuffer.java @@ -27,6 +27,7 @@ public class DepthBuffer { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { buffer[i * width + j] = Double.POSITIVE_INFINITY; + // buffer[i * width + j] = 0; } } @@ -44,6 +45,11 @@ public class DepthBuffer { return true; } + // if (fragment.getDepth() > this.buffer[fragment.getY() * width + + // fragment.getX()]) { + // return true; + // } + return false; } else { return false; diff --git a/GraphicsWrapper.java b/GraphicsWrapper.java index bbb31ab..0186b6b 100644 --- a/GraphicsWrapper.java +++ b/GraphicsWrapper.java @@ -65,7 +65,7 @@ public class GraphicsWrapper { drawComp.setPreferredSize(new Dimension(width * pixelSize, height * pixelSize)); drawComp.setVisible(true); - myFrame = new JFrame("Simple Inverse Rasterization Renderer (TSI)"); + myFrame = new JFrame("TP_RENDU1"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myFrame.add("Center", drawComp); myFrame.pack(); diff --git a/Renderer.java b/Renderer.java index 6742851..4544aca 100644 --- a/Renderer.java +++ b/Renderer.java @@ -20,7 +20,7 @@ public class Renderer { static Lighting lighting; static boolean lightingEnabled; static boolean Thong; - static boolean repaint; + static boolean repaint = false; static void init(String sceneFilename) throws Exception { scene = new Scene(sceneFilename); @@ -157,6 +157,14 @@ public class Renderer { } } + public static void wait(double sec) { + try { + Thread.sleep((int) (sec * 1000)); + } catch (Exception e) { + /* nothing */ + } + } + public static void waitKey() { Scanner s = new Scanner(System.in); s.nextLine(); @@ -222,6 +230,26 @@ public class Renderer { // wait(3); waitKey(); + /* solid rendering, with lighting and rotation */ + int nbRots = 100; + double radius = 7; + double angle; + setLightingEnabled(true); + for (int i = 0; i < nbRots; i++) { + angle = 2 * Math.PI / nbRots * i + Math.PI / 4; + System.out.println("solid rendering, with lighting, rotation=" + angle); + scene.cameraPosition.set(0, radius * Math.cos(angle)); + scene.cameraPosition.set(2, radius * Math.sin(angle)); + xform.setLookAt(scene.getCameraPosition(), scene.getCameraLookAt(), scene.getCameraUp()); + shader.reset(); + screen.clearBuffer(); + renderSolid(); + screen.swapBuffers(); + wait(0.016); + // waitKey(); + } + waitKey(); + /* solid rendering, with lighting Thong */ System.out.println("solid rendering, with lighting Thong"); screen.clearBuffer();