簡體   English   中英

如何使用Open TK C繪制3D形狀#

[英]How to draw a 3D shape using Open TK C#

我目前停留在一些工作上,我無法弄清楚如何計算出他們需要去的面和頂點或面。 如果有人能夠向我解釋代碼背后的數學,以及我如何能夠將六邊形制作成一個非常棒的3D。

謝謝

    protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    initProgram();

    vertdata = new Vector3[] { 

        //new Vector3(0.0f,0.0f,0.0f), // center
        //new Vector3(2.0f, 0f,0f), // right hand side
        //new Vector3(0f,2f,0f), // up

        new Vector3(0.0f,0.0f,-0.8f), // center point
        new Vector3(2.0f,0.0f,-0.8f), // right hand side
        new Vector3(1.0f,1.7f,-0.8f), // right hand top 
        new Vector3(-1.0f,1.7f,-0.8f), // right hand top 
        new Vector3(-2.0f,0.0f,-0.8f), // left hand top
        new Vector3(-1.0f,-1.7f,-0.8f),
        new Vector3(1.0f,-1.7f,-0.8f), // right hand top 
    };

    indicedata = new int[]{
        //front
        0, 1, 2,
        0, 2, 3,
        //back
        0, 3, 4,
        0, 4, 5,
        //left
        0, 5, 6,
        0, 6, 1,
    };

    coldata = new Vector3[] { new Vector3(1f, 0f, 0f),
        new Vector3( 0f, 0f, 1f),
        new Vector3( 0f,  1f, 0f),new Vector3(1f, 0f, 0f),
        new Vector3( 0f, 0f, 1f),
        new Vector3( 0f,  1f, 0f),new Vector3(1f, 0f, 0f),
        new Vector3( 0f, 0f, 1f)};

    mviewdata = new Matrix4[]{
        Matrix4.Identity
    };

    Title = "Hello OpenTK!";
    GL.ClearColor(Color.DarkTurquoise);
    GL.PointSize(5f);
}

你可以嘗試這樣的東西,讓你更多地控制你的六邊形:

points[0] = vec3(0.0f,0.0f,0.0f)
for(int i = 1; i < 7; ++i) {
    points[i] = vec3(sin(i/6.0*HEX_SIZE*M_PI),
                    cos(i/6.0*HEX_SIZE*M_PI));
}

基本上你一次移動60度並在正確的位置創建一個點。 如果你要創建單個三角形,你的索引看起來是正確的,但你可以使用以下方法創建一個三角扇,(有點過時),

private short[] indicedata = { 0, 1, 2, 3, 4, 5, 6, 1 };
...
glDrawElements(GL_TRIANGLE_FAN, indicedata.length, GL_UNSIGNED_SHORT, indexBuffer);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM