-
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.
Redesigned architecture; can draw names
- Loading branch information
Alex Badea
committed
Jul 5, 2018
1 parent
88a623e
commit 0945a18
Showing
23 changed files
with
422 additions
and
323 deletions.
There are no files selected for viewing
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class DrawableBlueprint { | ||
constructor(name, color) { | ||
if (new.target === DrawableBlueprint) | ||
throw new TypeError("Cannot instantiate abstract class"); | ||
if (name == undefined || color == undefined) | ||
throw new Error("Undefined or null params"); | ||
this.name = name; | ||
this.color = color; | ||
} | ||
|
||
instantiate(gl, programInfo) { | ||
throw new Error("Cannot call abstract method"); | ||
} | ||
} |
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,74 +1,64 @@ | ||
class Drawable { | ||
constructor(name) { | ||
if (new.target === Drawable) | ||
class DrawableInstance { | ||
constructor(drawable, gl, programInfo) { | ||
if (new.target === DrawableInstance) | ||
throw new TypeError("Cannot instantiate abstract class"); | ||
if (name == undefined) | ||
throw new Error("Undefined or null params"); | ||
this.name = name; | ||
} | ||
|
||
init(gl) { | ||
if (gl == undefined) | ||
if (drawable == undefined || gl == undefined || programInfo == undefined) | ||
throw new Error("Undefined or null params"); | ||
this.drawable = drawable; | ||
this.gl = gl; | ||
this.programInfo = programInfo; | ||
this.buffers = { | ||
position: gl.createBuffer(), | ||
color: gl.createBuffer() | ||
}; | ||
|
||
this._INIT_NAME(); | ||
this._INIT_NAME(drawable, gl); | ||
} | ||
|
||
// Depreciat: va fi înocuită când se va găsi o metodă mai bună | ||
_INIT_NAME() { | ||
if (this.gl == undefined) | ||
throw new Error("Must initialize drawable before drawing name"); | ||
draw() { | ||
if (this.gl.getUniform(this.programInfo.program, this.programInfo.uniformLocations.modelMatrix, 0).every((e, i) => mat4.fromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)[i] === e)) | ||
throw new Error("Stray drawable not bound to any drawing context (coordinate system): " + this.name); | ||
|
||
this._DRAW_NAME(this.programInfo); | ||
} | ||
|
||
getNamePos() { | ||
throw new Error("Cannot call abstract method"); | ||
} | ||
|
||
// Depreciat: va fi înocuitã când se va gãsi o metodã mai bunã | ||
_INIT_NAME(drawable, gl) { | ||
if (drawable == undefined || gl == undefined) | ||
throw new Error("Undefined or null params"); | ||
|
||
// NU MAI CREA DACÃ NUMELE E GOL@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
this.nameContainer = document.createElement("div"); | ||
this.nameContainer.innerHTML = this.name; | ||
this.nameContainer.innerHTML = drawable.name; | ||
this.nameContainer.setAttribute("style", "position: absolute;-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;"); | ||
document.body.appendChild(this.nameContainer); | ||
} | ||
|
||
draw(programInfo) { | ||
if (this.gl == undefined) | ||
throw new Error("Must initialize WebGL context before drawing"); | ||
// Depreciat: va fi înocuitã când se va gãsi o metodã mai bunã | ||
// DE TESTAT DACÃ SE DESENEAZÃ RELATIV LA PÂNZÃ SAU RELATIV LA FEREASTRÃ; REPARÃ DACÃ RELATIV LA FEREASTRÃ | ||
_DRAW_NAME(programInfo) { | ||
if (programInfo == undefined) | ||
throw new Error("Undefined or null params"); | ||
if (this.gl.getUniform(programInfo.program, programInfo.uniformLocations.modelMatrix, 0).every((e, i) => mat4.fromValues(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)[i] === e)) | ||
throw new Error("Stray drawable not bound to any drawing context (coordinate system): " + this.name); | ||
this.programInfo = programInfo; | ||
|
||
this._DRAW_NAME(); | ||
} | ||
|
||
// Depreciat: va fi înocuită când se va găsi o metodă mai bună | ||
_DRAW_NAME() { | ||
if (this.gl == undefined) | ||
throw new Error("Must initialize WebGL context before drawing name"); | ||
if (this.programInfo == undefined) | ||
throw new Error("Must draw drawable before drawing name"); | ||
|
||
const projectionMatrix = this.gl.getUniform(this.programInfo.program, this.programInfo.uniformLocations.projectionMatrix, 0); | ||
const viewMatrix = this.gl.getUniform(this.programInfo.program, this.programInfo.uniformLocations.viewMatrix, 0); | ||
const modelMatrix = this.gl.getUniform(this.programInfo.program, this.programInfo.uniformLocations.modelMatrix, 0); | ||
|
||
const projectionMatrix = this.gl.getUniform(programInfo.program, programInfo.uniformLocations.projectionMatrix, 0); | ||
const viewMatrix = this.gl.getUniform(programInfo.program, programInfo.uniformLocations.viewMatrix, 0); | ||
const modelMatrix = this.gl.getUniform(programInfo.program, programInfo.uniformLocations.modelMatrix, 0); | ||
|
||
const namePos = vec4.fromValues(...this.getNamePos(), 1); | ||
const mvp = mat4.multiply(mat4.create(), mat4.multiply(mat4.create(), projectionMatrix, viewMatrix), modelMatrix); | ||
const nameMvpPos = vec4.transformMat4(vec4.create(), namePos, mvp); | ||
const nameNormScrPos = [nameMvpPos[0]/nameMvpPos[3], nameMvpPos[1]/nameMvpPos[3]]; | ||
const nameScrPos = [(nameNormScrPos[0]*0.5+0.5)*this.gl.canvas.width, | ||
(nameNormScrPos[1]*-0.5+0.5)*this.gl.canvas.height]; | ||
if (nameScrPos[0] > 0 && nameScrPos[0] < this.gl.canvas.width && nameScrPos[1] > 0 && nameScrPos[1] < this.gl.canvas.height && nameMvpPos[2] > 0 | ||
&& this.nameContainer.innerHTML !== "") { | ||
if (nameScrPos[0] > 0 && nameScrPos[0] < this.gl.canvas.width && nameScrPos[1] > 0 && nameScrPos[1] < this.gl.canvas.height && nameMvpPos[2] > 0) { | ||
this.nameContainer.style.left = nameScrPos[0]; | ||
this.nameContainer.style.top = nameScrPos[1]; | ||
this.nameContainer.style.display = "inline"; | ||
} else | ||
this.nameContainer.style.display = "none"; | ||
} | ||
|
||
getNamePos() { | ||
throw new Error("Cannot call abstract method"); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.