diff --git a/example/index.js b/example/index.js index dd4837f..eb5c9b2 100644 --- a/example/index.js +++ b/example/index.js @@ -1,6 +1,14 @@ const lib = require('textvox3d'); -function caliblrateViewportDimensions(camera, d, cubeSize) { +/** + * Calculate viewport dimensions. + * + * @param {object} camera - The camera object. + * @param {number} d - Distance. + * @param {number} cubeSize - The size of the cube. + * @return {object} - Object containing the width and height of the viewport. + */ +function calibrateViewportDimensions(camera, d, cubeSize) { const focalLength = camera.fl; const viewportHeight = 2 * cubeSize; const viewportWidth = (viewportHeight * d) / focalLength; @@ -10,31 +18,37 @@ function caliblrateViewportDimensions(camera, d, cubeSize) { const f = 0; const camera = new lib.camera(55, 10, [7, -7, 5], [64, 0, 47]); -const viewport = new lib.viewport(process.stdout.columns, process.stdout.rows-1); +const viewport = new lib.viewport(process.stdout.columns, process.stdout.rows - 1); const cubeMesh = lib.getMesh('cube'); -const cube = new lib.item(cubeMesh, [0, 0, 0]/* pos*/, [0, 0, 0]/* rot*/, [2, 2, 2]/* scale*/); +const cube = new lib.item(cubeMesh, [0, 0, 0]/* pos */, [0, 0, 0]/* rot */, [2, 2, 2]/* scale */); // console.log(`Cube mesh: points: ${cubeMesh.points}, edges: ${cubeMesh.edges}`); // console.log(`Columns: ${process.stdout.columns}, Rows: ${process.stdout.rows}`); +/** + * Function to test the viewport. + */ function viewportTest() { - let i=0; - while (i 0) { @@ -6,21 +13,28 @@ exports.repeatStringNumTimes = function repeatStringNumTimes(string, times) { } return repeatedString; }; -exports.mesh = class mesh { +/** + * A class for generating a mesh + * + * @param {Array>} points - A list of all the points + * @param {Array>} edges - A list of all the edges + * @param {Array>} faces - A list of all the faces + */ +exports.Mesh = class Mesh { constructor(points, edges, faces) { this.points = points; this.edges = edges; this.faces = faces; } }; -exports.item = class item { +exports.GameObject = class GameObject { constructor(mesh, pos, rot) { this.mesh = mesh; this.pos = pos; this.rot = rot; } }; -exports.camera = class camera { +exports.Camera = class Camera { constructor(fov, samples, pos, rot) { this.fov = fov; this.samples = samples; @@ -28,13 +42,13 @@ exports.camera = class camera { this.rot = rot; } }; -exports.viewport = class viewport { +exports.Viewport = class Viewport { constructor(width, height) { this.width = width; this.height = height; } }; -exports.getMesh = function getMesh(meshName) { +exports.GetMesh = function getMesh(meshName) { switch (meshName) { case 'cube': return {'points': [[1, 1, 1], [-1, 1, 1], [-1, -1, 1], [1, -1, 1], [1, -1, -1], [1, 1, -1], [-1, -1, -1], [-1, 1, -1]], 'edges': [[0, 1], [0, 5], [0, 3], [1, 2], [1, 7], [2, 3], [2, 6], [3, 4], [4, 5], [4, 6], [5, 7], [7, 6]], 'faces': [[1, 3, 5, 2], [2, 8, 3, 7], [7, 5, 9, 6], [0, 4, 1, 10], [3, 4, 6, 11]]};