A unit cube whose eight corners are coloured by their own position:
colour (r, g, b) = position (x, y, z) with each coordinate in {0, 1}.
| Corner | Colour | Corner | Colour | |
|---|---|---|---|---|
| (0, 0, 0) | Black | (0, 0, 1) | Blue | |
| (1, 0, 0) | Red | (1, 0, 1) | Magenta (red + blue) | |
| (1, 1, 0) | Yellow (red + green) | (1, 1, 1) | White (red + green + blue) | |
| (0, 1, 0) | Green | (0, 1, 1) | Cyan (green + blue) |
Press M or Space to cycle four viewing modes:
Notes: black corners blend into the dark background, and a greyscale ramp has no
single background tone that keeps both ends visible; the dark background favours
the coloured end of every ramp. In mode 4 the hue hexagon is slightly irregular
because the projection is perspective — an orthographic projection down the
diagonal would give a perfectly regular hexagon.
Two optional extensions to the corner-on hexagon view are stubbed in
matrix.mjs and wired into main.mjs behind flags (both default off, so the app
runs unchanged until you switch one on). Suggested order:
ortho(...) — orthographic projection (EXERCISE 1, no trig). Fill in theORTHOGRAPHIC_HEXAGON = truemain.mjs. Payoff: the hue hexagon becomes perfectly regularrotationAxis(axis, rad) — Rodrigues rotation (EXERCISE 2). Fill in theSPIN_HUE_WHEEL = true. Payoff: the cuberotationAxis([1,0,0], t)rotationX(t), and rotationAxis([0,1,0], t) should equalrotationY(t).Turning a flag on before its function is implemented throws a clear error
naming the exercise; press M to cycle back to a working mode.
const / let only — no var.main.mjs, cube.mjs, gl-utils.mjs, matrix.mjs), loaded via<script type="module">..glsl files, fetched with async / await.matrix.mjs supplies the mat4 helpers,perspective and lookAt.Cube never touches the DOM; the controllerin / out, #version 300 es).ES modules and fetch do not work from file://, so the folder is served
with Vite. This folder depends on files from the
CS315StarterPack
Then, it is assumed that you have unpacked and configured that folder as a Vite project. Lab Setup instructions located here
You can then use
npm run dev
Open the printed URL (e.g. http://localhost:5173) to view the page.
It is possible to publish this folder to run as a standalone using:
npm run build
By modifying the entry point of the application in vite.config.js to point the index.html file of this folder as described here: https://vite.dev/config/shared-options#input
eg.:
input: {
ColourCube: resolve(import.meta.dirname, 'ColourCube_for_StarterPack/index.html'),
}
Multiple entry points are possible and all existing points will be published as static, optimised HTML, CSS and Javascript to the dist folder on build. Any external assets such as glsl files, textures, or 3D models, and their folder structures will need to be copied manually. The resulting folders can then be moved to a web accessible location to be published with no more need for Vite (eg. move dist to php_web to be viewed via www.webdev.cs.uregina.ca ).
However, since student webpages are not located at web root, the optimized javascript must be found relative to the html instead of from web root. ie: Change script path from:
<script type="module" crossorigin src="/assets/ColourCube-randomstring.js"></script>
to
<script type="module" crossorigin src="../assets/ColourCube-randomstring.js"></script>
index.html canvas, caption overlay, module entry point
main.mjs controller: GL context, shader loading, render loop, modes, cameras
cube.mjs Cube class (DOM-free renderer; solid + edges + diagonal)
matrix.mjs minimal column-major mat4 helpers (perspective, lookAt, ...)
shaders/
cube.vert.glsl vertex shader (GLSL ES 3.00)
cube.frag.glsl fragment shader (GLSL ES 3.00)