I’ve tried everything.
How to make an isometric cube render in the NW direction.
Considering that width is the length, height is the height, depth is the width.
I tried this, but it doesn’t work:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Render Cube4</title>
<style>
canvas {
border: 1px solid black;
display: block;
margin: 20px auto;
}
</style>
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<script>
function render_cube4(entity, ctx) {
ctx.strokeStyle = "#d17a26";
ctx.fillStyle = "rgba(32, 32, 32, 0.4)";
ctx.beginPath();
ctx.moveTo(-entity.width / 2, entity.height / 2 - entity.z);
ctx.lineTo(0, -entity.height / 2 - entity.z);
ctx.lineTo(entity.width / 2, entity.height / 2 - entity.z);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = "rgba(16, 16, 16, 0.32)";
ctx.beginPath();
ctx.moveTo(0, -entity.height / 2 - entity.z);
ctx.lineTo(entity.width / 2, entity.height / 2 - entity.z);
ctx.lineTo(entity.width / 2, -entity.height / 2 - entity.z - entity.depth);
ctx.lineTo(0, -entity.height / 2 - entity.z - entity.depth);
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = "rgba(0, 0, 0, 0.4)";
ctx.beginPath();
ctx.moveTo(-entity.width / 2, entity.height / 2 - entity.z);
ctx.lineTo(0, -entity.height / 2 - entity.z);
ctx.lineTo(-entity.width / 2, -entity.height / 2 - entity.z - entity.depth);
ctx.lineTo(0, -entity.height / 2 - entity.z - entity.depth);
ctx.closePath();
ctx.fill();
ctx.stroke();
}
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const entity = {
width: 100,
height: 100,
depth: 10,
z: 50
};
ctx.translate(canvas.width / 2, canvas.height / 2);
render_cube4(entity, ctx);
</script>
</body>
</html>
I’m already tired and confused! Help me out, guys!
I need to get: