add camera utils to API

This commit is contained in:
Nick Fisher
2022-08-26 00:25:45 +10:00
parent d78f70ac50
commit d3faaac6c0
7 changed files with 84 additions and 11 deletions

View File

@@ -121,6 +121,7 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource,
Entity camera = EntityManager::get().create();
_mainCamera = _engine->createCamera(camera);
Log("Main camera created");
_view = _engine->createView();
_view->setScene(_scene);
@@ -133,6 +134,8 @@ FilamentViewer::FilamentViewer(void *layer, LoadResource loadResource,
_view->setColorGrading(colorGrading);
_cameraFocalLength = 28.0f;
_mainCamera->setLensProjection(_cameraFocalLength, 1.0f, kNearPlane,
kFarPlane);
_mainCamera->setExposure(kAperture, kShutterSpeed, kSensitivity);
#if TARGET_OS_IPHONE
_swapChain = _engine->createSwapChain(layer, filament::backend::SWAP_CHAIN_CONFIG_APPLE_CVPIXELBUFFER);
@@ -435,6 +438,25 @@ void FilamentViewer::removeAsset(SceneAsset *asset) {
mtx.unlock();
}
///
/// Set the focal length of the active camera.
///
void FilamentViewer::setCameraFocalLength(float focalLength) {
Camera& cam =_view->getCamera();
_cameraFocalLength = focalLength;
cam.setLensProjection(_cameraFocalLength, 1.0f, kNearPlane,
kFarPlane);
}
///
/// Set the focus distance of the active camera.
///
void FilamentViewer::setCameraFocusDistance(float focusDistance) {
Camera& cam =_view->getCamera();
_cameraFocusDistance = focusDistance;
cam.setFocusDistance(_cameraFocusDistance);
}
///
/// Sets the active camera to the first GLTF camera node found in the hierarchy.
/// Useful when your asset only has one camera.

View File

@@ -76,6 +76,8 @@ namespace polyvox {
void setCameraPosition(float x, float y, float z);
void setCameraRotation(float rads, float x, float y, float z);
void setCameraFocalLength(float fl);
void setCameraFocusDistance(float focusDistance);
private:
void createImageRenderable();
@@ -120,7 +122,8 @@ namespace polyvox {
bool _actualSize = false;
float _cameraFocalLength = 0.0f;
float _cameraFocalLength = 28.0f;
float _cameraFocusDistance = 0.0f;
// these flags relate to the textured quad we use for rendering unlit background images
Texture* _imageTexture = nullptr;

View File

@@ -57,11 +57,15 @@ extern "C" {
}
void set_camera_position(void* viewer, float x, float y, float z) {
return ((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
((FilamentViewer*)viewer)->setCameraPosition(x, y, z);
}
void set_camera_rotation(void* viewer, float rads, float x, float y, float z) {
return ((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
((FilamentViewer*)viewer)->setCameraRotation(rads, x, y, z);
}
void set_camera_focal_length(void* viewer, float focalLength) {
((FilamentViewer*)viewer)->setCameraFocalLength(focalLength);
}
void render(

View File

@@ -60,5 +60,7 @@ void stop_animation(void* asset, int index);
void set_camera_position(void* viewer, float x, float y, float z);
void set_camera_rotation(void* viewer, float rads, float x, float y, float z);
void set_camera_focal_length(void* viewer, float focalLength);
void set_camera_focus_distance(void* viewer, float focusDistance);
#endif