37 lines
738 B
JavaScript
37 lines
738 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();
|
|
|
|
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 };
|