javascript - How to change the camera position with mouse dragging in Three.js? - Stack Overflow

I've made a Rolex cube kind of geometry with difference in "Z axis" between each layer.

I've made a Rolex cube kind of geometry with difference in "Z axis" between each layer. Now I want to change the camera position so that I could check the geometry is exactly what I was expecting. My question is how to change the camera position while dragging the window and also should be able manipulate the rotation of each individual cone based on mouse event.

Here is my jsfiddle Link: /

sample code but please make sure you visit jsfiddle to get detail idea of my question:

for ( var i = 0; i <nSize; i++)
{
    var k = i%10,
        j = (i-k)/10;

    j = j*2 - 10;
    k = k*2 - 10;

    var cone1 = lc_relationship.sensor1[i].Geometry; 
    scene.add(cone1);
    var cone2 = lc_relationship.sensor2[i].Geometry;
    scene.add(cone2);
    var cone3 = lc_relationship.sensor3[i].Geometry;
    scene.add(cone3);
    cone1.position.set(j, k, lc_relationship.sensor1[i].z_cordinate);
    cone2.position.set(j, k, lc_relationship.sensor2[i].z_cordinate);
    cone3.position.set(j, k, lc_relationship.sensor3[i].z_cordinate);
}

If someone could update my jsfiddle or provide me help is enough.

Thanks in advance.

I've made a Rolex cube kind of geometry with difference in "Z axis" between each layer. Now I want to change the camera position so that I could check the geometry is exactly what I was expecting. My question is how to change the camera position while dragging the window and also should be able manipulate the rotation of each individual cone based on mouse event.

Here is my jsfiddle Link: http://jsfiddle/sagh0900/gfraQ/8/

sample code but please make sure you visit jsfiddle to get detail idea of my question:

for ( var i = 0; i <nSize; i++)
{
    var k = i%10,
        j = (i-k)/10;

    j = j*2 - 10;
    k = k*2 - 10;

    var cone1 = lc_relationship.sensor1[i].Geometry; 
    scene.add(cone1);
    var cone2 = lc_relationship.sensor2[i].Geometry;
    scene.add(cone2);
    var cone3 = lc_relationship.sensor3[i].Geometry;
    scene.add(cone3);
    cone1.position.set(j, k, lc_relationship.sensor1[i].z_cordinate);
    cone2.position.set(j, k, lc_relationship.sensor2[i].z_cordinate);
    cone3.position.set(j, k, lc_relationship.sensor3[i].z_cordinate);
}

If someone could update my jsfiddle or provide me help is enough.

Thanks in advance.

Share Improve this question edited Dec 27, 2012 at 16:20 three.jsaddict asked Dec 27, 2012 at 15:52 three.jsaddictthree.jsaddict 3052 gold badges9 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I use a empty (null) mesh to add objects instead scene: Mesh

mesh = new THREE.Mesh(new THREE.Geometry());
scene.add(mesh);
/*[...]*/
mesh.add(cone1);
/*[...]*/
mesh.add(cone2);
/*[...]*/
mesh.add(cone3);
/*[...]*/

And add this to rotate this mesh:

var screenW = window.innerWidth;
var screenH = window.innerHeight; /*SCREEN*/
var spdx = 0, spdy = 0; mouseX = 0, mouseY = 0, mouseDown = false; /*MOUSE*/
document.addEventListener('mousemove', function(event) {
    mouseX = event.clientX;
    mouseY = event.clientY;
}, false);
document.body.addEventListener("mousedown", function(event) {
    mouseDown = true
}, false);
document.body.addEventListener("mouseup", function(event) {
    mouseDown = false
}, false);
function animate() {    
    spdy =  (screenH / 2 - mouseY) / 40;
    spdx =  (screenW / 2 - mouseX) / 40;
    if (mouseDown){
        mesh.rotation.x = spdy;
        mesh.rotation.y = spdx;
    }
}

Test: http://jsfiddle/gfraQ/11/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744937334a4602107.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信