AAAAAAAAAAAAAAAAAAAAAAAAH
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { client } from "../index.js";
|
||||
import { Game } from "../api/game/Game.js";
|
||||
import AbstractView from "./abstracts/AbstractView.js";
|
||||
import { initShaderProgram } from "../3D/shaders.js"
|
||||
import shaderInfos from "../3D/shaders.js"
|
||||
import { initShaderProgram, shaderInfos } from "../3D/shaders.js"
|
||||
import { initBuffers } from "../3D/buffers.js"
|
||||
import "../3D/maths/gl-matrix-min.js"
|
||||
import { renderCube } from "../3D/cube.js"
|
||||
|
||||
export default class extends AbstractView
|
||||
{
|
||||
@ -17,6 +17,8 @@ export default class extends AbstractView
|
||||
this.gl = null;
|
||||
this.shader_prog = null;
|
||||
this.buffers = null;
|
||||
this.cam_pos = [0, 10, 0];
|
||||
this.cam_target = [0, 0, 0];
|
||||
}
|
||||
|
||||
initGL()
|
||||
@ -33,19 +35,6 @@ export default class extends AbstractView
|
||||
this.shader_prog = initShaderProgram(this.gl);
|
||||
this.buffers = initBuffers(this.gl);
|
||||
|
||||
shaderInfos = {
|
||||
program: this.shader_prog,
|
||||
attribLocations: {
|
||||
vertexPosition: this.gl.getAttribLocation(this.shader_prog, "aPos"),
|
||||
vertexNormal: this.gl.getAttribLocation(this.shader_prog, "aNormal"),
|
||||
},
|
||||
uniformLocations: {
|
||||
projectionMatrix: this.gl.getUniformLocation(this.shader_prog, "uProj"),
|
||||
modelViewMatrix: this.gl.getUniformLocation(this.shader_prog, "uModView"),
|
||||
normalMatrix: this.gl.getUniformLocation(this.shader_prog, "uNormalMat"),
|
||||
},
|
||||
};
|
||||
|
||||
this.gl.enable(this.gl.CULL_FACE);
|
||||
this.gl.cullFace(this.gl.BACK);
|
||||
}
|
||||
@ -84,8 +73,10 @@ export default class extends AbstractView
|
||||
const zNear = 0.1;
|
||||
const zFar = 100.0;
|
||||
const projectionMatrix = mat4.create();
|
||||
const viewMatrix = mat4.create();
|
||||
|
||||
mat4.perspective(projectionMatrix, fieldOfView, aspect, zNear, zFar);
|
||||
mat4.lookAt(viewMatrix, this.cam_pos, this.cam_target, [0, 1, 0]);
|
||||
|
||||
this.setPositionAttribute();
|
||||
this.setNormalAttribute();
|
||||
@ -98,52 +89,14 @@ export default class extends AbstractView
|
||||
projectionMatrix
|
||||
);
|
||||
|
||||
//this.game.draw(this.gl);
|
||||
//this.renderCube(1, 0, -15);
|
||||
}
|
||||
|
||||
renderCube(x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||
{
|
||||
const modelViewMatrix = mat4.create();
|
||||
|
||||
mat4.translate(
|
||||
modelViewMatrix,
|
||||
modelViewMatrix,
|
||||
[x, y, z]
|
||||
);
|
||||
|
||||
mat4.rotate(
|
||||
modelViewMatrix,
|
||||
modelViewMatrix,
|
||||
angle,
|
||||
[0, 1, 1],
|
||||
);
|
||||
|
||||
mat4.scale(
|
||||
modelViewMatrix,
|
||||
modelViewMatrix,
|
||||
[sx, sy, sz]
|
||||
);
|
||||
|
||||
const normalMatrix = mat4.create();
|
||||
mat4.invert(normalMatrix, modelViewMatrix);
|
||||
mat4.transpose(normalMatrix, normalMatrix);
|
||||
|
||||
this.gl.uniformMatrix4fv(
|
||||
shaderInfos.uniformLocations.modelViewMatrix,
|
||||
shaderInfos.uniformLocations.viewMatrix,
|
||||
false,
|
||||
modelViewMatrix
|
||||
);
|
||||
this.gl.uniformMatrix4fv(
|
||||
shaderInfos.uniformLocations.normalMatrix,
|
||||
false,
|
||||
normalMatrix,
|
||||
viewMatrix
|
||||
);
|
||||
|
||||
const vertexCount = 36;
|
||||
const type = this.gl.UNSIGNED_SHORT;
|
||||
const offset = 0;
|
||||
this.gl.drawElements(this.gl.TRIANGLES, vertexCount, type, offset);
|
||||
this.game.draw(this.gl);
|
||||
renderCube(this.gl, 0, 0, 0);
|
||||
}
|
||||
|
||||
setNormalAttribute()
|
||||
|
Reference in New Issue
Block a user