| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 455 人关注过本帖
标题:怎样使用D3DXMatrixTranslation()函数把已经制作的立方体复制两个。
取消只看楼主 加入收藏
笨笨的小孩
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-12-23
结帖率:0
收藏
 问题点数:0 回复次数:0 
怎样使用D3DXMatrixTranslation()函数把已经制作的立方体复制两个。
// ------------------------------创建正面和背面顶点-------------------------
    // 创建正面顶点
    V_RETURN( g_pVB[0]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3( 1.0f,  1.0f, 1.0f);
    pVertices[0].normal   = D3DXVECTOR3( 0.0f,  0.0f,-1.0f);
    pVertices[0].tu          = 1;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3( 1.0f, -1.0f, 1.0f);
    pVertices[1].normal   = D3DXVECTOR3( 0.0f,  0.0f,-1.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 1;

    pVertices[2].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
    pVertices[2].normal   = D3DXVECTOR3( 0.0f,  0.0f,-1.0f);
    pVertices[2].tu          = 0;
    pVertices[2].tv          = 1;

    pVertices[3].position = D3DXVECTOR3( -1.0f, 1.0f, 1.0f);
    pVertices[3].normal   = D3DXVECTOR3(  0.0f, 0.0f,-1.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 0;

    g_pVB[0]->Unlock();

    // 创建背面顶点
    V_RETURN( g_pVB[1]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3( 1.0f,  1.0f,-1.0f);
    pVertices[0].normal   = D3DXVECTOR3( 0.0f,  0.0f, 1.0f);
    pVertices[0].tu          = 0;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3(-1.0f,  1.0f,-1.0f);
    pVertices[1].normal   = D3DXVECTOR3( 0.0f,  0.0f, 1.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 0;

    pVertices[2].position = D3DXVECTOR3(-1.0f, -1.0f,-1.0f);
    pVertices[2].normal   = D3DXVECTOR3( 0.0f,  0.0f, 1.0f);
    pVertices[2].tu          = 1;
    pVertices[2].tv          = 1;


    pVertices[3].position = D3DXVECTOR3(  1.0f,-1.0f,-1.0f);
    pVertices[3].normal   = D3DXVECTOR3(  0.0f, 0.0f, 1.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 1;

    g_pVB[1]->Unlock();

    // ------------------------------创建顶面和底面顶点-------------------------
    // 创建顶面顶点
    V_RETURN( g_pVB[2]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3( 1.0f,  1.0f, 1.0f);
    pVertices[0].normal   = D3DXVECTOR3( 0.0f, -1.0f, 0.0f);
    pVertices[0].tu          = 1;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3(-1.0f,  1.0f, 1.0f);
    pVertices[1].normal   = D3DXVECTOR3( 0.0f, -1.0f, 0.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 1;

    pVertices[2].position = D3DXVECTOR3(-1.0f,  1.0f, -1.0f);
    pVertices[2].normal   = D3DXVECTOR3( 0.0f, -1.0f,  0.0f);
    pVertices[2].tu          = 0;
    pVertices[2].tv          = 1;

    pVertices[3].position = D3DXVECTOR3( 1.0f,  1.0f, -1.0f);
    pVertices[3].normal   = D3DXVECTOR3( 0.0f, -1.0f,  0.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 0;
    g_pVB[2]->Unlock();

    // 创建底面顶点
    V_RETURN( g_pVB[3]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3( 1.0f, -1.0f, 1.0f);
    pVertices[0].normal   = D3DXVECTOR3( 0.0f,  1.0f, 0.0f);
    pVertices[0].tu          = 1;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3( 1.0f, -1.0f,-1.0f);
    pVertices[1].normal   = D3DXVECTOR3( 0.0f,  1.0f, 0.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 1;


    pVertices[2].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
    pVertices[2].normal   = D3DXVECTOR3( 0.0f,  1.0f,  0.0f);
    pVertices[2].tu          = 0;
    pVertices[2].tv          = 1;

    pVertices[3].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
    pVertices[3].normal   = D3DXVECTOR3( 0.0f,  1.0f,  0.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 0;
    g_pVB[3]->Unlock();


    // ------------------------------创建右面和左面顶点-------------------------
    // 创建右面顶点
    V_RETURN( g_pVB[4]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3( 1.0f,  1.0f, 1.0f);
    pVertices[0].normal   = D3DXVECTOR3(-1.0f,  0.0f, 0.0f);
    pVertices[0].tu          = 0;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3( 1.0f,  1.0f, -1.0f);
    pVertices[1].normal   = D3DXVECTOR3(-1.0f,  0.0f,  0.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 0;

    pVertices[2].position = D3DXVECTOR3( 1.0f, -1.0f, -1.0f);
    pVertices[2].normal   = D3DXVECTOR3(-1.0f,  0.0f,  0.0f);
    pVertices[2].tu          = 1;
    pVertices[2].tv          = 1;

    pVertices[3].position = D3DXVECTOR3( 1.0f, -1.0f,  1.0f);
    pVertices[3].normal   = D3DXVECTOR3(-1.0f,  0.0f,  0.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 1;
    g_pVB[4]->Unlock();

    // 创建左面顶点
    V_RETURN( g_pVB[5]->Lock(0, 0, (VOID**)&pVertices, 0) );

    pVertices[0].position = D3DXVECTOR3(-1.0f,  1.0f, 1.0f);
    pVertices[0].normal   = D3DXVECTOR3( 1.0f,  0.0f, 0.0f);
    pVertices[0].tu          = 1;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
    pVertices[1].normal   = D3DXVECTOR3( 1.0f,  0.0f,  0.0f);
    pVertices[1].tu          = 1;
    pVertices[1].tv          = 1;

    pVertices[2].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
    pVertices[2].normal   = D3DXVECTOR3( 1.0f,  0.0f,  0.0f);
    pVertices[2].tu          = 0;
    pVertices[2].tv          = 1;

    pVertices[3].position = D3DXVECTOR3(-1.0f,  1.0f, -1.0f);
    pVertices[3].normal   = D3DXVECTOR3( 1.0f,  0.0f,  0.0f);
    pVertices[3].tu          = 0;
    pVertices[3].tv          = 0;
    g_pVB[5]->Unlock();


    // Create the texture
    for ( int ix = 0; ix < 6; ++ix )
    {
        WCHAR fn[255];
        wsprintf( fn, L".\\picture\\pic0%d.jpg", ix );
        V_RETURN( D3DXCreateTextureFromFile( g_pd3dDevice, fn, &g_pTexture[ix] ) );
    }


    // Create the index buffer
    V_RETURN(g_pd3dDevice->CreateIndexBuffer(6*sizeof(WORD), 0, D3DFMT_INDEX16,
        D3DPOOL_MANAGED, &g_pIB, NULL));
    // Fill the index buffer with 2 triangles
    WORD* pIndices;    //声明一个变量来协助索引值填入Index buffer

    //与填入vertex buffer一样,填入前将存储区上锁
    V_RETURN(g_pIB->Lock(0, 0, (VOID**)&pIndices, 0));

    // Front triangle填入索引值,也就是两个组合成正方形的三角形;记得其顶点顺序为逆时针方向
    pIndices[0] = 0;
    pIndices[1] = 1;
    pIndices[2] = 2;
    pIndices[3] = 0;
    pIndices[4] = 2;
    pIndices[5] = 3;

    g_pIB->Unlock();    //填好索引值后,记得解锁

    //floor.============================================================
    V_RETURN(g_pd3dDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX), 0,
        D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED,
        &g_pFloorVB, NULL));

    V_RETURN(g_pFloorVB->Lock(0, 0, (VOID**)&pVertices, 0));

    float v = 20.f;
    float s = 1.f;

    pVertices[0].position = D3DXVECTOR3( 10.f*s, -2.0f, 10.f*s);
    pVertices[0].normal   = D3DXVECTOR3(0.0f,  1.0f,  0.0f);
    pVertices[0].tu          = 0;
    pVertices[0].tv          = 0;

    pVertices[1].position = D3DXVECTOR3( -10.0f*s, -2.0f, 10.0f*s);
    pVertices[1].normal   = D3DXVECTOR3(0.0f,  1.0f, 0.0f);
    pVertices[1].tu          = 0;
    pVertices[1].tv          = v;

    pVertices[2].position = D3DXVECTOR3( -10.0f*s, -2.0f, -10.0f*s);
    pVertices[2].normal   = D3DXVECTOR3(0.0f,  1.0f,  0.0f);
    pVertices[2].tu          = v;
    pVertices[2].tv          = v;

    pVertices[3].position = D3DXVECTOR3( 10.0f*s,  -2.0f,  -10.0f*s);
    pVertices[3].normal   = D3DXVECTOR3(0.0f,   1.0f,  0.0f);
    pVertices[3].tu          = v;
    pVertices[3].tv          = 0;

    g_pFloorVB->Unlock();
这是部分程序代码,我想知道我绘制了立方体之后,我要怎么样才可以用D3DXMatrixTranslation()函数把我已经绘制的立方体再复制2个呢?虽然我没有分了,但是求帮助
搜索更多相关主题的帖子: 立方体 制作 
2013-12-23 19:13
快速回复:怎样使用D3DXMatrixTranslation()函数把已经制作的立方体复制两个。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025867 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved