0

Right now, I put my object in my 3D environment using

object.position.y = 5;
object.position.x = getRandomInt(-90,100);
object.position.z = getRandomInt(-50,150);

function getRandomInt(min, max) {
   return Math.floor(Math.random() * (max - min + 1)) + min;
}

I want to place this object not just randomly, but randomly inside the viewport of the user. Anyone who knows how to do this? I'm using Pointer Lock Controls.

Update: I've managed to place the object in the center of the viewing port, using

object.position.x = 0;
object.position.y = 0;
object.position.z = -50;
object.position.applyMatrix4( camera.matrixWorld );

But I want it to appear on a random position in the camera view, so... not there yet...

binoculars
  • 2,226
  • 5
  • 33
  • 61
  • http://stackoverflow.com/questions/14614252/how-to-fit-camera-to-object – gaitat May 03 '16 at 17:46
  • Thanks for your reply. Maybe I misinterpreted the link you posted, but my question is about placing an object inside the viewing port, while the question you posted is about fitting the camera to an object. I don't wish to change the viewport. The viewport is determined by the users mouse via pointer lock controls. – binoculars May 03 '16 at 17:50

0 Answers0