chore: getter for native camera view matrix
This commit is contained in:
@@ -75,4 +75,9 @@ class ThermionFFICamera extends Camera {
|
||||
Future<double> getFocalLength() async {
|
||||
return Camera_getFocalLength(camera);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Matrix4> getViewMatrix() async {
|
||||
return double4x4ToMatrix4(Camera_getViewMatrix(camera));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,6 +887,16 @@ external double Camera_getCullingFar(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
);
|
||||
|
||||
@ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external double4x4 Camera_getViewMatrix(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
);
|
||||
|
||||
@ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external double4x4 Camera_getModelMatrix(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Double Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external double get_camera_near(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
@@ -947,11 +957,6 @@ external void Camera_setLensProjection(
|
||||
double focalLength,
|
||||
);
|
||||
|
||||
@ffi.Native<double4x4 Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external double4x4 Camera_getModelMatrix(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
);
|
||||
|
||||
@ffi.Native<EntityId Function(ffi.Pointer<TCamera>)>(isLeaf: true)
|
||||
external int Camera_getEntity(
|
||||
ffi.Pointer<TCamera> camera,
|
||||
|
||||
@@ -12,6 +12,7 @@ abstract class Camera {
|
||||
double aspect = 1.0,
|
||||
double focalLength = kFocalLength});
|
||||
|
||||
Future<Matrix4> getViewMatrix();
|
||||
Future<Matrix4> getModelMatrix();
|
||||
Future setModelMatrix(Matrix4 matrix);
|
||||
|
||||
|
||||
@@ -228,6 +228,9 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE double Camera_getFocalLength(TCamera *const camera);
|
||||
EMSCRIPTEN_KEEPALIVE double Camera_getNear(TCamera *const camera);
|
||||
EMSCRIPTEN_KEEPALIVE double Camera_getCullingFar(TCamera *const camera);
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const camera);
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera* camera);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double get_camera_near(TCamera *camera);
|
||||
EMSCRIPTEN_KEEPALIVE double get_camera_culling_far(TCamera *camera);
|
||||
EMSCRIPTEN_KEEPALIVE float get_camera_fov(TCamera *camera, bool horizontal);
|
||||
@@ -237,7 +240,7 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setCustomProjectionWithCulling(TCamera* camera, double4x4 projectionMatrix, double near, double far);
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setModelMatrix(TCamera* camera, double4x4 modelMatrix);
|
||||
EMSCRIPTEN_KEEPALIVE void Camera_setLensProjection(TCamera *camera, double near, double far, double aspect, double focalLength);
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera* camera);
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE EntityId Camera_getEntity(TCamera* camera);
|
||||
EMSCRIPTEN_KEEPALIVE TCamera *Engine_getCameraComponent(TEngine *engine, EntityId entity);
|
||||
|
||||
|
||||
@@ -1081,6 +1081,11 @@ EMSCRIPTEN_KEEPALIVE double4x4 Camera_getModelMatrix(TCamera* tCamera) {
|
||||
return convert_mat4_to_double4x4(camera->getModelMatrix());
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE double4x4 Camera_getViewMatrix(TCamera *const tCamera) {
|
||||
auto * camera = reinterpret_cast<Camera*>(tCamera);
|
||||
return convert_mat4_to_double4x4(camera->getViewMatrix());
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE EntityId Camera_getEntity(TCamera* tCamera) {
|
||||
auto * camera = reinterpret_cast<Camera*>(tCamera);
|
||||
return Entity::smuggle(camera->getEntity());
|
||||
|
||||
@@ -11,6 +11,7 @@ void main() async {
|
||||
var viewer = await createViewer();
|
||||
var matrix = await viewer.getCameraModelMatrix();
|
||||
expect(matrix.trace(), 4);
|
||||
|
||||
await viewer.setCameraPosition(2.0, 2.0, 2.0);
|
||||
matrix = await viewer.getCameraModelMatrix();
|
||||
var position = matrix.getColumn(3).xyz;
|
||||
@@ -33,6 +34,9 @@ void main() async {
|
||||
// The view matrix should be the inverse of the model matrix
|
||||
var identity = modelMatrix * viewMatrix;
|
||||
expect(identity.isIdentity(), isTrue);
|
||||
var camera = await viewer.getMainCamera();
|
||||
identity = modelMatrix * (await camera.getViewMatrix());
|
||||
expect(identity.isIdentity(), isTrue);
|
||||
|
||||
// Check that moving the camera affects the view matrix
|
||||
await viewer.setCameraPosition(3.0, 4.0, 5.0);
|
||||
|
||||
Reference in New Issue
Block a user