Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBinoculars committed Oct 24, 2023
1 parent 388e34a commit b579bee
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 86 deletions.
46 changes: 23 additions & 23 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
const lib = require("textvox3d");
const lib = require('textvox3d');

function caliblrateViewportDimensions(camera, d, cubeSize) {
const focalLength = camera.fl;
const viewportHeight = 2 * cubeSize;
const viewportWidth = (viewportHeight * d) / focalLength;

return { width: viewportWidth, height: viewportHeight };
return {width: viewportWidth, height: viewportHeight};
}

let f = 0;
let camera = new lib.camera(55, 10, [7,-7,5], [64,0,47]);
let viewport = new lib.viewport(process.stdout.columns, process.stdout.rows-1);
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);

let cubeMesh = lib.getMesh("cube");
let 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}`);
const cubeMesh = lib.getMesh('cube');
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}`);
// console.log(`Columns: ${process.stdout.columns}, Rows: ${process.stdout.rows}`);

function viewportTest() {
let i=0;
while (i<viewport.height) {
if (i==0){
let a = lib.repeatStringNumTimes("0", (viewport.width-(f.toString().length + 2)));
console.log(`${a}f=${f}`);
}else {
console.log("0");
}
i++;
}
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 frame() {
viewportTest();
fn++;
viewportTest();
fn++;
}

//frame();
//setInterval(frame, 50)
// frame();
// setInterval(frame, 50)
98 changes: 49 additions & 49 deletions example/testing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*Testing that I did whilst starting to make this (basically useless)
/* Testing that I did whilst starting to make this (basically useless)
let degrees = 70;
console.log(`deg: ${degrees}`);
let radians = degrees*(Math.PI/180);
Expand All @@ -9,61 +9,61 @@ console.log(`calc: y=${tangent}x`);
*/

function isPointInPolygon(x, y, polygon) {
//I know this only works for the square but if you are working on issue ticket #2 do not try to fix this unless it is what is causing the issue
if (x >= polygon[0][0] && x <= polygon[1][0] && y >= polygon[0][1] && y <= polygon[2][1]) {
return true;
}else {
return false;
}
// I know this only works for the square but if you are working on issue ticket #2 do not try to fix this unless it is what is causing the issue
if (x >= polygon[0][0] && x <= polygon[1][0] && y >= polygon[0][1] && y <= polygon[2][1]) {
return true;
} else {
return false;
}
}

//The field of view of the viewport (in degrees)
let fov = 70;
//Square is formatted like this [[point], [point]]
let square = [[-0.25,4], [0.25, 4], [-0.25,6], [0.25,6]];
// The field of view of the viewport (in degrees)
const fov = 70;
// Square is formatted like this [[point], [point]]
const square = [[-0.25, 4], [0.25, 4], [-0.25, 6], [0.25, 6]];
let y = 0;
//Max distance is set to low so it does not fill up the command prompt
let maxDistance = 10;
//Gets the dimentions of the viewport
let viewport = {"height":process.stdout.rows-1, "width":process.stdout.columns};
// Max distance is set to low so it does not fill up the command prompt
const maxDistance = 10;
// Gets the dimentions of the viewport
const viewport = {'height': process.stdout.rows-1, 'width': process.stdout.columns};
console.log(viewport);
let castAngle = 0;
//The current column that we are on
// The current column that we are on
let column = 0;
//Columns where we have hit an object
// Columns where we have hit an object
let columnHits = [];
while(castAngle<=degrees) {
//Calculate the exact angle that we need to cast at
castAngle = ((viewport.width/(fov*2))*column)-70;
//Convert the angle to a gradient for y=mx+c
let castTang = Math.tan(castAngle*(Math.PI/180));
while(y<maxDistance){
//Move the cursor for the raycast away from the camera
y += 0.01;
//Calculate x using y=mx+c(ish), Maybe I've got this wrong?
let x = castTang*y;
//Test if the current "raycast cursor" is inside/on the edge of an object
if(isPointInPolygon(x, y, square)){
//Exit the loop (the 1000 is for assurance)
y=maxDistance+1000;
//Add the current column to the list of columns that have hit an object
columnHits += column;
}
};
//Reset y
y=0;
//Move to the next column
column++;
while (castAngle<=degrees) {
// Calculate the exact angle that we need to cast at
castAngle = ((viewport.width/(fov*2))*column)-70;
// Convert the angle to a gradient for y=mx+c
const castTang = Math.tan(castAngle*(Math.PI/180));
while (y<maxDistance) {
// Move the cursor for the raycast away from the camera
y += 0.01;
// Calculate x using y=mx+c(ish), Maybe I've got this wrong?
const x = castTang*y;
// Test if the current "raycast cursor" is inside/on the edge of an object
if (isPointInPolygon(x, y, square)) {
// Exit the loop (the 1000 is for assurance)
y=maxDistance+1000;
// Add the current column to the list of columns that have hit an object
columnHits += column;
}
};
// Reset y
y=0;
// Move to the next column
column++;
};

//Initialise the output variable
let output = "";
for(i=0;i<=(viewport.width-1);i++){
//Check if the current column is listed in the columns that have hit an object
if(columnHits.includes(i)){
output += "#";
}else {
output += ".";
}
// Initialise the output variable
let output = '';
for (i=0; i<=(viewport.width-1); i++) {
// Check if the current column is listed in the columns that have hit an object
if (columnHits.includes(i)) {
output += '#';
} else {
output += '.';
}
}
console.log(output);
console.log(output);
28 changes: 14 additions & 14 deletions sum.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const lib = require("./index");
const lib = require('./index');

test("Camera", () => {
expect(new lib.camera(70, 10, [7,-7,5], [64,0,47])).toEqual({"fov":70, "samples":10, "pos": [7,-7,5], "rot":[64,0,47]});
test('Camera', () => {
expect(new lib.camera(70, 10, [7, -7, 5], [64, 0, 47])).toEqual({'fov': 70, 'samples': 10, 'pos': [7, -7, 5], 'rot': [64, 0, 47]});
});
test("Mesh", () => {
expect(new lib.mesh([1,1,1], [1,1,1], [1,1,1])).toEqual({"points":[1,1,1], "edges":[1,1,1], "faces":[1,1,1]})
test('Mesh', () => {
expect(new lib.mesh([1, 1, 1], [1, 1, 1], [1, 1, 1])).toEqual({'points': [1, 1, 1], 'edges': [1, 1, 1], 'faces': [1, 1, 1]});
});
test("Item", () => {
expect(new lib.item("cube", [1,1,1], [0,0,0])).toEqual({"mesh":"cube", "pos":[1,1,1], "rot":[0,0,0]})
test('Item', () => {
expect(new lib.item('cube', [1, 1, 1], [0, 0, 0])).toEqual({'mesh': 'cube', 'pos': [1, 1, 1], 'rot': [0, 0, 0]});
});
test("Viewport", () => {
expect(new lib.viewport(100, 100)).toEqual({"width":100, "height":100})
test('Viewport', () => {
expect(new lib.viewport(100, 100)).toEqual({'width': 100, 'height': 100});
});
test("Repeat string func", () => {
expect(lib.repeatStringNumTimes("a", 3)).toEqual("aaa")
test('Repeat string func', () => {
expect(lib.repeatStringNumTimes('a', 3)).toEqual('aaa');
});
test('Get Mesh', () => {
expect(lib.getMesh('cube')).toEqual({'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]]});
});
test("Get Mesh", () => {
expect(lib.getMesh("cube")).toEqual({"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]]})
});

0 comments on commit b579bee

Please sign in to comment.