通过三个坐标填充三角形内部的颜色

时间:2017-08-21 10:00:43

标签: java android opengl-es point-cloud-library google-project-tango

我正在使用Point Cloud。我有3D点。

让我们说:点P(x,y,z),点Q(x,y,z),点R(x,y,z)假设这个点为三角PQR我们继续前进。

Triangle像这样: Triangle created with 3 points

如何填充绘制的点内的区域,以便三角形将填充颜色。

像这样: image

我的研究可能有所帮助:

修改:

成功的一些方法:

public void make_polygon(float[] points_x,float[] points_y,float[] points_z)
{
    Material mSphereMaterial_z = new Material();
    //mSphereMaterial_z.setColor(Color.BLUE);
    Bitmap p_z_bitty = getTriangleBitmap(BitmapFactory.decodeResource(mContext.getResources(),R.drawable.label_bg_sm),5,points_x,points_y,points_z);
    Texture t = new Texture("text",p_z_bitty);
    try {
        mSphereMaterial_z.addTexture(t);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    Object3D p_z =  new Plane();
    p_z.setPosition(points_x[0],points_y[1],points_z[2]);
    p_z.setMaterial(mSphereMaterial_z);
    p_z.setDoubleSided(true);
    getCurrentScene().addChild(p_z);
}

public static Bitmap getTriangleBitmap(Bitmap bitmap, int radius,float[] a,float[] b,float[] c) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
        finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius,
                false);
    else
        finalBitmap = bitmap;
    Bitmap output = Bitmap.createBitmap(finalBitmap.getWidth(),
            finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(),
            finalBitmap.getHeight());

     //        Point point1_draw = new Point(75, 0);
     //        Point point2_draw = new Point(0, 180);
     //        Point point3_draw = new Point(180, 180);
    PointF point1_draw = new PointF(a[0],a[1]);
    PointF point2_draw = new PointF(b[0], b[1]);
    PointF point3_draw = new PointF(c[0],c[1] );

    Path path = new Path();
    path.moveTo(point1_draw.x, point1_draw.y);
    path.lineTo(point2_draw.x, point2_draw.y);
    path.lineTo(point3_draw.x, point3_draw.y);
    path.lineTo(point1_draw.x, point1_draw.y);
    path.close();
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawPath(path, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
}

现在的结果是:enter image description here

有人可以指导我或为Android java推荐一些关于它的文章吗?

如果需要更多信息/代码,则应提供。

1 个答案:

答案 0 :(得分:0)

你应该能够通过简单地将三角形中的顶点传递给Rajawali来将三角形绘制为基元。这样您就可以避免使用Canvas或绘制位图并简化渲染。

// p, q, and r are triangle vertices and are of the form {x, y, z}.
public void make_triangle(float[] p, float[] q, float[] r)
{
    Object3D triangle = new Object3D();

    // Copy three points into a flat array as our vertices.
    float[] vertices = new float[3 * 3];
    for (int i = 0; i < 3; i++) {
        vertices[i] = p[i];
        vertices[3 + i] = q[i];
        vertices[6 + i] = r[i];
    }

    // Set up index buffer to point at our three vertices and thus draw one triangle.
    int[] indices = new int[3];
    for (int i = 0; i < 3; i++) {
        indices[i] = i;
    }

    // Set up the rendering data.
    triangle.setData(vertices, null, null, null, indices, true);

    // Render the triangle double sided.
    triangle.setDoubleSided(true);

    // Use a blue material.
    Material material = new Material();
    material.setColor(Color.BLUE);
    triangle.setMaterial(material);

    // Add the triangle to the current scene.
    getCurrentScene().addChild(triangle);
}