Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
6be53f62
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,发现更多精彩内容 >>
提交
6be53f62
编写于
8月 13, 2018
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Editor: Update position after raycasting in arkanoid example.
上级
0e9e5e5d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
editor/examples/arkanoid.app.json
editor/examples/arkanoid.app.json
+1
-1
未找到文件。
editor/examples/arkanoid.app.json
浏览文件 @
6be53f62
...
...
@@ -272,7 +272,7 @@
"31517222-A9A7-4EAF-B5F6-60751C0BABA3"
:
[
{
"name"
:
"Game Logic"
,
"source"
:
"var ball = this.getObjectByName( 'Ball' );
\n\n
var direction = new THREE.Vector3();
\n
direction.x = Math.random() - 0.5;
\n
direction.z = - 0.5;
\n
direction.normalize();
\n\n
var speed = new THREE.Vector3();
\n\n
//
\n\n
var group = new THREE.Group();
\n
this.add( group );
\n\n
var paddle = this.getObjectByName( 'Paddle' );
\n
paddle.material.visible = false;
\n
group.add( paddle );
\n\n
var brick = this.getObjectByName( 'Brick' );
\n\n
for ( var j = 0; j < 8; j ++ ) {
\n\n\t
var material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );
\n\n\t
for ( var i = 0; i < 12; i ++ ) {
\n\t\t\n\t\t
var object = brick.clone();
\n\t\t
object.position.x = i * 2.2 - 12;
\n\t\t
object.position.z = j * 1.4 - 12;
\n\t\t
group.add( object );
\n\n\t\t
var cylinder = object.getObjectByName( 'Cylinder' );
\n\t\t
cylinder.material = material;
\n\n\t
}
\n\t\n
}
\n\n
brick.visible = false;
\n
brick.material.visible = false;
\n\n
//
\n\n
var raycaster = new THREE.Raycaster();
\n\n
function update( event ) {
\n\t\n\t
if ( ball.position.x < - 15 || ball.position.x > 15 ) direction.x = - direction.x;
\n\t
if ( ball.position.z < - 20 || ball.position.z > 20 ) direction.z = - direction.z;
\n\n\t
ball.position.x = Math.max( - 15, Math.min( 15, ball.position.x ) );
\n\t
ball.position.z = Math.max( - 20, Math.min( 20, ball.position.z ) );
\n\t\
n\t
ball.position.add( speed.copy( direction ).multiplyScalar( event.delta / 40 ) );
\n\t\n\t
raycaster.set( ball.position, direction );
\n\t\n\t
var intersections = raycaster.intersectObjects( group.children );
\n\t\n\t
if ( intersections.length > 0 ) {
\n\t\n\t\t
var intersection = intersections[ 0 ];
\n\t\t\n\t\t
if ( intersection.distance < 0.5 ) {
\n\t\t\t\n\t\t\t
if ( intersection.object !== paddle ) {
\n\n\t\t\t\t
group.remove( intersection.object );
\n\t\t\t\t\n\t\t\t
}
\n\t\t\t\n\t\t\t
direction.reflect( intersection.face.normal );
\n\t\t\t\n\t\t
}
\n\t\t\n\t
}
\n
\n
}"
"source"
:
"var ball = this.getObjectByName( 'Ball' );
\n\n
var direction = new THREE.Vector3();
\n
direction.x = Math.random() - 0.5;
\n
direction.z = - 0.5;
\n
direction.normalize();
\n\n
var speed = new THREE.Vector3();
\n\n
//
\n\n
var group = new THREE.Group();
\n
this.add( group );
\n\n
var paddle = this.getObjectByName( 'Paddle' );
\n
paddle.material.visible = false;
\n
group.add( paddle );
\n\n
var brick = this.getObjectByName( 'Brick' );
\n\n
for ( var j = 0; j < 8; j ++ ) {
\n\n\t
var material = new THREE.MeshPhongMaterial( { color: Math.random() * 0xffffff } );
\n\n\t
for ( var i = 0; i < 12; i ++ ) {
\n\t\t\n\t\t
var object = brick.clone();
\n\t\t
object.position.x = i * 2.2 - 12;
\n\t\t
object.position.z = j * 1.4 - 12;
\n\t\t
group.add( object );
\n\n\t\t
var cylinder = object.getObjectByName( 'Cylinder' );
\n\t\t
cylinder.material = material;
\n\n\t
}
\n\t\n
}
\n\n
brick.visible = false;
\n
brick.material.visible = false;
\n\n
//
\n\n
var raycaster = new THREE.Raycaster();
\n\n
function update( event ) {
\n\t\n\t
if ( ball.position.x < - 15 || ball.position.x > 15 ) direction.x = - direction.x;
\n\t
if ( ball.position.z < - 20 || ball.position.z > 20 ) direction.z = - direction.z;
\n\n\t
ball.position.x = Math.max( - 15, Math.min( 15, ball.position.x ) );
\n\t
ball.position.z = Math.max( - 20, Math.min( 20, ball.position.z ) );
\n\t\
t\n\t
raycaster.set( ball.position, direction );
\n\t\n\t
var intersections = raycaster.intersectObjects( group.children );
\n\t\n\t
if ( intersections.length > 0 ) {
\n\t\n\t\t
var intersection = intersections[ 0 ];
\n\t\t\n\t\t
if ( intersection.distance < 0.5 ) {
\n\t\t\t\n\t\t\t
if ( intersection.object !== paddle ) {
\n\n\t\t\t\t
group.remove( intersection.object );
\n\t\t\t\t\n\t\t\t
}
\n\t\t\t\n\t\t\t
direction.reflect( intersection.face.normal );
\n\t\t\t\n\t\t
}
\n\t\t\n\t
}
\n\n\t
ball.position.add( speed.copy( direction ).multiplyScalar( event.delta / 40 ) );
\n\t
\n
}"
}]
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录