游戏开发论坛

 找回密码
 立即注册
搜索
查看: 9021|回复: 11

怎样用D3D画出一条直线

[复制链接]

3

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
发表于 2008-9-13 00:03:00 | 显示全部楼层 |阅读模式
如题,不希望用三角形逼近,谢谢大家

125

主题

364

帖子

396

积分

中级会员

Rank: 3Rank: 3

积分
396
QQ
发表于 2008-9-13 03:04:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

D3DXCreateLine
你看看这个函数。

4

主题

10

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2008-9-13 10:07:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

对了,这个画出来的Line可以像GDI那样设置画笔样式吗?前几天做了一个画一系列不规则折线的,因为画出来两头都是平的,拐点看起来跟要掰断了似的。。。

3

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2008-9-13 16:25:00 | 显示全部楼层

Re: Re:怎样用D3D画出一条直线

shaoxiaoning: Re:怎样用D3D画出一条直线

D3DXCreateLine
你看看这个函数。

LPD3DXLINE
Input is in the form of an array that defines points (of D3DXVECTOR2) on the line strip.
是不是只能画一个二维的线呢?我想在控件画线,怎么办呢?

4

主题

10

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2008-9-13 18:00:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

这个东西直接画呀,DrawPrimitives( LineStrip/List 。。。)

Line Lists (Direct3D 9)
A line list is a list of isolated, straight line segments. Line lists are useful for such tasks as adding sleet or heavy rain to a 3D scene. Applications create a line list by filling an array of vertices. Note that the number of vertices in a line list must be an even number greater than or equal to two.

The following illustration shows a rendered line list.



You can apply materials and textures to a line list. The colors in the material or texture appear only along the lines drawn, not at any point in between the lines.

The following code shows how to create vertices for this line list.

struct CUSTOMVERTEX
{
        float x,y,z;
};

CUSTOMVERTEX Vertices[] =
{
        {-5.0, -5.0, 0.0},
        { 0.0,  5.0, 0.0},
        { 5.0, -5.0, 0.0},
        {10.0,  5.0, 0.0},
        {15.0, -5.0, 0.0},
        {20.0,  5.0, 0.0}
};

The code example below shows how to use IDirect3DDevice9:rawPrimitive to render this line list.

//
// It is assumed that d3dDevice is a valid
// pointer to a IDirect3DDevice9 interface.
//
d3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, 3 );

3

主题

6

帖子

6

积分

新手上路

Rank: 1

积分
6
 楼主| 发表于 2008-9-20 01:20:00 | 显示全部楼层

Re: 怎样用D3D画出一条直线

谢谢楼上

1

主题

15

帖子

15

积分

新手上路

Rank: 1

积分
15
发表于 2008-9-21 00:23:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

给两个顶点坐标,把绘制模式改为LINER

4

主题

125

帖子

127

积分

注册会员

Rank: 2

积分
127
QQ
发表于 2008-9-23 20:38:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

这个只能画一个像素宽的直线

4

主题

13

帖子

13

积分

新手上路

Rank: 1

积分
13
发表于 2008-9-23 23:45:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

呵呵,我也正碰到同样的问题
如果对直线没有宽度的要求,就用DrawPrimitives好了
否则可以用ID3DXLine类,其中的ID3DXLine:raw可以画二维的
ID3DXLine::DrawTransform可以画三维的,这个函数中用到的矩阵需要将世界,观察,投影矩阵相乘。
我用这个实现了一些效果,不过总的效率太低
不知道有没有什么好的方法?

5

主题

46

帖子

55

积分

注册会员

Rank: 2

积分
55
QQ
发表于 2008-9-24 09:25:00 | 显示全部楼层

Re:怎样用D3D画出一条直线

不知道PointSize有没有用
另外还可以用4个顶点画个细长的带,还可以带贴图
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-21 05:59

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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