0

I'm trying to figure out how to position an object inside the edge of the camera's fov if it goes outside of it. I've looked at this: Three.js - Width of view But if I plug in the values, it returns 5.12 if the screen width is 512, and 3.12 for height if the screen height is 320. I have the camera positioned -150 on the z axis, and the objects are located at 0 on the z axis. I was hoping it would tell me how much x and y distance there is visible in the fov where z axis is 0 if camera is looking along the z axis. That way I could position objects if they go outside the limits. Anyone know how to get this data?

Community
  • 1
  • 1
user3591153
  • 409
  • 4
  • 14

1 Answers1

2

Okay, I found the answer. Had to use some trigonometry.

h = tan(fov/2)*dist dist is the distance to the object from the camera. h is half of the screen space in y axis. to get x axis multiply by (screenwidth/screenheight)

user3591153
  • 409
  • 4
  • 14
  • I'm using pointer lock controls for a first person shooter. On mouse click, I want to place an object randomly in the 3D world, but always inside the current viewing port (fov). I'm guessing your answer might hold the key to my problem, but I can't seem to wrap my head around it since the distance to the camera isn't known (because the object still has to be created). Any idea? – binoculars May 14 '16 at 18:17
  • I don't know. maybe if you know the current angle of the camera, and the fov, you could pick a random degree between camera angle and half the fov angle, and then project out a random distance? – user3591153 May 20 '16 at 23:19