新的PrimitiveComponent::GetWorldOBBMatrix函数,进一步减少中间计算步骤,直接出OBBMATRIX
This commit is contained in:
Submodule CMSceneGraph updated: 50f5514aee...a4d3950af6
@@ -240,7 +240,8 @@ private:
|
||||
{
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
cci.mat=AxisYRotate(deg2rad(i*30.0f));
|
||||
cci.mat=AxisYRotate(deg2rad(i*30.0f))*ScaleMatrix((i+1)*1.0f);
|
||||
|
||||
rm_torus->component[i]=CreateComponent<MeshComponent>(&cci,rm_torus->cdp);
|
||||
rm_torus->component[i]->SetOverrideMaterial(solid.mi[i]);
|
||||
}
|
||||
@@ -257,13 +258,12 @@ private:
|
||||
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
PrimitiveComponent *component=rm_torus->component[i];
|
||||
MeshComponent *component=rm_torus->component[i];
|
||||
|
||||
component->GetWorldOBB(obb);
|
||||
if(!component->GetWorldOBBMatrix(cci.mat))
|
||||
continue;
|
||||
|
||||
cci.mat=obb.GetMatrix();
|
||||
|
||||
CreateComponent<MeshComponent>(&cci,rm_box->cdp);
|
||||
auto *box_component=CreateComponent<MeshComponent>(&cci,rm_box->cdp);
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
@@ -31,6 +31,34 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool GetWorldOBBMatrix(Matrix4f &obb_matrix,const float cube_size=1.0f)
|
||||
{
|
||||
AABB aabb;
|
||||
|
||||
if(!GetLocalAABB(aabb))
|
||||
return false;
|
||||
|
||||
//这两行也是对的
|
||||
//OBB obb(GetLocalToWorldMatrix(),aabb);
|
||||
//obb_matrix=obb.GetMatrix(cube_size);
|
||||
|
||||
// 1. 计算最终的缩放向量
|
||||
const Vector3f scale_vector = aabb.GetLength() * cube_size;
|
||||
|
||||
// 2. 直接构建局部空间的变换矩阵 (Translate * Scale)
|
||||
Matrix4f local_aabb_matrix;
|
||||
|
||||
local_aabb_matrix[0] = Vector4f(scale_vector.x, 0.0f, 0.0f, 0.0f);
|
||||
local_aabb_matrix[1] = Vector4f(0.0f, scale_vector.y, 0.0f, 0.0f);
|
||||
local_aabb_matrix[2] = Vector4f(0.0f, 0.0f, scale_vector.z, 0.0f);
|
||||
local_aabb_matrix[3] = Vector4f(aabb.GetCenter(), 1.0f);
|
||||
|
||||
// 3. 将局部 AABB 矩阵与组件的 LocalToWorld 矩阵相乘,得到最终的世界 OBB 矩阵
|
||||
obb_matrix = GetLocalToWorldMatrix() * local_aabb_matrix;
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//class PrimitiveComponent
|
||||
|
||||
COMPONENT_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user