camera
This commit is contained in:
parent
c88a0f8c52
commit
b9be62273f
|
@ -56,15 +56,6 @@ class Bot extends Pushable
|
||||||
|
|
||||||
geom = new THREE.TorusGeometry 0.5-tireRadius, tireRadius, 16, 16
|
geom = new THREE.TorusGeometry 0.5-tireRadius, tireRadius, 16, 16
|
||||||
|
|
||||||
tireMat = new THREE.MeshStandardMaterial
|
|
||||||
color: 0x2222ff
|
|
||||||
side: THREE.FrontSide
|
|
||||||
shading: THREE.FlatShading
|
|
||||||
roughness: 0.8
|
|
||||||
metalness: 1
|
|
||||||
transparent: true
|
|
||||||
opacity: 0.7
|
|
||||||
|
|
||||||
tireMat = new THREE.MeshPhongMaterial
|
tireMat = new THREE.MeshPhongMaterial
|
||||||
color: 0x000066
|
color: 0x000066
|
||||||
specular: 0x222255
|
specular: 0x222255
|
||||||
|
|
|
@ -11,12 +11,13 @@ Matrix = require './lib/matrix'
|
||||||
|
|
||||||
class Perspective extends Matrix
|
class Perspective extends Matrix
|
||||||
|
|
||||||
constructor: (fov,near=0.1,far=10000) ->
|
constructor: (fov,near=0.01,far=1000) ->
|
||||||
@znear = near
|
@znear = near
|
||||||
@zfar = far
|
@zfar = far
|
||||||
@fov = fov
|
@fov = fov
|
||||||
@aspect_ratio = -1.0
|
@aspect_ratio = -1.0
|
||||||
@eye_distance = 5.0
|
@eye_distance = @znear
|
||||||
|
# @eye_distance = 5.0
|
||||||
@border = [0,0,0,0]
|
@border = [0,0,0,0]
|
||||||
@setViewport 0.0, 0.0, 1.0, 1.0
|
@setViewport 0.0, 0.0, 1.0, 1.0
|
||||||
super
|
super
|
||||||
|
@ -28,36 +29,36 @@ class Perspective extends Matrix
|
||||||
super
|
super
|
||||||
@translate 0, 0, @eye_distance
|
@translate 0, 0, @eye_distance
|
||||||
|
|
||||||
rotate: (x,y,z) ->
|
# rotate: (x,y,z) ->
|
||||||
savePos = @getLookAtPosition()
|
# savePos = @getLookAtPosition()
|
||||||
@translate -@getPosition()
|
# @translate -@getPosition()
|
||||||
|
#
|
||||||
up = @getYVector()
|
# up = @getYVector()
|
||||||
look = @getZVector()
|
# look = @getZVector()
|
||||||
|
#
|
||||||
rotxz = KMatrix.rotation x, 0.0, z
|
# rotxz = Matrix.rotation x, 0.0, z
|
||||||
roty = KMatrix.rotation 0.0, y, 0.0
|
# roty = Matrix.rotation 0.0, y, 0.0
|
||||||
|
#
|
||||||
yunit = new Vector 0.0, 1.0, 0.0
|
# yunit = new Vector 0.0, 1.0, 0.0
|
||||||
zunit = new Vector 0.0, 0.0, 1.0
|
# zunit = new Vector 0.0, 0.0, 1.0
|
||||||
|
#
|
||||||
lookperp = @look.perpendicular yunit # y-axis rotation
|
# lookperp = @look.perpendicular yunit # y-axis rotation
|
||||||
if lookperp.length() > 0
|
# if lookperp.length() > 0
|
||||||
look = roty.transform lookperp.plus look.parallel(yunit)
|
# look = roty.transform lookperp.plus look.parallel(yunit)
|
||||||
up = roty.transform up.perpendicular(yunit).plus up.parallel(yunit)
|
# up = roty.transform up.perpendicular(yunit).plus up.parallel(yunit)
|
||||||
|
#
|
||||||
# x & z-axis rotation
|
# # x & z-axis rotation
|
||||||
transmat = new Matrix up.cross(look), up, look
|
# transmat = new Matrix up.cross(look), up, look
|
||||||
|
#
|
||||||
uprotxz = rotxz.transform yunit
|
# uprotxz = rotxz.transform yunit
|
||||||
lookrotxz = rotxz.transform zunit
|
# lookrotxz = rotxz.transform zunit
|
||||||
|
#
|
||||||
up = transmat.transform uprotxz
|
# up = transmat.transform uprotxz
|
||||||
look = transmat.transform lookrotxz
|
# look = transmat.transform lookrotxz
|
||||||
|
#
|
||||||
@.initXYZ up.cross(look), up, look
|
# @.initXYZ up.cross(look), up, look
|
||||||
|
#
|
||||||
@setPosition savePos.plus @getZVector().mul @eye_distance
|
# @setPosition savePos.plus @getZVector().mul @eye_distance
|
||||||
|
|
||||||
apply: (camera) ->
|
apply: (camera) ->
|
||||||
camPos = @getPosition()
|
camPos = @getPosition()
|
||||||
|
@ -70,22 +71,23 @@ class Perspective extends Matrix
|
||||||
@light.setDirection -@getZVector()
|
@light.setDirection -@getZVector()
|
||||||
@light.setPosition new Vector pos[X], pos[Y], pos[Z], 1.0 # positional light source
|
@light.setPosition new Vector pos[X], pos[Y], pos[Z], 1.0 # positional light source
|
||||||
|
|
||||||
setEyeDistance: (distance) ->
|
# setEyeDistance: (distance) ->
|
||||||
lookAtPos = @getLookAtPosition()
|
# log 'setEyeDistance', distance
|
||||||
@eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
# lookAtPos = @getLookAtPosition()
|
||||||
@setPosition lookAtPos.plus @getZVector().mul @eye_distance
|
# @eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
||||||
|
# @setPosition lookAtPos.plus @getZVector().mul @eye_distance
|
||||||
|
|
||||||
setLookAtPosition: (lookAtPos) ->
|
# setLookAtPosition: (lookAtPos) ->
|
||||||
up = @getYVector()
|
# up = @getYVector()
|
||||||
newLook = lookAtPos.minus(@getPosition()).normal()
|
# newLook = lookAtPos.minus(@getPosition()).normal()
|
||||||
newRight = up.cross(newLook).normal()
|
# newRight = up.cross(newLook).normal()
|
||||||
newUp = newLook.cross(newRight).normal()
|
# newUp = newLook.cross(newRight).normal()
|
||||||
|
#
|
||||||
@setXVector newRight
|
# @setXVector newRight
|
||||||
@setYVector newUp
|
# @setYVector newUp
|
||||||
@setZVector newLook
|
# @setZVector newLook
|
||||||
log 'setLookAtPosition', @matrix
|
# # log 'setLookAtPosition', @matrix
|
||||||
@eye_distance = lookAtPos.minus(@getPosition()).length()
|
# @eye_distance = lookAtPos.minus(@getPosition()).length()
|
||||||
|
|
||||||
getLookAtPosition: -> @getZVector().mul(-@eye_distance).plus @getPosition()
|
getLookAtPosition: -> @getZVector().mul(-@eye_distance).plus @getPosition()
|
||||||
|
|
||||||
|
@ -113,7 +115,5 @@ class Perspective extends Matrix
|
||||||
|
|
||||||
setFov: (fov) -> @fov = Math.max(2.0, Math.min fov, 175.0)
|
setFov: (fov) -> @fov = Math.max(2.0, Math.min fov, 175.0)
|
||||||
|
|
||||||
setEyeDistance: (distance) -> @eye_distance = clamp @znear, distance, 0.9 * @zfar
|
|
||||||
|
|
||||||
module.exports = Perspective
|
module.exports = Perspective
|
||||||
|
|
|
@ -65,21 +65,6 @@ 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
|
||||||
|
|
||||||
updatePosition: () ->
|
|
||||||
if @move_action
|
|
||||||
relTime = (world.getTime()-@move_action.start) / @move_action.duration
|
|
||||||
# log "updatePosition #{@move_action.id} #{relTime} #{@move_action.start} #{world.getTime()}"
|
|
||||||
if 0 <= relTime <= 1.0
|
|
||||||
switch @move_action.id
|
|
||||||
when Action.FORWARD
|
|
||||||
@current_position = @position.plus @getDir().mul relTime
|
|
||||||
when Action.FALL
|
|
||||||
@current_position = @position.minus @getUp().mul relTime
|
|
||||||
when Action.JUMP_FORWARD
|
|
||||||
@current_position = @position.plus @getDir().mul(1.0 - Math.cos(Math.PI/2 * relTime)).plus @getUp().mul Math.cos(Math.PI/2 - Math.PI/2 * relTime)
|
|
||||||
when Action.FALL_FORWARD
|
|
||||||
@current_position = @position.plus @getDir().mul(Math.cos(Math.PI/2 - Math.PI/2 * relTime)).plus @getUp().mul -(1.0 - Math.cos Math.PI/2 * relTime)
|
|
||||||
|
|
||||||
# 00000000 00000000 0000000 000 00000000 0000000 000000000 000 0000000 000 000
|
# 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
|
# 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
|
# 00000000 0000000 000 000 000 0000000 000 000 000 000 000 000 0 000
|
||||||
|
@ -117,7 +102,6 @@ class Player extends Bot
|
||||||
# 0000000 00000000 000 000 000 000 000 0000000
|
# 0000000 00000000 000 000 000 000 000 0000000
|
||||||
|
|
||||||
getBehindProjection: () ->
|
getBehindProjection: () ->
|
||||||
@updatePosition()
|
|
||||||
|
|
||||||
playerDir = @getCurrentDir()
|
playerDir = @getCurrentDir()
|
||||||
playerUp = @current_orientation.rotate(new Vector(0,1,0)).normal()
|
playerUp = @current_orientation.rotate(new Vector(0,1,0)).normal()
|
||||||
|
@ -164,8 +148,6 @@ class Player extends Bot
|
||||||
cameraPos = @projection.getPosition()
|
cameraPos = @projection.getPosition()
|
||||||
desiredDistance = 2.0 # desired distance from camera to bot
|
desiredDistance = 2.0 # desired distance from camera to bot
|
||||||
|
|
||||||
@updatePosition()
|
|
||||||
|
|
||||||
playerPos = @current_position # desired look pos
|
playerPos = @current_position # desired look pos
|
||||||
playerDir = @getCurrentDir()
|
playerDir = @getCurrentDir()
|
||||||
playerUp = @current_orientation.rotate new Vector(0,1,0).normal()
|
playerUp = @current_orientation.rotate new Vector(0,1,0).normal()
|
||||||
|
|
|
@ -48,7 +48,7 @@ class World extends Actor
|
||||||
|
|
||||||
super
|
super
|
||||||
|
|
||||||
@speed = 5.0
|
@speed = 4
|
||||||
|
|
||||||
@screenSize = new Size @view.clientWidth, @view.clientHeight
|
@screenSize = new Size @view.clientWidth, @view.clientHeight
|
||||||
# log "view @screenSize:", @screenSize
|
# log "view @screenSize:", @screenSize
|
||||||
|
@ -67,9 +67,9 @@ class World extends Actor
|
||||||
# 000 000 000 000 0 000 000 000 000 000 000
|
# 000 000 000 000 0 000 000 000 000 000 000
|
||||||
# 0000000 000 000 000 000 00000000 000 000 000 000
|
# 0000000 000 000 000 000 00000000 000 000 000 000
|
||||||
|
|
||||||
@fov = 60
|
@fov = 70
|
||||||
@near = 0.1
|
@near = 0.001
|
||||||
@far = 1000
|
@far = 500
|
||||||
@aspect = @view.offsetWidth / @view.offsetHeight
|
@aspect = @view.offsetWidth / @view.offsetHeight
|
||||||
@dist = 10
|
@dist = 10
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ class World extends Actor
|
||||||
@size = new Pos()
|
@size = new Pos()
|
||||||
@depth = -Number.MAX_SAFE_INTEGER
|
@depth = -Number.MAX_SAFE_INTEGER
|
||||||
# @camera_mode = World.CAMERA_INSIDE
|
# @camera_mode = World.CAMERA_INSIDE
|
||||||
# @camera_mode = World.CAMERA_BEHIND
|
@camera_mode = World.CAMERA_BEHIND
|
||||||
@camera_mode = World.CAMERA_FOLLOW
|
# @camera_mode = World.CAMERA_FOLLOW
|
||||||
@raster_size = 0.1
|
@raster_size = 0.1
|
||||||
|
|
||||||
# 0000000 0000000 0000000 00000000
|
# 0000000 0000000 0000000 00000000
|
||||||
|
@ -117,12 +117,13 @@ class World extends Actor
|
||||||
|
|
||||||
initCage: ->
|
initCage: ->
|
||||||
mat = new THREE.MeshPhongMaterial
|
mat = new THREE.MeshPhongMaterial
|
||||||
color: 0x440000
|
color: 0x880000
|
||||||
side: THREE.BackSide
|
side: THREE.BackSide
|
||||||
shading: THREE.SmoothShading
|
shading: THREE.SmoothShading
|
||||||
transparent: true
|
transparent: false
|
||||||
opacity: 0.5
|
opacity: 0.5
|
||||||
shininess: 0.99
|
shininess: 2
|
||||||
|
|
||||||
geom = new THREE.BoxGeometry @size.x, @size.y, @size.z
|
geom = new THREE.BoxGeometry @size.x, @size.y, @size.z
|
||||||
@cage = new THREE.Mesh geom, mat
|
@cage = new THREE.Mesh geom, mat
|
||||||
@cage.translateX @size.x/2-0.5
|
@cage.translateX @size.x/2-0.5
|
||||||
|
|
Loading…
Reference in New Issue
Block a user