资源简介
D3D 实现的AABB 碰撞检测 D3D

代码片段和文件信息
#include “aabb.h“
const int kNumCorners = 8;
const int kMaxIndices = 36;
// Overloaded constructor
CAxisAlgnBB::CAxisAlgnBB(const CPos &min const CPos &max)
{
set(min max);
}
void CAxisAlgnBB::render(int argb)
{
SVertex verts[kNumCorners];
WORD indexList[kMaxIndices] = { 0 2 3
3 1 0
7 6 4
4 5 7
4 6 2
2 0 4
1 3 7
7 5 1
4 0 1
1 5 4
2 6 7
7 3 2 };
// Fill in the 8 vertices
for(int i = 0; i < kNumCorners; ++i)
{
CPos pos = getCorner(i);
verts[i].x = pos.x;
verts[i].y = pos.y;
verts[i].z = pos.z;
verts[i].color = argb;
}
// Render the AABB
g3D->render(verts kNumCorners indexList kMaxIndices);
// Render lines on the top and bottom of the the front and
// back sides of the box. This allow us to see the full dimensions
// of the AABB better.
for(int i = 0; i < kNumCorners; ++i)
verts[i].color = D3DCOLOR_ARGB(255 255 255 255);
g3D->renderLine(verts kNumCorners);
}
/* So lets quickly digest how this algorithm works. First we assume that the
origin of the ray is inside of the AABB. If this is true then we know that
the ray MUST collide with AABB because it is contained inside of the AABB.
If the origin is not inside of the AABB then we check to see if the
direction the ray is heading is away from the AABB. If it is then it
must NOT collide.
Lastly if the origin is outside of the AABB and the ray is heading towards
the AABB we use the length of the ray and test to see if there is an
intersection.
*/
bool CAxisAlgnBB::intersect(const CRay &ray)
{
// Compute the ray delta
CVector rayDelta = ray.getDir() * ray.getLength();
// First we check to see if the origin of the ray is
// inside the AABB. If it is the ray intersects the AABB so
// we‘ll return true. We start by assuming the ray origin is
// inside the AABB
bool inside = true;
// This stores the distance from either the min or max (xyz) to the ray‘s
// origin (xyz) respectively divided by the length of the ray. The largest
// value has the delta time of a possible intersection.
float xt yt zt;
// Test the X component of the ray‘s origin to see if we are inside or not
if(ray.getOrigin().x < mMin.x)
{
xt = mMin.x - ray.getOrigin().x;
if(xt > rayDelta.x) // If the ray is moving away from the AABB there is no intersection
return false;
xt /= rayDelta.x;
inside = false;
}
else if(ray.getOrigin().x > mMax.x)
{
xt = mMax.x - ray.getOrigin().x;
if(xt < rayDelta.x) // If the ray is moving away from the AABB there is no intersection
return false;
xt /= rayDelta.x;
inside = false;
}
else
{
// Later on we use the “xt“ “yt“ and “zt“ variables to determine which plane (either
// xy xz or yz) we may collide with. Since the x compone
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7181 2011-10-29 09:17 Ray and AABB Collision\aabb.cpp
文件 3496 2006-11-26 19:44 Ray and AABB Collision\aabb.h
文件 9887 2006-06-24 12:17 Ray and AABB Collision\d3d_obj.cpp
文件 3140 2011-10-28 20:58 Ray and AABB Collision\d3d_obj.h
文件 44677 2011-10-29 22:18 Ray and AABB Collision\Debug\aabb.obj
文件 6814 2011-10-29 22:18 Ray and AABB Collision\Debug\BuildLog.htm
文件 59448 2011-10-28 20:58 Ray and AABB Collision\Debug\d3d_obj.obj
文件 65 2011-10-29 22:18 Ray and AABB Collision\Debug\mt.dep
文件 36593 2011-10-28 20:58 Ray and AABB Collision\Debug\ray.obj
文件 69632 2011-10-29 22:18 Ray and AABB Collision\Debug\RayAABBCollision.exe
文件 403 2011-10-28 20:58 Ray and AABB Collision\Debug\RayAABBCollision.exe.em
文件 468 2011-10-28 20:58 Ray and AABB Collision\Debug\RayAABBCollision.exe.em
文件 385 2011-10-29 22:18 Ray and AABB Collision\Debug\RayAABBCollision.exe.intermediate.manifest
文件 404712 2011-10-29 22:18 Ray and AABB Collision\Debug\RayAABBCollision.ilk
文件 617472 2011-10-29 22:18 Ray and AABB Collision\Debug\RayAABBCollision.pdb
文件 502784 2011-10-29 22:18 Ray and AABB Collision\Debug\vc80.idb
文件 225280 2011-10-29 22:18 Ray and AABB Collision\Debug\vc80.pdb
文件 18264 2011-10-28 20:56 Ray and AABB Collision\Debug\vector.obj
文件 46612 2011-10-29 08:46 Ray and AABB Collision\Debug\win_main.obj
文件 886 2011-03-28 17:01 Ray and AABB Collision\ray.cpp
文件 2614 2011-03-28 17:01 Ray and AABB Collision\ray.h
文件 11881472 2011-11-02 21:29 Ray and AABB Collision\RayAABBCollision.ncb
文件 896 2006-11-26 19:54 Ray and AABB Collision\RayAABBCollision.sln
..A..H. 69120 2011-11-02 21:29 Ray and AABB Collision\RayAABBCollision.suo
文件 4560 2011-10-29 22:18 Ray and AABB Collision\RayAABBCollision.vcproj
文件 1433 2011-03-28 19:54 Ray and AABB Collision\RayAABBCollision.vcproj.2083C87BAA6145D.Administrator.user
文件 1413 2011-11-02 21:29 Ray and AABB Collision\RayAABBCollision.vcproj.HP-PC.HP.user
文件 2368 2006-11-26 20:05 Ray and AABB Collision\ReadMe - RayPlaneCollide.txt
文件 3009 2006-06-24 12:17 Ray and AABB Collision\vector.cpp
文件 1569 2011-03-27 22:23 Ray and AABB Collision\vector.h
............此处省略7个文件信息
- 上一篇:远程DNS缓存攻击
- 下一篇:matpower 程序 潮流计算代码
相关资源
- MFC程序-碰撞的小球
- D3D烟花粒子
- opengl室内场景的绘制,包括碰撞检测
- Direct3d做的演示程序有源代码
- 碰撞检测的算法及一些算法的代码实
- d3d9_2.exe
- e92d3d2f5aef63448696ba0aa5ef9ed1.pdf
- Real-Time Collision Detection实时碰撞检测算
- D3D9 SDK中文文档
- 运用DirectX9绘制太阳系
- DirectX3D太阳系
- Game-EC 驱动辅助模块8.4 D3D透视版
- opengl 编写的cs 游戏
- 基于D3D的魔方小程序
- 基于D3D的YV12视频渲染 更新
- D3D11_DirectionalShadowMap
- d3dx9_27.DLL202096
- open inventor 碰撞检测
- 简单的D3D9纹理共享
- 多边形相交检测demo
- D3D11_DerfferredShading
- 原创3D游戏引擎源代码
- 太阳地球月亮旋转公转自转
- openGL做的小球三维碰撞检测程序
- D3D11_ShadowMap1
- D3D中.X模型文件
- D3D11_SpecularMap
- directx 3D 坦克大战 源码
- 碰撞检测毕业论文
- d3d方块透视外部透明窗口
评论
共有 条评论