简体   繁体   English

如何使用WebGL(和THREE.js库)基于对象的位置旋转对象?

[英]How can I rotate an object based on its position with WebGL (and THREE.js library)?

I'm doing a Rubik's cube in WebGL. 我正在WebGL中创建Rubik的多维数据集。 I created 27 little cubes That form a big one, but I do not know how to say "rotate the cubes that are in that particular position (the block of 9 on the top for example)". 我创建了27个构成一个大立方体的小立方体,但是我不知道怎么说“旋转处于特定位置的立方体(例如,顶部的9块)”。 The cubes always change their position so I need a dinamic way to call them. 多维数据集始终会更改其位置,因此我需要一种动态的方式来调用它们。 How can I do it? 我该怎么做? How can I call a group of cubes and rotate them not by their names but thanks their position? 如何调用一组多维数据集并不按名称旋转它们,而是感谢它们的位置?

In my code I have only created the cubes and I have added them to the scene to create the big one, not more. 在我的代码中,我仅创建了多维数据集,并将其添加到场景中以创建大型多维数据集,而不是更多。

I really need help, so thx a lot. 我真的需要帮助,所以很多。

I've been following and contributing to a project that lets you create WebGL based apps very easily. 我一直在关注并致力于一个使您可以非常轻松地创建基于WebGL的应用程序的项目。 It's called whitestormJS and you can check it out here 叫做whitestormJS,您可以在这里查看

So whitestorm is just simply a wrapper for Three.js tt has a nice API and it will simplify many things. 因此,whitestorm只是Three.js的一个包装。tt有一个不错的API,它将简化很多事情。 Anyways despite of what you're using. 无论如何,无论您使用什么。 I would suggest you to use groups to move all the faces. 我建议您使用组来移动所有面孔。 Jonathan Petitcolas has a nice tutorial about rotation in Three.js. Jonathan Petitcolas有一个关于Three.js旋转的不错的教程

//you should create a group for each face with its proper cubes
var face1 = new THREE.Group();
group.add(piece1);
group.add(piece2);
// and so on, finally set a rotation to the group on the proper axis.
pivot.rotation.y = 1.5708; //this is 90 degrees in radians

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM