Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
dbedded4
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,发现更多精彩内容 >>
提交
dbedded4
编写于
3月 12, 2014
作者:
R
richtr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DeviceOrientationControls.js: Minor code performance optimizations and clean-up
上级
49fdb26d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
64 deletion
+44
-64
examples/js/controls/DeviceOrientationControls.js
examples/js/controls/DeviceOrientationControls.js
+44
-64
未找到文件。
examples/js/controls/DeviceOrientationControls.js
浏览文件 @
dbedded4
...
...
@@ -8,14 +8,15 @@ THREE.DeviceOrientationControls = function ( object ) {
this
.
object
=
object
;
this
.
degtorad
=
Math
.
PI
/
180
;
this
.
freeze
=
true
;
this
.
deviceOrientation
=
{};
this
.
screenOrientation
=
0
;
this
.
_rotationVector
=
new
THREE
.
Vector3
();
this
.
_rotationMatrix
=
new
THREE
.
Matrix4
();
var
degtorad
=
Math
.
PI
/
180
;
var
_objectRotationMatrix
=
new
THREE
.
Matrix4
();
var
_tmpRotationMatrix
=
new
THREE
.
Matrix4
();
this
.
onDeviceOrientationChangeEvent
=
function
(
rawEvtData
)
{
this
.
deviceOrientation
=
rawEvtData
;
...
...
@@ -25,20 +26,10 @@ THREE.DeviceOrientationControls = function ( object ) {
this
.
screenOrientation
=
window
.
orientation
||
0
;
};
this
.
setRotationVectorFromDeviceOrientation
=
function
(
alpha
,
beta
,
gamma
)
{
this
.
_rotationVector
.
set
(
(
beta
||
0
)
*
this
.
degtorad
,
// x
(
gamma
||
0
)
*
this
.
degtorad
,
// y
(
alpha
||
0
)
*
this
.
degtorad
// z
);
return
this
.
_rotationVector
;
};
this
.
setRotationMatrixFromRotationVector
=
function
(
rotationVector
)
{
var
x
=
rotationVector
.
x
||
0
;
// beta
var
y
=
rotationVector
.
y
||
0
;
// gamma
var
z
=
rotationVector
.
z
||
0
;
// alpha
this
.
setObjectRotationMatrixFromDeviceOrientation
=
function
()
{
var
x
=
this
.
deviceOrientation
.
beta
?
this
.
deviceOrientation
.
beta
*
degtorad
:
0
;
// beta
var
y
=
this
.
deviceOrientation
.
gamma
?
this
.
deviceOrientation
.
gamma
*
degtorad
:
0
;
// gamma
var
z
=
this
.
deviceOrientation
.
alpha
?
this
.
deviceOrientation
.
alpha
*
degtorad
:
0
;
// alpha
var
cX
=
Math
.
cos
(
x
);
var
cY
=
Math
.
cos
(
y
);
...
...
@@ -65,21 +56,20 @@ THREE.DeviceOrientationControls = function ( object ) {
var
m32
=
sX
;
var
m33
=
cX
*
cY
;
this
.
_r
otationMatrix
.
set
(
_objectR
otationMatrix
.
set
(
m11
,
m12
,
m13
,
0
,
m21
,
m22
,
m23
,
0
,
m31
,
m32
,
m33
,
0
,
0
,
0
,
0
,
1
);
return
this
.
_r
otationMatrix
;
return
_objectR
otationMatrix
;
};
this
.
remapRotationMatrixByScreenOrientation
=
function
(
screenOrientation
,
rotationMatrix
)
{
var
transformedRotationMatrix
=
new
THREE
.
Matrix4
();
transformedRotationMatrix
.
copy
(
rotationMatrix
);
this
.
remapObjectRotationMatrixFromScreenOrientation
=
function
()
{
_tmpRotationMatrix
.
copy
(
_objectRotationMatrix
);
switch
(
screenOrientation
)
{
switch
(
this
.
screenOrientation
)
{
case
90
:
case
-
270
:
//
...
...
@@ -93,17 +83,17 @@ THREE.DeviceOrientationControls = function ( object ) {
// (see: http://bit.ly/1itCOq2)
//
transformedRotationMatrix
.
elements
[
0
]
=
-
r
otationMatrix
.
elements
[
4
];
transformedRotationMatrix
.
elements
[
4
]
=
r
otationMatrix
.
elements
[
0
];
transformedRotationMatrix
.
elements
[
8
]
=
r
otationMatrix
.
elements
[
8
];
_objectRotationMatrix
.
elements
[
0
]
=
-
_tmpR
otationMatrix
.
elements
[
4
];
_objectRotationMatrix
.
elements
[
4
]
=
_tmpR
otationMatrix
.
elements
[
0
];
_objectRotationMatrix
.
elements
[
8
]
=
_tmpR
otationMatrix
.
elements
[
8
];
transformedRotationMatrix
.
elements
[
1
]
=
-
r
otationMatrix
.
elements
[
5
];
transformedRotationMatrix
.
elements
[
5
]
=
r
otationMatrix
.
elements
[
1
];
transformedRotationMatrix
.
elements
[
9
]
=
r
otationMatrix
.
elements
[
9
];
_objectRotationMatrix
.
elements
[
1
]
=
-
_tmpR
otationMatrix
.
elements
[
5
];
_objectRotationMatrix
.
elements
[
5
]
=
_tmpR
otationMatrix
.
elements
[
1
];
_objectRotationMatrix
.
elements
[
9
]
=
_tmpR
otationMatrix
.
elements
[
9
];
transformedRotationMatrix
.
elements
[
2
]
=
-
r
otationMatrix
.
elements
[
6
];
transformedRotationMatrix
.
elements
[
6
]
=
r
otationMatrix
.
elements
[
2
];
transformedRotationMatrix
.
elements
[
10
]
=
r
otationMatrix
.
elements
[
10
];
_objectRotationMatrix
.
elements
[
2
]
=
-
_tmpR
otationMatrix
.
elements
[
6
];
_objectRotationMatrix
.
elements
[
6
]
=
_tmpR
otationMatrix
.
elements
[
2
];
_objectRotationMatrix
.
elements
[
10
]
=
_tmpR
otationMatrix
.
elements
[
10
];
break
;
case
180
:
...
...
@@ -119,17 +109,17 @@ THREE.DeviceOrientationControls = function ( object ) {
// (see: http://bit.ly/1dIrx0I)
//
transformedRotationMatrix
.
elements
[
0
]
=
-
r
otationMatrix
.
elements
[
0
];
transformedRotationMatrix
.
elements
[
4
]
=
-
r
otationMatrix
.
elements
[
4
];
transformedRotationMatrix
.
elements
[
8
]
=
r
otationMatrix
.
elements
[
8
];
_objectRotationMatrix
.
elements
[
0
]
=
-
_tmpR
otationMatrix
.
elements
[
0
];
_objectRotationMatrix
.
elements
[
4
]
=
-
_tmpR
otationMatrix
.
elements
[
4
];
_objectRotationMatrix
.
elements
[
8
]
=
_tmpR
otationMatrix
.
elements
[
8
];
transformedRotationMatrix
.
elements
[
1
]
=
-
r
otationMatrix
.
elements
[
1
];
transformedRotationMatrix
.
elements
[
5
]
=
-
r
otationMatrix
.
elements
[
5
];
transformedRotationMatrix
.
elements
[
9
]
=
r
otationMatrix
.
elements
[
9
];
_objectRotationMatrix
.
elements
[
1
]
=
-
_tmpR
otationMatrix
.
elements
[
1
];
_objectRotationMatrix
.
elements
[
5
]
=
-
_tmpR
otationMatrix
.
elements
[
5
];
_objectRotationMatrix
.
elements
[
9
]
=
_tmpR
otationMatrix
.
elements
[
9
];
transformedRotationMatrix
.
elements
[
2
]
=
-
r
otationMatrix
.
elements
[
2
];
transformedRotationMatrix
.
elements
[
6
]
=
-
r
otationMatrix
.
elements
[
6
];
transformedRotationMatrix
.
elements
[
10
]
=
r
otationMatrix
.
elements
[
10
];
_objectRotationMatrix
.
elements
[
2
]
=
-
_tmpR
otationMatrix
.
elements
[
2
];
_objectRotationMatrix
.
elements
[
6
]
=
-
_tmpR
otationMatrix
.
elements
[
6
];
_objectRotationMatrix
.
elements
[
10
]
=
_tmpR
otationMatrix
.
elements
[
10
];
break
;
case
270
:
...
...
@@ -145,17 +135,17 @@ THREE.DeviceOrientationControls = function ( object ) {
// (see: http://bit.ly/1h73sQ0)
//
transformedRotationMatrix
.
elements
[
0
]
=
r
otationMatrix
.
elements
[
4
];
transformedRotationMatrix
.
elements
[
4
]
=
-
r
otationMatrix
.
elements
[
0
];
transformedRotationMatrix
.
elements
[
8
]
=
r
otationMatrix
.
elements
[
8
];
_objectRotationMatrix
.
elements
[
0
]
=
_tmpR
otationMatrix
.
elements
[
4
];
_objectRotationMatrix
.
elements
[
4
]
=
-
_tmpR
otationMatrix
.
elements
[
0
];
_objectRotationMatrix
.
elements
[
8
]
=
_tmpR
otationMatrix
.
elements
[
8
];
transformedRotationMatrix
.
elements
[
1
]
=
r
otationMatrix
.
elements
[
5
];
transformedRotationMatrix
.
elements
[
5
]
=
-
r
otationMatrix
.
elements
[
1
];
transformedRotationMatrix
.
elements
[
9
]
=
r
otationMatrix
.
elements
[
9
];
_objectRotationMatrix
.
elements
[
1
]
=
_tmpR
otationMatrix
.
elements
[
5
];
_objectRotationMatrix
.
elements
[
5
]
=
-
_tmpR
otationMatrix
.
elements
[
1
];
_objectRotationMatrix
.
elements
[
9
]
=
_tmpR
otationMatrix
.
elements
[
9
];
transformedRotationMatrix
.
elements
[
2
]
=
r
otationMatrix
.
elements
[
6
];
transformedRotationMatrix
.
elements
[
6
]
=
-
r
otationMatrix
.
elements
[
2
];
transformedRotationMatrix
.
elements
[
10
]
=
r
otationMatrix
.
elements
[
10
];
_objectRotationMatrix
.
elements
[
2
]
=
_tmpR
otationMatrix
.
elements
[
6
];
_objectRotationMatrix
.
elements
[
6
]
=
-
_tmpR
otationMatrix
.
elements
[
2
];
_objectRotationMatrix
.
elements
[
10
]
=
_tmpR
otationMatrix
.
elements
[
10
];
break
;
default
:
...
...
@@ -172,9 +162,7 @@ THREE.DeviceOrientationControls = function ( object ) {
break
;
}
this
.
_rotationMatrix
.
copy
(
transformedRotationMatrix
);
return
this
.
_rotationMatrix
;
return
_objectRotationMatrix
;
};
this
.
update
=
function
(
delta
)
{
...
...
@@ -182,19 +170,11 @@ THREE.DeviceOrientationControls = function ( object ) {
return
;
}
this
.
setRotationVectorFromDeviceOrientation
(
this
.
deviceOrientation
.
alpha
,
this
.
deviceOrientation
.
beta
,
this
.
deviceOrientation
.
gamma
);
this
.
setRotationMatrixFromRotationVector
(
this
.
_rotationVector
);
this
.
remapRotationMatrixByScreenOrientation
(
this
.
screenOrientation
,
this
.
_rotationMatrix
);
this
.
setObjectRotationMatrixFromDeviceOrientation
();
this
.
object
.
quaternion
.
setFromRotationMatrix
(
this
.
_rotationMatrix
);
this
.
remapObjectRotationMatrixFromScreenOrientation
(
);
this
.
object
.
updateProjectionMatrix
(
);
this
.
object
.
quaternion
.
setFromRotationMatrix
(
_objectRotationMatrix
);
};
function
bind
(
scope
,
fn
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录