Refactor rendering
This commit is contained in:
parent
edca93fcfe
commit
76282a4cf7
4 changed files with 239 additions and 213 deletions
|
|
@ -1,10 +1,13 @@
|
|||
import { BoundingBox } from './bounding-box';
|
||||
import { vec2 } from 'gl-matrix';
|
||||
import { GameObject } from '../objects/game-object';
|
||||
|
||||
export interface IShape {
|
||||
readonly isInverted: boolean;
|
||||
readonly boundingBox: BoundingBox;
|
||||
|
||||
readonly gameObject?: GameObject;
|
||||
|
||||
distance(target: vec2): number;
|
||||
normal(from: vec2): vec2;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { IShape } from '../i-shape';
|
|||
import { BoundingBox } from '../bounding-box';
|
||||
import { Circle } from './circle';
|
||||
import { settings } from '../../drawing/settings';
|
||||
import { GameObject } from '../../objects/game-object';
|
||||
|
||||
export class Blob implements IShape {
|
||||
private static readonly boundingCircleRadius = 19;
|
||||
|
|
@ -31,7 +32,10 @@ export class Blob implements IShape {
|
|||
settings.shaderMacros.footRadius
|
||||
);
|
||||
|
||||
public constructor(center: vec2) {
|
||||
public constructor(
|
||||
center: vec2,
|
||||
public readonly gameObject: GameObject = null
|
||||
) {
|
||||
this.position = center;
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +72,6 @@ export class Blob implements IShape {
|
|||
}
|
||||
|
||||
public clone(): Blob {
|
||||
return new Blob(this.boundingCircle.center);
|
||||
return new Blob(this.boundingCircle.center, this.gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,16 @@
|
|||
import { vec2 } from 'gl-matrix';
|
||||
import { IShape } from '../i-shape';
|
||||
import { BoundingBox } from '../bounding-box';
|
||||
import { GameObject } from '../../objects/game-object';
|
||||
|
||||
export class Circle implements IShape {
|
||||
public readonly isInverted = false;
|
||||
|
||||
public constructor(public center = vec2.create(), public radius = 0) {}
|
||||
public constructor(
|
||||
public center = vec2.create(),
|
||||
public radius = 0,
|
||||
public readonly gameObject: GameObject = null
|
||||
) {}
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return vec2.distance(this.center, target) - this.radius;
|
||||
|
|
@ -36,6 +41,6 @@ export class Circle implements IShape {
|
|||
}
|
||||
|
||||
public clone(): Circle {
|
||||
return new Circle(vec2.clone(this.center), this.radius);
|
||||
return new Circle(vec2.clone(this.center), this.radius, this.gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { clamp01 } from '../../helper/clamp';
|
|||
import { mix } from '../../helper/mix';
|
||||
import { IShape } from '../i-shape';
|
||||
import { rotate90Deg } from '../../helper/rotate-90-deg';
|
||||
import { GameObject } from '../../objects/game-object';
|
||||
|
||||
export class TunnelShape implements IShape {
|
||||
public readonly isInverted = true;
|
||||
|
|
@ -14,7 +15,8 @@ export class TunnelShape implements IShape {
|
|||
public readonly from: vec2,
|
||||
public readonly to: vec2,
|
||||
public readonly fromRadius: number,
|
||||
public readonly toRadius: number
|
||||
public readonly toRadius: number,
|
||||
public readonly gameObject: GameObject = null
|
||||
) {
|
||||
this.toFromDelta = vec2.subtract(vec2.create(), to, from);
|
||||
}
|
||||
|
|
@ -106,7 +108,8 @@ export class TunnelShape implements IShape {
|
|||
vec2.clone(this.from),
|
||||
vec2.clone(this.to),
|
||||
this.fromRadius,
|
||||
this.toRadius
|
||||
this.toRadius,
|
||||
this.gameObject
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue