From 2b735340cacfd491b15385b6d2c8811a7ad3e4b7 Mon Sep 17 00:00:00 2001 From: Brulijam Date: Tue, 28 Nov 2023 01:40:26 +0100 Subject: [PATCH] Implemented looking around horizontally; Randomized colors for Objects --- Abgabe_3/common/objects3D.js | 28 +++++++++++++++---- Abgabe_3/index.html | 6 ++--- Abgabe_3/main.js | 52 +++++++++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/Abgabe_3/common/objects3D.js b/Abgabe_3/common/objects3D.js index ebd4e4e..224c757 100644 --- a/Abgabe_3/common/objects3D.js +++ b/Abgabe_3/common/objects3D.js @@ -17,6 +17,10 @@ class Object3D this.SetModelMatrix(); } + getRandomFloat(min, max) { + return Math.random() * (max-min) + min; + } + initBuffers() { // Create VBO for positions and activate it @@ -356,7 +360,11 @@ class Insel extends Object3D this.colors = []; for(var i = 0; i < this.positions.length; i += 3) { - this.colors.push(0.5, 0.5, 0.5, 1); + let r = this.getRandomFloat(0.4, 0.7); + let g = this.getRandomFloat(0.4, 0.6); + let b = this.getRandomFloat(0.4, 0.45); + + this.colors.push(r, g, b, 1); } this.initBuffers(); @@ -415,7 +423,11 @@ class River extends Object3D this.colors = []; for(var i = 0; i < this.positions.length; i += 3) { - this.colors.push(0.2, 0.2, 0.8, 1); + let r = this.getRandomFloat(0.1, 0.2); + let g = this.getRandomFloat(0.2, 0.6); + let b = this.getRandomFloat(0.6, 0.7); + + this.colors.push(r, g, b, 1); } this.initBuffers(); @@ -716,7 +728,11 @@ class Tree extends Object3D this.colors = []; for(var i = 0; i < this.positions.length; i += 3) { - this.colors.push(0.2, 0.5, 0.0, 1.0); + let r = this.getRandomFloat(0.3, 0.4); + let g = this.getRandomFloat(0.4, 0.6); + let b = this.getRandomFloat(0.1, 0.2); + + this.colors.push(r, g, b, 1); } this.initBuffers(); @@ -860,9 +876,11 @@ class Cloud extends Object3D this.colors = []; for(var i = 0; i < this.positions.length; i += 3) { - this.colors.push(0.9, 0.9, 0.9, 1); + let gray = this.getRandomFloat(0.8, 0.9); + + this.colors.push(gray, gray, gray, 1); } this.initBuffers(); } -} \ No newline at end of file +} diff --git a/Abgabe_3/index.html b/Abgabe_3/index.html index 444f65a..679f430 100644 --- a/Abgabe_3/index.html +++ b/Abgabe_3/index.html @@ -19,16 +19,14 @@ 0, 0, -1.0100502967834473, -1, 0, 0, -1.0050251483917236, 0); - vfColor = vColor; gl_Position = projectionMatrix * viewMatrix * modelMatrix * vPosition; //projectionMatrix eig auch - }