| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 801 人关注过本帖
标题:关于DirectX 3D中画图问题
只看楼主 加入收藏
leizh007
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-7-18
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
关于DirectX 3D中画图问题
我想画个圆柱体
下面是显示代码:
程序代码:
bool Display(float timeDelta)
{
    if( Device )
    {
        static float angle  = (3.0f * D3DX_PI) / 2.0f;
        static float height = 5.0f;
        if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
            angle -= 0.5f * timeDelta;

        if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
            angle += 0.5f * timeDelta;

        if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
            height += 5.0f * timeDelta;
        if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
            height -= 5.0f * timeDelta;        
        D3DXVECTOR3 position( cosf(angle) * 7.0f, height, sinf(angle) * 7.0f );
        D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
        D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
        D3DXMATRIX V;
        D3DXMatrixLookAtLH(&V, &position, &target, &up);
        Device->SetTransform(D3DTS_VIEW, &V);
        Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
        Device->BeginScene();
        if((float)timeGetTime()-timenow<500)
        {
            for(int i = 0; i < 3; i++)
            {
                Device->SetMaterial(&Mtrls[i]);
                Device->SetTransform(D3DTS_WORLD, &Worlds[i]);
                Objects[i]->DrawSubset(0);
            }
        }
        else
        {
            //timenow=(float)timeGetTime();
            srand((unsigned)time(NULL));
            int r=rand()%6;
            D3DXMATRIX Rx,Ry,Rz,R,p;
            D3DXMatrixRotationX(&Rx,(float)atan(DirectionSet[r][1]/DirectionSet[r][2]));
            D3DXMatrixRotationX(&Ry,(float)atan(DirectionSet[r][2]/DirectionSet[r][0]));
            D3DXMatrixRotationX(&Rz,(float)atan(DirectionSet[r][0]/DirectionSet[r][1]));
            D3DXMatrixTranslation(&p,len[0]*DirectionSet[r][0]/2,len[0]*DirectionSet[r][1]/2,len[0]*DirectionSet[r][2]/2);
            p=Rx*Ry*Rz*R;
            Device->SetTransform(D3DTS_WORLD,&p);
            Device->SetMaterial(&Mtrls[0]);
            Objects[0]->DrawSubset(0);
        }
        Device->EndScene();
        Device->Present(0, 0, 0, 0);
    }
    return true;
}

我就一共定义了6个方向,我想让它0.5s以后随机转变方向
float len[3]={0.5f,2.0f,2.5f};
float CurrentDirection[3][3]={0.0f,0.0f,1.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f};
float DirectionSet[6][3]={1.0f,0.01f,0.01f,0.01f,0.01f,1.0f,-1.0f,0.01f,0.01f,0.01f,0.01f,-1.0f,0.01f,1.0f,0.01f,0.01f,-1.0f,0.01f};

但是0.5s以后它画出来的怎么是乱七八糟的东西,连圆柱都没有了?
第一个图一开始的0.5s内显示出来的东西
图片附件: 游客没有浏览图片的权限,请 登录注册

二三图是之后显示出来的东西
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: DirectX 圆柱体 color 
2013-07-18 15:28
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:20 
debug过没?

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-07-18 15:47
快速回复:关于DirectX 3D中画图问题
数据加载中...
 
   



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

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