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?

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.