博客登录
用户名:
密 码:
注册
|
登录
忘记密码?
51cto首页
|
博客
|
论坛
|
招聘
热点文章
《掌控Windows SErver 2..
帮助
转载
:1
翻译
:0
原创
:3
小祥
http://xiaoxiang.blog.51cto.com
>
复制链接
邀请加入技术圈
加友情链接
发短消息
相册
技术圈
博客
51CTO
首页
|
技术论坛
|
短消息
博 客
我的博客
发表文章
管理博客
技术圈
创建圈子
我的圈子
寻找圈子
相 册
我的相册
上传图片
管理相册
首页
|
Directx9学习笔记
|
C++ Language
xfxsworld 的BLOG
博客统计信息
用户名:xfxsworld
文章数:4
评论数:6
访问量:3553
无忧币:58
博客积分
:58
博客等级:1
注册日期:2006-12-14
热门文章
DirectX下 Viewing Frust..
c++指针 指针入门
地形高度算法小结
Alpha混合
搜索BLOG文章
最新评论
[匿名]Creator_Chen:
对了,我已经买了域名和空间。等域..
[匿名]Creator_Chen:
总结的很不错。继续努力。。呵呵。..
[匿名]51cto游客:
恭喜开张啊。
[匿名]gufeng_yes:
看过。很详细
xfxsworld
:
的确...... 好像你还是处女访客啊。..
友情链接
崔小方
阳阳
韩猛
张敬杰
周正
苏紫旭
张丽洁
张向东
包晖
王正统
刘真想
陈超
背景音乐
我的音乐
00:00 | 00:00
文章
文章列表>>
c++指针 指针入门
2007-06-21 15:21:37
这是一篇我所见过的关于指针的最好的入门级文章,它可使初学者在很短的时间内掌握复杂的指针操作。虽然,现在的Java、C#等语言已经取消了指针,但作为一个C++程序员,指针的直接操作内存,在数据操作方面有着速度快,节约内存等优点,仍是很多C++程序员的最爱。指针就像是一把良剑,就看你怎么去应用它!
什么是指针?
其实指针就像是其它变量一样,所不同的是一般的变量包含的是实际的真实的数据,而指针是一个指示器,它告诉程序在内存的哪块区域可以找到数据。这是一个非常重要的概念,有很多程序和算法都是围绕指针而设计的..
类别:C++ Language
|
阅读全文(753)
|
回复(0)
DirectX下 Viewing Frustum 的详细实现
2007-05-15 22:38:15
本文大部分内容翻译自Gil Gribb和Klaus Hartmann合写的《Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix》这篇文章,有兴趣的朋友可以搜索看下原文,里面DirectX下和OpenGL下的实现过程都说的很清楚,这里只说DirectX部分。
这里介绍的算法,可以直接从世界、观察以及投影矩阵中计算出Viewing Frustum的六个面。它快速,准确,并且允许我们在相机空间(camera space)、世界空间(world space)或着物体空间(object space)快速确定Frustum planes。
我们先仅仅从投影矩阵(pro..
类别:Directx9学习笔记
|
阅读全文(1174)
|
回复(0)
地形高度算法小结
2007-03-25 12:53:35
地形一般是用网格再从高度图里读取每个顶点的高度来生成。若进一步,想实现摄像机在地形上行走的效果,就需要算出地形上任意一点的高度。总结了3个方法:
一:
《Introduction to 3D Game Programming With Directx 9.0》这本书里介绍的,利用向量来算。
float Terrain::GetHeight(float x, float z)
{
// Translate on xz-plane by the transformation that takes
// the terrain START point to the origin.
x = ((float)_width / 2.0f) + x;
z = ((float)_depth / 2.0f) - z;
// Scale down by the transformation that makes the
// cellspacing equal to one. This is given by
// 1 / cellspacing since; cellspacing * 1 / cellspacing = 1.
x /= (float)_CellSpacing;
z /= (float)_CellSpacing;
// From now on, we will interpret our positive z-axis as
// going in the 'down' direction, rather than the 'up' direction.
// This allows to extract the row and column simply by 'flooring'
// x and z:
float col = ::floorf(x);
float row = ::floorf(z);
// get the heights of the quad we're in:
//
// A B
// *---*
// | / |
// *---*
// C D
float A = GetHeightMapEntry(row, col);
float B = GetHeightMapEntry(row, col+1);
float C = GetHeightMapEntry(row+1, col);
float D = GetHeightMapEntry(row+1, col+1);
//
// Find the triangle we are in:
//
// Translate by the transformation that takes the upper-left
// corner of the cell we are in to the origin. Recall that our
// cellspacing was nomalized to 1. Thus we have a unit square
// at the origin of our +x -> 'right' and +z -> 'down' system.
float dx = x - col;
float dz = z - row;
// Note the below compuations of u and v are unneccessary, we really
// only need the height, but we compute the entire vector to emphasis
// the books discussion.
float height = 0.0f;
if(dz < 1.0f - dx) // upper triangle ABC
{
float uy = B - A; // A->B
float vy = C - A; // A->C
// Linearly interpolate on each vector. The height is the vertex
// height the vectors u and v originate from {A}, plus the heights
// found by interpolating on each vector u and v.
height = A + Lerp(0.0f, uy, dx) + Lerp(0.0f, vy, dz);
}
else // lower triangle DCB
{
float uy = C - D; // D->C
float vy = B - D; // D->B
// Linearly interpolate on each vector. The height is the vertex
// height the vectors u and v originate from {D}, plus the heights
// found by interpolating on each vector u and v.
height = D + Lerp(0.0f, uy, 1.0f - dx) + Lerp(0.0f, vy, 1.0f - dz);
}
return height;
}
用到的2个函数
float Terrain::Lerp(float a, float b, float t) //一个插值函数
{
return (a - (a*t) + (b*t));
}
int Terrain::GetHeightMapEntry(int row, int col) //读取高度函数
{
return _heightmap[row * _numVertsPerRow + col]; // 高度图数据存在_heightmap里
}
二:
先计算出摄像机所在三角形的平面方程,然后带入摄像机的X,Z坐标,即可得高度Y
具体实现过程见[url]http://creatorchen1984.spaces.live.com/[/url] 《获取地形上某一点高度》,写的十分详细
三:
网上找的一个方法
假设你的地形为terrain[][];用下面的函数求出地形上点(x,z);的y值,将人物的高度加上这个y值即可.
float GetHeight(GLfloat x, GLfloat z)
{
float h=0;
float Xb,Yb;
int Xa,Ya;
Xa=(int)x;
Ya=(int)z;
Xb=x-Xa;
Yb=z-Ya;
float a=terrain[Xa][Ya].y;
float b=terrain[Xa+1][Ya].y;
float c=terrain[Xa][Ya+1].y;
float d=terrain[Xa+1][Ya+1].y;
h=(a*(1-Xb)+b*Xb)*(1-Yb)+(c*(1-Xb)+d*Xb)*Yb;
return h;
} [/img]..
类别:Directx9学习笔记
|
阅读全文(632)
|
回复(3)
Alpha混合
2007-03-23 22:48:58
Direct3D计算Alpha混合的颜色公式:
Color = ( SrcRGB * SrcK ) + ( DestRGB * DestK )
SrcRGB表示源颜色值,即将要绘制的颜色值。SrcK表示源混合系数,通常赋值为D3DBLEND_SRCALPHA,即当前绘制像素的Alpha值
DestRGB表示目标颜色值,即当前缓冲区中的颜色值。DestK表示目标系数,通常赋值为D3DBLEND_INVSRCALPHA,即1减去当前绘制像素的Alpha值
则Direct3D计算Alpha混合的颜色公式可表示为
Color = ( SrcRGB * SrcAlpha ) + ( DestRGB * ( 1 - SrcAlpha ) )
混合步骤
Alpha混合默认关闭..
类别:Directx9学习笔记
|
阅读全文(331)
|
回复(3)