setRotation/setPosition from center
This commit is contained in:
@@ -597,4 +597,14 @@ void FilamentViewer::updateViewportAndCameraProjection(
|
|||||||
contentScaleFactor);
|
contentScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FilamentViewer::setCameraPosition(float x, float y, float z) {
|
||||||
|
Camera& cam =_view->getCamera();
|
||||||
|
auto &tm = _engine->getTransformManager();
|
||||||
|
// tm.setTransform(tm.getInstance(_asset->getRoot()), math::mat4f::translation(math::float3(x,y,z)) * _cameraRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FilamentViewer::setCameraRotation(float rads, float x, float y, float z) {
|
||||||
|
Camera& cam =_view->getCamera();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace polyvox
|
} // namespace polyvox
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ namespace polyvox {
|
|||||||
|
|
||||||
void setBackgroundImage(const char* resourcePath);
|
void setBackgroundImage(const char* resourcePath);
|
||||||
|
|
||||||
|
void setCameraPosition(float x, float y, float z);
|
||||||
|
void setCameraRotation(float rads, float x, float y, float z);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createImageRenderable();
|
void createImageRenderable();
|
||||||
void loadResources(std::string relativeResourcePath);
|
void loadResources(std::string relativeResourcePath);
|
||||||
|
|||||||
@@ -56,6 +56,14 @@ extern "C" {
|
|||||||
return ((FilamentViewer*)viewer)->setCamera((SceneAsset*)asset, nodeName);
|
return ((FilamentViewer*)viewer)->setCamera((SceneAsset*)asset, nodeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_camera_position(void* viewer, float x, float y, float z) {
|
||||||
|
return ((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);
|
||||||
|
}
|
||||||
|
|
||||||
void render(
|
void render(
|
||||||
void* viewer
|
void* viewer
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -56,5 +56,9 @@ void set_position(void* asset, float x, float y, float z);
|
|||||||
void set_rotation(void* asset, float rads, float x, float y, float z);
|
void set_rotation(void* asset, float rads, float x, float y, float z);
|
||||||
|
|
||||||
void stop_animation(void* asset, int index);
|
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);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ using namespace filament;
|
|||||||
using namespace filament::gltfio;
|
using namespace filament::gltfio;
|
||||||
using namespace image;
|
using namespace image;
|
||||||
using namespace utils;
|
using namespace utils;
|
||||||
using namespace filament::math;
|
|
||||||
|
|
||||||
SceneAsset::SceneAsset(FilamentAsset *asset, Engine *engine,
|
SceneAsset::SceneAsset(FilamentAsset *asset, Engine *engine,
|
||||||
NameComponentManager *ncm, LoadResource loadResource, FreeResource freeResource)
|
NameComponentManager *ncm, LoadResource loadResource, FreeResource freeResource)
|
||||||
@@ -294,15 +293,29 @@ void SceneAsset::transformToUnitCube() {
|
|||||||
void SceneAsset::setPosition(float x, float y, float z) {
|
void SceneAsset::setPosition(float x, float y, float z) {
|
||||||
Log("Setting position to %f %f %f", x, y, z);
|
Log("Setting position to %f %f %f", x, y, z);
|
||||||
auto &tm = _engine->getTransformManager();
|
auto &tm = _engine->getTransformManager();
|
||||||
auto transform = tm.getTransform(tm.getInstance(_asset->getRoot()));
|
_position = math::mat4f::translation(math::float3(x,y,z));
|
||||||
tm.setTransform(tm.getInstance(_asset->getRoot()), transform * math::mat4f::translation(math::float3(x,y,z)));
|
auto aabb = _asset->getBoundingBox();
|
||||||
|
auto center = aabb.center();
|
||||||
|
auto halfExtent = aabb.extent();
|
||||||
|
auto maxExtent = max(halfExtent) * 2;
|
||||||
|
auto scaleFactor = 2.0f / maxExtent;
|
||||||
|
auto transform =
|
||||||
|
math::mat4f::scaling(scaleFactor) * math::mat4f::translation(-center) * _position * _rotation;
|
||||||
|
tm.setTransform(tm.getInstance(_asset->getRoot()), transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneAsset::setRotation(float rads, float x, float y, float z) {
|
void SceneAsset::setRotation(float rads, float x, float y, float z) {
|
||||||
Log("Rotating %f radians around axis %f %f %f", x, y, z);
|
Log("Rotating %f radians around axis %f %f %f", x, y, z);
|
||||||
auto &tm = _engine->getTransformManager();
|
auto &tm = _engine->getTransformManager();
|
||||||
auto transform = tm.getTransform(tm.getInstance(_asset->getRoot()));
|
_rotation = math::mat4f::rotation(rads, math::float3(x,y,z));
|
||||||
tm.setTransform(tm.getInstance(_asset->getRoot()), transform * math::mat4f::rotation(rads, math::float3(x,y,z)));
|
auto aabb = _asset->getBoundingBox();
|
||||||
|
auto center = aabb.center();
|
||||||
|
auto halfExtent = aabb.extent();
|
||||||
|
auto maxExtent = max(halfExtent) * 2;
|
||||||
|
auto scaleFactor = 2.0f / maxExtent;
|
||||||
|
auto transform =
|
||||||
|
math::mat4f::scaling(scaleFactor) * math::mat4f::translation(-center) * _position * _rotation;
|
||||||
|
tm.setTransform(tm.getInstance(_asset->getRoot()), transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,15 @@
|
|||||||
#include <filament/Scene.h>
|
#include <filament/Scene.h>
|
||||||
#include <filament/Texture.h>
|
#include <filament/Texture.h>
|
||||||
|
|
||||||
|
#include <math/vec3.h>
|
||||||
|
#include <math/vec4.h>
|
||||||
|
#include <math/mat3.h>
|
||||||
|
#include <math/norm.h>
|
||||||
|
|
||||||
#include <gltfio/AssetLoader.h>
|
#include <gltfio/AssetLoader.h>
|
||||||
#include <gltfio/FilamentAsset.h>
|
#include <gltfio/FilamentAsset.h>
|
||||||
#include <gltfio/ResourceLoader.h>
|
#include <gltfio/ResourceLoader.h>
|
||||||
|
|
||||||
|
|
||||||
#include <utils/NameComponentManager.h>
|
#include <utils/NameComponentManager.h>
|
||||||
|
|
||||||
#include "SceneResources.hpp"
|
#include "SceneResources.hpp"
|
||||||
@@ -102,5 +106,8 @@ namespace polyvox {
|
|||||||
// a slot to preload textures
|
// a slot to preload textures
|
||||||
filament::Texture* _texture = nullptr;
|
filament::Texture* _texture = nullptr;
|
||||||
|
|
||||||
|
math::mat4f _position;
|
||||||
|
math::mat4f _rotation;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user