-
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
Showing
7 changed files
with
254 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
Mesh, | ||
MeshLambertMaterial, | ||
RingGeometry, | ||
TorusGeometry, | ||
Vector3, | ||
} from 'three'; | ||
import { Renderable } from './interface'; | ||
import { RendererContext } from '../context'; | ||
import { Vector } from '../../math/vector'; | ||
import { VectorInternalAdapter } from '../../math/vector-internal-adapter'; | ||
|
||
type Dimensions = { | ||
radius: number; | ||
width: number; | ||
}; | ||
|
||
export class Torus implements Renderable { | ||
private mesh: Mesh; | ||
private material = new MeshLambertMaterial({ color: 0xffffff }); | ||
|
||
constructor(dimensions: Dimensions) { | ||
const geometry = new TorusGeometry( | ||
dimensions.radius, | ||
dimensions.width, | ||
8, | ||
24, | ||
); | ||
this.mesh = new Mesh(geometry, this.material); | ||
} | ||
|
||
registerRenderer(context: RendererContext): void { | ||
context.scene.getInternal().add(this.mesh); | ||
} | ||
|
||
setColor(rgb: { r: number; g: number; b: number }): void { | ||
this.material.setValues({ | ||
color: `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`, | ||
}); | ||
} | ||
|
||
setPosition(position: Vector<[number, number, number]>): void { | ||
this.mesh.position.set( | ||
position.get(0), | ||
position.get(1), | ||
position.get(2), | ||
); | ||
} | ||
|
||
getInternalMesh(): Mesh { | ||
return this.mesh; | ||
} | ||
|
||
getWorldCoordinates(): Vector<[number, number, number]> { | ||
const vector3 = new Vector3(); | ||
return VectorInternalAdapter.toVector( | ||
this.mesh.getWorldPosition(vector3), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,47 @@ | ||
import { Engine } from '../../engine'; | ||
import { Box } from '../../engine/gfx/renderable/box'; | ||
import { Group } from '../../engine/gfx/renderable/group'; | ||
import { Vector } from '../../engine/math/vector'; | ||
import { BoardPosition } from '../board/abstract-board'; | ||
import { GamePiece } from './interface'; | ||
|
||
export class Cross implements GamePiece {} | ||
const cellSize = 4; | ||
const boardLength = cellSize * 4; | ||
const crossDepth = 1; | ||
const zDistance = 2; | ||
|
||
export class Cross implements GamePiece { | ||
private group = new Group(); | ||
|
||
constructor( | ||
private boardPosition: { | ||
x: BoardPosition; | ||
y: BoardPosition; | ||
z: BoardPosition; | ||
}, | ||
) { | ||
const color = { r: 255, g: 0, b: 0 }; | ||
|
||
const box1 = new Box({ width: 1, height: cellSize, depth: crossDepth }); | ||
box1.rotate(new Vector(0, 0, 1)); | ||
box1.setColor(color); | ||
this.group.add(box1); | ||
|
||
const box2 = new Box({ width: 1, height: cellSize, depth: crossDepth }); | ||
box2.rotate(new Vector(0, 0, -1)); | ||
box2.setColor(color); | ||
this.group.add(box2); | ||
|
||
this.group.translate( | ||
new Vector( | ||
cellSize * this.boardPosition.x - boardLength / 2, | ||
cellSize * this.boardPosition.y - boardLength / 2, | ||
zDistance * this.boardPosition.z - boardLength / 2 + crossDepth, | ||
), | ||
); | ||
} | ||
|
||
bootstrap(engine: Engine): void { | ||
this.group.registerRenderer(engine.getRendererContext()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
export interface GamePiece {} | ||
import { Engine } from '../../engine'; | ||
|
||
export interface GamePiece { | ||
bootstrap(engine: Engine): void; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,41 @@ | ||
import { Engine } from '../../engine'; | ||
import { Torus } from '../../engine/gfx/renderable/torus'; | ||
import { Vector } from '../../engine/math/vector'; | ||
import { BoardPosition } from '../board/abstract-board'; | ||
import { GamePiece } from './interface'; | ||
|
||
export class Nought implements GamePiece {} | ||
const cellSize = 4; | ||
const boardLength = cellSize * 4; | ||
const torusWidth = 0.5; | ||
const zDistance = 2; | ||
|
||
export class Nought implements GamePiece { | ||
private ring: Torus; | ||
|
||
constructor( | ||
private boardPosition: { | ||
x: BoardPosition; | ||
y: BoardPosition; | ||
z: BoardPosition; | ||
}, | ||
) { | ||
this.ring = new Torus({ | ||
radius: cellSize / 2 - torusWidth, | ||
width: torusWidth, | ||
}); | ||
this.ring.setColor({ r: 0, g: 0, b: 255 }); | ||
this.ring.setPosition( | ||
new Vector<[number, number, number]>( | ||
cellSize * this.boardPosition.x - boardLength / 2, | ||
cellSize * this.boardPosition.y - boardLength / 2, | ||
zDistance * this.boardPosition.z - | ||
boardLength / 2 + | ||
torusWidth * 2, | ||
), | ||
); | ||
} | ||
|
||
bootstrap(engine: Engine): void { | ||
this.ring.registerRenderer(engine.getRendererContext()); | ||
} | ||
} |