Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
seflless committed Oct 16, 2023
1 parent d63bf47 commit 4c02506
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 55 deletions.
41 changes: 2 additions & 39 deletions src/renderer/renderCylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// https://observablehq.com/d/011f054fc7eaf966

import { projectToScreenCoordinate } from "../cameras/Camera";
import { Color, ColorToCSS } from "../colors/Color";
import { ColorToCSS } from "../colors/Color";
import { applyLighting } from "../lighting/LightingModel";
import { Matrix4x4 } from "../math/Matrix4x4";
import { Vector3 } from "../math/Vector3";
import { CylinderShape } from "../shapes/Shape";
import { DebugLine2D } from "./DebugRenderer";
import { Scene } from "./Scene";
import { Viewport } from "./Viewport";

Expand All @@ -28,7 +27,7 @@ export function renderCylinder(
viewport: Viewport,
worldTransform: Matrix4x4,
cameraZoom: number,
cameraDirection: Vector3,
_cameraDirection: Vector3,
inverseCameraMatrix: Matrix4x4,
inverseAndProjectionMatrix: Matrix4x4
) {
Expand Down Expand Up @@ -112,14 +111,6 @@ export function renderCylinder(
? capsInScreenSpace[CylinderEnds.Bottom]
: capsInScreenSpace[CylinderEnds.Top];

// addCylinderEnd(
// capCenter,
// cylinder.radius,
// dotProduct,
// isTopVisible ? Color(255, 0, 0) : Color(0, 0, 255),
// svg
// );

const leftNormal = Vector3(
-visibleUpAxisScreenSpace.y,
visibleUpAxisScreenSpace.x,
Expand Down Expand Up @@ -343,34 +334,6 @@ function addStrokeAttribute(
}
}

function addCylinderEnd(
{ x, y }: Vector3,
radius: number,
dotProductAbsolute: number,
fill: Color,
svg: SVGElement
) {
// Create a 'circle' element
const circle = document.createElementNS(
"http://www.w3.org/2000/svg",
"ellipse"
);

circle.id = "sphere";
circle.setAttribute("cx", x.toString());
circle.setAttribute("cy", y.toString());

// TODO: Factor in camera projection matrix, this currectly
// ignores all zoom factors. Can we even handle skew with sphere?!
// I don't think we can.
circle.setAttribute("rx", radius.toString());
circle.setAttribute("ry", (radius * dotProductAbsolute).toString());

circle.setAttribute("fill", ColorToCSS(fill));

svg.appendChild(circle);
}

function normalToXAxisDegrees(x: number, y: number) {
return (Math.atan2(y, x) / Math.PI) * 180;
}
24 changes: 12 additions & 12 deletions src/renderer/renderSphere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ function dotProductToDegrees(dotProduct: number) {
return angleInDegrees;
}

// function normalToDegrees(x: number, z: number) {
// return (Math.atan2(x, z) / Math.PI) * 180;
// // function normalToDegrees(x: number, z: number) {
// // return (Math.atan2(x, z) / Math.PI) * 180;
// // }

// function normalizeDegrees(degrees: number) {
// let adjustedDegrees = degrees;
// if (adjustedDegrees < 0) {
// adjustedDegrees = 360 + (adjustedDegrees % 360);
// } else {
// adjustedDegrees = adjustedDegrees % 360;
// }
// return adjustedDegrees;
// }

function normalizeDegrees(degrees: number) {
let adjustedDegrees = degrees;
if (adjustedDegrees < 0) {
adjustedDegrees = 360 + (adjustedDegrees % 360);
} else {
adjustedDegrees = adjustedDegrees % 360;
}
return adjustedDegrees;
}

function calculateRotationAngle(x: number, y: number) {
const angleInRadians = Math.atan2(y, x);
// Convert radians to degrees
Expand Down
4 changes: 2 additions & 2 deletions workbench/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { getPaused, setPaused } from "./Settings";
import Cylinders from "./scenes/Cylinders";
import SingleCylinder from "./scenes/SingleCylinder";

// KitchenSink();
KitchenSink();
// Transforms();
// Octopus();
// Spheres();
Cylinders();
// Cylinders();
// SingleSphere();
// SingleCylinder();
// Worm();
Expand Down
2 changes: 1 addition & 1 deletion workbench/scenes/KitchenSink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default function () {
const cylinderScaleSpeed = 0.25;
const cylinderTranslationSpeed = 1;
// cylinder.rotation.x = 90;
// cylinder.rotation.z = now * 360 * cylinderRotationSpeed;
cylinder.rotation.z = now * 360 * cylinderRotationSpeed;

const boxRotationSpeed = 0.25;
// transparentBox.rotation.y = now * 360 * boxRotationSpeed;
Expand Down
2 changes: 1 addition & 1 deletion workbench/scenes/SingleCylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function () {
...getLighting("black and white"),
shapes: [
getEnvironment("grid"),
Axii(Vector3(-referenceRadius * 3, 0, 0)),
// Axii(Vector3(-referenceRadius * 3, 0, 0)),
// Group({
// position: Vector3(0, 0, 0),
// rotation: Vector3(45, 0, 0),
Expand Down

0 comments on commit 4c02506

Please sign in to comment.