Mandroid
Mandroid

Reputation: 7478

Coordinate system issue in three.js

I am working on a program in three.js. So I have a particle system loaded from a LAS file. It has a coordinate system. I have added a functionality which enables user to click on a particle, and it would add a bounding box to the scene. My aim is to find which particles lie inside this bounding box.

Code for adding bounding box at point p clicked by user:

var cubeGeometry = new THREE.BoxGeometry( 1, 1, 1 );
var cubeMaterial = new THREE.MeshLambertMaterial( { color: 
   0xffff00,wireframe: true } );
var cube = new THREE.Mesh( cubeGeometry, cubeMaterial );
cube.position.x = p.x;
cube.position.y = p.y;
cube.position.z = p.z;
scene.add(cube);

But I am facing an issue. The box created has a different coordinate axis orientation than particle system. It's Y axis is oriented in direction of particle system's Z axis. This causes containsPoint method to give wrong answer.

How to solve this issue?

Upvotes: 0

Views: 560

Answers (1)

Mugen87
Mugen87

Reputation: 31026

Try this:

var e = new THREE.Euler( - Math.PI / 2, 0, 0 );
p.applyEuler( e );

This will apply a rotation of 90 degrees around the x-axis or a conversion from Z-up to Y-up.

Upvotes: 1

Related Questions