游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3210|回复: 3

sea_bug帮我看看

[复制链接]

3

主题

4

帖子

26

积分

注册会员

Rank: 2

积分
26
发表于 2003-9-8 16:46:00 | 显示全部楼层 |阅读模式
我就是这样做,但效果不好,我写了一个类,你可帮我看看,

class CDrawLine
{
public:
        CDrawLine(LPDIRECT3DDEVICE9 pD3DDevice);
        virtual ~CDrawLine();
        HRESULT InitialiseVertexBuffer();
        void Render();
       
        LPDIRECT3DDEVICE9    m_pD3DDevice;
        LPDIRECT3DVERTEXBUFFER9    m_pVertexBuffer; // Buffer to hold vertices
       
private:
        struct CUSTOMVERTEX
        {
                  FLOAT x, y, z;                // The transformed position for the vertex.
                DWORD colour;                        // The vertex colour.
        };

};


CDrawLine::CDrawLine(LPDIRECT3DDEVICE9 pD3DDevice)
{
        m_pD3DDevice =pD3DDevice;
        m_pVertexBuffer = NULL;
        InitialiseVertexBuffer();

}

CDrawLine::~CDrawLine()
{
  SafeRelease(m_pVertexBuffer);
}

void CDrawLine::Render()
{
  if(m_pD3DDevice == NULL)
    {
        return;
    }

    //Rendering our triangle
        m_pD3DDevice->SetStreamSource(0, m_pVertexBuffer, 0,sizeof(CUSTOMVERTEX));
        m_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
        m_pD3DDevice->DrawPrimitive(D3DPT_LINELIST, 0, 2);

    m_pD3DDevice-&gtresent(NULL, NULL, NULL, NULL);
}

HRESULT CDrawLine::InitialiseVertexBuffer()
{
  VOID* pVertices;
//Store each point of the triangle together with it's colour
        CUSTOMVERTEX cvVertices[] =
        {
       
                { 0,  0,    0,      D3DCOLOR_XRGB(255,0,0) },
                { 10, 120, 0,  D3DCOLOR_XRGB(255,0,0) },
        };
       
        //Create the vertex buffer from our device
        if(FAILED(m_pD3DDevice->CreateVertexBuffer(2 * sizeof(CUSTOMVERTEX),
                0, D3DFVF_CUSTOMVERTEX,
                D3DPOOL_DEFAULT, &m_pVertexBuffer,NULL)))
        {
                return E_FAIL;
        }

        //Get a pointer to the vertex buffer vertices and lock the vertex buffer
        if(FAILED(m_pVertexBuffer->Lock(0, sizeof(cvVertices), (VOID**)&pVertices, 0)))
        {
                return E_FAIL;
        }

        //Copy our stored vertices values into the vertex buffer
        memcpy(pVertices, cvVertices, sizeof(cvVertices));

        //Unlock the vertex buffer
        m_pVertexBuffer->Unlock();

    return S_OK;
}

这个程序调入到我的程序中能画出真线,但是感觉其与并非我场景中的所要的长度,

3

主题

4

帖子

26

积分

注册会员

Rank: 2

积分
26
 楼主| 发表于 2003-9-8 16:57:00 | 显示全部楼层

Re:sea_bug帮我看看

我想在我的direct3D程序.做一个三维的类似于放风筝的游戏,一固定点用真线始终与一在空中运动的物体相连,我把这个类加入到我的场景程序中,发现加入我的固定点的坐标和运动物体坐标,有真线画出,但却没有达到我想要的效果,这两点根本就没有连起来,

90

主题

797

帖子

833

积分

高级会员

论坛版主

Rank: 4

积分
833
QQ
发表于 2003-9-8 17:12:00 | 显示全部楼层

Re:sea_bug帮我看看

误差肯定是有的
建议多调试。

1万

主题

1万

帖子

2万

积分

管理员

中级会员

Rank: 9Rank: 9Rank: 9

积分
20475
发表于 2003-9-8 17:14:00 | 显示全部楼层

Re:sea_bug帮我看看

确会有问题,这个关系到显卡的渲染,你可以考虑把线加粗些,当然,你要考虑视线和场景距离等,还有,你可以打开滤波渲染,效果可能会好一些。

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-4-5 22:03

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表