最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Rotation anchor point in Three.js - Stack Overflow

programmeradmin2浏览0评论

I am defining a cone that I need to be able to rotate around its top point (the point where the cone thickness is the smallest one). I couldn't find yet the way to set the point around which the rotation to happen.

var coneGeometry = new THREE.CylinderGeometry(1000, 0, width, 50, 50, false);
var cone = new THREE.Mesh(coneGeometry, material);
cone.position.x = x;
cone.position.y = y + width / 2;
cone.position.z = z;
// I want this rotation to happen around the point given by the (x, y, z) location
cone.rotation.x = dip;

I am defining a cone that I need to be able to rotate around its top point (the point where the cone thickness is the smallest one). I couldn't find yet the way to set the point around which the rotation to happen.

var coneGeometry = new THREE.CylinderGeometry(1000, 0, width, 50, 50, false);
var cone = new THREE.Mesh(coneGeometry, material);
cone.position.x = x;
cone.position.y = y + width / 2;
cone.position.z = z;
// I want this rotation to happen around the point given by the (x, y, z) location
cone.rotation.x = dip;
Share Improve this question asked Sep 24, 2012 at 10:55 Dan D.Dan D. 32.4k6 gold badges65 silver badges81 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 14

The cone geometry is centered at the origin. What you need to do is translate the cone geometry right after it is created so the tip of the cone is at the origin.

coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, coneHeight/2, 0 ) );

(The sign of the translation changes depending on which end of the cone is the small end.)

Now, when you rotate the cone, it will rotate around the tip. The tip will also be located at the position you set.

EDIT: You can now do this, instead:

coneGeometry.translate( 0, coneHeight/2, 0 ); // three.js r.72
发布评论

评论列表(0)

  1. 暂无评论