player
This commit is contained in:
parent
b3db929331
commit
438be70529
|
@ -62,6 +62,7 @@ class Actor extends Emitter
|
||||||
return a if action.name = name
|
return a if action.name = name
|
||||||
|
|
||||||
addEventWithName: (eventName) ->
|
addEventWithName: (eventName) ->
|
||||||
|
log "Actor.addEventWithName eventName:#{eventName}"
|
||||||
if @getEventWithName eventName # to be removed
|
if @getEventWithName eventName # to be removed
|
||||||
log "Actor.addEventWithName '#{eventName}' already in use!"
|
log "Actor.addEventWithName '#{eventName}' already in use!"
|
||||||
return -1; # shouldn't happen anyway :-)
|
return -1; # shouldn't happen anyway :-)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
# 000 000 000 000
|
# 000 000 000 000
|
||||||
# 0000000 00000000 0000000 0000000
|
# 0000000 00000000 0000000 0000000
|
||||||
|
|
||||||
|
TmpObject = require './tmpobject'
|
||||||
|
|
||||||
class Cell
|
class Cell
|
||||||
|
|
||||||
constructor: () -> @objects = []
|
constructor: () -> @objects = []
|
||||||
|
@ -12,7 +14,7 @@ class Cell
|
||||||
getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss
|
getObjectsOfType: (clss) -> @objects.filter (o) -> o instanceof clss
|
||||||
getObjectOfType: (clss) -> _.find @objects, (o) -> o instanceof clss
|
getObjectOfType: (clss) -> _.find @objects, (o) -> o instanceof clss
|
||||||
|
|
||||||
getRealObjectOfType: (clss) -> _.find @objects, (o) -> o instanceof clss or o instanceof KikiTmpObject and o.object instanceof clss
|
getRealObjectOfType: (clss) -> _.find @objects, (o) -> o instanceof clss or o instanceof TmpObject and o.object instanceof clss
|
||||||
getOccupant: -> _.find @objects, (o) -> o.isSpaceEgoistic()
|
getOccupant: -> _.find @objects, (o) -> o.isSpaceEgoistic()
|
||||||
|
|
||||||
removeObject: (object) ->
|
removeObject: (object) ->
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
log = require '/Users/kodi/s/ko/js/tools/log'
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
Actor = require './actor'
|
Actor = require './actor'
|
||||||
Vector = require './lib/vector'
|
Vector = require './lib/vector'
|
||||||
|
Quat = require './lib/quaternion'
|
||||||
Pos = require './lib/pos'
|
Pos = require './lib/pos'
|
||||||
|
|
||||||
class Item extends Actor
|
class Item extends Actor
|
||||||
|
@ -29,26 +30,17 @@ class Item extends Actor
|
||||||
isSpaceEgoistic: -> true
|
isSpaceEgoistic: -> true
|
||||||
isSlippery: -> false
|
isSlippery: -> false
|
||||||
|
|
||||||
setPosition: (p) ->
|
setPosition: (x,y,z) ->
|
||||||
@position = @current_position = p
|
@position = @current_position = new Vector x, y, z
|
||||||
if @mesh?
|
@mesh?.position.copy @position
|
||||||
log 'setPosition', @mesh.position
|
|
||||||
# @mesh.position = new THREE.Vector3 @position.x, @position.y, @position.z
|
|
||||||
# @mesh.matrixWorldNeedsUpdate = true
|
|
||||||
# @mesh.updateMatrix()
|
|
||||||
# @mesh.updateMatrixWorld true
|
|
||||||
@mesh.translateX @position.x
|
|
||||||
@mesh.translateY @position.y
|
|
||||||
@mesh.translateZ @position.z
|
|
||||||
log 'setPosition', p, @mesh.position
|
|
||||||
|
|
||||||
getPos: -> new Pos @current_position
|
getPos: -> new Pos @current_position
|
||||||
|
|
||||||
getPosition: -> @position
|
# getPosition: -> @position
|
||||||
getOrientation: -> @orientation
|
# getOrientation: -> @orientation
|
||||||
getCurrentPosition: -> @current_position
|
# getCurrentPosition: -> @current_position
|
||||||
getCurrentOrientation: -> @current_orientation
|
# getCurrentOrientation: -> @current_orientation
|
||||||
setOrientation: (q) -> @current_orientation = @orientation = q
|
setOrientation: (q) -> @current_orientation = @orientation = new Quat q
|
||||||
setCurrentPosition: (p) -> @current_position = p
|
setCurrentPosition: (p) -> @current_position = p
|
||||||
setCurrentOrientation: (q) -> @current_orientation = q
|
setCurrentOrientation: (q) -> @current_orientation = q
|
||||||
|
|
||||||
|
|
|
@ -13,21 +13,17 @@ class Matrix
|
||||||
|
|
||||||
@matrix = []
|
@matrix = []
|
||||||
|
|
||||||
if o instanceof Matrix
|
switch
|
||||||
@copy o
|
when not o? then @reset()
|
||||||
|
when o instanceof Quaternion then @initQuat o
|
||||||
else if o instanceof Array
|
when o instanceof Matrix then @copy o
|
||||||
|
when o instanceof Array
|
||||||
if o.length == 16
|
if o.length == 16
|
||||||
for i in [0...16]
|
for i in [0...16]
|
||||||
@matrix[i] = o[i]
|
@matrix[i] = o[i]
|
||||||
|
when o?.x? and o?.y? and o?.z?
|
||||||
else if o?.x? and o?.y? and o?.z?
|
|
||||||
@initXYZ o.x, o.y, o.z
|
@initXYZ o.x, o.y, o.z
|
||||||
|
else @reset()
|
||||||
else if o instanceof Quaternion
|
|
||||||
@initQuat o
|
|
||||||
else
|
|
||||||
@reset()
|
|
||||||
|
|
||||||
initXYZ: (x,y,z) ->
|
initXYZ: (x,y,z) ->
|
||||||
@matrix[0] = x.x
|
@matrix[0] = x.x
|
||||||
|
|
|
@ -9,7 +9,7 @@ Matrix = require './lib/matrix'
|
||||||
|
|
||||||
class Perspective extends Matrix
|
class Perspective extends Matrix
|
||||||
|
|
||||||
constructor: (fov,near,far) ->
|
constructor: (fov,near=0.1,far=10000) ->
|
||||||
@znear = near
|
@znear = near
|
||||||
@zfar = far
|
@zfar = far
|
||||||
@fov = fov
|
@fov = fov
|
||||||
|
@ -19,8 +19,9 @@ class Perspective extends Matrix
|
||||||
@setViewport 0.0, 0.0, 1.0, 1.0
|
@setViewport 0.0, 0.0, 1.0, 1.0
|
||||||
# WINDOW_SIZE_CHANGED -> updateViewport
|
# WINDOW_SIZE_CHANGED -> updateViewport
|
||||||
super
|
super
|
||||||
|
log "Perspective #{@fov} #{@znear} #{@zfar}"
|
||||||
|
|
||||||
reset: () ->
|
reset: ->
|
||||||
@fov = 60.0
|
@fov = 60.0
|
||||||
@eye_distance = @znear
|
@eye_distance = @znear
|
||||||
super
|
super
|
||||||
|
@ -65,7 +66,7 @@ class Perspective extends Matrix
|
||||||
up = @getYVector()
|
up = @getYVector()
|
||||||
lookAt = @getLookAtPosition()
|
lookAt = @getLookAtPosition()
|
||||||
|
|
||||||
log "Perspective.apply", camPos, up, lookAt
|
# log "Perspective.apply", @matrix #camPos, up, lookAt
|
||||||
|
|
||||||
camera.position.clone camPos #set camPos.x, camPos.y, camPos.z
|
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.up.clone up #new THREE.Vector3 up.x, up.y, up.z
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
# 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
|
||||||
|
|
||||||
|
log = require '/Users/kodi/s/ko/js/tools/log'
|
||||||
Bot = require './bot'
|
Bot = require './bot'
|
||||||
Action = require './action'
|
Action = require './action'
|
||||||
Timer = require './timer'
|
Timer = require './timer'
|
||||||
|
@ -49,43 +50,41 @@ class Player extends Bot
|
||||||
# @projection.getLight().setCutoff 90.0
|
# @projection.getLight().setCutoff 90.0
|
||||||
# @projection.getLight().setAttenuation 1.0, 0.0, 0.05
|
# @projection.getLight().setAttenuation 1.0, 0.0, 0.05
|
||||||
|
|
||||||
getActionForKey: (keyName) ->
|
# getActionForKey: (keyName) ->
|
||||||
index = 0
|
# index = 0
|
||||||
while actionKeyMapping[index].actionName
|
# while actionKeyMapping[index].actionName
|
||||||
if keyName == actionKeyMapping[index].keyName
|
# if keyName == actionKeyMapping[index].keyName
|
||||||
return actionKeyMapping[index].actionName
|
# return actionKeyMapping[index].actionName
|
||||||
index++
|
# index += 1
|
||||||
|
# return ''
|
||||||
|
#
|
||||||
|
# getKeyForAction: (actionName) ->
|
||||||
|
# index = 0
|
||||||
|
# while actionKeyMapping[index].actionName
|
||||||
|
# if actionName == actionKeyMapping[index].actionName
|
||||||
|
# return actionKeyMapping[index].keyName
|
||||||
|
# index += 1
|
||||||
|
# return ''
|
||||||
|
#
|
||||||
|
# setKeyForAction: (keyName, actionName) ->
|
||||||
|
# index = 0
|
||||||
|
# while actionKeyMapping[index].actionName
|
||||||
|
# if actionName == actionKeyMapping[index].actionName
|
||||||
|
# actionKeyMapping[index].keyName = keyName
|
||||||
|
# index += 1
|
||||||
|
|
||||||
return ""
|
# recordKeyForAction: (actionName) ->
|
||||||
|
# RecordingActionName = actionName
|
||||||
getKeyForAction: (actionName) ->
|
# KeyRecorder.startRecordingSequence @, @setRecordedKey, 1
|
||||||
index = 0
|
#
|
||||||
while actionKeyMapping[index].actionName
|
# setRecordedKey: (keyName) ->
|
||||||
if actionName == actionKeyMapping[index].actionName
|
# index = 0
|
||||||
return actionKeyMapping[index].keyName
|
# while actionKeyMapping[index].actionName
|
||||||
index++
|
# if keyName == actionKeyMapping[index].keyName and actionKeyMapping[index].actionName != RecordingActionName
|
||||||
|
# setKeyForAction "", actionKeyMapping[index].actionName
|
||||||
return ""
|
# index += 1
|
||||||
|
# setKeyForAction keyName, RecordingActionName
|
||||||
setKeyForAction: (keyName, actionName) ->
|
# getEventWithName("keyset").triggerActions()
|
||||||
index = 0
|
|
||||||
while actionKeyMapping[index].actionName
|
|
||||||
if actionName == actionKeyMapping[index].actionName
|
|
||||||
actionKeyMapping[index].keyName = keyName
|
|
||||||
index++
|
|
||||||
|
|
||||||
recordKeyForAction: (actionName) ->
|
|
||||||
RecordingActionName = actionName
|
|
||||||
KeyRecorder.startRecordingSequence @, @setRecordedKey, 1
|
|
||||||
|
|
||||||
setRecordedKey: (keyName) ->
|
|
||||||
index = 0
|
|
||||||
while actionKeyMapping[index].actionName
|
|
||||||
if keyName == actionKeyMapping[index].keyName and actionKeyMapping[index].actionName != RecordingActionName
|
|
||||||
setKeyForAction "", actionKeyMapping[index].actionName
|
|
||||||
index += 1
|
|
||||||
setKeyForAction keyName, RecordingActionName
|
|
||||||
getEventWithName("keyset").triggerActions()
|
|
||||||
|
|
||||||
updatePosition: () ->
|
updatePosition: () ->
|
||||||
if @move_action
|
if @move_action
|
||||||
|
@ -101,7 +100,14 @@ class Player extends Bot
|
||||||
when Action.FALL_FORWARD
|
when Action.FALL_FORWARD
|
||||||
@current_position = @position + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getDir() + (1.0 - Math.cos(Math.PI/2 * relTime)) * -@getUp()
|
@current_position = @position + Math.cos(Math.PI/2 - Math.PI/2 * relTime) * @getDir() + (1.0 - Math.cos(Math.PI/2 * relTime)) * -@getUp()
|
||||||
|
|
||||||
|
# 00000000 00000000 0000000 000 00000000 0000000 000000000 000 0000000 000 000
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 000 000 000 0000 000
|
||||||
|
# 00000000 0000000 000 000 000 0000000 000 000 000 000 000 000 0 000
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 000 000 000 000 0000
|
||||||
|
# 000 000 000 0000000 0000000 00000000 0000000 000 000 0000000 000 000
|
||||||
|
|
||||||
getProjection: () ->
|
getProjection: () ->
|
||||||
|
log 'getProjection'
|
||||||
# smooth camera movement a little bit
|
# smooth camera movement a little bit
|
||||||
posDelta = world.getSpeed() / 10.0
|
posDelta = world.getSpeed() / 10.0
|
||||||
@projection.setPosition ((1.0 - posDelta) * @projection.getPosition() + posDelta * @current_position)
|
@projection.setPosition ((1.0 - posDelta) * @projection.getPosition() + posDelta * @current_position)
|
||||||
|
@ -126,7 +132,14 @@ class Player extends Bot
|
||||||
|
|
||||||
@projection
|
@projection
|
||||||
|
|
||||||
|
# 0000000 00000000 000 000 000 000 000 0000000
|
||||||
|
# 000 000 000 000 000 000 0000 000 000 000
|
||||||
|
# 0000000 0000000 000000000 000 000 0 000 000 000
|
||||||
|
# 000 000 000 000 000 000 000 0000 000 000
|
||||||
|
# 0000000 00000000 000 000 000 000 000 0000000
|
||||||
|
|
||||||
getBehindProjection: () ->
|
getBehindProjection: () ->
|
||||||
|
log 'getBehindProjection'
|
||||||
@updatePosition()
|
@updatePosition()
|
||||||
|
|
||||||
@playerDir = getCurrentDir()
|
@playerDir = getCurrentDir()
|
||||||
|
@ -162,7 +175,15 @@ class Player extends Bot
|
||||||
|
|
||||||
@projection
|
@projection
|
||||||
|
|
||||||
|
|
||||||
|
# 00000000 0000000 000 000 0000000 000 000
|
||||||
|
# 000 000 000 000 000 000 000 000 0 000
|
||||||
|
# 000000 000 000 000 000 000 000 000000000
|
||||||
|
# 000 000 000 000 000 000 000 000 000
|
||||||
|
# 000 0000000 0000000 0000000 0000000 00 00
|
||||||
|
|
||||||
getFollowProjection: () ->
|
getFollowProjection: () ->
|
||||||
|
log 'getFollowProjection'
|
||||||
cameraPos = @projection.getPosition() # current camera position
|
cameraPos = @projection.getPosition() # current camera position
|
||||||
desiredDistance = 2.0 # desired distance from camera to bot
|
desiredDistance = 2.0 # desired distance from camera to bot
|
||||||
|
|
||||||
|
@ -253,6 +274,13 @@ class Player extends Bot
|
||||||
|
|
||||||
@projection
|
@projection
|
||||||
|
|
||||||
|
|
||||||
|
# 0000000 0000000 000000000 000 0000000 000 000
|
||||||
|
# 000 000 000 000 000 000 000 0000 000
|
||||||
|
# 000000000 000 000 000 000 000 000 0 000
|
||||||
|
# 000 000 000 000 000 000 000 000 0000
|
||||||
|
# 000 000 0000000 000 000 0000000 000 000
|
||||||
|
|
||||||
initAction: (action) ->
|
initAction: (action) ->
|
||||||
actionId = action.id
|
actionId = action.id
|
||||||
switch actionId
|
switch actionId
|
||||||
|
@ -266,6 +294,17 @@ class Player extends Bot
|
||||||
|
|
||||||
super action
|
super action
|
||||||
|
|
||||||
|
finishRotateAction: () ->
|
||||||
|
if rotate_action
|
||||||
|
@rotate = false
|
||||||
|
@finishAction rotate_action
|
||||||
|
|
||||||
|
# 00000000 00000000 00000000 00000000 0000000 00000000 00 00
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
# 00000000 0000000 0000000 000000 000 000 0000000 000000000
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 0 000
|
||||||
|
# 000 00000000 000 000 000 0000000 000 000 000 000
|
||||||
|
|
||||||
performAction: (action) ->
|
performAction: (action) ->
|
||||||
relTime = action.getRelativeTime()
|
relTime = action.getRelativeTime()
|
||||||
|
|
||||||
|
@ -286,6 +325,12 @@ class Player extends Bot
|
||||||
else
|
else
|
||||||
super action
|
super action
|
||||||
|
|
||||||
|
# 00000000 000 000 000 000 0000000 000 000
|
||||||
|
# 000 000 0000 000 000 000 000 000
|
||||||
|
# 000000 000 000 0 000 000 0000000 000000000
|
||||||
|
# 000 000 000 0000 000 000 000 000
|
||||||
|
# 000 000 000 000 000 0000000 000 000
|
||||||
|
|
||||||
finishAction: (action) ->
|
finishAction: (action) ->
|
||||||
actionId = action.id
|
actionId = action.id
|
||||||
|
|
||||||
|
@ -294,14 +339,14 @@ class Player extends Bot
|
||||||
@look_angle = 0.0
|
@look_angle = 0.0
|
||||||
else
|
else
|
||||||
if action == @move_action # move finished, update direction
|
if action == @move_action # move finished, update direction
|
||||||
dir_sgn = new_dir_sgn
|
@dir_sgn = @new_dir_sgn
|
||||||
|
|
||||||
if actionId != Action.LOOK_UP and actionId != Action.LOOK_DOWN
|
if actionId != Action.LOOK_UP and actionId != Action.LOOK_DOWN
|
||||||
KikiBot.finishAction(action)
|
KikiBot.finishAction(action)
|
||||||
|
|
||||||
if actionId == Action.TURN_LEFT or actionId == Action.TURN_RIGHT
|
if actionId == Action.TURN_LEFT or actionId == Action.TURN_RIGHT
|
||||||
if rotate
|
if rotate
|
||||||
rotate_action = getActionWithId rotate
|
@rotate_action = getActionWithId rotate
|
||||||
rotate_action.reset()
|
rotate_action.reset()
|
||||||
Timer.addAction rotate_action
|
Timer.addAction rotate_action
|
||||||
|
|
||||||
|
@ -314,29 +359,36 @@ class Player extends Bot
|
||||||
|
|
||||||
reborn: () ->
|
reborn: () ->
|
||||||
# Controller.addKeyHandler @
|
# Controller.addKeyHandler @
|
||||||
died = false
|
@died = false
|
||||||
|
|
||||||
reset: () ->
|
reset: () ->
|
||||||
KikiBot.reset()
|
super
|
||||||
Timer.removeActionsOfObject @
|
Timer.removeActionsOfObject @
|
||||||
|
|
||||||
@look_action = null
|
@look_action = null
|
||||||
@look_angle = 0.0
|
@look_angle = 0.0
|
||||||
new_dir_sgn = 1.0
|
@new_dir_sgn = 1.0
|
||||||
rotate = 0
|
@rotate = 0
|
||||||
|
|
||||||
recorder = null
|
# @recorder = null
|
||||||
playback = null
|
# @playback = null
|
||||||
|
|
||||||
saveRecorder: () ->
|
# saveRecorder: () ->
|
||||||
if @recorder
|
# if @recorder
|
||||||
@recorder.save()
|
# @recorder.save()
|
||||||
@recorder = null
|
# @recorder = null
|
||||||
|
#
|
||||||
|
# startRecorder: (file) ->
|
||||||
|
# if @recorder
|
||||||
|
# saveRecorder()
|
||||||
|
# @recorder = new KikiRecorder file
|
||||||
|
|
||||||
startRecorder: (file) ->
|
|
||||||
if @recorder
|
# 000 000 00000000 000 000
|
||||||
saveRecorder()
|
# 000 000 000 000 000
|
||||||
@recorder = new KikiRecorder file
|
# 0000000 0000000 00000
|
||||||
|
# 000 000 000 000
|
||||||
|
# 000 000 00000000 000
|
||||||
|
|
||||||
handleKey: (key) ->
|
handleKey: (key) ->
|
||||||
keyName = key.getUnmodifiedName()
|
keyName = key.getUnmodifiedName()
|
||||||
|
@ -349,11 +401,11 @@ class Player extends Bot
|
||||||
|
|
||||||
if @move_action == null # player is currently not performing a move action
|
if @move_action == null # player is currently not performing a move action
|
||||||
# forward or backward direction
|
# forward or backward direction
|
||||||
new_dir_sgn = dir_sgn = (key.getUnmodifiedName() == backward_key) ? -1 : 1
|
@new_dir_sgn = @dir_sgn = (key.getUnmodifiedName() == backward_key) ? -1 : 1
|
||||||
|
|
||||||
moveBot() # perform new move action (depending on environment)
|
moveBot() # perform new move action (depending on environment)
|
||||||
else
|
else
|
||||||
new_dir_sgn = (keyName == backward_key) ? -1 : 1
|
@new_dir_sgn = (keyName == backward_key) ? -1 : 1
|
||||||
|
|
||||||
return keyHandled()
|
return keyHandled()
|
||||||
|
|
||||||
|
@ -395,6 +447,12 @@ class Player extends Bot
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
# 00000000 00000000 000 00000000 0000000 0000000 00000000
|
||||||
|
# 000 000 000 000 000 000 000 000 000
|
||||||
|
# 0000000 0000000 000 0000000 000000000 0000000 0000000
|
||||||
|
# 000 000 000 000 000 000 000 000 000
|
||||||
|
# 000 000 00000000 0000000 00000000 000 000 0000000 00000000
|
||||||
|
|
||||||
handleKeyRelease: (key) ->
|
handleKeyRelease: (key) ->
|
||||||
keyName = key.getUnmodifiedName()
|
keyName = key.getUnmodifiedName()
|
||||||
releaseHandled = ->
|
releaseHandled = ->
|
||||||
|
@ -440,6 +498,13 @@ class Player extends Bot
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
|
# 0000000 000 0000000 00000000 000 0000000 000 000
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
# 000 000 000 0000000 00000000 000 000000000 00000
|
||||||
|
# 000 000 000 000 000 000 000 000 000
|
||||||
|
# 0000000 000 0000000 000 0000000 000 000 000
|
||||||
|
|
||||||
display: () ->
|
display: () ->
|
||||||
if world.getCameraMode() != world.CAMERA_INSIDE or world.getEditMode()
|
if world.getCameraMode() != world.CAMERA_INSIDE or world.getEditMode()
|
||||||
render()
|
render()
|
||||||
|
@ -462,9 +527,4 @@ class Player extends Bot
|
||||||
|
|
||||||
return colors[KikiPlayer_tire_color]
|
return colors[KikiPlayer_tire_color]
|
||||||
|
|
||||||
finishRotateAction: () ->
|
|
||||||
if rotate_action
|
|
||||||
@rotate = false
|
|
||||||
@finishAction rotate_action
|
|
||||||
|
|
||||||
module.exports = Player
|
module.exports = Player
|
||||||
|
|
18
coffee/tmpobject.coffee
Normal file
18
coffee/tmpobject.coffee
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# 000000000 00 00 00000000 0000000 0000000 000 00000000 0000000 000000000
|
||||||
|
# 000 000 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
# 000 000000000 00000000 000 000 0000000 000 0000000 000 000
|
||||||
|
# 000 000 0 000 000 000 000 000 000 000 000 000 000 000
|
||||||
|
# 000 000 000 000 0000000 0000000 0000000 00000000 0000000 000
|
||||||
|
|
||||||
|
Item = require './item'
|
||||||
|
|
||||||
|
class TmpObject extends Item
|
||||||
|
|
||||||
|
constructor: (o) ->
|
||||||
|
@time = 0
|
||||||
|
@object = o
|
||||||
|
super
|
||||||
|
|
||||||
|
del: ->
|
||||||
|
|
||||||
|
module.exports = TmpObject
|
|
@ -13,6 +13,8 @@ Size = require './lib/size'
|
||||||
Cell = require './cell'
|
Cell = require './cell'
|
||||||
Light = require './light'
|
Light = require './light'
|
||||||
Player = require './player'
|
Player = require './player'
|
||||||
|
Timer = require './timer'
|
||||||
|
TmpObject = require './tmpobject'
|
||||||
Quaternion = require './lib/quaternion'
|
Quaternion = require './lib/quaternion'
|
||||||
Vector = require './lib/vector'
|
Vector = require './lib/vector'
|
||||||
Pos = require './lib/pos'
|
Pos = require './lib/pos'
|
||||||
|
@ -86,6 +88,8 @@ class World
|
||||||
@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_BEHIND
|
||||||
|
@camera_mode = World.CAMERA_INSIDE
|
||||||
|
@camera_mode = World.CAMERA_FOLLOW
|
||||||
@edit_projection = null
|
@edit_projection = null
|
||||||
@raster_size = 0.1
|
@raster_size = 0.1
|
||||||
|
|
||||||
|
@ -96,7 +100,6 @@ class World
|
||||||
# 0000000 000 000 0000000 00000000
|
# 0000000 000 000 0000000 00000000
|
||||||
|
|
||||||
initCage: ->
|
initCage: ->
|
||||||
log "initCage size:", @size
|
|
||||||
mat = new THREE.MeshPhongMaterial
|
mat = new THREE.MeshPhongMaterial
|
||||||
color: 0x440000
|
color: 0x440000
|
||||||
side: THREE.BackSide
|
side: THREE.BackSide
|
||||||
|
@ -110,12 +113,6 @@ class World
|
||||||
@cage.translateY @size.y/2-0.5
|
@cage.translateY @size.y/2-0.5
|
||||||
@cage.translateZ @size.z/2-0.5
|
@cage.translateZ @size.z/2-0.5
|
||||||
@scene.add @cage
|
@scene.add @cage
|
||||||
# glDisable(GL_BLEND);
|
|
||||||
# glDisable(GL_DEPTH_TEST);
|
|
||||||
# glDisable(GL_ALPHA_TEST);
|
|
||||||
# glDisable(GL_NORMALIZE);
|
|
||||||
#
|
|
||||||
# # colors[World_plate_color].glColor();
|
|
||||||
#
|
#
|
||||||
@init: (view) ->
|
@init: (view) ->
|
||||||
return if world?
|
return if world?
|
||||||
|
@ -138,7 +135,7 @@ class World
|
||||||
|
|
||||||
@levelList = [
|
@levelList = [
|
||||||
# intro
|
# intro
|
||||||
# "start",
|
"start",
|
||||||
"steps",
|
"steps",
|
||||||
#"move", "electro", "elevate",
|
#"move", "electro", "elevate",
|
||||||
# "throw",
|
# "throw",
|
||||||
|
@ -494,7 +491,6 @@ class World
|
||||||
menu.addItem(Controller.getLocalizedString("quit"), once(Controller.quit))
|
menu.addItem(Controller.getLocalizedString("quit"), once(Controller.quit))
|
||||||
|
|
||||||
setSize: (size) ->
|
setSize: (size) ->
|
||||||
log 'World.setSize!', size
|
|
||||||
@deleteAllObjects()
|
@deleteAllObjects()
|
||||||
@cells = []
|
@cells = []
|
||||||
@size = new Pos size
|
@size = new Pos size
|
||||||
|
@ -517,7 +513,7 @@ class World
|
||||||
getOccupantAtPos: (pos) -> @getCellAtPos(pos)?.getOccupant()
|
getOccupantAtPos: (pos) -> @getCellAtPos(pos)?.getOccupant()
|
||||||
getRealOccupantAtPos: (pos) ->
|
getRealOccupantAtPos: (pos) ->
|
||||||
occupant = @getOccupantAtPos pos
|
occupant = @getOccupantAtPos pos
|
||||||
if occupant and occupant instanceof KikiTmpObject
|
if occupant and occupant instanceof TmpObject
|
||||||
occupant.object
|
occupant.object
|
||||||
else
|
else
|
||||||
occupant
|
occupant
|
||||||
|
@ -528,17 +524,15 @@ class World
|
||||||
return
|
return
|
||||||
|
|
||||||
cell = @getCellAtPos pos
|
cell = @getCellAtPos pos
|
||||||
log "world.setObjectAtPos", cell
|
|
||||||
|
|
||||||
if object.isSpaceEgoistic() and cell and cell.getOccupant()
|
if object.isSpaceEgoistic() and cell and cell.getOccupant()
|
||||||
objectAtNewPos = cell.getOccupant()
|
objectAtNewPos = cell.getOccupant()
|
||||||
if objectAtNewPos instanceof KikiTmpObject
|
if objectAtNewPos instanceof TmpObject
|
||||||
if objectAtNewPos.time > 0
|
if objectAtNewPos.time > 0
|
||||||
log "WARNING World.setObject already occupied pos:", pos
|
log "WARNING World.setObject already occupied pos:", pos
|
||||||
# "already occupied by %s with time %d!",
|
# "already occupied by %s with time %d!",
|
||||||
# object.getClassName(), pos.x, pos.y, pos.z,
|
# object.getClassName(), pos.x, pos.y, pos.z,
|
||||||
# cell.getOccupant().getClassName(),
|
# cell.getOccupant().getClassName(),
|
||||||
# ((KikiTmpObject*)objectAtNewPos).time)
|
# ((TmpObject*)objectAtNewPos).time)
|
||||||
objectAtNewPos.del() # temporary object at new pos will vanish anyway . delete it
|
objectAtNewPos.del() # temporary object at new pos will vanish anyway . delete it
|
||||||
|
|
||||||
cell = @getCellAtPos pos
|
cell = @getCellAtPos pos
|
||||||
|
@ -605,12 +599,12 @@ class World
|
||||||
@picked_pickable = null
|
@picked_pickable = null
|
||||||
@moved_objects = []
|
@moved_objects = []
|
||||||
|
|
||||||
# if Controller.player
|
if @player?
|
||||||
# Controller.player.finishRotateAction()
|
@player.finishRotateAction()
|
||||||
# @removeObject (Controller.player) # remove the player first, to keep it's state
|
@removeObject @player # remove the player first, to keep it's state
|
||||||
# Controller.timer_event.removeAllActions ()
|
Timer.removeAllActions()
|
||||||
# Controller.removeKeyHandler (Controller.player) # prevent keyboard input while building world
|
# Controller.removeKeyHandler (Controller.player) # prevent keyboard input while building world
|
||||||
# Controller.player.reset ()
|
@player.reset()
|
||||||
|
|
||||||
while @lights.length
|
while @lights.length
|
||||||
oldSize = @lights.length
|
oldSize = @lights.length
|
||||||
|
@ -638,14 +632,14 @@ class World
|
||||||
log "World.getObjectWithName :: no object found with name #{objectName}"
|
log "World.getObjectWithName :: no object found with name #{objectName}"
|
||||||
null
|
null
|
||||||
|
|
||||||
setCameraMode: (mode) -> @camera_mode = clamp CAMERA_INSIDE, CAMERA_FOLLOW, mode
|
setCameraMode: (mode) -> @camera_mode = clamp World.CAMERA_INSIDE, World.CAMERA_FOLLOW, mode
|
||||||
|
|
||||||
changeCameraMode: () -> @camera_mode = (@camera_mode+1) % (CAMERA_FOLLOW+1)
|
changeCameraMode: () -> @camera_mode = (@camera_mode+1) % (World.CAMERA_FOLLOW+1)
|
||||||
|
|
||||||
objectMovedFromPos: (object, pos) ->
|
objectMovedFromPos: (object, pos) ->
|
||||||
|
|
||||||
if cell = @getCellAtPos(pos)
|
if cell = @getCellAtPos(pos)
|
||||||
if tmpObject = cell.getObjectOfType KikiTmpObject
|
if tmpObject = cell.getObjectOfType TmpObject
|
||||||
if tmpObject.object == object
|
if tmpObject.object == object
|
||||||
tmpObject.del()
|
tmpObject.del()
|
||||||
@moved_objects.push object
|
@moved_objects.push object
|
||||||
|
@ -662,10 +656,10 @@ class World
|
||||||
|
|
||||||
if cell
|
if cell
|
||||||
if objectAtNewPos = cell.getOccupant()
|
if objectAtNewPos = cell.getOccupant()
|
||||||
if objectAtNewPos instanceof KikiTmpObject
|
if objectAtNewPos instanceof TmpObject
|
||||||
tmpObject = objectAtNewPos
|
tmpObject = objectAtNewPos
|
||||||
|
|
||||||
if (objectAtNewPos.time < 0 and -objectAtNewPos.time <= duration)
|
if objectAtNewPos.time < 0 and -objectAtNewPos.time <= duration
|
||||||
# temporary object at new pos will vanish before object will arrive . delete it
|
# temporary object at new pos will vanish before object will arrive . delete it
|
||||||
objectAtNewPos.del()
|
objectAtNewPos.del()
|
||||||
else
|
else
|
||||||
|
@ -675,13 +669,13 @@ class World
|
||||||
|
|
||||||
@unsetObject object # remove object from cell grid
|
@unsetObject object # remove object from cell grid
|
||||||
|
|
||||||
tmpObject = new KikiTmpObject object # insert temporary objects at new pos
|
tmpObject = new TmpObject object # insert temporary objects at new pos
|
||||||
tmpObject.setPosition pos
|
tmpObject.setPosition pos
|
||||||
tmpObject.time = duration
|
tmpObject.time = duration
|
||||||
@addObjectAtPos tmpObject, pos
|
@addObjectAtPos tmpObject, pos
|
||||||
|
|
||||||
tmpObject = new KikiTmpObject object # insert temporary objects at old pos
|
tmpObject = new TmpObject object # insert temporary objects at old pos
|
||||||
tmpObject.setPosition object.getPosition()
|
tmpObject.setPosition object.position
|
||||||
tmpObject.time = -duration
|
tmpObject.time = -duration
|
||||||
@addObjectAtPos tmpObject, object.getPos()
|
@addObjectAtPos tmpObject, object.getPos()
|
||||||
|
|
||||||
|
@ -695,7 +689,7 @@ class World
|
||||||
log "World.updateStatus invalid new pos"
|
log "World.updateStatus invalid new pos"
|
||||||
return
|
return
|
||||||
|
|
||||||
if tmpObject = @getObjectOfTypeAtPos KikiTmpObject, pos
|
if tmpObject = @getObjectOfTypeAtPos TmpObject, pos
|
||||||
if tmpObject.object == movedObject
|
if tmpObject.object == movedObject
|
||||||
tmpObject.del()
|
tmpObject.del()
|
||||||
else
|
else
|
||||||
|
@ -864,18 +858,19 @@ class World
|
||||||
glRectf w+l, h+l, w+t, h+t
|
glRectf w+l, h+l, w+t, h+t
|
||||||
|
|
||||||
getProjection: () ->
|
getProjection: () ->
|
||||||
if @projection == NULL
|
log "world.getProjection #{@camera_mode}"
|
||||||
|
if not @projection
|
||||||
switch @camera_mode
|
switch @camera_mode
|
||||||
when CAMERA_INSIDE then @projection = @player.getProjection()
|
when World.CAMERA_INSIDE then @projection = @player.getProjection()
|
||||||
when CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
when World.CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
||||||
when CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
when World.CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
||||||
@projection
|
@projection
|
||||||
|
|
||||||
display: (mode) ->
|
display: (mode) ->
|
||||||
switch @camera_mode
|
switch @camera_mode
|
||||||
when CAMERA_INSIDE then @projection = @player.getProjection()
|
when World.CAMERA_INSIDE then @projection = @player.getProjection()
|
||||||
when CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
when World.CAMERA_BEHIND then @projection = @player.getBehindProjection()
|
||||||
when CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
when World.CAMERA_FOLLOW then @projection = @player.getFollowProjection()
|
||||||
|
|
||||||
@player_projection = @projection
|
@player_projection = @projection
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user