Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
594f7882
T
three.js
项目概览
Ablesons
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
594f7882
编写于
11月 05, 2014
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5576 from ucarion/refactor-pointerlock
Decouple PointerLockControls from its example.
上级
7ec810a1
5afaec7d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
112 addition
and
130 deletion
+112
-130
examples/js/controls/PointerLockControls.js
examples/js/controls/PointerLockControls.js
+0
-122
examples/misc_controls_pointerlock.html
examples/misc_controls_pointerlock.html
+112
-8
未找到文件。
examples/js/controls/PointerLockControls.js
浏览文件 @
594f7882
...
...
@@ -15,18 +15,6 @@ THREE.PointerLockControls = function ( camera ) {
yawObject
.
position
.
y
=
10
;
yawObject
.
add
(
pitchObject
);
var
moveForward
=
false
;
var
moveBackward
=
false
;
var
moveLeft
=
false
;
var
moveRight
=
false
;
var
isOnObject
=
false
;
var
canJump
=
false
;
var
prevTime
=
performance
.
now
();
var
velocity
=
new
THREE
.
Vector3
();
var
PI_2
=
Math
.
PI
/
2
;
var
onMouseMove
=
function
(
event
)
{
...
...
@@ -43,69 +31,7 @@ THREE.PointerLockControls = function ( camera ) {
};
var
onKeyDown
=
function
(
event
)
{
switch
(
event
.
keyCode
)
{
case
38
:
// up
case
87
:
// w
moveForward
=
true
;
break
;
case
37
:
// left
case
65
:
// a
moveLeft
=
true
;
break
;
case
40
:
// down
case
83
:
// s
moveBackward
=
true
;
break
;
case
39
:
// right
case
68
:
// d
moveRight
=
true
;
break
;
case
32
:
// space
if
(
canJump
===
true
)
velocity
.
y
+=
350
;
canJump
=
false
;
break
;
}
};
var
onKeyUp
=
function
(
event
)
{
switch
(
event
.
keyCode
)
{
case
38
:
// up
case
87
:
// w
moveForward
=
false
;
break
;
case
37
:
// left
case
65
:
// a
moveLeft
=
false
;
break
;
case
40
:
// down
case
83
:
// s
moveBackward
=
false
;
break
;
case
39
:
// right
case
68
:
// d
moveRight
=
false
;
break
;
}
};
document
.
addEventListener
(
'
mousemove
'
,
onMouseMove
,
false
);
document
.
addEventListener
(
'
keydown
'
,
onKeyDown
,
false
);
document
.
addEventListener
(
'
keyup
'
,
onKeyUp
,
false
);
this
.
enabled
=
false
;
...
...
@@ -115,13 +41,6 @@ THREE.PointerLockControls = function ( camera ) {
};
this
.
isOnObject
=
function
(
boolean
)
{
isOnObject
=
boolean
;
canJump
=
boolean
;
};
this
.
getDirection
=
function
()
{
// assumes the camera itself is not rotated
...
...
@@ -141,45 +60,4 @@ THREE.PointerLockControls = function ( camera ) {
}();
this
.
update
=
function
()
{
if
(
scope
.
enabled
===
false
)
return
;
var
time
=
performance
.
now
();
var
delta
=
(
time
-
prevTime
)
/
1000
;
velocity
.
x
-=
velocity
.
x
*
10.0
*
delta
;
velocity
.
z
-=
velocity
.
z
*
10.0
*
delta
;
velocity
.
y
-=
9.8
*
100.0
*
delta
;
// 100.0 = mass
if
(
moveForward
)
velocity
.
z
-=
400.0
*
delta
;
if
(
moveBackward
)
velocity
.
z
+=
400.0
*
delta
;
if
(
moveLeft
)
velocity
.
x
-=
400.0
*
delta
;
if
(
moveRight
)
velocity
.
x
+=
400.0
*
delta
;
if
(
isOnObject
===
true
)
{
velocity
.
y
=
Math
.
max
(
0
,
velocity
.
y
);
}
yawObject
.
translateX
(
velocity
.
x
*
delta
);
yawObject
.
translateY
(
velocity
.
y
*
delta
);
yawObject
.
translateZ
(
velocity
.
z
*
delta
);
if
(
yawObject
.
position
.
y
<
10
)
{
velocity
.
y
=
0
;
yawObject
.
position
.
y
=
10
;
canJump
=
true
;
}
prevTime
=
time
;
};
};
examples/misc_controls_pointerlock.html
浏览文件 @
594f7882
...
...
@@ -96,6 +96,7 @@
if
(
document
.
pointerLockElement
===
element
||
document
.
mozPointerLockElement
===
element
||
document
.
webkitPointerLockElement
===
element
)
{
controlsEnabled
=
true
;
controls
.
enabled
=
true
;
blocker
.
style
.
display
=
'
none
'
;
...
...
@@ -174,6 +175,16 @@
init
();
animate
();
var
controlsEnabled
=
false
;
var
moveForward
=
false
;
var
moveBackward
=
false
;
var
moveLeft
=
false
;
var
moveRight
=
false
;
var
prevTime
=
performance
.
now
();
var
velocity
=
new
THREE
.
Vector3
();
function
init
()
{
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
1000
);
...
...
@@ -188,6 +199,69 @@
controls
=
new
THREE
.
PointerLockControls
(
camera
);
scene
.
add
(
controls
.
getObject
()
);
var
onKeyDown
=
function
(
event
)
{
switch
(
event
.
keyCode
)
{
case
38
:
// up
case
87
:
// w
moveForward
=
true
;
break
;
case
37
:
// left
case
65
:
// a
moveLeft
=
true
;
break
;
case
40
:
// down
case
83
:
// s
moveBackward
=
true
;
break
;
case
39
:
// right
case
68
:
// d
moveRight
=
true
;
break
;
case
32
:
// space
if
(
canJump
===
true
)
velocity
.
y
+=
350
;
canJump
=
false
;
break
;
}
};
var
onKeyUp
=
function
(
event
)
{
switch
(
event
.
keyCode
)
{
case
38
:
// up
case
87
:
// w
moveForward
=
false
;
break
;
case
37
:
// left
case
65
:
// a
moveLeft
=
false
;
break
;
case
40
:
// down
case
83
:
// s
moveBackward
=
false
;
break
;
case
39
:
// right
case
68
:
// d
moveRight
=
false
;
break
;
}
};
document
.
addEventListener
(
'
keydown
'
,
onKeyDown
,
false
);
document
.
addEventListener
(
'
keyup
'
,
onKeyUp
,
false
);
raycaster
=
new
THREE
.
Raycaster
(
new
THREE
.
Vector3
(),
new
THREE
.
Vector3
(
0
,
-
1
,
0
),
0
,
10
);
// floor
...
...
@@ -274,20 +348,50 @@
requestAnimationFrame
(
animate
);
controls
.
isOnObject
(
false
);
if
(
controlsEnabled
)
{
raycaster
.
ray
.
origin
.
copy
(
controls
.
getObject
().
position
);
raycaster
.
ray
.
origin
.
y
-=
10
;
var
intersections
=
raycaster
.
intersectObjects
(
objects
);
if
(
intersections
.
length
>
0
)
{
var
isOnObject
=
intersections
.
length
>
0
;
var
time
=
performance
.
now
();
var
delta
=
(
time
-
prevTime
)
/
1000
;
velocity
.
x
-=
velocity
.
x
*
10.0
*
delta
;
velocity
.
z
-=
velocity
.
z
*
10.0
*
delta
;
velocity
.
y
-=
9.8
*
100.0
*
delta
;
// 100.0 = mass
if
(
moveForward
)
velocity
.
z
-=
400.0
*
delta
;
if
(
moveBackward
)
velocity
.
z
+=
400.0
*
delta
;
controls
.
isOnObject
(
true
);
if
(
moveLeft
)
velocity
.
x
-=
400.0
*
delta
;
if
(
moveRight
)
velocity
.
x
+=
400.0
*
delta
;
if
(
isOnObject
===
true
)
{
velocity
.
y
=
Math
.
max
(
0
,
velocity
.
y
);
canJump
=
true
;
}
controls
.
update
();
controls
.
getObject
().
translateX
(
velocity
.
x
*
delta
);
controls
.
getObject
().
translateY
(
velocity
.
y
*
delta
);
controls
.
getObject
().
translateZ
(
velocity
.
z
*
delta
);
if
(
controls
.
getObject
().
position
.
y
<
10
)
{
velocity
.
y
=
0
;
controls
.
getObject
().
position
.
y
=
10
;
canJump
=
true
;
}
prevTime
=
time
;
}
renderer
.
render
(
scene
,
camera
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录