WIP
This commit is contained in:
parent
24cc572e47
commit
345e183e34
6 changed files with 614 additions and 173 deletions
|
|
@ -1,7 +1,11 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { ImmutableBoundingBox } from '../../physics/containers/immutable-bounding-box';
|
||||
import { GameObject } from '../../objects/game-object';
|
||||
|
||||
export interface IDrawable {
|
||||
serializeToUniforms(uniforms: any): void;
|
||||
distance(target: vec2): number;
|
||||
minimumDistance(target: vec2): number;
|
||||
readonly owner: GameObject;
|
||||
readonly boundingBox: ImmutableBoundingBox;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { ILight } from './i-light';
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { settings } from '../../settings';
|
||||
import { IDrawableDescriptor } from '../i-drawable-descriptor';
|
||||
import { ImmutableBoundingBox } from '../../../physics/containers/immutable-bounding-box';
|
||||
import { GameObject } from '../../../objects/game-object';
|
||||
|
||||
export class CircleLight implements ILight {
|
||||
public static descriptor: IDrawableDescriptor = {
|
||||
|
|
@ -11,12 +13,15 @@ export class CircleLight implements ILight {
|
|||
};
|
||||
|
||||
constructor(
|
||||
public readonly owner: GameObject,
|
||||
public center: vec2,
|
||||
public radius: number,
|
||||
public color: vec3,
|
||||
public lightness: number
|
||||
) {}
|
||||
|
||||
boundingBox: ImmutableBoundingBox;
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import { ILight } from './i-light';
|
|||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { IDrawableDescriptor } from '../i-drawable-descriptor';
|
||||
import { settings } from '../../settings';
|
||||
import { ImmutableBoundingBox } from '../../../physics/containers/immutable-bounding-box';
|
||||
import { GameObject } from '../../../objects/game-object';
|
||||
|
||||
export class PointLight implements ILight {
|
||||
public static descriptor: IDrawableDescriptor = {
|
||||
|
|
@ -10,13 +12,16 @@ export class PointLight implements ILight {
|
|||
shaderCombinationSteps: settings.shaderCombinations.pointLightSteps,
|
||||
};
|
||||
|
||||
constructor(
|
||||
public constructor(
|
||||
public readonly owner: GameObject,
|
||||
public center: vec2,
|
||||
public radius: number,
|
||||
public color: vec3,
|
||||
public lightness: number
|
||||
) {}
|
||||
|
||||
boundingBox: ImmutableBoundingBox;
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return vec2.distance(this.center, target) - this.radius;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { IPrimitive } from './i-primitive';
|
||||
import { ImmutableBoundingBox } from '../../../physics/containers/immutable-bounding-box';
|
||||
import { GameObject } from '../../../objects/game-object';
|
||||
|
||||
export class Circle implements IPrimitive {
|
||||
public constructor(public center = vec2.create(), public radius = 0) {}
|
||||
public constructor(
|
||||
public readonly owner: GameObject,
|
||||
public center = vec2.create(),
|
||||
public radius = 0
|
||||
) {}
|
||||
|
||||
public serializeToUniforms(uniforms: any): void {
|
||||
throw new Error('Method not implemented.');
|
||||
|
|
@ -16,6 +22,16 @@ export class Circle implements IPrimitive {
|
|||
return vec2.distance(this.center, target) - this.radius;
|
||||
}
|
||||
|
||||
public get boundingBox(): ImmutableBoundingBox {
|
||||
return new ImmutableBoundingBox(
|
||||
this,
|
||||
this.center.x - this.radius,
|
||||
this.center.x + this.radius,
|
||||
this.center.y - this.radius,
|
||||
this.center.y + this.radius
|
||||
);
|
||||
}
|
||||
|
||||
public isInside(target: vec2): boolean {
|
||||
return this.distance(target) < 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
|
||||
export class Rectangle {
|
||||
public constructor(
|
||||
public topLeft: vec2 = vec2.create(),
|
||||
public size: vec2 = vec2.create()
|
||||
) {}
|
||||
|
||||
public isInside(position: vec2): boolean {
|
||||
const translated = vec2.subtract(vec2.create(), position, this.topLeft);
|
||||
return (
|
||||
0 <= translated.x &&
|
||||
translated.x < this.size.x &&
|
||||
0 <= translated.y &&
|
||||
translated.y < this.size.y
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,12 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { clamp01 } from '../../../helper/clamp';
|
||||
import { mix } from '../../../helper/mix';
|
||||
import { Circle } from './circle';
|
||||
import { IPrimitive } from './i-primitive';
|
||||
import { IDrawableDescriptor } from '../i-drawable-descriptor';
|
||||
import { IPrimitive } from './i-primitive';
|
||||
import { settings } from '../../settings';
|
||||
import { Circle } from './circle';
|
||||
import { mix } from '../../../helper/mix';
|
||||
import { clamp01 } from '../../../helper/clamp';
|
||||
import { ImmutableBoundingBox } from '../../../physics/containers/immutable-bounding-box';
|
||||
import { GameObject } from '../../../objects/game-object';
|
||||
|
||||
export class TunnelShape implements IPrimitive {
|
||||
public static descriptor: IDrawableDescriptor = {
|
||||
|
|
@ -14,11 +16,11 @@ export class TunnelShape implements IPrimitive {
|
|||
};
|
||||
|
||||
public readonly toFromDelta: vec2;
|
||||
private toFromDeltaLength: number;
|
||||
|
||||
private boundingCircle: Circle;
|
||||
|
||||
constructor(
|
||||
public readonly owner: GameObject,
|
||||
public readonly from: vec2,
|
||||
public readonly to: vec2,
|
||||
public readonly fromRadius: number,
|
||||
|
|
@ -27,12 +29,13 @@ export class TunnelShape implements IPrimitive {
|
|||
this.toFromDelta = vec2.subtract(vec2.create(), to, from);
|
||||
|
||||
this.boundingCircle = new Circle(
|
||||
this.owner,
|
||||
vec2.fromValues(from.x / 2 + to.x / 2, from.y / 2 + to.y / 2),
|
||||
Math.max(fromRadius, toRadius) + vec2.distance(from, to)
|
||||
);
|
||||
}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
public serializeToUniforms(uniforms: any): void {
|
||||
if (!uniforms.hasOwnProperty(TunnelShape.descriptor.uniformName)) {
|
||||
uniforms[TunnelShape.descriptor.uniformName] = [];
|
||||
}
|
||||
|
|
@ -45,6 +48,27 @@ export class TunnelShape implements IPrimitive {
|
|||
});
|
||||
}
|
||||
|
||||
public get boundingBox(): ImmutableBoundingBox {
|
||||
const xMin = Math.min(
|
||||
this.from.x - this.fromRadius,
|
||||
this.to.x - this.toRadius
|
||||
);
|
||||
const yMin = Math.min(
|
||||
this.from.y - this.fromRadius,
|
||||
this.to.y - this.toRadius
|
||||
);
|
||||
const xMax = Math.max(
|
||||
this.from.x + this.fromRadius,
|
||||
this.to.x + this.toRadius
|
||||
);
|
||||
const yMax = Math.max(
|
||||
this.from.y + this.fromRadius,
|
||||
this.to.y + this.toRadius
|
||||
);
|
||||
|
||||
return new ImmutableBoundingBox(this, xMin, xMax, yMin, yMax);
|
||||
}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
const targetFromDelta = vec2.subtract(vec2.create(), target, this.from);
|
||||
const h = clamp01(
|
||||
|
|
|
|||
Loading…
Reference in a new issue