wat
This commit is contained in:
@ -27,16 +27,8 @@ function renderCube(ctx, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
|
||||
mat4.invert(normalMatrix, modelMatrix);
|
||||
mat4.transpose(normalMatrix, normalMatrix);
|
||||
|
||||
ctx.uniformMatrix4fv(
|
||||
shaderInfos.uniformLocations.modelMatrix,
|
||||
false,
|
||||
modelMatrix
|
||||
);
|
||||
ctx.uniformMatrix4fv(
|
||||
shaderInfos.uniformLocations.normalMatrix,
|
||||
false,
|
||||
normalMatrix,
|
||||
);
|
||||
ctx.uniformMatrix4fv(shaderInfos.uniformLocations.modelMatrix, false, modelMatrix);
|
||||
ctx.uniformMatrix4fv(shaderInfos.uniformLocations.normalMatrix, false, normalMatrix);
|
||||
|
||||
ctx.drawElements(ctx.TRIANGLES, 36, ctx.UNSIGNED_SHORT, 0);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Game } from "./Game.js";
|
||||
import { Point } from "./Point.js";
|
||||
|
||||
import { renderCube } from "../../3D/cube.js"
|
||||
|
||||
class Ball
|
||||
{
|
||||
@ -46,7 +46,19 @@ class Ball
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
ctx.rect(this.position.x - this.size / 2, this.position.y - this.size / 2, this.size, this.size);
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
ctx.rect(this.position.x - this.size / 2, this.position.y - this.size / 2, this.size, this.size);
|
||||
}
|
||||
else if(ctx instanceof WebGLRenderingContext)
|
||||
{
|
||||
console.log((this.position.x - this.size / 2) / 10, 0, (this.position.y - this.size / 2) / 10)
|
||||
renderCube(ctx, (this.position.x - this.size / 2) / 10, 0, (this.position.y - this.size / 2) / 10, 0, this.size * 10, this.size * 10, this.size * 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Unknown rendering context type');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Game } from "./Game.js";
|
||||
import { Point } from "./Point.js";
|
||||
import { Segment } from "./Segment.js";
|
||||
import { renderCube } from "../../3D/cube.js"
|
||||
|
||||
class Player
|
||||
{
|
||||
@ -61,8 +62,11 @@ class Player
|
||||
{
|
||||
if (this.is_connected === false)
|
||||
{
|
||||
ctx.moveTo(this.rail.start.x, this.rail.start.y);
|
||||
ctx.lineTo(this.rail.stop.x, this.rail.stop.y);
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
ctx.moveTo(this.rail.start.x, this.rail.start.y);
|
||||
ctx.lineTo(this.rail.stop.x, this.rail.stop.y);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -17,8 +17,8 @@ export default class extends AbstractView
|
||||
this.gl = null;
|
||||
this.shader_prog = null;
|
||||
this.buffers = null;
|
||||
this.cam_pos = [0, 100, 0];
|
||||
this.cam_target = [4, 0, 4];
|
||||
this.cam_pos = [0, 500, 0];
|
||||
this.cam_target = [0, 0, 35];
|
||||
}
|
||||
|
||||
initGL()
|
||||
@ -71,7 +71,7 @@ export default class extends AbstractView
|
||||
const projectionMatrix = mat4.create();
|
||||
const viewMatrix = mat4.create();
|
||||
|
||||
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, 10000000.0);
|
||||
mat4.lookAt(viewMatrix, this.cam_pos, this.cam_target, [0, 1, 0]);
|
||||
|
||||
this.setPositionAttribute();
|
||||
@ -82,7 +82,7 @@ export default class extends AbstractView
|
||||
this.gl.uniformMatrix4fv(shaderInfos.uniformLocations.projectionMatrix, false, projectionMatrix);
|
||||
this.gl.uniformMatrix4fv(shaderInfos.uniformLocations.viewMatrix, false, viewMatrix);
|
||||
|
||||
this.game.draw(this.gl);
|
||||
this.game.render(this.gl);
|
||||
}
|
||||
|
||||
setNormalAttribute()
|
||||
|
Reference in New Issue
Block a user