Formatting

This commit is contained in:
Julian Brammer 2023-11-30 22:37:29 +01:00
parent 7502ab9cdb
commit 27408aeed3
3 changed files with 9 additions and 50 deletions

View File

@ -1,10 +1,6 @@
class Object3D { class Object3D {
// DONE: Füge Default-Materialkoeffizienten hinzu // DONE: Füge Default-Materialkoeffizienten hinzu
constructor( constructor(ka = [0.5, 0.5, 0.5], kd = [0.5, 0.5, 0.5], ks = [0.5, 0.5, 0.5]) {
ka = [0.5, 0.5, 0.5],
kd = [0.5, 0.5, 0.5],
ks = [0.5, 0.5, 0.5]
) {
this.posVBO = gl.createBuffer(); this.posVBO = gl.createBuffer();
// DONE: Kein colorVBO mehr! (Farben werden über Materialkoeffizienten bestimmt) // DONE: Kein colorVBO mehr! (Farben werden über Materialkoeffizienten bestimmt)
this.indexVBO = gl.createBuffer(); this.indexVBO = gl.createBuffer();
@ -27,25 +23,13 @@ class Object3D {
InitBuffers() { InitBuffers() {
gl.bindBuffer(gl.ARRAY_BUFFER, this.posVBO); gl.bindBuffer(gl.ARRAY_BUFFER, this.posVBO);
gl.bufferData( gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(this.positions), gl.STATIC_DRAW);
gl.ARRAY_BUFFER,
new Float32Array(this.positions),
gl.STATIC_DRAW
);
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexVBO); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexVBO);
gl.bufferData( gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(this.indices), gl.STATIC_DRAW);
gl.ELEMENT_ARRAY_BUFFER,
new Uint16Array(this.indices),
gl.STATIC_DRAW
);
} }
SetModelMatrix( SetModelMatrix(position = this.position, orientation = this.orientation, scale = this.scale) {
position = this.position,
orientation = this.orientation,
scale = this.scale
) {
this.position = position; this.position = position;
this.orientation = [ this.orientation = [
(orientation[0] * Math.PI) / 180, (orientation[0] * Math.PI) / 180,
@ -56,24 +40,9 @@ class Object3D {
this.modelMatrix = mat4.create(); this.modelMatrix = mat4.create();
mat4.translate(this.modelMatrix, this.modelMatrix, position); mat4.translate(this.modelMatrix, this.modelMatrix, position);
mat4.rotate( mat4.rotate(this.modelMatrix, this.modelMatrix, this.orientation[0], [1, 0, 0]);
this.modelMatrix, mat4.rotate(this.modelMatrix, this.modelMatrix, this.orientation[1], [0, 1, 0]);
this.modelMatrix, mat4.rotate(this.modelMatrix, this.modelMatrix, this.orientation[2], [0, 0, 1]);
this.orientation[0],
[1, 0, 0]
);
mat4.rotate(
this.modelMatrix,
this.modelMatrix,
this.orientation[1],
[0, 1, 0]
);
mat4.rotate(
this.modelMatrix,
this.modelMatrix,
this.orientation[2],
[0, 0, 1]
);
mat4.scale(this.modelMatrix, this.modelMatrix, scale); mat4.scale(this.modelMatrix, this.modelMatrix, scale);
} }

View File

@ -82,9 +82,7 @@
<body> <body>
<h1>Lorem Ipsum</h1> <h1>Lorem Ipsum</h1>
<canvas id="gl-canvas" width="1024" height="512"> <canvas id="gl-canvas" width="1024" height="512"> If you see this, your browser doesn't support WebGL. </canvas>
If you see this, your browser doesn't support WebGL.
</canvas>
<script src="main.js" type="text/javascript"></script> <script src="main.js" type="text/javascript"></script>
</body> </body>

View File

@ -6,15 +6,7 @@ let objects = [];
let posLoc; let posLoc;
// DONE: Deklariere benötigte Locations von Shadervariablen als globale Variablen // DONE: Deklariere benötigte Locations von Shadervariablen als globale Variablen
let normalLoc, let normalLoc, lightPositionLoc, IaLoc, IdLoc, IsLoc, kaLoc, kdLoc, ksLoc, specularExponentLoc;
lightPositionLoc,
IaLoc,
IdLoc,
IsLoc,
kaLoc,
kdLoc,
ksLoc,
specularExponentLoc;
let modelMatrixLoc; let modelMatrixLoc;