Skip to content

Commit ff499a5

Browse files
committed
Added Camera extensions
1 parent b8fbea4 commit ff499a5

File tree

1 file changed

+44
-1
lines changed
  • sceneview/src/main/java/io/github/sceneview/scene

1 file changed

+44
-1
lines changed

sceneview/src/main/java/io/github/sceneview/scene/Camera.kt

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.github.sceneview.scene
22

33
import com.google.android.filament.Camera
4+
import com.google.android.filament.Engine
45
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
69
import kotlin.math.log2
710

811
/**
@@ -51,6 +54,46 @@ fun Camera.illuminance(ev100: Float) = 2.5f * pow(2.0f, ev100)
5154
val Camera.luminance get() = luminance(ev100)
5255
fun Camera.luminance(ev100: Float) = pow(2.0f, ev100 - 3.0f)
5356

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+
5497
/**
5598
* Destroys the Camera component associated with the camera entity.
5699
*/

0 commit comments

Comments
 (0)