From d1d837f3278e6a3b127acc7fe1a678d2e65e3836 Mon Sep 17 00:00:00 2001 From: monsterkodi Date: Sun, 21 Aug 2016 00:49:04 +0200 Subject: [PATCH] gears --- coffee/gear.coffee | 27 ++++----------------------- coffee/generator.coffee | 18 ++---------------- coffee/geom.coffee | 4 ++-- coffee/levels/test.coffee | 10 ++++------ coffee/valve.coffee | 12 ++++++------ coffee/world.coffee | 2 +- 6 files changed, 19 insertions(+), 54 deletions(-) diff --git a/coffee/gear.coffee b/coffee/gear.coffee index c481ee4..c97e55b 100644 --- a/coffee/gear.coffee +++ b/coffee/gear.coffee @@ -4,7 +4,7 @@ # 000 000 000 000 000 000 000 # 0000000 00000000 000 000 000 000 -log = require '/Users/kodi/s/ko/js/tools/log' +log = require '/Users/kodi/s/ko/js/tools/log' Valve = require './valve' Action = require './action' Pos = require './lib/pos' @@ -12,9 +12,10 @@ Cage = require './cage' Geom = require './geom' class Gear extends Valve + + @neighbors = [ [[0,1,0], [0,-1,0], [0,0,1], [0,0,-1]], [[1,0,0], [-1,0,0], [0,0,1], [0,0,-1]], [[1,0,0], [-1,0,0], [0,1,0], [0,-1,0]] ] constructor: (@face) -> - super @face @updateMesh() @@ -23,16 +24,8 @@ class Gear extends Valve @mesh.add new THREE.Mesh Geom.valve(), Cage.rasterMat @mesh.receiveShadow = true - getNeighborDirections: (face) -> - neighbors = [ - [[0,1,0], [0,-1,0], [0,0,1], [0,0,-1]] - [[1,0,0], [-1,0,0], [0,0,1], [0,0,-1]] - [[1,0,0], [-1,0,0], [0,1,0], [0,-1,0]] - ] - neighbors[face % 3] - getNeighborGears: -> - dirs = @getNeighborDirections @face + dirs = Gear.neighbors[@face % 3] pos = @getPos() gears = [] for i in [0...4] @@ -74,16 +67,4 @@ class Gear extends Valve else gear.updateActive() - render: -> - # if (@active) - # glRotatef (clockwise ? angle : -angle, 0.0, 0.0, 1.0); -# - # KikiValve::colors[0].glColor(); - # render_valve; -# - # glTranslatef (0.0, 0.0, 0.4); -# - # colors[0].glColor(); - # render_gear; - module.exports = Gear diff --git a/coffee/generator.coffee b/coffee/generator.coffee index 82e4d13..2d9fe6f 100644 --- a/coffee/generator.coffee +++ b/coffee/generator.coffee @@ -16,7 +16,7 @@ class Generator extends Gear createMesh: -> @mesh = new THREE.Mesh Geom.generator(), Cage.cageMat - # @mesh.add new THREE.Mesh Geom.gear(), Cage.rasterMat + @mesh.add new THREE.Mesh Geom.gear(), Cage.rasterMat @mesh.receiveShadow = true activateWires: -> @@ -30,19 +30,5 @@ class Generator extends Gear super active @activateWires() world.playSound @active and 'GENERATOR_ON' or 'GENERATOR_OFF' - - render: -> - # if (active) - # glRotatef (clockwise ? angle : -angle, 0.0, 0.0, 1.0); -# - # colors[0].glColor(); -# - # render_generator; -# - # KikiGear::colors[0].glColor(); -# - # glTranslatef (0.0, 0.0, 0.4); -# - # render_gear; - + module.exports = Generator diff --git a/coffee/geom.coffee b/coffee/geom.coffee index b4fcd65..20b0615 100644 --- a/coffee/geom.coffee +++ b/coffee/geom.coffee @@ -444,8 +444,8 @@ class Geom @valveQuadStrip2 = [ 0.042, 0.042, -0.220, 0.042, 0.042, 0.220, - -0.220, - 0.220, + 0.059, 0, -0.220, + 0.059, 0, 0.220, 0.042, -0.042, -0.220, 0.042, -0.042, 0.220, 0, -0.059, -0.220, diff --git a/coffee/levels/test.coffee b/coffee/levels/test.coffee index bff4e0e..3d64c20 100644 --- a/coffee/levels/test.coffee +++ b/coffee/levels/test.coffee @@ -19,15 +19,13 @@ module.exports = s = world.size {Gear,Generator,MotorCylinder,MotorGear,Face} = require '../items' - world.addObjectAtPos new Generator(Face.NX), 4, 5, 0 - world.addObjectAtPos new Generator(Face.X), 6, 5, 0 - # world.addObjectAtPos new Gear(Face.NZ), 6, 5, 0 - # world.addObjectAtPos new Gear(Face.Z), 4, 5, 0 - return + world.addObjectAtPos new Generator(Face.Z), 5, 5, 0 + world.addObjectAtPos new Gear(Face.Z), 4, 5, 0 + world.addObjectAtPos new Gear(Face.Z), 6, 5, 0 world.addObjectAtPos new Gear(Face.Z), 5, 6, 0 world.addObjectAtPos new Gear(Face.Z), 5, 4, 0 - + world.addObjectAtPos new Gear(Face.Z), 6, 6, 0 world.addObjectAtPos new Gear(Face.Z), 4, 4, 0 world.addObjectAtPos new Gear(Face.Z), 4, 6, 0 diff --git a/coffee/valve.coffee b/coffee/valve.coffee index 1882fc3..c3607b1 100644 --- a/coffee/valve.coffee +++ b/coffee/valve.coffee @@ -4,11 +4,11 @@ # 000 000 000 000 000 000 # 0 000 000 0000000 0 00000000 -log = require '/Users/kodi/s/ko/js/tools/log' +log = require '/Users/kodi/s/ko/js/tools/log' Quaternion = require './lib/quaternion' -Pushable = require './pushable' -Action = require './action' -Face = require './face' +Pushable = require './pushable' +Action = require './action' +Face = require './face' class Valve extends Pushable @@ -18,7 +18,7 @@ class Valve extends Pushable @active = false @clockwise = false @addAction new Action @, Action.ROTATE, "rotation", 2000, Action.REPEAT - @startTimedAction @getActionWithId Action.ROTATE + # @startTimedAction @getActionWithId Action.ROTATE updateMesh: -> # log "Valve.updateMesh #{@angle} #{@face}" @@ -31,7 +31,7 @@ class Valve extends Pushable dir = @face % 3 sum = ((dir == Face.Y or dir == Face.Z) and p.x or 0) + ((dir == Face.X or dir == Face.Z) and p.y or 0) + ((dir == Face.X or dir == Face.Y) and p.z or 0) @clockwise = sum % 2 - log "Valve.setPosition sum #{sum} @clockwise #{@clockwise}", pos + # log "Valve.setPosition sum #{sum} @clockwise #{@clockwise}", pos performAction: (action) -> switch action.id diff --git a/coffee/world.coffee b/coffee/world.coffee index 170154c..4a1e34f 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -61,7 +61,7 @@ class World extends Actor super - @noRotations = true + @noRotations = false @screenSize = new Size @view.clientWidth, @view.clientHeight # log "view @screenSize:", @screenSize