Camera EntityInView help...
Blitz3D Forums/Blitz3D Programming/Camera EntityInView help...
| ||
In the game I'm working, I have 4-5 characters on the screen at the same time. I need to know at runtime at what distance, camera have to be positioned to have all the characters inside cameraview with a cameraZoom of 1.7 I think I have to use camera projection/perspective matrix but I don't know how to do it... ...anyone? |
| ||
Well, the math required for that is out of my league, but for starters you could try to find out the averaged center for all those models. Compute the average position for the characters in relation to eachother, and then average those points and you'll find out the center for all the characters. Having the camera pointing that center is a start. From then on you can start to move the camera on the negative Z axis (so it goes backward) by certain increments, and checking every iteration to see if all the models are visible. When they are all visible, you know you got a good distance. Also, projecting their coordinates onto the screenspace (using CameraProject) and seeing the distance of those projected points in relation to the screen's extremities will also tell you if they are well distributed on screen. It's a way to do it, but far from a mathematical precise algorithm. |
| ||
hi with a zoom of 1.7 you see aprox 1.2 units for each 1 unit of distance so you have to put your camera at a distance of : SizeOfObjectToSee/1.2 if you want to see it completelly (1.2 is an aproximation the coorect number is 1.17... derived from the formula Zoom=1/Tan(FOV/2) where FOV is Field Of View, in your case you are using a FOV of 60 degrees) but that formula alone doesn't help too much, you first has to know the size of a sphere? that surrounds all your players (kryzon way is better than mine i think) and then use the diameter of the sphere to calc the distance of the camera. The center of the sphere should be in the center of all the characters as keyzon say. hope that help Juan |