When I setup my scene, add geometries etc, how do I set the camera so I can see my whole scene? I'm trying to implement an algorithm using boundingboxes, but I'm kinda stuck.
Asked
Active
Viewed 1,627 times
1
-
2Please post some examples on jsfiddle. And be more specific next time. – TalesTk Nov 26 '12 at 20:08
-
If i had some code, it would be posted, but I don't know how to proceed...I'm still thinking :(. My scene would have n meshes, with different widths, heights and depths. I want to find the "best fit" camera position, which shows all the meshes. – Leprosy Nov 26 '12 at 20:14
-
Please try first. Then, if you have problems, post your code and ask a specific question. – WestLangley Nov 26 '12 at 20:21
-
How can I begin trying? I'm asking help with the algorithm...how can I implement something If I don't know how to begin? – Leprosy Nov 26 '12 at 21:23
-
2You _do_ know how to begin. You just don't know how to _finish_. :-) – WestLangley Nov 27 '12 at 00:12
-
2Take a look at http://stackoverflow.com/questions/2866350/move-camera-to-fit-3d-scene – Juan Mellado Nov 27 '12 at 10:53
-
@WestLangley that's right :P – Leprosy Nov 27 '12 at 12:40
1 Answers
0
You really only need to find the greatest absolute value between all your variables by using Math.abs(number)
, once you have found the greatest of all you can set the depth(position.z) of the camera to that number. I have made a simple function which receives 2 numbers and returns the greatest.
function findGreatestAbsolute( firstNumber, secondNumber ) {
if( Math.abs( firstNumber ) > Math.abs( secondNumber )) {
return Math.abs( firstNumber );
} else { return Math.abs( secondNumber ); }
}
You can also use Arrays if there are too many numbers. Once you have found your number you do:
camera = new THREE.PerspectiveCamera( cameraFov, windowHalfX / windowHalfY , 1, someDepth );
camera.position.z(greatestNumber);
or
camera.position.set(yourX, yourY, greatestNumber);
Well I hope it helps.

TalesTk
- 181
- 3