弧面为二次多项式的uv纹理设置 directx

弧面为二次多项式的uv纹理设置 directx 

 

void  SphereCylDemo::bulidCurveBuffer()
{


    
if(g_pVB==NULL)
    
{
        
if( FAILED( gd3dDevice->CreateVertexBuffer( 6*x_step*y_step*sizeof(CUSTOMVERTEX),
            
0, D3DFVF_CUSTOMVERTEX,
            D3DPOOL_MANAGED, 
&g_pVB, NULL ) ) )
        
{
            
int error = 0;   
        }

    }


    
    FILE
* pFile  = fopen("log.txt""w");    

    CUSTOMVERTEX
* pVertices;
    g_pVB
->Lock( 00, (void**)&pVertices, 0 );
    
    
float _sumx = 0.5;
    
float _sumx1 = 0.5;
    
float eachStep= 0.5/(x_step/2);

    
for(int k=0;k<x_step;k++)
    
{        
        
float x0 = 0;
        
float x1 = 0;
        
int i = 0;
        
        
if(k<=x_step/2)
        
{
             i 
= x_step/2 -k;

             
float xx = (float)(abs(i-x_step/2))/(x_step/2);        
             
float len_segment = eachStep/sqrt(1+(2*A*xx+B)*(2*A*xx+B));    

             x0 
= _sumx1;
             _sumx1 
= _sumx1 - len_segment; 
             x1 
= _sumx1;    
             
//x0=0;
             
//x1=0;

             
int i1 = (i-1);

             
for(int j=0;j<y_step;j++)
             
{
                 
int j1 = (j+1);
                 
float y0 = (float)j/y_step;
                 
float y1 = (float)j1/y_step;

                 
//0
                 pVertices->position.x = x0;
                 pVertices
->position.y = y0;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i/x_step;
                 pVertices
->tv  = (float)j/y_step;    
                 pVertices
++;

                 
//1
                 pVertices->position.x = x1;
                 pVertices
->position.y = y0;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i1/x_step;
                 pVertices
->tv  = (float)j/y_step;    
                 pVertices
++;            


                 
//2
                 pVertices->position.x = x0;
                 pVertices
->position.y = y1;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i/x_step;
                 pVertices
->tv  = (float)j1/y_step;    
                 pVertices
++;


                 
//2
                 pVertices->position.x = x0;
                 pVertices
->position.y = y1;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i/x_step;
                 pVertices
->tv  = (float)j1/y_step;    
                 pVertices
++;

                 
//1
                 pVertices->position.x = x1;
                 pVertices
->position.y = y0;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i1/x_step;
                 pVertices
->tv  = (float)j/y_step;    
                 pVertices
++;

                 
//3
                 pVertices->position.x = x1;
                 pVertices
->position.y = y1;
                 pVertices
->position.z = 0;
                 pVertices
->color  = D3DCOLOR_XRGB(255255255);
                 pVertices
->tu  = (float)i1/x_step;
                 pVertices
->tv  = (float)j1/y_step;    
                 pVertices
++;

             }


        }

        
else
        
{    
            i 
=  k;

            
float xx = (float)(abs(i-x_step/2))/(x_step/2);        
            
float len_segment = eachStep/sqrt(1+(2*A*xx+B)*(2*A*xx+B));    

            x0 
= _sumx;
            _sumx 
= _sumx + len_segment; 
            x1 
= _sumx;            

            
int i1 = (i+1);

            
for(int j=0;j<y_step;j++)
            
{

                
int j1 = (j+1);
                
float y0 = (float)j/y_step;
                
float y1 = (float)j1/y_step;

                
//0
                pVertices->position.x = x0;
                pVertices
->position.y = y0;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i/x_step;
                pVertices
->tv  = (float)j/y_step;    
                pVertices
++;

                
//2
                pVertices->position.x = x0;
                pVertices
->position.y = y1;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i/x_step;
                pVertices
->tv  = (float)j1/y_step;    
                pVertices
++;

                
//1
                pVertices->position.x = x1;
                pVertices
->position.y = y0;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i1/x_step;
                pVertices
->tv  = (float)j/y_step;    
                pVertices
++;            


                
//2
                pVertices->position.x = x0;
                pVertices
->position.y = y1;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i/x_step;
                pVertices
->tv  = (float)j1/y_step;    
                pVertices
++;


                
//3
                pVertices->position.x = x1;
                pVertices
->position.y = y1;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i1/x_step;
                pVertices
->tv  = (float)j1/y_step;    
                pVertices
++;

                
//1
                pVertices->position.x = x1;
                pVertices
->position.y = y0;
                pVertices
->position.z = 0;
                pVertices
->color  = D3DCOLOR_XRGB(255255255);
                pVertices
->tu  = (float)i1/x_step;
                pVertices
->tv  = (float)j/y_step;    
                pVertices
++;

            }

        }

        fprintf(pFile,
"%.4f , %.4f  ",x0,x1);

        
    }

    fclose(pFile);

    g_pVB
->Unlock();    
}


void  SphereCylDemo::drawCurve()
{
    IDirect3DDevice9
* pd3dDevice = gd3dDevice;

    pd3dDevice
->SetRenderState(D3DRS_LIGHTING, FALSE);    

    pd3dDevice
->SetTexture( 0, mCylTex );
    pd3dDevice
->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
     
    pd3dDevice
->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
    pd3dDevice
->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

    pd3dDevice
->SetStreamSource( 0, g_pVB, 0sizeof(CUSTOMVERTEX) );
    pd3dDevice
->SetFVF( D3DFVF_CUSTOMVERTEX );
    
//HR(pd3dDevice->SetIndices(g_pIB));

    
//设置格式    
    pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, x_step*y_step*2);        
    pd3dDevice
->SetTexture(0,NULL);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值