In developer preview samples 3d objects are created via Anchor position. i want to draw an object from camera position.is it possible to draw object from camera position instead of anchor position?
Usually when drawing 3D graphics you compose three transformations: 1. from model space to world space (the model matrix), from world space to camera space (the view matrix), and from camera space to clip space (the projection matrix). The easiest way to draw things relative to the camera is to simply skip the view matrix. Compose the model matrix (now position relative to the camera instead of relative to the world origin) directly with the projection matrix, ignoring the view matrix. With ObjectRenderer that would mean supplying an identity matrix for the cameraView argument of draw().
Alternately, you could position the object in the world relative to the camera by doing something like something like this every frame:
// mMatrix is a persistent float[16] for temporary matrices
frame.getCamera().getDisplayOrientedPose()
.compose(mCameraRelativePose).toMatrix(mMatrix, 0)
model.updateModelMatrix(mMatrix)
What is mCameraRelativePose and how can i find?
I have found mCameraRelativePose using:
Pose mCameraRelativePose =frame.getCamera().getDisplayOrientedPose();
Draw object using:
frame.getCamera().getDisplayOrientedPose().compose(mCameraRelativePos).toMatrix(mMatrix,0);
mVirtualObject.updateModelMatrix(mMatrix,1f);
mVirtualObject.draw(viewmtx,projmtx,lightIntensity);
is it right? it's not place object center position of the camera
See #108 for an example of drawing a camera-relative object in HelloAR Java.
Thank you for the solution.objects placed based on the camera position.but object placed left side of the camera not placing center.
I have changed from this
Pose.makeTranslation(0.15f, -0.15f, -0.5f)
to this:
Pose.makeTranslation(0.01f, -0.07f, -0.5f)
it positioned center. thank you so much
Good to hear this worked. 0.0f for the first and second args should put it exactly in the center.
Most helpful comment
Usually when drawing 3D graphics you compose three transformations: 1. from model space to world space (the model matrix), from world space to camera space (the view matrix), and from camera space to clip space (the projection matrix). The easiest way to draw things relative to the camera is to simply skip the view matrix. Compose the model matrix (now position relative to the camera instead of relative to the world origin) directly with the projection matrix, ignoring the view matrix. With
ObjectRendererthat would mean supplying an identity matrix for thecameraViewargument ofdraw().Alternately, you could position the object in the world relative to the camera by doing something like something like this every frame: