Branimir Karadžić 9 年 前
コミット
f9bc9d560f
2 ファイル変更18 行追加18 行削除
  1. 13 13
      examples/common/bounds.cpp
  2. 5 5
      examples/common/bounds.h

+ 13 - 13
examples/common/bounds.cpp

@@ -94,15 +94,7 @@ void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx)
 	memcpy(_obb.m_mtx, result, sizeof(result) );
 	memcpy(_obb.m_mtx, result, sizeof(result) );
 }
 }
 
 
-float calcAreaAabb(Aabb& _aabb)
-{
-	float ww = _aabb.m_max[0] - _aabb.m_min[0];
-	float hh = _aabb.m_max[1] - _aabb.m_min[1];
-	float dd = _aabb.m_max[2] - _aabb.m_min[2];
-	return 2.0f * (ww*hh + ww*dd + hh*dd);
-}
-
-void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
+void toAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
 {
 {
 	float min[3], max[3];
 	float min[3], max[3];
 	uint8_t* vertex = (uint8_t*)_vertices;
 	uint8_t* vertex = (uint8_t*)_vertices;
@@ -136,7 +128,7 @@ void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_
 	_aabb.m_max[2] = max[2];
 	_aabb.m_max[2] = max[2];
 }
 }
 
 
-void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
+void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
 {
 {
 	float min[3], max[3];
 	float min[3], max[3];
 	uint8_t* vertex = (uint8_t*)_vertices;
 	uint8_t* vertex = (uint8_t*)_vertices;
@@ -172,6 +164,14 @@ void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _n
 	_aabb.m_max[2] = max[2];
 	_aabb.m_max[2] = max[2];
 }
 }
 
 
+float calcAreaAabb(const Aabb& _aabb)
+{
+	float ww = _aabb.m_max[0] - _aabb.m_min[0];
+	float hh = _aabb.m_max[1] - _aabb.m_min[1];
+	float dd = _aabb.m_max[2] - _aabb.m_min[2];
+	return 2.0f * (ww*hh + ww*dd + hh*dd);
+}
+
 void aabbExpand(Aabb& _aabb, float _factor)
 void aabbExpand(Aabb& _aabb, float _factor)
 {
 {
 	_aabb.m_min[0] -= _factor;
 	_aabb.m_min[0] -= _factor;
@@ -204,7 +204,7 @@ uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1)
 void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
 void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _stride, uint32_t _steps)
 {
 {
 	Aabb aabb;
 	Aabb aabb;
-	calcAabb(aabb, _vertices, _numVertices, _stride);
+	toAabb(aabb, _vertices, _numVertices, _stride);
 	float minArea = calcAreaAabb(aabb);
 	float minArea = calcAreaAabb(aabb);
 
 
 	Obb best;
 	Obb best;
@@ -228,7 +228,7 @@ void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _
 
 
 				float mtxT[16];
 				float mtxT[16];
 				bx::mtxTranspose(mtxT, mtx);
 				bx::mtxTranspose(mtxT, mtx);
-				calcAabb(aabb, mtxT, _vertices, _numVertices, _stride);
+				toAabb(aabb, mtxT, _vertices, _numVertices, _stride);
 
 
 				float area = calcAreaAabb(aabb);
 				float area = calcAreaAabb(aabb);
 				if (area < minArea)
 				if (area < minArea)
@@ -252,7 +252,7 @@ void calcObb(Obb& _obb, const void* _vertices, uint32_t _numVertices, uint32_t _
 void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
 void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride)
 {
 {
 	Aabb aabb;
 	Aabb aabb;
-	calcAabb(aabb, _vertices, _numVertices, _stride);
+	toAabb(aabb, _vertices, _numVertices, _stride);
 
 
 	float center[3];
 	float center[3];
 	center[0] = (aabb.m_min[0] + aabb.m_max[0]) * 0.5f;
 	center[0] = (aabb.m_min[0] + aabb.m_max[0]) * 0.5f;

+ 5 - 5
examples/common/bounds.h

@@ -75,18 +75,18 @@ void toAabb(Aabb& _aabb, const Disk& _disk);
 /// Convert cylinder to axis aligned bounding box.
 /// Convert cylinder to axis aligned bounding box.
 void toAabb(Aabb& _aabb, const Cylinder& _cylinder);
 void toAabb(Aabb& _aabb, const Cylinder& _cylinder);
 
 
-/// Calculate surface area of axis aligned bounding box.
-float calcAabbArea(Aabb& _aabb);
-
 /// Calculate axis aligned bounding box.
 /// Calculate axis aligned bounding box.
-void calcAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
+void toAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
 
 
 /// Transform vertices and calculate axis aligned bounding box.
 /// Transform vertices and calculate axis aligned bounding box.
-void calcAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
+void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride);
 
 
 /// Expand AABB.
 /// Expand AABB.
 void aabbExpand(Aabb& _aabb, float _factor);
 void aabbExpand(Aabb& _aabb, float _factor);
 
 
+/// Calculate surface area of axis aligned bounding box.
+float calcAreaAabb(const Aabb& _aabb);
+
 /// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
 /// Returns 0 is two AABB don't overlap, otherwise returns flags of overlap
 /// test.
 /// test.
 uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1);
 uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1);