资源简介
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 程序 潮流计算代码
相关资源
- openGL做的小球三维碰撞检测程序
- D3D11_ShadowMap1
- D3D中.X模型文件
- D3D11_SpecularMap
- directx 3D 坦克大战 源码
- 碰撞检测毕业论文
- d3d方块透视外部透明窗口
- read3Dmodel.zip
- D3D11 Cube Mapping程序
- D3D11基本几何体绘制
- 简单的d3d第一人称射击游戏源码
- 实时碰撞检测算法技术pdf
- 实时碰撞检测算法技术(PDF加代码)
- SurfaceView碰撞检测小程序
- JLU D3D计算机游戏与动画技术作业项目
- 对Dxva2解码数据进行简单图像处理
- h264视频流解码并通过D3D显示
- d3d11游戏编程入门(美)Allen+Wendy中英
- unfold3d-9.02 汉化 附带教程.rar
- Unfold3D Networking v9.0.2 Build 2457汉化版
- d3d做的太阳系
- D3D11地形渲染
- DEM渲染程序完整源代码
- d3d(texture)渲染YUV420
- 实时碰撞检测算法技术.pdf
- D3D三层Texture纹理经像素着色器实现渲
- ffmpeg实现dxva2硬件加速
- D3D11_SkeletonAnimation.rar
- DirectX实时渲染技术详解第二部分含源
- D3D11_LoadOBJ
评论
共有 条评论