generated from jacklehamster/bun-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92d3daf
commit a8c2056
Showing
8 changed files
with
155 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { MediaId } from "gl/texture/ImageManager"; | ||
import { Box } from "./Box"; | ||
import Matrix from "gl/transform/Matrix"; | ||
import { Sprite } from "world/sprite/Sprite"; | ||
import { Sprites } from "world/sprite/Sprites"; | ||
|
||
export class DisplayBox implements Sprites { | ||
private readonly sprites: Sprite[]; | ||
constructor(box: Box, imageId: MediaId) { | ||
const cX = (box.left + box.right) / 2; | ||
const cY = (box.top + box.bottom) / 2; | ||
const cZ = (box.near + box.far) / 2; | ||
const groundScale: [number, number, number] = [box.right - box.left, 2, box.near - box.far]; | ||
const sideScale: [number, number, number] = [2, box.top - box.bottom, box.near - box.far]; | ||
const faceScale: [number, number, number] = [box.right - box.left, box.top - box.bottom, 2]; | ||
|
||
const outside = [ | ||
Matrix.create().translate(cX, box.bottom, cZ).scale(...groundScale).scale(1 / 2).rotateX(Math.PI / 2), | ||
Matrix.create().translate(cX, box.top, cZ).scale(...groundScale).scale(1 / 2).rotateX(-Math.PI / 2), | ||
Matrix.create().translate(box.left, cY, cZ).scale(...sideScale).scale(1 / 2).rotateY(-Math.PI / 2), | ||
Matrix.create().translate(box.right, cY, cZ).scale(...sideScale).scale(1 / 2).rotateY(Math.PI / 2), | ||
Matrix.create().translate(cX, cY, box.near).scale(...faceScale).scale(1 / 2).rotateY(0), | ||
Matrix.create().translate(cX, cY, box.far).scale(...faceScale).scale(1 / 2).rotateY(Math.PI), | ||
].map(transform => ({ imageId, transform })); | ||
|
||
const inside = [ | ||
Matrix.create().translate(cX, box.bottom, cZ).scale(...groundScale).scale(1 / 2).rotateX(-Math.PI / 2), | ||
Matrix.create().translate(cX, box.top, cZ).scale(...groundScale).scale(1 / 2).rotateX(+Math.PI / 2), | ||
Matrix.create().translate(box.left, cY, cZ).scale(...sideScale).scale(1 / 2).rotateY(+Math.PI / 2), | ||
Matrix.create().translate(box.right, cY, cZ).scale(...sideScale).scale(1 / 2).rotateY(-Math.PI / 2), | ||
Matrix.create().translate(cX, cY, box.near).scale(...faceScale).scale(1 / 2).rotateY(Math.PI), | ||
Matrix.create().translate(cX, cY, box.far).scale(...faceScale).scale(1 / 2).rotateY(0), | ||
].map(transform => ({ imageId, transform })); | ||
this.sprites = [...inside, ...outside]; | ||
} | ||
|
||
get length(): number { | ||
return this.sprites.length; | ||
} | ||
|
||
at(index: number): Sprite | undefined { | ||
return this.sprites.at(index); | ||
} | ||
|
||
informUpdate(_id: number, _type: number | undefined): void { | ||
throw new Error("Method not implemented."); | ||
} | ||
} |