开发者

How do I setup vertices for a rectangle?

I need to setup vertices for a rectangle - I have a square example, how would I modify it to get a rectangle 5 times the width and half the height?

    /** 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, 
                                        };

Okay so I think I setup the vertices correctly but now I need to setup the normals textures and indices:

/** 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, 
                                        };

Any suggestions how to set these up:

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, 
                                            };


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜