How to always place an object in front of the camera

I am making the application in that I am making a 360 image and I want to add an object or cross myself in front of the ie camera (billboard concept).

So, I'm tired of things from, but I did not understand how to do this below, this is my code that I am trying to do.

Vector3 position;
    float[] newPosition4 = new float[4];
    position = obj.getPosition();
    float[] posVec4 = {0, 0, -8, 0.0f};
    float[] HeadViewMatrix_inv = new float[16];
    Matrix4 HeadViewMatrix4 = new Matrix4();
    HeadViewMatrix4.setAll(getCurrentCamera().getViewMatrix());
    HeadViewMatrix4 = HeadViewMatrix4.inverse();

    //Copy matrix to HeadViewMatrix array,
    HeadViewMatrix4.toFloatArray(HeadViewMatrix_inv);

    //Translation of viewMatrix 
    Matrix.multiplyMV(newPosition4, 0, HeadViewMatrix_inv, 0, posVec4, 0);
    obj.setPosition(newPosition4[0], newPosition4[1], newPosition4[2]);

Therefore, anyone can help me with this.

+4
source share
2 answers

If I understand what you are asking for, this is perhaps the easiest thing. You need to build a new matrix or just delete the current one (use identifier).

, A(-0.5, 0.0, 0.0) B(0.5, 0.0, 0.0), . .

, (width/2, height/2) .

, , , , .

- , , , , , ( ) ( ). , , (.0f, .0f, distanceToObject).

+4

, .

    <RelativeLayout
    android:id="@+id/layout_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- Camera Preview -->

    <FrameLayout
        android:id="@+id/camera_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />   
</RelativeLayout>

SurfaceView Canvas FrameLayout .

+2

Source: https://habr.com/ru/post/1679864/


All Articles