diff --git a/coffee/bot.coffee b/coffee/bot.coffee index 5574e88..f05700a 100644 --- a/coffee/bot.coffee +++ b/coffee/bot.coffee @@ -436,10 +436,10 @@ class Bot extends Pushable moveBot: () -> @move_action = null - log "bot.moveBot @position", @position - log "bot.moveBot @getDir", @getDir() + # log "bot.moveBot @position", @position + # log "bot.moveBot @getDir", @getDir() forwardPos = @position.plus @getDir() - log "bot.moveBot", forwardPos + # log "bot.moveBot", forwardPos if @jump or @jump_once and # jump mode or jump activated while moving @dir_sgn == 1.0 and # and moving forward world.isUnoccupiedPos @position.plus @getUp() # and above empty diff --git a/coffee/lib/vector.coffee b/coffee/lib/vector.coffee index 9e5ddb6..7e74dc8 100644 --- a/coffee/lib/vector.coffee +++ b/coffee/lib/vector.coffee @@ -85,15 +85,15 @@ class Vector add: (v) -> @x += v.x @y += v.y - @z += v.z - @w += v.w + @z += v.z ? 0 + @w += v.w ? 0 @ sub: (v) -> @x -= v.x @y -= v.y - @z -= v.z - @w -= v.w + @z -= v.z ? 0 + @w -= v.w ? 0 @ scale: (f) -> @@ -117,7 +117,12 @@ class Vector point.minus(planeNormal).dot point.minus(planePos).dot(planeNormal) @rayPlaneIntersectionFactor: (rayPos, rayDirection, planePos, planeNormal) -> - planePos.minus(rayPos).dot(planeNormal) / rayDirection.dot(planeNormal) + # ((planePos - rayPos) * planeNormal) / (rayDirection * planeNormal); + r = planePos.minus(rayPos).dot(planeNormal) / rayDirection.dot(planeNormal) + # log 'rayPlaneIntersectionFactor', r + if Number.isNaN r + throw new Error + r @DEG2RAD: (d) -> Math.PI*d/180.0 @RAD2DEG: (r) -> r*180.0/Math.PI diff --git a/coffee/perspective.coffee b/coffee/perspective.coffee index 47abf0e..cef1aee 100644 --- a/coffee/perspective.coffee +++ b/coffee/perspective.coffee @@ -59,18 +59,10 @@ class Perspective extends Matrix @setPosition savePos.plus @getZVector().mul @eye_distance apply: (camera) -> - camPos = @getPosition() - up = @getYVector() - lookAt = @getLookAtPosition() - - # log "Perspective.apply", @matrix #camPos, up, lookAt - # log "Perspective.apply", camPos, up, lookAt - # log "Perspective.apply", new Pos(camPos), new Pos(up), new Pos(lookAt) - - camera.position.clone camPos #set camPos.x, camPos.y, camPos.z - camera.up.clone up #new THREE.Vector3 up.x, up.y, up.z - camera.lookAt new THREE.Vector3 lookAt.x, lookAt.y, lookAt.z + camera.position.copy camPos + camera.up.copy @getYVector() + camera.lookAt camPos.minus @getZVector() if @light? pos = @getPosition().plus @light_offset diff --git a/coffee/player.coffee b/coffee/player.coffee index cad63c7..a452929 100644 --- a/coffee/player.coffee +++ b/coffee/player.coffee @@ -4,7 +4,9 @@ # 00000000 000 000000000 00000 0000000 0000000 # 000 000 000 000 000 000 000 000 # 000 0000000 000 000 000 00000000 000 000 - +{ +clamp +} = require '/Users/kodi/s/ko/js/tools/tools' log = require '/Users/kodi/s/ko/js/tools/log' Bot = require './bot' Action = require './action' @@ -96,18 +98,15 @@ class Player extends Bot @look_rot = Quaternion.rotationAroundVector @look_angle, @projection.getXVector() @projection.setYVector @look_rot.rotate playerUp @projection.setZVector @look_rot.rotate playerDir.neg() - log 'Player.getProjection 2', @projection.matrix else # smooth camera rotation a little bit lookDelta = (2.0 - @projection.getZVector().dot playerDir) * world.getSpeed() / 50.0 newLookVector = @projection.getZVector().mul(1.0 - lookDelta).minus playerDir.mul lookDelta newLookVector.normalize() - @projection.setXVector playerUp.cross(newLookVector).normal() @projection.setYVector playerUp @projection.setZVector newLookVector - # log 'Player.getProjection', @projection.getPosition() @projection # 0000000 00000000 000 000 000 000 000 0000000 @@ -150,7 +149,7 @@ class Player extends Bot @projection.setXVector playerUp.cross(newLookVector).normal() @projection.setYVector newLookVector.cross(@projection.getXVector()).normal() - log 'Player.getBehindProjection', @projection.getPosition() + # log 'Player.getBehindProjection', @projection.getPosition() @projection # 00000000 0000000 000 000 0000000 000 000 @@ -167,6 +166,7 @@ class Player extends Bot @updatePosition() playerPos = @current_position # desired look pos + # log 'getFollowProjection.current_position', @current_position playerDir = @getCurrentDir() playerUp = @current_orientation.rotate new Vector(0,1,0).normal() playerRight = playerDir.cross(playerUp).normal() @@ -203,6 +203,7 @@ class Player extends Bot botToCameraNormal = botToCamera.normal() rotFactor = 1.0 + log "playerPos", playerPos wall_distance = world.getWallDistanceForPos playerPos.plus botToCamera if wall_distance < 0.5 # ____________________________________________________ piercing walls @@ -228,7 +229,7 @@ class Player extends Bot # ____________________________________________________ finally, set the position @projection.setPosition cameraPos - log 'cameraPos:', cameraPos + # log 'cameraPos:', cameraPos # ____________________________________________________ refining camera orientation # slowly adjust look direction by interpolating current and desired directions @@ -248,7 +249,7 @@ class Player extends Bot @projection.setZVector newLookVector @projection.setXVector newRightVector @projection.setYVector newUpVector - log 'Player.getFollowProjection', @projection.getPosition() + # log 'Player.getFollowProjection', @projection.getPosition() @projection # 0000000 0000000 000000000 000 0000000 000 000 diff --git a/coffee/world.coffee b/coffee/world.coffee index bcb1118..9bc204d 100644 --- a/coffee/world.coffee +++ b/coffee/world.coffee @@ -48,7 +48,7 @@ class World extends Actor super - @speed = 2.0 + @speed = 5.0 @screenSize = new Size @view.clientWidth, @view.clientHeight # log "view @screenSize:", @screenSize @@ -104,8 +104,8 @@ class World extends Actor @cells = [] @size = new Pos() @depth = -Number.MAX_SAFE_INTEGER - # @camera_mode = World.CAMERA_BEHIND @camera_mode = World.CAMERA_INSIDE + # @camera_mode = World.CAMERA_BEHIND # @camera_mode = World.CAMERA_FOLLOW @edit_projection = null @raster_size = 0.1 @@ -230,13 +230,6 @@ class World extends Actor # else # @applyColorScheme default_scheme - # if "border" in @dict - # border = @dict["border"] - # else - # border = 1 - - # @setDisplayBorder border - # ............................................................ intro text # if "intro" in @dict # if not @preview @@ -804,17 +797,15 @@ class World extends Actor Timer.event.finishActions() o.step?(step) for o in @objects - @display() - @sun.position.copy @camera.position - @renderer.render @scene, @camera - display: () -> - # log "world.display #{@camera_mode}" switch @camera_mode when World.CAMERA_INSIDE then @projection = @player.getProjection() when World.CAMERA_BEHIND then @projection = @player.getBehindProjection() when World.CAMERA_FOLLOW then @projection = @player.getFollowProjection() @projection.apply @camera + + @sun.position.copy @camera.position + @renderer.render @scene, @camera # 000000000 000 00 00 00000000 # 000 000 000 000 000 @@ -922,7 +913,7 @@ class World extends Actor f = Vector.rayPlaneIntersectionFactor pos, World.normals[w].neg(), planePos, World.normals[w] if f < delta insidePos.add World.normals[w].mul delta-f - log 'getInsideWallPosWithDelta', insidePos + # log 'getInsideWallPosWithDelta', insidePos insidePos getWallDistanceForPos: (pos) -> # distance to the next wall (positive or negative) @@ -931,9 +922,9 @@ class World extends Actor planePos = new Vector -0.5, -0.5, -0.5 if w >= 3 then planePos.add @size f = Vector.rayPlaneIntersectionFactor pos, World.normals[w].neg(), planePos, World.normals[w] - log "getWallDistanceForPos #{min_f} #{f}" + log "getWallDistanceForPos w #{w} min_f #{min_f} f #{f}" min_f = absMin min_f, f - log "getWallDistanceForPos #{min_f}", pos + # log "getWallDistanceForPos #{min_f}", pos min_f getWallDistanceForRay: (rayPos, rayDirection) -> # distance to the next wall in rayDirection