如何为矩形设置顶点?

时间:2010-09-16 20:00:30

标签: android opengl-es

我需要为一个矩形设置顶点 - 我有一个方形示例,我如何修改它以获得宽度为5倍且高度为一半的矩形?

    /** The initial vertex definition */    
private float vertices[] = {
                    //Vertices according to faces
                    -1.0f, -1.0f, 1.0f, //v0
                    1.0f, -1.0f, 1.0f,     //v1
                    -1.0f, 1.0f, 1.0f,     //v2
                    1.0f, 1.0f, 1.0f,     //v3

                    1.0f, -1.0f, 1.0f,     // ...
                    1.0f, -1.0f, -1.0f, 
                    1.0f, 1.0f, 1.0f, 
                    1.0f, 1.0f, -1.0f,

                    1.0f, -1.0f, -1.0f, 
                    -1.0f, -1.0f, -1.0f, 
                    1.0f, 1.0f, -1.0f, 
                    -1.0f, 1.0f, -1.0f,

                    -1.0f, -1.0f, -1.0f, 
                    -1.0f, -1.0f, 1.0f, 
                    -1.0f, 1.0f, -1.0f, 
                    -1.0f, 1.0f, 1.0f,

                    -1.0f, -1.0f, -1.0f, 
                    1.0f, -1.0f, -1.0f, 
                    -1.0f, -1.0f, 1.0f, 
                    1.0f, -1.0f, 1.0f,

                    -1.0f, 1.0f, 1.0f, 
                    1.0f, 1.0f, 1.0f, 
                    -1.0f, 1.0f, -1.0f, 
                    1.0f, 1.0f, -1.0f, 
                                        };

好的,所以我认为我正确设置了顶点,但现在我需要设置法线纹理和索引:

/** The initial vertex definition */    
private float vertices[] = {
                    //Vertices according to faces
                    -1.0f, -.5f, 1.0f, //v0
                    4.0f, -.5f, 1.0f,     //v1
                    -1.0f, .5f, 1.0f,     //v2
                    4.0f, .5f, 1.0f,     //v3

                    4.0f, -.5f, 1.0f,     // 2...
                    4.0f, -.5f, -1.0f, 
                    4.0f, .5f, 1.0f, 
                    4.0f, .5f, -1.0f,

                    4.0f, -.5f, -1.0f, //3
                    -1.0f, -.5f, -1.0f, 
                    4.0f, .5f, -1.0f, 
                    -1.0f, .5f, -1.0f,

                    -1.0f, -.5f, -1.0f, //4
                    -1.0f, -.5f, 1.0f, 
                    -1.0f, .5f, -1.0f, 
                    -1.0f, .5f, 1.0f,

                    -1.0f, -.5f, -1.0f, //5
                    4.0f, -.5f, -1.0f, 
                    -1.0f, -.5f, 1.0f, 
                    4.0f, -.5f, 1.0f,

                    -1.0f, .5f, 1.0f, //6
                    4.0f, .5f, 1.0f, 
                    -1.0f, .5f, -1.0f, 
                    4.0f, .5f, -1.0f, 
                                        };

有关如何设置这些内容的任何建议:

private float normals[] = {
                        // Normals
                        0.0f, 0.0f, 1.0f, 


                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f, 

                    0.0f, 0.0f, 1.0f, 
                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, 
                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, 
                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, 
                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f,

                    0.0f, 0.0f, 1.0f, 
                    0.0f, 0.0f, -1.0f, 
                    0.0f, 1.0f, 0.0f, 
                    0.0f, -1.0f, 0.0f,
                                        };

/** The initial texture coordinates (u, v) */   
private float texture[] = {
                    //Mapping coordinates for the vertices
                    0.0f, 0.0f, 
                    0.0f, 1.0f, 
                    1.0f, 0.0f, 
                    1.0f, 1.0f,

                    0.0f, 0.0f,
                    0.0f, 1.0f, 
                    1.0f, 0.0f,
                    1.0f, 1.0f,

                    0.0f, 0.0f, 
                    0.0f, 1.0f, 
                    1.0f, 0.0f, 
                    1.0f, 1.0f,

                    0.0f, 0.0f, 
                    0.0f, 1.0f, 
                    1.0f, 0.0f, 
                    1.0f, 1.0f,

                    0.0f, 0.0f, 
                    0.0f, 1.0f, 
                    1.0f, 0.0f, 
                    1.0f, 1.0f,

                    0.0f, 0.0f, 
                    0.0f, 1.0f, 
                    1.0f, 0.0f, 
                    1.0f, 1.0f, 
                                };

/** The initial indices definition */
private byte indices[] = {
                    // Faces definition
                    0, 1, 3, 0, 3, 2,       // Face front
                    4, 5, 7, 4, 7, 6,       // Face right
                    8, 9, 11, 8, 11, 10,    // ...
                    12, 13, 15, 12, 15, 14, 
                    16, 17, 19, 16, 19, 18, 
                    20, 21, 23, 20, 23, 22, 
                                            };

1 个答案:

答案 0 :(得分:0)

glScalef(5.0f, 0.5f, 1.0f);