2

I have a bunch of data and I know their lat/lon position (circles on the image). Now I have a camera in three.js and I know it's position, rotation and which way is north from it's perspective.

I want to go on top of these circles on mouse click but I'd like that the program would choose the closest one to the player and it should also be in the current field of view.

I've tried finding the angle between camera look direction and circle's position but it still moves quite randomly.

Any ideas where to start with this?

enter image description here

Noripsni
  • 425
  • 1
  • 5
  • 21
  • for the closest circle you may yet have found how to get the distance yet ? What is wrong calculating the angle with the camera's look direction ? Why does it finally move randomly if actually the player has to click a circle that necessary is in the field of view ? – Mouloud85 Jun 12 '15 at 16:37
  • I think you need to better explain this, as is, i've no idea what you're trying to do. – pailhead Jun 12 '15 at 17:43

1 Answers1

3

I'm not totally sure what you're asking regarding the "going on top of the circles and mouse click" part but here's a utility function for getting the distance between a camera and a point you know the x, y, z coordinates for.

var getCameraDistanceFrom = function(camera,x,y,z) {
    var cameraDistance = new THREE.Vector3();
    var target = new THREE.Vector3(x,y,z);
    cameraDistance.subVectors(camera.position, target);
    return cameraDistance.length();
};

This answer seems to have a good way to check if an object is in the camera's field of view: Determine if a mesh is visible on the viewport according to current camera

Community
  • 1
  • 1