42_ft_transcendence/frontend/static/js/3D/cube.js
2024-03-31 10:59:39 +02:00

47 lines
779 B
JavaScript

import { shaderInfos } from "../3D/shaders.js"
function renderCube(ctx, x, y, z, angle = 0, sx = 1, sy = 1, sz = 1)
{
const modelMatrix = mat4.create();
console.log("test")
mat4.translate(
modelMatrix,
modelMatrix,
[x, y, z]
);
mat4.rotate(
modelMatrix,
modelMatrix,
angle,
[0, 1, 1],
);
mat4.scale(
modelMatrix,
modelMatrix,
[sx, sy, sz]
);
const normalMatrix = mat4.create();
mat4.invert(normalMatrix, modelMatrix);
mat4.transpose(normalMatrix, normalMatrix);
ctx.uniformMatrix4fv(
shaderInfos.uniformLocations.modelMatrix,
false,
modelMatrix
);
ctx.uniformMatrix4fv(
shaderInfos.uniformLocations.normalMatrix,
false,
normalMatrix,
);
ctx.drawElements(ctx.TRIANGLES, 36, ctx.UNSIGNED_SHORT, 0);
}
export { renderCube };