Do some more refactoring
This commit is contained in:
parent
c892ca2d01
commit
24cc572e47
3 changed files with 194 additions and 155 deletions
|
|
@ -5,8 +5,8 @@ import { IDrawableDescriptor } from '../i-drawable-descriptor';
|
|||
|
||||
export class CircleLight implements ILight {
|
||||
public static descriptor: IDrawableDescriptor = {
|
||||
uniformName: 'lights',
|
||||
countMacroName: 'lightCount',
|
||||
uniformName: 'circleLights',
|
||||
countMacroName: 'circleLightCount',
|
||||
shaderCombinationSteps: settings.shaderCombinations.circleLightSteps,
|
||||
};
|
||||
|
||||
|
|
@ -17,15 +17,15 @@ export class CircleLight implements ILight {
|
|||
public lightness: number
|
||||
) {}
|
||||
|
||||
distance(target: vec2): number {
|
||||
public distance(target: vec2): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
minimumDistance(target: vec2): number {
|
||||
public minimumDistance(target: vec2): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
public serializeToUniforms(uniforms: any): void {
|
||||
const listName = CircleLight.descriptor.uniformName;
|
||||
|
||||
if (!uniforms.hasOwnProperty(listName)) {
|
||||
|
|
@ -39,7 +39,7 @@ export class CircleLight implements ILight {
|
|||
});
|
||||
}
|
||||
|
||||
get value(): vec3 {
|
||||
public get value(): vec3 {
|
||||
return vec3.scale(
|
||||
vec3.create(),
|
||||
vec3.normalize(this.color, this.color),
|
||||
|
|
|
|||
|
|
@ -1,23 +1,32 @@
|
|||
import { ILight } from './i-light';
|
||||
import { vec2, vec3 } from 'gl-matrix';
|
||||
import { IDrawableDescriptor } from '../i-drawable-descriptor';
|
||||
import { settings } from '../../settings';
|
||||
|
||||
export class PointLight implements ILight {
|
||||
public static uniformName = 'lights';
|
||||
public static descriptor: IDrawableDescriptor = {
|
||||
uniformName: 'pointLights',
|
||||
countMacroName: 'pointLightCount',
|
||||
shaderCombinationSteps: settings.shaderCombinations.pointLightSteps,
|
||||
};
|
||||
|
||||
constructor(
|
||||
public center: vec2,
|
||||
public radius: number,
|
||||
public color: vec3,
|
||||
public lightness: number
|
||||
) {}
|
||||
distance(target: vec2): number {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
minimumDistance(target: vec2): number {
|
||||
throw new Error('Method not implemented.');
|
||||
|
||||
public distance(target: vec2): number {
|
||||
return vec2.distance(this.center, target) - this.radius;
|
||||
}
|
||||
|
||||
serializeToUniforms(uniforms: any): void {
|
||||
const listName = PointLight.uniformName;
|
||||
public minimumDistance(target: vec2): number {
|
||||
return vec2.distance(this.center, target) - this.radius;
|
||||
}
|
||||
|
||||
public serializeToUniforms(uniforms: any): void {
|
||||
const listName = PointLight.descriptor.uniformName;
|
||||
|
||||
if (!uniforms.hasOwnProperty(listName)) {
|
||||
uniforms[listName] = [];
|
||||
|
|
@ -25,12 +34,12 @@ export class PointLight implements ILight {
|
|||
|
||||
uniforms[listName].push({
|
||||
center: this.center,
|
||||
radius: 0,
|
||||
radius: this.radius,
|
||||
value: this.value,
|
||||
});
|
||||
}
|
||||
|
||||
get value(): vec3 {
|
||||
public get value(): vec3 {
|
||||
return vec3.scale(vec3.create(), this.color, this.lightness);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ export class TunnelShape implements IPrimitive {
|
|||
public readonly toRadius: number
|
||||
) {
|
||||
this.toFromDelta = vec2.subtract(vec2.create(), to, from);
|
||||
this.toFromDeltaLength = vec2.length(this.toFromDelta);
|
||||
|
||||
this.boundingCircle = new Circle(
|
||||
vec2.fromValues(from.x / 2 + to.x / 2, from.y / 2 + to.y / 2),
|
||||
|
|
@ -50,8 +49,7 @@ export class TunnelShape implements IPrimitive {
|
|||
const targetFromDelta = vec2.subtract(vec2.create(), target, this.from);
|
||||
const h = clamp01(
|
||||
vec2.dot(targetFromDelta, this.toFromDelta) /
|
||||
this.toFromDeltaLength /
|
||||
this.toFromDeltaLength
|
||||
vec2.dot(this.toFromDelta, this.toFromDelta)
|
||||
);
|
||||
return (
|
||||
vec2.distance(
|
||||
|
|
|
|||
Loading…
Reference in a new issue