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