Skip to content

Commit

Permalink
Added JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBinoculars committed Oct 24, 2023
1 parent b579bee commit 2ad11f4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
34 changes: 24 additions & 10 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<viewport.height) {
if (i==0) {
const a = lib.repeatStringNumTimes('0', (viewport.width-(f.toString().length + 2)));
let i = 0;
while (i < viewport.height) {
if (i === 0) {
const a = lib.repeatStringNumTimes('0', (viewport.width - (f.toString().length + 2)));
console.log(`${a}f=${f}`);
} else {
console.log('0');
}
i++;
}
};
}

/**
* Function to update the frame.
*/
function frame() {
viewportTest();
fn++;
f++;
}

// frame();
frame();
// setInterval(frame, 50)
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* Repeats a string an amount of times - For developers
*
* @param {string} string - The string to be repeated
* @param {number} times - How many times to repeat the string
* @return {string} - Returns the string repeated n times
*/
exports.repeatStringNumTimes = function repeatStringNumTimes(string, times) {
let repeatedString = '';
while (times > 0) {
Expand All @@ -6,35 +13,42 @@ exports.repeatStringNumTimes = function repeatStringNumTimes(string, times) {
}
return repeatedString;
};
exports.mesh = class mesh {
/**
* A class for generating a mesh
*
* @param {Array<Array<number>>} points - A list of all the points
* @param {Array<Array<number>>} edges - A list of all the edges
* @param {Array<Array<number>>} 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;
this.pos = pos;
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]]};
Expand Down

0 comments on commit 2ad11f4

Please sign in to comment.