summaryrefslogtreecommitdiff
path: root/client/assets/javascripts/mx/primitives/mx.coords.js
blob: 80b148c03db872c7f401187916cee479495d611e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
MX.Coords = (function () {

    var colors = {
        x: '#f33',
        y: '#3f3',
        z: '#66f'
    }

    var Axis = MX.Object3D.extend({
        init: function (axis, size) {

            var label = document.createElement('span')
            label.textContent = axis.toUpperCase()
            label.style.position = 'absolute'
            label.style.right = '0px'
            label.style.bottom = '3px'
            label.style.fontSize = Math.round(size / 10) + 'px'
            this.el.appendChild(label)

            var faceA = new MX.Object3D(),
                faceB = new MX.Object3D()
            faceA.rotationX = 90
            this.add(faceA, faceB)

            this.el.style.color =
            faceA.el.style.backgroundColor = 
            faceB.el.style.backgroundColor = colors[axis]

            this.width =
            faceA.width =
            faceB.width = size

            this.height =
            faceA.height =
            faceB.height = Math.round(size / 100)

            var angle = MX.rotationUnit === 'deg' ? 90 : (Math.PI / 2)

            if (axis === 'y') {
                this.rotationZ = -angle
            } else if (axis === 'z') {
                this.rotationY = angle
            }
        }
    })

    var Coords = MX.Object3D.extend({
        init: function (size) {
            size = size || 100
            var x = new Axis('x', size),
                y = new Axis('y', size),
                z = new Axis('z', size)
            this.add(x, y, z)
            this.update()
            this.updateChildren = false
        }
    })

    return Coords

})()