首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 游戏天堂 > 游戏开发 > The Annotated ATI SDK BSP Tree Source Part II:Data Structure
【标  题】:The Annotated ATI SDK BSP Tree Source Part II:Data Structure
【关键字】:The,Annotated,ATI,SDK,BSP,Tree,Source,Part,II,Data,Structure
【来  源】:http://blog.csdn.net/Silent_Spring/archive/2006/08/09/1042901.aspx

The Annotated ATI SDK BSP Tree Source Part II:Data Structure

 

The Annotated ATI SDK BSP Tree Source

Part II:Data Structure

丁欧南

Keyword:[Triangle Split][Collision Detection][Bounding Sphere]

此系列文章介绍包含在ATI SDK(March 2006)中的BSP Tree源代码,它实现了这些主要功能:BSP Tree 的离线编译,对第一人称视角的碰撞检测(实际上是Bounding Sphere Collision Detection).

这篇文章将接触BSP.h中所定义的数据结构.

 

1.BSP Tree数据结构

1.1三角形信息

ATI SDK以三角形作为基本单位.

struct BTri {

       void setup();

       void split(BTri *dest, int &nPos, int &nNeg, const vec3 &normal, const float offset, const float epsilon = 0) const;

       bool intersects(const vec3 &v0, const vec3 &v1) const;

       bool isAbove(const vec3 &pos) const;

       vec3 v[3];

       vec3 edgeNormals[3];

       float edgeOffsets[3];

       vec3 normal;

       float offset;

       void *data;

};

 

setup:      初始化信息

split:        在构建BSP,若分割面与相应三角形相交,则分割当前三角形.

              dest是分割后的三角形集,dest[0,nPos)是位于分割面法线方向的三角形,dest[nPos,nNeg)是位于分割面发现反方向的三角形.

              normal,offset分别是分割面的法线(已归一化),偏移量.

              epsilon是对于误差的容量.

isAbove:  判断pos所指出的位置是否正投影在当前三角形上.

v:            三角形的三个顶点,逆时针旋向为正面.

edgeNormals:  每条边的法线,都是垂直于边且指向三角形里.

edgeOffsets:   每条边的偏移量,但其计算方法却是以-edgeNormals为其法线,详细情况见setup的剖析.

normal:    三角形所在平面的法线.

offset:     三角形所在平面的偏移量,normal为法线.

data:        BSP未使用.

 

1.2BSP Tree节点信息

struct BNode {

       ~BNode();

       int getSize() const;

       void build(Array <BTri> &tris, const int cutWeight, const int unbalanceWeight);

       void read(FILE *file);

       void write(FILE *file) const;

       bool intersects(const vec3 &v0, const vec3 &v1, const vec3 &dir, vec3 *point, const BTri **triangle) const;

       bool pushSphere(vec3 &pos, const float radius) const;

       BNode *back;

       BNode *front;

       BTri tri;

};

 

build:       根据三角形集tris构建BSP Tree,cutWeight,unbalanceWeight是为了提供构建基本平衡的BSP Tree的权重,通过计算权重,来决断最佳分割面.

intersects:       取得以v0为始,v1为终的线段dir与但前三角形triangle的交点point.

pushSphere:    BSP Tree中插入一个以pos为圆心,radius为半径的球,通过pushSphere的迭代,不断修正pos,使球体不与场景相碰撞.

back:       当前三角形所在平面反面(法线反向)的三角形集.

front:      当前三角形所在平面正面(法线方向)的三角形集.

tri:          存储的当前三角形.

 

1.3BSP Tree

class BSP {

public:

       BSP(){

              top = NULL;

       }

       ~BSP(){

              delete top;

       }

       int getSize() const;

       void addTriangle(const vec3 &v0, const vec3 &v1, const vec3 &v2, void *data = NULL);

       void build(const int cutWeight = 3, const int unbalanceWeight = 1);

       bool load(const char *fileName);

       bool save(const char *fileName) const;

       bool intersects(const vec3 &v0, const vec3 &v1, vec3 *point = NULL, const BTri **triangle = NULL) const;

       bool pushSphere(vec3 &pos, const float radius) const;

protected:

       Array <BTri> tris;

       BNode *top;

};

 

tris:         三角形集.

top:         BSP Tree根节点.

addTriangle:    向三角形集tris中添加三角形.

build:       构建BSP Tree.

intersects:       BNodeintersects的包装调用.

pushSphere:    BNodeintersects的包装调用.

 

The Annotated ATI SDK BSP Tree Source Part III:Implementation:【上一篇】
The Annotated ATI SDK BSP Tree Source Part I:Theory:【下一篇】
【相关文章】
  • The Annotated ATI SDK BSP Tree Source Part III:Implementation
  • const&static&mutable
  • (codes)Huffman tree utilized with non-recursion(to be amended)
  • [open source] xmlconfig发布
  • 今天我做的一道经典动归题The Tower of Babylon
  • The /etc/nodename File(From SUN 399)
  • The code to get the size of kernel stack
  • DB2 V9 常用SQL整理 - Part 1
  • attempt to write a readonly database错误的解决(C#,SQLite)
  • [原创] GridView[DataGrid]导出成Excel文件的万能解决方法
  • 【随机文章】
  • 为QQ添加显示IP和端口功能
  • oracle SQL性能优化
  • C#中使用网络函数
  • 用C#读取GPS数据的基类,适用于wince操作系统
  • 广州ADSL MODEN的router配置
  • PS美女抽线效果大法
  • 发现DreamWeaver 8.0 简体中文版本 Bug,取消了自动换行,没有效果
  • Maya 制作水的涟漪效果(2)
  • 《Windows Heap 溢出利用》一文学习笔记 上
  • WebSphere Application Server DataSource Connect
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.