diff options
| author | Julie Lala <jules@okfoc.us> | 2014-07-17 03:04:28 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-07-17 03:04:28 -0400 |
| commit | f20841988ccd27780d3801e4a6c32bf9afcc9368 (patch) | |
| tree | 43d4db07f0dfc44ac1e41db25397a9982db8850f /public/assets/javascripts | |
| parent | d81c96616859a57d5d5d63a6ae7b1492a5c4974a (diff) | |
conversions between feet/meters/pixels
Diffstat (limited to 'public/assets/javascripts')
| -rw-r--r-- | public/assets/javascripts/app.js | 9 | ||||
| -rw-r--r-- | public/assets/javascripts/mx/extensions/mx.movements.js | 2 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/builder/BuilderInfo.js | 112 | ||||
| -rw-r--r-- | public/assets/javascripts/ui/builder/BuilderView.js | 1 | ||||
| -rw-r--r-- | public/assets/javascripts/util.js | 1 |
5 files changed, 110 insertions, 15 deletions
diff --git a/public/assets/javascripts/app.js b/public/assets/javascripts/app.js index 0b441c7..1419d1d 100644 --- a/public/assets/javascripts/app.js +++ b/public/assets/javascripts/app.js @@ -17,8 +17,6 @@ else { var scene, cam, map; -var viewHeight = window.viewHeight || 186 - var app = new function(){} app.mode = { editor: false, builder: false } @@ -99,4 +97,11 @@ app.position = function(obj){ return pos } +app.defaults = { + viewHeight: window.viewHeight = 186, + units: app.units = "ft", + footResolution: 36, + meterResolution: 100, +} + document.addEventListener('DOMContentLoaded', app.init) diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js index f176e8b..191088f 100644 --- a/public/assets/javascripts/mx/extensions/mx.movements.js +++ b/public/assets/javascripts/mx/extensions/mx.movements.js @@ -1,6 +1,6 @@ -MX.Movements = function (cam, viewHeight) { +MX.Movements = function (cam) { var moveForward, moveLeft, diff --git a/public/assets/javascripts/ui/builder/BuilderInfo.js b/public/assets/javascripts/ui/builder/BuilderInfo.js index 53a122d..9bbd385 100644 --- a/public/assets/javascripts/ui/builder/BuilderInfo.js +++ b/public/assets/javascripts/ui/builder/BuilderInfo.js @@ -5,28 +5,35 @@ var BuilderInfo = View.extend({ events: { "keydown": 'stopPropagation', "change [name=x]": 'changePosition', - "change [name=z]": 'changePosition', + "change [name=y]": 'changePosition', "change [name=width]": 'changeDimensions', "change [name=depth]": 'changeDimensions', "change [name=height]": 'changeDimensions', "change [name=units]": 'changeUnits', "change [name=resolution]": 'changeResolution', - "change [name=camera-height]": 'changeCameraHeight', + "change [name=viewHeight]": 'changeViewHeight', }, initialize: function(opt){ this.parent = opt.parent this.$x = this.$("[name=x]") - this.$z = this.$("[name=z]") + this.$y = this.$("[name=y]") this.$width = this.$("[name=width]") this.$depth = this.$("[name=depth]") this.$height = this.$("[name=height]") this.$units = this.$("[name=units]") - this.$resolution = this.$("[name=resolution]") - this.$cameraHeight = this.$("[name=camera-height]") + this.$viewHeight = this.$("[name=viewHeight]") + this.$unitName = this.$(".unitName") app.on("builder-pick-room", this.pick.bind(this)) app.on("builder-destroy-room", this.destroy.bind(this)) }, + + load: function(data){ + this.$viewHeight.unitVal( data.viewHeight || app.defaults.viewHeight ) + this.$units.val( "ft" ) + this.$unitName.html( "ft" ) + this.$resolution.val( app.defaults.footResolution ) + }, toggle: function(state){ this.$el.toggleClass("active", state) @@ -44,11 +51,11 @@ var BuilderInfo = View.extend({ pick: function(room){ this.room = room - this.$width.val( room.rect.x.length() ) - this.$depth.val( room.rect.y.length() ) - this.$height.val( room.height ) - this.$x.val( room.rect.x.a ) - this.$z.val( room.rect.y.a ) + this.$width.unitVal( room.rect.x.length() ) + this.$depth.unitVal( room.rect.y.length() ) + this.$height.unitVal( room.height ) + this.$x.unitVal( room.rect.x.a ) + this.$y.unitVal( room.rect.y.a ) console.log(room) }, @@ -59,12 +66,95 @@ var BuilderInfo = View.extend({ }, changeDimensions: function(){ +// this.$width.unitVal( room.rect.x.length() ) +// this.$depth.unitVal( room.rect.y.length() ) +// this.$height.unitVal( room.height ) }, changeUnits: function(){ + app.units = this.$units.val() + this.$('.units').resetUnitVal() }, - changeCameraHeight: function(){ + changeViewHeight: function(){ + window.viewHeight = this.$viewHeight.unitVal( ) }, }) + +$.fn.resetUnitVal = function(){ + this.each(function(){ + var n = $(this).data("px") + $(this).unitVal(n) + }); +} + +$.fn.unitVal = function(n){ + var s + if (typeof n === "undefined") { + s = $(this).val() + n = stringToMeasurement( s ) + } + s = measurementToString( n ) + $(this).val( s ).data("px", n) + return n +} + +function measurementToString( n ) { + var s, ft, inch + switch (app.units) { + case 'm': + s = round(n/36 * 0.3048 * 100) / 100 + " m" + break + case 'ft': + ft = floor(n / 36) + inch = abs(round((n % 36) / 3)) + s = ft + "'" + if (inch > 0) { + s += " " + inch + '"' + } + break + case 'px': + default: + s = round(n) + " px" + break + } + return s +} +function stringToMeasurement( s ) { + var ft, inch, ft_in, type + if (s.indexOf("'") !== -1 || s.indexOf('"') !== -1 || s.indexOf('ft') !== -1) { + ft_in = s.match(/[0-9.]+/g) + if (ft_in.length >= 2) { + ft = parseFloat( ft_in[0] ) + inch = parseFloat( ft_in[1] ) + } + else if (ft_in.length == 1) { + if (s.indexOf('"') !== -1) { + ft = 0 + inch = parseFloat( ft_in[0] ) + } + else { + ft = parseFloat( ft_in[0] ) + inch = 0 + } + } + else { + ft = inch = 0 + } + n = ft * 36 + inch * 3 + } + else if (type === "m") { + n = parseFloat(s.match(/[0-9.]+/)) * 36 / 0.3048 + } + else if (s.indexOf("px") !== -1) { + n = parseFloat(s.match(/[0-9.]+/)) + } + else { + n = abs( stringToMeasurement( s + app.units ) ) + } + if (s.indexOf('-') !== -1) { + n *= -1 + } + return n +}
\ No newline at end of file diff --git a/public/assets/javascripts/ui/builder/BuilderView.js b/public/assets/javascripts/ui/builder/BuilderView.js index 7a92738..555cd58 100644 --- a/public/assets/javascripts/ui/builder/BuilderView.js +++ b/public/assets/javascripts/ui/builder/BuilderView.js @@ -26,6 +26,7 @@ var BuilderView = View.extend({ ready: function(data){ this.settings.load(data) + this.info.load(data) }, hideExtras: function(){ diff --git a/public/assets/javascripts/util.js b/public/assets/javascripts/util.js index b58da1f..58dcc3a 100644 --- a/public/assets/javascripts/util.js +++ b/public/assets/javascripts/util.js @@ -176,4 +176,3 @@ function bitcount(v) { v = (v & 0x33333333) + ((v >>> 2) & 0x33333333); return ((v + (v >>> 4) & 0xF0F0F0F) * 0x1010101) >>> 24; } - |
