Add worldToDisplayCoordinates method

This commit is contained in:
schmelczerandras 2020-10-18 15:42:38 +02:00
commit 184d1a1e39
3 changed files with 37 additions and 7 deletions

View file

@ -143,6 +143,13 @@ export class ContextAwareRenderer implements Renderer {
);
}
public worldToDisplayCoordinates(worldCoordinates: vec2): vec2 {
return this.handle(
() => this.renderer.worldToDisplayCoordinates(worldCoordinates),
vec2.create()
);
}
public renderDrawables(): void {
return this.handle(() => this.renderer.renderDrawables(), undefined);
}

View file

@ -242,6 +242,10 @@ export class RendererImplementation implements Renderer {
return this.uniformsProvider.screenToWorldPosition(displayCoordinates);
}
public worldToDisplayCoordinates(worldCoordinates: vec2): vec2 {
return this.uniformsProvider.worldToDisplayCoordinates(worldCoordinates);
}
public setViewArea(topLeft: vec2, size: vec2) {
this.uniformsProvider.setViewArea(topLeft, size);
}

View file

@ -30,7 +30,8 @@ export interface Renderer {
setViewArea(topLeft: vec2, size: vec2): void;
/**
* Return the world coordinates from a pixel's position.
* The inverse of `worldToDisplayCoordinates`, returns the world coordinates
* from a pixel's position.
*
* The view area coordinates are also given in world coordinates.
*
@ -41,6 +42,17 @@ export interface Renderer {
*/
displayToWorldCoordinates(displayCoordinates: vec2): vec2;
/**
* The inverse of `displayToWorldCoordinates`, returns the screen space position
* of a point given in world space cooridnates.
*
* While the origin for worldCoordinates resides in the bottom-left corner,
* the origin of the returned display coordinates is placed in the top left.
*
* @param worldCoordinates Coordinates used when drawing objects.
*/
worldToDisplayCoordinates(worldCoordinates: vec2): vec2;
/**
* Patch the current runtime settings with new values.
* @param overrides