Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
656d0532
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
提交
656d0532
编写于
2月 20, 2014
作者:
R
richtr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add W3C DeviceOrientation Event controls and demo
上级
8413a860
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
173 addition
and
0 deletion
+173
-0
examples/js/controls/DeviceOrientationControls.js
examples/js/controls/DeviceOrientationControls.js
+49
-0
examples/misc_controls_deviceorientation.html
examples/misc_controls_deviceorientation.html
+124
-0
未找到文件。
examples/js/controls/DeviceOrientationControls.js
0 → 100644
浏览文件 @
656d0532
/**
* @author richt / http://richt.me
*
* W3C Device Orientation control (http://www.w3.org/TR/orientation-event/)
*/
THREE
.
DeviceOrientationControls
=
function
(
object
)
{
this
.
object
=
object
;
this
.
degtorad
=
Math
.
PI
/
180
;
this
.
freeze
=
true
;
this
.
orientationData
=
{};
this
.
eulerRotationOrder
=
"
ZXY
"
;
this
.
registerOrientationData
=
function
(
data
)
{
this
.
freeze
=
false
;
this
.
orientationData
=
data
;
};
this
.
update
=
function
(
delta
)
{
if
(
this
.
freeze
)
{
return
;
}
this
.
object
.
rotation
.
set
(
(
this
.
orientationData
[
'
beta
'
]
||
0
)
*
this
.
degtorad
,
(
this
.
orientationData
[
'
gamma
'
]
||
0
)
*
this
.
degtorad
,
(
this
.
orientationData
[
'
alpha
'
]
||
0
)
*
this
.
degtorad
,
this
.
eulerRotationOrder
);
};
function
bind
(
scope
,
fn
)
{
return
function
()
{
fn
.
apply
(
scope
,
arguments
);
};
};
this
.
connect
=
function
()
{
window
.
addEventListener
(
'
deviceorientation
'
,
bind
(
this
,
this
.
registerOrientationData
),
false
);
};
this
.
disconnect
=
function
()
{
window
.
removeEventListener
(
'
deviceorientation
'
,
bind
(
this
,
this
.
registerOrientationData
),
false
);
this
.
freeze
=
true
;
};
};
examples/misc_controls_deviceorientation.html
0 → 100644
浏览文件 @
656d0532
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - controls - deviceorientation
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"user-scalable=no, initial-scale=1"
>
<style>
body
{
margin
:
0px
;
background-color
:
#000000
;
overflow
:
hidden
;
}
#info
{
position
:
absolute
;
top
:
0px
;
width
:
100%
;
color
:
#ffffff
;
padding
:
5px
;
font-family
:
Monospace
;
font-size
:
13px
;
font-weight
:
bold
;
text-align
:
center
;
}
a
{
color
:
#ff8800
;
}
</style>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
- equirectangular panorama demo with DeviceOrientation controls.
photo by
<a
href=
"http://www.flickr.com/photos/jonragnarsson/2294472375/"
target=
"_blank"
>
Jón Ragnarsson
</a>
.
</div>
<div
id=
"container"
></div>
<script
src=
"../build/three.min.js"
></script>
<script
src=
"js/controls/DeviceOrientationControls.js"
></script>
<script>
(
function
()
{
"
use strict
"
var
hasWebGL
=
(
function
()
{
try
{
var
canvas
=
document
.
createElement
(
'
canvas
'
);
return
!!
window
.
WebGLRenderingContext
&&
(
canvas
.
getContext
(
'
webgl
'
)
||
canvas
.
getContext
(
'
experimental-webgl
'
)
);
}
catch
(
e
)
{
return
false
;
}
})();
window
.
addEventListener
(
'
load
'
,
function
()
{
var
container
,
camera
,
scene
,
renderer
,
controls
,
geometry
,
mesh
;
var
animate
=
function
(){
controls
.
update
();
renderer
.
render
(
scene
,
camera
);
window
.
requestAnimationFrame
(
animate
);
};
container
=
document
.
getElementById
(
'
container
'
);
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
1100
);
controls
=
new
THREE
.
DeviceOrientationControls
(
camera
);
scene
=
new
THREE
.
Scene
();
var
geometry
=
new
THREE
.
SphereGeometry
(
500
,
60
,
40
);
geometry
.
applyMatrix
(
new
THREE
.
Matrix4
().
makeScale
(
-
1
,
1
,
1
)
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
map
:
THREE
.
ImageUtils
.
loadTexture
(
'
textures/2294472375_24a3b8ef46_o.jpg
'
)
}
);
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
rotation
.
x
=
90
;
scene
.
add
(
mesh
);
renderer
=
hasWebGL
?
new
THREE
.
WebGLRenderer
()
:
new
THREE
.
CanvasRenderer
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
domElement
.
style
.
position
=
'
absolute
'
;
renderer
.
domElement
.
style
.
top
=
0
;
container
.
appendChild
(
renderer
.
domElement
);
var
resizeWindow
=
function
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
};
var
setScreenOrientation
=
function
()
{
window
.
setTimeout
(
function
()
{
renderer
.
domElement
.
style
[
'
MozTransform
'
]
=
renderer
.
domElement
.
style
[
'
MsTransform
'
]
=
renderer
.
domElement
.
style
[
'
WebkitTransform
'
]
=
renderer
.
domElement
.
style
[
'
OTransform
'
]
=
renderer
.
domElement
.
style
[
'
Transform
'
]
=
"
rotate(
"
+
(
-
window
.
orientation
||
0
)
+
"
deg)
"
;
},
200
);
};
window
.
addEventListener
(
'
resize
'
,
resizeWindow
,
false
);
window
.
addEventListener
(
'
orientationchange
'
,
setScreenOrientation
,
false
);
setScreenOrientation
();
controls
.
connect
();
animate
();
},
false
);
})();
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录