working camera support

This commit is contained in:
Kbz-8 2024-02-14 18:48:35 +01:00 committed by AdrienLSH
parent 3729beec1e
commit f1f6cc939a
3 changed files with 7 additions and 21 deletions

View File

@ -4,8 +4,6 @@ function renderCube(ctx, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
{ {
const modelMatrix = mat4.create(); const modelMatrix = mat4.create();
console.log("test")
mat4.translate( mat4.translate(
modelMatrix, modelMatrix,
modelMatrix, modelMatrix,

View File

@ -52,7 +52,7 @@ class Ball
} }
else if(ctx instanceof WebGLRenderingContext) else if(ctx instanceof WebGLRenderingContext)
{ {
renderCube(ctx, this.position_x, 0, this.position_y, 0, this.game.config.ball_size, this.game.config.ball_size, this.game.config.ball_size); renderCube(ctx, this.position_x / 1000, 0, this.position_y / 1000, 0, this.game.config.ball_size, this.game.config.ball_size, this.game.config.ball_size);
} }
else else
{ {

View File

@ -17,8 +17,8 @@ export default class extends AbstractView
this.gl = null; this.gl = null;
this.shader_prog = null; this.shader_prog = null;
this.buffers = null; this.buffers = null;
this.cam_pos = [0, 1, 0]; this.cam_pos = [0, 100, 0];
this.cam_target = [0, 0, 0]; this.cam_target = [4, 0, 4];
} }
initGL() initGL()
@ -62,7 +62,7 @@ export default class extends AbstractView
if(canvas === null) if(canvas === null)
return 1; return 1;
this.gl.clearColor(0.0, 0.0, 0.0, 1.0); this.gl.clearColor(0.1, 0.1, 0.1, 1.0);
this.gl.clearDepth(1.0); this.gl.clearDepth(1.0);
this.gl.enable(this.gl.DEPTH_TEST); this.gl.enable(this.gl.DEPTH_TEST);
this.gl.depthFunc(this.gl.LEQUAL); this.gl.depthFunc(this.gl.LEQUAL);
@ -74,27 +74,15 @@ export default class extends AbstractView
mat4.perspective(projectionMatrix, (90 * Math.PI) / 180, this.gl.canvas.clientWidth / this.gl.canvas.clientHeight, 0.1, 1000.0); mat4.perspective(projectionMatrix, (90 * Math.PI) / 180, this.gl.canvas.clientWidth / this.gl.canvas.clientHeight, 0.1, 1000.0);
mat4.lookAt(viewMatrix, this.cam_pos, this.cam_target, [0, 1, 0]); mat4.lookAt(viewMatrix, this.cam_pos, this.cam_target, [0, 1, 0]);
mat4.invert(viewMatrix, viewMatrix);
this.setPositionAttribute(); this.setPositionAttribute();
this.setNormalAttribute(); this.setNormalAttribute();
this.gl.useProgram(shaderInfos.program); this.gl.useProgram(shaderInfos.program);
this.gl.uniformMatrix4fv( this.gl.uniformMatrix4fv(shaderInfos.uniformLocations.projectionMatrix, false, projectionMatrix);
shaderInfos.uniformLocations.projectionMatrix, this.gl.uniformMatrix4fv(shaderInfos.uniformLocations.viewMatrix, false, viewMatrix);
false,
projectionMatrix
);
this.gl.uniformMatrix4fv( this.game.draw(this.gl);
shaderInfos.uniformLocations.viewMatrix,
false,
viewMatrix
);
renderCube(this.gl, -2, -3, -10, 0, 5);
//this.game.draw(this.gl);
} }
setNormalAttribute() setNormalAttribute()