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
|
||||
|
||||
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
|
||||
color: 0x000066
|
||||
specular: 0x222255
|
||||
|
|
|
@ -11,12 +11,13 @@ Matrix = require './lib/matrix'
|
|||
|
||||
class Perspective extends Matrix
|
||||
|
||||
constructor: (fov,near=0.1,far=10000) ->
|
||||
constructor: (fov,near=0.01,far=1000) ->
|
||||
@znear = near
|
||||
@zfar = far
|
||||
@fov = fov
|
||||
@aspect_ratio = -1.0
|
||||
@eye_distance = 5.0
|
||||
@eye_distance = @znear
|
||||
# @eye_distance = 5.0
|
||||
@border = [0,0,0,0]
|
||||
@setViewport 0.0, 0.0, 1.0, 1.0
|
||||
super
|
||||
|
@ -28,36 +29,36 @@ class Perspective extends Matrix
|
|||
super
|
||||
@translate 0, 0, @eye_distance
|
||||
|
||||
rotate: (x,y,z) ->
|
||||
savePos = @getLookAtPosition()
|
||||
@translate -@getPosition()
|
||||
|
||||
up = @getYVector()
|
||||
look = @getZVector()
|
||||
|
||||
rotxz = KMatrix.rotation x, 0.0, z
|
||||
roty = KMatrix.rotation 0.0, y, 0.0
|
||||
|
||||
yunit = new Vector 0.0, 1.0, 0.0
|
||||
zunit = new Vector 0.0, 0.0, 1.0
|
||||
|
||||
lookperp = @look.perpendicular yunit # y-axis rotation
|
||||
if lookperp.length() > 0
|
||||
look = roty.transform lookperp.plus look.parallel(yunit)
|
||||
up = roty.transform up.perpendicular(yunit).plus up.parallel(yunit)
|
||||
|
||||
# x & z-axis rotation
|
||||
transmat = new Matrix up.cross(look), up, look
|
||||
|
||||
uprotxz = rotxz.transform yunit
|
||||
lookrotxz = rotxz.transform zunit
|
||||
|
||||
up = transmat.transform uprotxz
|
||||
look = transmat.transform lookrotxz
|
||||
|
||||
@.initXYZ up.cross(look), up, look
|
||||
|
||||
@setPosition savePos.plus @getZVector().mul @eye_distance
|
||||
# rotate: (x,y,z) ->
|
||||
# savePos = @getLookAtPosition()
|
||||
# @translate -@getPosition()
|
||||
#
|
||||
# up = @getYVector()
|
||||
# look = @getZVector()
|
||||
#
|
||||
# rotxz = Matrix.rotation x, 0.0, z
|
||||
# roty = Matrix.rotation 0.0, y, 0.0
|
||||
#
|
||||
# yunit = new Vector 0.0, 1.0, 0.0
|
||||
# zunit = new Vector 0.0, 0.0, 1.0
|
||||
#
|
||||
# lookperp = @look.perpendicular yunit # y-axis rotation
|
||||
# if lookperp.length() > 0
|
||||
# look = roty.transform lookperp.plus look.parallel(yunit)
|
||||
# up = roty.transform up.perpendicular(yunit).plus up.parallel(yunit)
|
||||
#
|
||||
# # x & z-axis rotation
|
||||
# transmat = new Matrix up.cross(look), up, look
|
||||
#
|
||||
# uprotxz = rotxz.transform yunit
|
||||
# lookrotxz = rotxz.transform zunit
|
||||
#
|
||||
# up = transmat.transform uprotxz
|
||||
# look = transmat.transform lookrotxz
|
||||
#
|
||||
# @.initXYZ up.cross(look), up, look
|
||||
#
|
||||
# @setPosition savePos.plus @getZVector().mul @eye_distance
|
||||
|
||||
apply: (camera) ->
|
||||
camPos = @getPosition()
|
||||
|
@ -70,22 +71,23 @@ class Perspective extends Matrix
|
|||
@light.setDirection -@getZVector()
|
||||
@light.setPosition new Vector pos[X], pos[Y], pos[Z], 1.0 # positional light source
|
||||
|
||||
setEyeDistance: (distance) ->
|
||||
lookAtPos = @getLookAtPosition()
|
||||
@eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
||||
@setPosition lookAtPos.plus @getZVector().mul @eye_distance
|
||||
|
||||
setLookAtPosition: (lookAtPos) ->
|
||||
up = @getYVector()
|
||||
newLook = lookAtPos.minus(@getPosition()).normal()
|
||||
newRight = up.cross(newLook).normal()
|
||||
newUp = newLook.cross(newRight).normal()
|
||||
|
||||
@setXVector newRight
|
||||
@setYVector newUp
|
||||
@setZVector newLook
|
||||
log 'setLookAtPosition', @matrix
|
||||
@eye_distance = lookAtPos.minus(@getPosition()).length()
|
||||
# setEyeDistance: (distance) ->
|
||||
# log 'setEyeDistance', distance
|
||||
# lookAtPos = @getLookAtPosition()
|
||||
# @eye_distance = Math.min Math.max(@znear, distance), 0.9*@zfar
|
||||
# @setPosition lookAtPos.plus @getZVector().mul @eye_distance
|
||||
|
||||
# setLookAtPosition: (lookAtPos) ->
|
||||
# up = @getYVector()
|
||||
# newLook = lookAtPos.minus(@getPosition()).normal()
|
||||
# newRight = up.cross(newLook).normal()
|
||||
# newUp = newLook.cross(newRight).normal()
|
||||
#
|
||||
# @setXVector newRight
|
||||
# @setYVector newUp
|
||||
# @setZVector newLook
|
||||
# # log 'setLookAtPosition', @matrix
|
||||
# @eye_distance = lookAtPos.minus(@getPosition()).length()
|
||||
|
||||
getLookAtPosition: -> @getZVector().mul(-@eye_distance).plus @getPosition()
|
||||
|
||||
|
@ -112,8 +114,6 @@ class Perspective extends Matrix
|
|||
@updateViewport()
|
||||
|
||||
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
|
||||
|
|
@ -64,22 +64,7 @@ class Player extends Bot
|
|||
|
||||
# @projection.getLight().setCutoff 90.0
|
||||
# @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
|
||||
# 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
|
||||
|
@ -117,7 +102,6 @@ class Player extends Bot
|
|||
# 0000000 00000000 000 000 000 000 000 0000000
|
||||
|
||||
getBehindProjection: () ->
|
||||
@updatePosition()
|
||||
|
||||
playerDir = @getCurrentDir()
|
||||
playerUp = @current_orientation.rotate(new Vector(0,1,0)).normal()
|
||||
|
@ -164,8 +148,6 @@ class Player extends Bot
|
|||
cameraPos = @projection.getPosition()
|
||||
desiredDistance = 2.0 # desired distance from camera to bot
|
||||
|
||||
@updatePosition()
|
||||
|
||||
playerPos = @current_position # desired look pos
|
||||
playerDir = @getCurrentDir()
|
||||
playerUp = @current_orientation.rotate new Vector(0,1,0).normal()
|
||||
|
|
|
@ -48,7 +48,7 @@ class World extends Actor
|
|||
|
||||
super
|
||||
|
||||
@speed = 5.0
|
||||
@speed = 4
|
||||
|
||||
@screenSize = new Size @view.clientWidth, @view.clientHeight
|
||||
# log "view @screenSize:", @screenSize
|
||||
|
@ -67,9 +67,9 @@ class World extends Actor
|
|||
# 000 000 000 000 0 000 000 000 000 000 000
|
||||
# 0000000 000 000 000 000 00000000 000 000 000 000
|
||||
|
||||
@fov = 60
|
||||
@near = 0.1
|
||||
@far = 1000
|
||||
@fov = 70
|
||||
@near = 0.001
|
||||
@far = 500
|
||||
@aspect = @view.offsetWidth / @view.offsetHeight
|
||||
@dist = 10
|
||||
|
||||
|
@ -105,8 +105,8 @@ class World extends Actor
|
|||
@size = new Pos()
|
||||
@depth = -Number.MAX_SAFE_INTEGER
|
||||
# @camera_mode = World.CAMERA_INSIDE
|
||||
# @camera_mode = World.CAMERA_BEHIND
|
||||
@camera_mode = World.CAMERA_FOLLOW
|
||||
@camera_mode = World.CAMERA_BEHIND
|
||||
# @camera_mode = World.CAMERA_FOLLOW
|
||||
@raster_size = 0.1
|
||||
|
||||
# 0000000 0000000 0000000 00000000
|
||||
|
@ -117,12 +117,13 @@ class World extends Actor
|
|||
|
||||
initCage: ->
|
||||
mat = new THREE.MeshPhongMaterial
|
||||
color: 0x440000
|
||||
color: 0x880000
|
||||
side: THREE.BackSide
|
||||
shading: THREE.SmoothShading
|
||||
transparent: true
|
||||
transparent: false
|
||||
opacity: 0.5
|
||||
shininess: 0.99
|
||||
shininess: 2
|
||||
|
||||
geom = new THREE.BoxGeometry @size.x, @size.y, @size.z
|
||||
@cage = new THREE.Mesh geom, mat
|
||||
@cage.translateX @size.x/2-0.5
|
||||
|
|
Loading…
Reference in New Issue
Block a user