Havok物理引擎 关于凸面体

1649 篇文章 11 订阅
1623 篇文章 22 订阅

作者:CYM

Convex Hull:凸面体:

1.Havok物理引擎有健壮的,快速的,和详细的支持对于去产生一个凸面体.同时我们也可以使用Havok提供的API来查询和处理凸面体.

什么是凸面体?其实说白了,在我们周围有各种形状:正方体,长方体,球体,胶囊体,这些形状都可以叫出名字,.但同时也有很多叫不出名字的形状,我们把这些形状成为凸面体.


2.构造一个凸面体:

Havok中有各种方式去构造一个凸面体;

在使用构造凸面体的函数时,我们可以为其指定hkgpConvexHull::BuildConfig结构体来作为构造凸面体函数的最后一个参数,他的作用是指示如何去构造一个凸面体.下面是hkgpConvexHull::BuildConfig结构体的成员列表,以及相关的描述.

m_allowLowerDimensions (hkBool, default: false)

布尔型,这个成员变量的默认值是false,如果将它设置为true,那么当Havok无法创建一个3D的凸面体的时候将会自动降级从而创建一个2D凸面体

m_buildIndices (hkBool, default: true)

布尔型,这个成员变量的默认值是true,如果将它设置为true,那么Havok将会自动为他计算索引值

m_buildMassProperties (hkBool, default: false)

布尔型,这个成员变量的默认值是false,如果将它设置为true,那么Havok将会自动为他计算质量属性


3.使用顶点创建3D凸面体:

使用hkgpConvexHull::build()函数可以用顶点来创建一个3D凸面体:

函数原型:hkgpConvexHull::build(consthkVector4* points, int numPoints, const BuildConfig& config=BuildConfig())

4.使用平面创建凸面体:

使用hkgpConvexHull::buildFromPlanes()函数可以用平面来创建一个3D凸面体;

函数原型:hkgpConvexHull::buildFromPlanes(const hkVector4* planes, int numPlanes, const BuildConfig& config=BuildConfig()).

 

5.使用顶点来创建一个2D的凸面体:

使用hkgpConvexHull::buildPlanar()函数可以用顶点来创建一个2D的凸面体;

函数原型:hkgpConvexHull::buildPlanar(consthkStridedVertices& points, consthkVector4& plane, const BuildConfigconfig=BuildConfig()).

6.使用平面来创建一个2D的凸面体:

使用hkgpConvexHull::buildFromPlanes()函数可以用来创建一个2D的凸面体;

函数原型:hkgpConvexHull::buildFromPlanes(const hkVector4* planes, int numPlanes, consthkVector4& projectionPlane, const BuildConfig& config=BuildConfig()).

 

 

 

7.获取凸面体信息;

一些函数可以用来获取已经构造好的凸面体信息

注意:有些函数会要求你指定你想获取的坐标类型;

以下是两种坐标类型:

hkgpConvexHull::SOURCE_VERTICES

The original vertices used as input to build the convex hull.

hkgpConvexHull::INTERNAL_VERTICES

The internal vertices used to robustly compute the convex hull.

 

一般情况下都推荐使用hkgpConvexHull::INTERNAL_VERTICES坐标类型


8.获取凸面体的一般信息:

以下几个函数可以用来获取凸面体的一般信息

int getDimensions()

获取凸面体的维数,如果是空的就返回-1

const BuildConfig& getConfiguration()

获取凸面体的配置信息

const hkVector4& getProjectionPlane()

如果是2D的凸面体就返回他的投影平面

 

9.获取顶点信息:

y以下几个函数可以被用来获取多面体的顶点信息

int getNumVertices()

返回顶点的数量

Vertex* getFirstVertex()

返回第一个顶点

Vertex* getNext(const Vertex* vertex)

返回下一个顶点

hkVector4 getPosition(const Vertex* vertex)

返回顶点的位置

void fetchPositions(Inputs inputs, hkArray<hkVector4>& positionsOut)

返回所有顶点的位置信息,并且将他们存储在一个数组中

 

10.获取三角形信息:

y以下几个函数可以用来获取三角形信息

int getNumTriangles()

返回三角形的数量

Triangle* getFirstTriangle()

返回第一个三角形

Triangle* getNext(const Triangle* triangle)

返回下一个三角形

Vertex* getVertex(const Triangle* triangle, int index)

返回一个三角形的顶点信息

 

11.获取平面信息:

y以下几个函数可以被用来获取平面信息

int getNumPlanes()

返回平面的数量

const hkVector4& getPlane(int index)

返回平面的向量

void fetchPlanes(hkArray<hkVector4>& planesOut)

获取所有平面

 

12.获取几何信息:

void generateGeometry(Inputs inputs, struct hkGeometry& geometryOut)

生成凸面体的几何体

hkAabb getBoundingBox(Inputs inputs, hkReal scale=1, hkReal radialScale=0)

返回凸面体的世界AABB框

void getOrientedBoundingBox(hkVector4& halfExtents, hkTransform& worldTransform)

获取凸面体的定向包围盒和世界变化

void getOrientedRectangle(const hkVector4& projectionPlane, hkVector4& halfExtents, hkTransform& worldTransform)

给定一个平面,用来获取凸面体的矩形包围盒和世界变化信息

const hkVector4& getCentroid()

返回凸面体的几何中心

 

13.获取凸面体的索引信息:(不翻译了,以后有空再翻译,详细的请参考SDK)

minCosAngle (hkReal)

Defines the minimum (cosine) of an angle between two triangles for them to be classified as part of the same face.

forceRebuild (hkBool)

Force the algorithm to rebuild indices even if previous indices exist.

 

14.获取重力属性:

const hkVector4& getCenterOfMass()

Retrieve the center of mass of the convex hull.

void getLocalInertia(hkTransform& inertiaSpace, hkVector4& inertiaDiagonal)

Retrieve the inertia tensor in local space.

hkReal getVolume()

Retrieve the volume of the convex hull.

hkReal getSurfaceArea()

Retrieve the surface area of the convex hull.

 

15,获取用户数据;

Unmanaged user pointer.

Using the function userData(), one can retrieve a reference to a void pointer.

This is a light-weight method to store and retrieve custom data,

Managed user object.

Using the function userObject(), one can set or get a reference to an instance of an object implementing thehkgpConvexHull::IUserObject interface.

This object will be destroyed automatically when the convex hull is destroyed.

 

16.凸面体的加工:

暂时省略..睡觉去了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值