From 908c76d6c3f70e37ea6cb02c9613e9ee0fb657a6 Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 27 Sep 2023 14:21:31 +0800 Subject: [PATCH] make iOS/MacOS consistent re moveCameraToBoundingBox --- ios/src/FilamentViewer.cpp | 12 +++++++----- ios/src/PolyvoxFilamentApi.cpp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ios/src/FilamentViewer.cpp b/ios/src/FilamentViewer.cpp index 9e759d60..ac9bb435 100644 --- a/ios/src/FilamentViewer.cpp +++ b/ios/src/FilamentViewer.cpp @@ -872,17 +872,19 @@ void FilamentViewer::setCameraPosition(float x, float y, float z) { void FilamentViewer::moveCameraToAsset(EntityId entityId) { - auto asset = _assetManager->getAssetByEntityId(entityId); +auto asset = _assetManager->getAssetByEntityId(entityId); if(!asset) { Log("Failed to find asset attached to specified entity id."); return; } - const filament::Aabb bb = asset->mAsset->getBoundingBox(); + const filament::Aabb bb = asset->getBoundingBox(); + auto corners = bb.getCorners(); Camera& cam =_view->getCamera(); - _cameraPosition = math::mat4f::translation(bb.getCorners()); - _cameraRotation = math::mat4f(); - cam.setModelMatrix(_cameraPosition * _cameraRotation); + auto eye = corners.vertices[0] * 1.5; + auto lookAt = corners.vertices[7]; + cam.lookAt(eye, lookAt); + Log("Moved camera to %f %f %f, lookAt %f %f %f, near %f far %f", eye[0], eye[1], eye[2], lookAt[0], lookAt[1], lookAt[2], cam.getNear(), cam.getCullingFar()); } void FilamentViewer::setCameraRotation(float rads, float x, float y, float z) { diff --git a/ios/src/PolyvoxFilamentApi.cpp b/ios/src/PolyvoxFilamentApi.cpp index d90c9395..182daac0 100644 --- a/ios/src/PolyvoxFilamentApi.cpp +++ b/ios/src/PolyvoxFilamentApi.cpp @@ -98,7 +98,7 @@ extern "C" { } FLUTTER_PLUGIN_EXPORT void move_camera_to_asset(const void* const viewer, EntityId asset) { - ((FilamentViewer*)viewer)->moveCameraToAsset(asset, asset); + ((FilamentViewer*)viewer)->moveCameraToAsset(asset); } FLUTTER_PLUGIN_EXPORT void set_camera_focus_distance(const void* const viewer, float distance) {