diff --git a/frontend/src/scripts/drawing/settings.ts b/frontend/src/scripts/drawing/settings.ts index 34dc169..6d8d0d3 100644 --- a/frontend/src/scripts/drawing/settings.ts +++ b/frontend/src/scripts/drawing/settings.ts @@ -23,6 +23,7 @@ export const settings = { shaderMacros: { distanceScale: 64, distanceOffset: 0.15, + //edgeSmoothing: 0, edgeSmoothing: 10, }, shaderCombinations: { diff --git a/frontend/src/scripts/drawing/shaders/lights-shading-fs.glsl b/frontend/src/scripts/drawing/shaders/lights-shading-fs.glsl index d92cf11..9e0fb2e 100644 --- a/frontend/src/scripts/drawing/shaders/lights-shading-fs.glsl +++ b/frontend/src/scripts/drawing/shaders/lights-shading-fs.glsl @@ -59,6 +59,10 @@ void main() { for (int i = 0; i < CIRCLE_LIGHT_COUNT; i++) { float lightCenterDistance = distance(circleLights[i].center, worldCoordinates); + /*if (lightCenterDistance < circleLights[i].radius) { + lighting = vec3(1.0, 1.0, 0.0); + }*/ + vec3 lightColorAtPosition = circleLights[i].value / pow( lightCenterDistance / LIGHT_DROP + 1.0, 2.0 ); diff --git a/frontend/src/scripts/objects/types/camera.ts b/frontend/src/scripts/objects/types/camera.ts index d5fc19b..ed2aead 100644 --- a/frontend/src/scripts/objects/types/camera.ts +++ b/frontend/src/scripts/objects/types/camera.ts @@ -17,7 +17,7 @@ export class Camera extends GameObject { super(); this.boundingBox = new BoundingBox(null); - physics.addDynamicBoundingBox(this.boundingBox); + //physics.addDynamicBoundingBox(this.boundingBox); this.addCommandExecutor(BeforeRenderCommand, this.draw.bind(this)); this.addCommandExecutor(MoveToCommand, this.moveTo.bind(this)); diff --git a/frontend/src/scripts/objects/types/character.ts b/frontend/src/scripts/objects/types/character.ts index aff0637..256d295 100644 --- a/frontend/src/scripts/objects/types/character.ts +++ b/frontend/src/scripts/objects/types/character.ts @@ -43,17 +43,13 @@ export class Character extends GameObject { const nextPrimitive = this.primitive.clone(); nextPrimitive.center = value; - console.log(this.physics - .findIntersecting(nextPrimitive.boundingBox) - .filter(b => b.value) - .map((b) => b.value.distance(nextPrimitive.center) + 2 * nextPrimitive.radius) - ) - if ( this.physics .findIntersecting(nextPrimitive.boundingBox) - .filter(b => b.value) - .map((b) => b.value.distance(nextPrimitive.center) + 2 * nextPrimitive.radius) + .filter((b) => b.value) + .map( + (b) => b.value.distance(nextPrimitive.center) + nextPrimitive.radius + ) .find((d) => d < 0) !== undefined ) { this.setPosition(value); diff --git a/frontend/src/scripts/physics/containers/bounding-box-tree.ts b/frontend/src/scripts/physics/containers/bounding-box-tree.ts index 058dbf9..5598838 100644 --- a/frontend/src/scripts/physics/containers/bounding-box-tree.ts +++ b/frontend/src/scripts/physics/containers/bounding-box-tree.ts @@ -12,10 +12,8 @@ class Node { export class BoundingBoxTree { root?: Node; - constructor(boxes?: Array) { - if (boxes) { - this.build(boxes); - } + constructor(boxes: Array = []) { + this.build(boxes); } public build(boxes: Array) { @@ -83,7 +81,7 @@ export class BoundingBoxTree { box: ImmutableBoundingBox ): Array { const maybeResults = this.findMaybeIntersecting(box, this.root, 0); - const results = maybeResults.filter(box.intersects.bind(box)); + const results = maybeResults.filter((b) => b.intersects(box)); return results; } @@ -96,25 +94,27 @@ export class BoundingBoxTree { return []; } - const comparisons: Array<( - a: ImmutableBoundingBox, - b: ImmutableBoundingBox - ) => boolean> = [ - (a, b) => a.xMin < b.xMax, - (a, b) => a.xMax > b.xMin, - (a, b) => a.yMin < b.yMax, - (a, b) => a.xMax > b.xMin, - ]; - - if (comparisons[depth % 4](node.rectangle, box)) { - return [ - node.rectangle, - ...this.findMaybeIntersecting(box, node.left, depth + 1), - ...this.findMaybeIntersecting(box, node.right, depth + 1), - ]; + if (depth % 4 == 0 && box.xMax < node.rectangle.xMin) { + return this.findMaybeIntersecting(box, node.left, depth + 1); } - return this.findMaybeIntersecting(box, node.left, depth + 1); + if (depth % 4 == 1 && box.xMin > node.rectangle.xMax) { + return this.findMaybeIntersecting(box, node.right, depth + 1); + } + + if (depth % 4 == 2 && box.yMax < node.rectangle.yMin) { + return this.findMaybeIntersecting(box, node.left, depth + 1); + } + + if (depth % 4 == 3 && box.yMin > node.rectangle.yMax) { + return this.findMaybeIntersecting(box, node.right, depth + 1); + } + + return [ + node.rectangle, + ...this.findMaybeIntersecting(box, node.left, depth + 1), + ...this.findMaybeIntersecting(box, node.right, depth + 1), + ]; } private findParent( @@ -124,7 +124,7 @@ export class BoundingBoxTree { parent: Node ): [Node, number] { if (node === null) { - return [parent, depth]; + return [parent, depth - 1]; } const dimension = depth % 4; diff --git a/frontend/src/scripts/physics/physics.ts b/frontend/src/scripts/physics/physics.ts index 77dcd57..0d541ba 100644 --- a/frontend/src/scripts/physics/physics.ts +++ b/frontend/src/scripts/physics/physics.ts @@ -4,22 +4,22 @@ import { ImmutableBoundingBox } from './containers/immutable-bounding-box'; import { BoundingBoxBase } from './containers/bounding-box-base'; export class Physics { - private staticBoundingBoxesWaitList = []; private isTreeInitialized = false; + private staticBoundingBoxesWaitList = []; private staticBoundingBoxes = new BoundingBoxTree(); private dynamicBoundingBoxes = new BoundingBoxList(); public addStaticBoundingBox(boundingBox: ImmutableBoundingBox) { - this.staticBoundingBoxesWaitList.push(boundingBox); + if (!this.isTreeInitialized) { + this.staticBoundingBoxesWaitList.push(boundingBox); + } else { + this.staticBoundingBoxes.insert(boundingBox); + } } public addDynamicBoundingBox(boundingBox: BoundingBoxBase) { - if (this.isTreeInitialized) { - this.staticBoundingBoxes.insert(boundingBox); - } else { - this.dynamicBoundingBoxes.insert(boundingBox); - } + this.dynamicBoundingBoxes.insert(boundingBox); } public findIntersecting(box: BoundingBoxBase): Array {