|
1 | 1 | package io.github.sceneview.scene |
2 | 2 |
|
3 | 3 | import com.google.android.filament.Camera |
| 4 | +import com.google.android.filament.Engine |
4 | 5 | import com.google.android.filament.utils.pow |
5 | | -import io.github.sceneview.Filament |
| 6 | +import io.github.sceneview.math.Transform |
| 7 | +import io.github.sceneview.math.toColumnsDoubleArray |
| 8 | +import io.github.sceneview.math.toColumnsFloatArray |
6 | 9 | import kotlin.math.log2 |
7 | 10 |
|
8 | 11 | /** |
@@ -51,6 +54,46 @@ fun Camera.illuminance(ev100: Float) = 2.5f * pow(2.0f, ev100) |
51 | 54 | val Camera.luminance get() = luminance(ev100) |
52 | 55 | fun Camera.luminance(ev100: Float) = pow(2.0f, ev100 - 3.0f) |
53 | 56 |
|
| 57 | +/** |
| 58 | + * Sets the camera's model matrix. |
| 59 | + * <p> |
| 60 | + * Helper method to set the camera's entity transform component. |
| 61 | + * Remember that the Camera "looks" towards its -z axis. |
| 62 | + * <p> |
| 63 | + * This has the same effect as calling: |
| 64 | + * |
| 65 | + * <pre> |
| 66 | + * engine.getTransformManager().setTransform( |
| 67 | + * engine.getTransformManager().getInstance(camera->getEntity()), modelMatrix); |
| 68 | + * </pre> |
| 69 | + * |
| 70 | + * @param transform The camera position and orientation provided as a <b>rigid transform</b> matrix. |
| 71 | + */ |
| 72 | +fun Camera.setModelTransform(transform: Transform) = setModelMatrix(transform.toColumnsFloatArray()) |
| 73 | + |
| 74 | +/** |
| 75 | + * Sets a custom projection matrix. |
| 76 | + * |
| 77 | + * <p>The projection matrix must define an NDC system that must match the OpenGL convention, |
| 78 | + * that is all 3 axis are mapped to [-1, 1].</p> |
| 79 | + * |
| 80 | + * @param transform custom projection matrix for rendering and culling |
| 81 | + * @param near distance in world units from the camera to the near plane. |
| 82 | + * The near plane's position in view space is z = -<code>near</code>. |
| 83 | + * Precondition: |
| 84 | + * <code>near</code> > 0 for {@link Projection#PERSPECTIVE} or |
| 85 | + * <code>near</code> != <code>far</code> for {@link Projection#ORTHO}. |
| 86 | + * @param far distance in world units from the camera to the far plane. |
| 87 | + * The far plane's position in view space is z = -<code>far</code>. |
| 88 | + * Precondition: |
| 89 | + * <code>far</code> > <code>near</code> |
| 90 | + * for {@link Projection#PERSPECTIVE} or |
| 91 | + * <code>far</code> != <code>near</code> |
| 92 | + * for Projection.ORTHO. |
| 93 | + */ |
| 94 | +fun Camera.setCustomProjection(transform: Transform, near: Float, far: Float) = |
| 95 | + setCustomProjection(transform.toColumnsDoubleArray(), near.toDouble(), far.toDouble()) |
| 96 | + |
54 | 97 | /** |
55 | 98 | * Destroys the Camera component associated with the camera entity. |
56 | 99 | */ |
|
0 commit comments