Camera
rooomSpaces Viewer API camera controls for immersive navigation. Get/set camera position, rotation, movement, transitions, and field of view for exploring 3D virtual environments.
Essential Camera Control
getCameraPosition
getCameraPosition(callback: Function)
Gets the current camera position as an array [x, y, z].
api.getCameraPosition(function(position){
console.log('Camera at:', position); // [x, y, z]
});setCameraPosition
setCameraPosition(position: [x: number, y: number, z: number], [duration: number], [callback: Function])
Sets the camera position. Optionally animates the transition over the given duration in seconds.
api.setCameraPosition([5, 2, 5], 1.5, function(){
console.log('Moved to new viewpoint');
});getCameraRotation
getCameraRotation(callback: Function)
Gets the camera rotation in radians as an array [x, y, z].
api.getCameraRotation(function(rotation){
console.log('Camera rotation:', rotation); // [x, y, z]
});setCameraRotation
setCameraRotation(rotation: [x: number, y: number, z: number], [duration: number], [callback: Function])
Sets the camera rotation. Optionally animates the transition over the given duration in seconds.
api.setCameraRotation([0, Math.PI/2, 0], 2.0, function(){
console.log('Now looking east');
});Advanced Camera Control
getCameraOrientation
getCameraOrientation(callback: Function)
Gets both camera position and rotation in one call.
api.getCameraOrientation(function(camera){
console.log('Position:', camera.position); // [x, y, z]
console.log('Rotation:', camera.rotation); // [x, y, z]
});setCameraOrientation
setCameraOrientation(position: [x: number, y: number, z: number], rotation: [x: number, y: number, z: number], [duration: number], [callback: Function])
Sets both camera position and rotation simultaneously.
api.setCameraOrientation([0, 10, 0], [0, Math.PI, 0], 2.5, function(){
console.log('Camera orientation set');
});Camera Targeting
getCameraTarget
getCameraTarget(callback: Function)
Gets the point the camera is looking at as an array [x, y, z].
api.getCameraTarget(function(target){
console.log('Camera target:', target); // [x, y, z]
});setCameraTarget
setCameraTarget(target: [x: number, y: number, z: number], [duration: number], [callback: Function])
Points the camera at a specific location.
api.setCameraTarget([5, 2, -3], 1.5, function(){
console.log('Camera target set');
});Camera Types & Zoom
switchCameraType
switchCameraType(type: 'walk' | 'birdseye' | 'vr' | 'cardboard' | 'anaglyph' | 'topdown' | 'virtual-joysticks' | 'device-orientation', [callback: Function])
Changes the camera control mode for different interaction styles.
api.switchCameraType('birdseye', function(){
console.log('Switched to birdseye mode');
});getCameraZoom
getCameraZoom(callback: Function)
Gets the current zoom level (birdseye camera radius).
api.getCameraZoom(function(radius){
console.log('Zoom level:', radius);
});setCameraZoom
setCameraZoom(radius: number, [duration=0], [callback: Function])
Sets the zoom level for birdseye camera mode.
// Zoom in for detail view
api.setCameraZoom(15, 2, function(){
console.log('Zoomed in for detail view');
});
// Zoom out for overview
api.setCameraZoom(50, 2, function(){
console.log('Zoomed out for overview');
});Field of View
getFov
getFov(callback: Function)
Gets the current field of view in degrees - affects how much of the scene is visible.
api.getFov(function(fov){
console.log('Current FOV:', fov, 'degrees');
});setFov
setFov(angle: number, [callback: Function])
Sets the field of view (1-179 degrees) - wider angles show more, narrower angles zoom in.
// Wide angle for architectural overview
api.setFov(90, function(){
console.log('Wide angle view enabled');
});
// Narrow angle for focused detail
api.setFov(45, function(){
console.log('Focused detail view');
});Best Practices
Navigation Patterns:
- Use
setCameraPosition()for location changes - Use
setCameraTarget()to direct attention - Combine both with
setCameraOrientation()for complete scene transitions
User Experience:
- Provide smooth transitions with appropriate duration values
- Save/restore camera states for bookmarks and undo functionality
- Match camera type to interaction context (walk for exploration, birdseye for overview)
Performance:
- Cache camera positions for frequently visited locations
- Use shorter durations for responsive interactions
- Consider user motion sensitivity when setting transition speeds