游戏开发论坛

 找回密码
 立即注册
搜索
查看: 5370|回复: 4

请问vertex的position,normal,Tu,Tv四个参数怎么设置?

[复制链接]

8

主题

26

帖子

32

积分

注册会员

Rank: 2

积分
32
发表于 2005-2-1 18:00:00 | 显示全部楼层 |阅读模式
我用4个vertex做一个正方形,然后贴一张图片(texture)上去。
只是想显示一幅图片而已:

VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, dev, Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default);

CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])vb.Lock(0,0); // Lock the buffer (which will return our structs)

// Fill up our structs
verts[0].Position = new Vector3(0, 1, 0);
verts[0].Normal = new Vector3(0, 1, 0);
verts[0].Tu = 1.0f;
verts[0].Tv = 1.0f;
verts[1].Position = new Vector3(1, 1, 0);
verts[1].Normal = new Vector3(1, 1, 0);
verts[1].Tu = 0.0f;
verts[1].Tv = 1.0f;
verts[2].Position = new Vector3(1, 0, 0);
verts[2].Normal = new Vector3(1, 0, 0);
verts[2].Tu = 0.0f;
verts[2].Tv = 0.0f;
verts[3].Position = new Vector3(0, 0, 0);
verts[3].Normal = new Vector3(0, 0, 0);
verts[3].Tu = 0.0f;
verts[3].Tv = 1.0f;

// Unlock (and copy) the data
vb.Unlock();

...
texture = TextureLoader.FromFile(dev, Application.StartupPath + @"\..\..\19.jpg");
...

device.SetTexture(0,texture);
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaOperation = TextureOperation.Disable;

device.SetStreamSource(0, vertexBuffer, 0);
device.VertexFormat = CustomVertex.PositionNormalTextured.Format;
device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

显示老是不对,最好的结果就是显示了两张三角形的图片。
原因是不理解Tu和Tv的意思,不好意思,我是从来没有玩过D3D的。

请大侠们简单讲解一下,谢谢!

8

主题

26

帖子

32

积分

注册会员

Rank: 2

积分
32
 楼主| 发表于 2005-2-1 18:07:00 | 显示全部楼层

Re:请问vertex的position,normal,Tu,Tv四个参数怎么设置?

哦,我知道了,tu是图片的x坐标,tv是y坐标。
晕死!这么简单!上面的代码改正如下:

...
verts[0].Position = new Vector3(0, 1, 0);
verts[0].Normal = new Vector3(0, 1, 0);
verts[0].Tu = 0.0f;
verts[0].Tv = 0.0f;
verts[1].Position = new Vector3(1, 1, 0);
verts[1].Normal = new Vector3(1, 1, 0);
verts[1].Tu = 1.0f;
verts[1].Tv = 0.0f;
verts[2].Position = new Vector3(1, 0, 0);
verts[2].Normal = new Vector3(1, 0, 0);
verts[2].Tu = 1.0f;
verts[2].Tv = 1.0f;
verts[3].Position = new Vector3(0, 0, 0);
verts[3].Normal = new Vector3(0, 0, 0);
verts[3].Tu = 0.0f;
verts[3].Tv = 1.0f;

...

感谢您的关注!

8

主题

26

帖子

32

积分

注册会员

Rank: 2

积分
32
 楼主| 发表于 2005-2-2 10:17:00 | 显示全部楼层

Re:请问vertex的position,normal,Tu,Tv四个参数怎么设置?

可是normal是什么意思,请哪位大侠告诉我?

8

主题

26

帖子

32

积分

注册会员

Rank: 2

积分
32
 楼主| 发表于 2005-2-2 16:15:00 | 显示全部楼层

Re:请问vertex的position,normal,Tu,Tv四个参数怎么设置?

哦!normal是法线,晕!

1

主题

5

帖子

11

积分

新手上路

Rank: 1

积分
11
发表于 2007-5-23 23:03:00 | 显示全部楼层

Re:请问vertex的position,normal,Tu,Tv四个参数怎么设置?

能详细解释下顶点法线吗?一个顶点怎么会有法线呢?意味着什么呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2026-1-26 09:21

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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