Search code examples
androidopengl-esarcore

Pointcloud to screen point


I want to obtain the point cloud as screen point. I multiply the projectionMatrix and ViewMatrix. and then each point is treated as separately.

I really don't know what I am doing wrong. any help?

 for (int i = 0; i < pointCloud.getPoints().remaining() / 4; i = i + 4) {
                    float x = pointCloud.getPoints().get(i);
                    float y = pointCloud.getPoints().get(i + 1);
                    float z = pointCloud.getPoints().get(i + 2);
                    float p = pointCloud.getPoints().get(i + 3);

                    float[] pointC = new float[]{x, y, z, 1.0F};
                    float[] screenPoint = new float[4];

                    float[] viewProjMtx = new float[16];
                    Matrix.multiplyMM(viewProjMtx, 0, projmtx, 0,viewmtx , 0);
                    Matrix.multiplyMV(screenPoint, 0,viewProjMtx , 0, pointC, 0);
                    float screenX = (result[0]+1)/2*1080;
                    float screenY = 2220-((result[1]+1)/2*2220);
                    String str = screenX+" "+screenY+"\r";
                }

Solution

  • I found a suitable solution or at least I think it is. I multiplied the View Matrix with Projection Matrix. The result with the acquired point in a 4X1 matrix.

    We obtain a 4x1 matrix that must be divided by w to get the perspective projection.

    To obtain the normalised point, we build the "transformation screen" matrix and multiply.

    Finally, just using the width and height we get our 3Dpoint into screen Coordinates.

     for (int i = 0; i < pointCloud.getPoints().remaining() ; i = i + 4) {
                            float x = pointCloud.getPoints().get(i);
                            float y = pointCloud.getPoints().get(i + 1);
                            float z = pointCloud.getPoints().get(i + 2);
                            float p = pointCloud.getPoints().get(i + 3);
    
                            float[] pointC = new float[]{x, y, z, 1.0F};
                            float[] res = new float[4];
                            float[] vpMatrix = new float[16];
    
                            Matrix.multiplyMM(vpMatrix, 0, projmtx, 0, viewmtx, 0);
                            Matrix.multiplyMV(res, 0, vpMatrix, 0, pointC, 0);
    
                            float[] mPp = new float[4];
                            mPp[0] = res[0] / res[3];
                            mPp[1] = res[1] / res[3];
                            mPp[2] = res[2] / res[3];
                            mPp[3] = 1;
    
                            float[] mVp = new float[16];
                            float[] ere = new float[4];
    
                            mVp[0] = 0.5f;
                            mVp[1] = 0;
                            mVp[2] = 0;
                            mVp[3] = 0;
    
                            mVp[4] = 0;
                            mVp[5] = -0.5f;
                            mVp[6] = 0;
                            mVp[7] = 0;
    
                            mVp[8] = 0;
                            mVp[9] = 0;
                            mVp[10] = 0.5f;
                            mVp[11] = 0;
    
                            mVp[12] = 0.5f;
                            mVp[13] = 0.5f;
                            mVp[14] = 0.5f;
                            mVp[15] = 1;
                            Matrix.multiplyMV(ere, 0, mVp, 0, mPp, 0);
    
                            float width = 1080;
                            float height = 1920;
                            float winX = ere[0] * width;
                            float winY = ere[1] * height;
                        }