summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/rectangles/models
diff options
context:
space:
mode:
authorryderr <r@okfoc.us>2014-10-07 16:12:46 -0400
committerryderr <r@okfoc.us>2014-10-07 16:12:46 -0400
commit038a4ed165df6f3ad64ce7c9375934384a9b5d43 (patch)
tree813fbcebb018c088bf525ba44aa4419f6606abc5 /public/assets/javascripts/rectangles/models
parent06e38245987304ef6bddb1f9c3e6cad16a215209 (diff)
parentf5ab61241bf9519325a36b86ee74ab2df13a4331 (diff)
merge
Diffstat (limited to 'public/assets/javascripts/rectangles/models')
-rw-r--r--public/assets/javascripts/rectangles/models/mat4.js78
-rw-r--r--public/assets/javascripts/rectangles/models/wall.js95
2 files changed, 76 insertions, 97 deletions
diff --git a/public/assets/javascripts/rectangles/models/mat4.js b/public/assets/javascripts/rectangles/models/mat4.js
deleted file mode 100644
index b061199..0000000
--- a/public/assets/javascripts/rectangles/models/mat4.js
+++ /dev/null
@@ -1,78 +0,0 @@
-function mat4(e){
- this.elements = [ 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1 ]
- return this
-}
-mat4.prototype.set = function (a) {
- var els = this.elements
- a.forEach(function(n,i){ els[i] = n })
- return this
-}
-mat4.prototype.clone = function(){
- return (new mat4).set(this.els)
-}
-mat4.prototype.identity = function () {
- this.set([
- 1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1
- ]);
- return this;
-}
-mat4.prototype.getInverse = function (m, throwOnInvertible) {
-
- // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
- var te = this.elements;
- var me = m.elements;
-
- var n11 = me[0], n12 = me[4], n13 = me[8], n14 = me[12];
- var n21 = me[1], n22 = me[5], n23 = me[9], n24 = me[13];
- var n31 = me[2], n32 = me[6], n33 = me[10], n34 = me[14];
- var n41 = me[3], n42 = me[7], n43 = me[11], n44 = me[15];
-
- te[0] = n23*n34*n42 - n24*n33*n42 + n24*n32*n43 - n22*n34*n43 - n23*n32*n44 + n22*n33*n44;
- te[4] = n14*n33*n42 - n13*n34*n42 - n14*n32*n43 + n12*n34*n43 + n13*n32*n44 - n12*n33*n44;
- te[8] = n13*n24*n42 - n14*n23*n42 + n14*n22*n43 - n12*n24*n43 - n13*n22*n44 + n12*n23*n44;
- te[12] = n14*n23*n32 - n13*n24*n32 - n14*n22*n33 + n12*n24*n33 + n13*n22*n34 - n12*n23*n34;
- te[1] = n24*n33*n41 - n23*n34*n41 - n24*n31*n43 + n21*n34*n43 + n23*n31*n44 - n21*n33*n44;
- te[5] = n13*n34*n41 - n14*n33*n41 + n14*n31*n43 - n11*n34*n43 - n13*n31*n44 + n11*n33*n44;
- te[9] = n14*n23*n41 - n13*n24*n41 - n14*n21*n43 + n11*n24*n43 + n13*n21*n44 - n11*n23*n44;
- te[13] = n13*n24*n31 - n14*n23*n31 + n14*n21*n33 - n11*n24*n33 - n13*n21*n34 + n11*n23*n34;
- te[2] = n22*n34*n41 - n24*n32*n41 + n24*n31*n42 - n21*n34*n42 - n22*n31*n44 + n21*n32*n44;
- te[6] = n14*n32*n41 - n12*n34*n41 - n14*n31*n42 + n11*n34*n42 + n12*n31*n44 - n11*n32*n44;
- te[10] = n12*n24*n41 - n14*n22*n41 + n14*n21*n42 - n11*n24*n42 - n12*n21*n44 + n11*n22*n44;
- te[14] = n14*n22*n31 - n12*n24*n31 - n14*n21*n32 + n11*n24*n32 + n12*n21*n34 - n11*n22*n34;
- te[3] = n23*n32*n41 - n22*n33*n41 - n23*n31*n42 + n21*n33*n42 + n22*n31*n43 - n21*n32*n43;
- te[7] = n12*n33*n41 - n13*n32*n41 + n13*n31*n42 - n11*n33*n42 - n12*n31*n43 + n11*n32*n43;
- te[11] = n13*n22*n41 - n12*n23*n41 - n13*n21*n42 + n11*n23*n42 + n12*n21*n43 - n11*n22*n43;
- te[15] = n12*n23*n31 - n13*n22*n31 + n13*n21*n32 - n11*n23*n32 - n12*n21*n33 + n11*n22*n33;
-
- var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
-
- if ( det == 0 ) {
- var msg = "Matrix4.getInverse(): can't invert matrix, determinant is 0";
-
- if ( throwOnInvertible || false ) {
- throw new Error( msg )
- }
- else {
- console.warn( msg )
- }
- this.identity();
- return this
- }
- this.multiplyScalar( 1 / det );
- return this
-}
-mat4.prototype.multiplyScalar = function (n) {
- var els = this.elements
- els[0] *= n; els[4] *= n; els[8] *= n; els[12] *= n
- els[1] *= n; els[5] *= n; els[9] *= n; els[13] *= n
- els[2] *= n; els[6] *= n; els[10] *= n; els[14] *= n
- els[3] *= n; els[7] *= n; els[11] *= n; els[15] *= n
- return this
-}
-
diff --git a/public/assets/javascripts/rectangles/models/wall.js b/public/assets/javascripts/rectangles/models/wall.js
index fdc8d8c..820fb5f 100644
--- a/public/assets/javascripts/rectangles/models/wall.js
+++ b/public/assets/javascripts/rectangles/models/wall.js
@@ -68,14 +68,12 @@
},
*/
mousedown: function(e){
- if (Scenery.nextText) {
- }
- else if (Scenery.nextMedia) {
- var offset = offsetFromPoint(e, mx.el)
- if (! offset) { return }
+ var offset = offsetFromPoint(e, mx.el)
+ if (! offset) { return }
- var pos = base.mxOffsetToPosition( offset, index )
+ var pos = base.mxOffsetToPosition( offset, index )
+ if (Scenery.nextMedia) {
var scenery = Scenery.addNextToWall({
wall: base,
index: index,
@@ -91,13 +89,15 @@
app.controller.toolbar.resetPermissions()
Scenery.resize.show(scenery)
Scenery.hovering = true
+
+ app.controller.pick(scenery)
UndoStack.push({
type: 'create-scenery',
undo: { id: scenery.id },
redo: scenery.serialize(),
})
-
+
// TODO: watch individual scenery object here
Minotaur.watch( app.router.editorView.settings )
}
@@ -116,7 +116,7 @@
Minotaur.watch( app.router.editorView.settings )
}
else {
- app.controller.hideExtras()
+ app.controller.pickWall(base, pos)
}
}
})
@@ -214,22 +214,79 @@
}
Wall.prototype.wallpaper = function(background){
- var useX = this.side & FRONT_BACK
- var shouldFlip = this.side & (LEFT | BACK)
-
- this.background = background || "none"
+ if (! background) {
+ background = { src: "none" }
+ }
+ else if (typeof background == "string") {
+ background = { src: background }
+ }
+ else if (! background.src) {
+ background = { src: "none" }
+ }
+ background.x = background.x || 0
+ background.y = background.y || 0
+ background.scale = background.scale || 1
+
+ this.background = background
+ this.background.src = this.background.src.replace("url(","").replace(")","")
+
+ if (this.background.src == "none") {
+ this.wallpaperLoad(this.background.src)
+ return
+ }
+ var img = new Image ()
+ img.onload = function(){
+ this.backgroundImage = img
+ this.wallpaperLoad(this.background.src)
+ this.wallpaperPosition(background)
+ }.bind(this)
+ img.src = this.background.src
+ img.complete && img.onload()
+ }
+
+ Wall.prototype.wallpaperLoad = function(url){
+ if (url !== "none") {
+ url = "url(" + url + ")"
+ }
this.mx.forEach(function(mx){
- var partitionOffset = useX ? mx.x : mx.z
- if (shouldFlip) partitionOffset *= -1
- partitionOffset += mx.width/2
- var floorOffset = mx.y + mx.height/2
-
- mx.el.style.backgroundImage = background
- mx.el.style.backgroundPosition = (~~partitionOffset) + "px " + (~~floorOffset) + "px"
+ mx.el.style.backgroundImage = url
})
}
+
+ Wall.prototype.wallpaperPosition = function(background){
+ if (this.background.src == "none") { return }
+ this.background.x = background.x || this.background.x
+ this.background.y = background.y || this.background.y
+ this.background.scale = background.scale || this.background.scale || 1
+
+ var useX = this.side & FRONT_BACK
+ var shouldFlip = this.side & (LEFT | BACK)
+
+ var mx, dx, dy
+ var w = Math.round( this.backgroundImage.naturalWidth * this.background.scale )
+ var h = Math.round( this.backgroundImage.naturalHeight * this.background.scale )
+
+ this.surface.faces.forEach(function(face, i){
+
+ if (shouldFlip) {
+ mx = this.mx[this.mx.length-1-i]
+ dx = Math.round( this.background.x + face.x.a )
+ dy = Math.round( this.background.y + face.y.b )
+ }
+ else {
+ mx = this.mx[i]
+ dx = Math.round( this.background.x - face.x.b )
+ dy = Math.round( this.background.y + face.y.b )
+ }
+
+ mx.el.style.backgroundPosition = dx + 'px ' + dy + 'px'
+ mx.el.style.backgroundSize = w + 'px ' + h + 'px'
+ }.bind(this))
+ bbb = this
+ }
+
Wall.prototype.outline = function(wallColor, outlineColor){
var useX = this.side & FRONT_BACK
var mx = this.mx