|
|
|
@ -2,6 +2,7 @@ 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 { initBuffers } from "../3D/buffers.js"
|
|
|
|
|
import "../3D/maths/gl-matrix-min.js"
|
|
|
|
|
|
|
|
|
@ -16,7 +17,6 @@ export default class extends AbstractView
|
|
|
|
|
this.gl = null;
|
|
|
|
|
this.shader_prog = null;
|
|
|
|
|
this.buffers = null;
|
|
|
|
|
this.programInfo = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initGL()
|
|
|
|
@ -33,7 +33,7 @@ export default class extends AbstractView
|
|
|
|
|
this.shader_prog = initShaderProgram(this.gl);
|
|
|
|
|
this.buffers = initBuffers(this.gl);
|
|
|
|
|
|
|
|
|
|
this.programInfo = {
|
|
|
|
|
shaderInfos = {
|
|
|
|
|
program: this.shader_prog,
|
|
|
|
|
attribLocations: {
|
|
|
|
|
vertexPosition: this.gl.getAttribLocation(this.shader_prog, "aPos"),
|
|
|
|
@ -90,16 +90,16 @@ export default class extends AbstractView
|
|
|
|
|
this.setPositionAttribute();
|
|
|
|
|
this.setNormalAttribute();
|
|
|
|
|
|
|
|
|
|
this.gl.useProgram(this.programInfo.program);
|
|
|
|
|
this.gl.useProgram(shaderInfos.program);
|
|
|
|
|
|
|
|
|
|
this.gl.uniformMatrix4fv(
|
|
|
|
|
this.programInfo.uniformLocations.projectionMatrix,
|
|
|
|
|
shaderInfos.uniformLocations.projectionMatrix,
|
|
|
|
|
false,
|
|
|
|
|
projectionMatrix
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// rendering player bar
|
|
|
|
|
this.renderCube(0.0, -5.0, -8.0, 0.0, 5);
|
|
|
|
|
//this.game.draw(this.gl);
|
|
|
|
|
//this.renderCube(1, 0, -15);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderCube(x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
|
|
|
@ -130,12 +130,12 @@ export default class extends AbstractView
|
|
|
|
|
mat4.transpose(normalMatrix, normalMatrix);
|
|
|
|
|
|
|
|
|
|
this.gl.uniformMatrix4fv(
|
|
|
|
|
this.programInfo.uniformLocations.modelViewMatrix,
|
|
|
|
|
shaderInfos.uniformLocations.modelViewMatrix,
|
|
|
|
|
false,
|
|
|
|
|
modelViewMatrix
|
|
|
|
|
);
|
|
|
|
|
this.gl.uniformMatrix4fv(
|
|
|
|
|
this.programInfo.uniformLocations.normalMatrix,
|
|
|
|
|
shaderInfos.uniformLocations.normalMatrix,
|
|
|
|
|
false,
|
|
|
|
|
normalMatrix,
|
|
|
|
|
);
|
|
|
|
@ -155,17 +155,17 @@ export default class extends AbstractView
|
|
|
|
|
const offset = 0;
|
|
|
|
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffers.normal);
|
|
|
|
|
this.gl.vertexAttribPointer(
|
|
|
|
|
this.programInfo.attribLocations.vertexNormal,
|
|
|
|
|
shaderInfos.attribLocations.vertexNormal,
|
|
|
|
|
numComponents,
|
|
|
|
|
type,
|
|
|
|
|
normalize,
|
|
|
|
|
stride,
|
|
|
|
|
offset,
|
|
|
|
|
);
|
|
|
|
|
this.gl.enableVertexAttribArray(this.programInfo.attribLocations.vertexNormal);
|
|
|
|
|
this.gl.enableVertexAttribArray(shaderInfos.attribLocations.vertexNormal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPositionAttribute(programInfo)
|
|
|
|
|
setPositionAttribute()
|
|
|
|
|
{
|
|
|
|
|
const numComponents = 3;
|
|
|
|
|
const type = this.gl.FLOAT;
|
|
|
|
@ -175,14 +175,14 @@ export default class extends AbstractView
|
|
|
|
|
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.buffers.vertex);
|
|
|
|
|
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.buffers.index);
|
|
|
|
|
this.gl.vertexAttribPointer(
|
|
|
|
|
this.programInfo.attribLocations.vertexPosition,
|
|
|
|
|
shaderInfos.attribLocations.vertexPosition,
|
|
|
|
|
numComponents,
|
|
|
|
|
type,
|
|
|
|
|
normalize,
|
|
|
|
|
stride,
|
|
|
|
|
offset
|
|
|
|
|
);
|
|
|
|
|
this.gl.enableVertexAttribArray(this.programInfo.attribLocations.vertexPosition);
|
|
|
|
|
this.gl.enableVertexAttribArray(shaderInfos.attribLocations.vertexPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render_game()
|
|
|
|
|