forked from margelo/react-native-filament
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNFCameraWrapper.cpp
More file actions
44 lines (36 loc) · 2.27 KB
/
RNFCameraWrapper.cpp
File metadata and controls
44 lines (36 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "RNFCameraWrapper.h"
#include "RNFCameraFovEnum.h"
void margelo::CameraWrapper::loadHybridMethods() {
registerHybridMethod("lookAtCameraManipulator", &CameraWrapper::lookAtCameraManipulator, this);
registerHybridMethod("lookAt", &CameraWrapper::lookAt, this);
registerHybridMethod("setLensProjection", &CameraWrapper::setLensProjection, this);
registerHybridMethod("setProjection", &CameraWrapper::setProjection, this);
registerHybridMethod("setOrthographicProjection", &CameraWrapper::setOrthographicProjection, this);
}
void margelo::CameraWrapper::lookAtCameraManipulator(std::shared_ptr<ManipulatorWrapper> cameraManipulator) {
if (!cameraManipulator) {
throw std::invalid_argument("CameraManipulator is null");
}
math::float3 eye, center, up;
cameraManipulator->getManipulator()->getLookAt(&eye, ¢er, &up);
pointee()->lookAt(eye, center, up);
}
void margelo::CameraWrapper::lookAt(std::vector<double> eye, std::vector<double> center, std::vector<double> up) {
math::float3 eyeVec = {static_cast<float>(eye[0]), static_cast<float>(eye[1]), static_cast<float>(eye[2])};
math::float3 centerVec = {static_cast<float>(center[0]), static_cast<float>(center[1]), static_cast<float>(center[2])};
math::float3 upVec = {static_cast<float>(up[0]), static_cast<float>(up[1]), static_cast<float>(up[2])};
pointee()->lookAt(eyeVec, centerVec, upVec);
}
void margelo::CameraWrapper::setLensProjection(double fov, double aspect, double near, double far) {
pointee()->setLensProjection(static_cast<float>(fov), static_cast<float>(aspect), static_cast<float>(near), static_cast<float>(far));
}
void margelo::CameraWrapper::setProjection(double fovInDegrees, double aspect, double near, double far,
std::string directionStr = "vertical") {
Camera::Fov direction;
EnumMapper::convertJSUnionToEnum(directionStr, &direction);
pointee()->setProjection(static_cast<float>(fovInDegrees), static_cast<float>(aspect), static_cast<float>(near), static_cast<float>(far),
direction);
}
void margelo::CameraWrapper::setOrthographicProjection(double left, double right, double bottom, double top, double near, double far) {
pointee()->setProjection(Camera::Projection::ORTHO, left, right, bottom, top, near, far);
}