From 35f5be16c3b0edaa5fc22fb3b9eefd3d186dd0ff Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 8 Jul 2025 13:46:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E8=A7=84=E8=8C=83Pr?= =?UTF-8?q?imitiveComponent/MeshComponent=E4=B8=AD=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=9B=92=E7=9A=84=E5=87=BD=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E5=B9=B6=E6=AD=A3=E7=A1=AE=E6=B8=B2=E6=9F=93?= =?UTF-8?q?OBB=E3=80=82=E4=B8=8D=E8=BF=87=E6=B2=A1=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMCore | 2 +- CMSceneGraph | 2 +- example/Basic/RenderBoundBox.cpp | 10 ++++++++-- inc/hgl/component/MeshComponent.h | 4 ++-- inc/hgl/component/PrimitiveComponent.h | 8 ++++---- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CMCore b/CMCore index 6b97ffdf..a9e37e62 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit 6b97ffdf79ff978fff89ca5276a21c1a18c98669 +Subproject commit a9e37e6219e538592686e00f0447d3144677ff97 diff --git a/CMSceneGraph b/CMSceneGraph index 584ac021..048acfdf 160000 --- a/CMSceneGraph +++ b/CMSceneGraph @@ -1 +1 @@ -Subproject commit 584ac02106791566f6df9a45ccd0678f333efbc7 +Subproject commit 048acfdf45554155de4ca6e79e67480a9c9eebd1 diff --git a/example/Basic/RenderBoundBox.cpp b/example/Basic/RenderBoundBox.cpp index 53fced5d..6e50791e 100644 --- a/example/Basic/RenderBoundBox.cpp +++ b/example/Basic/RenderBoundBox.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -250,7 +250,13 @@ private: { CreateComponentInfo cci(GetSceneRoot()); - //cci.mat=rm_torus->component->GetLocalMatrix()*rm_torus->component->GetMesh()->GetBoundingBox(); + ParsePrimitiveType + OBB obb; + rm_torus->component->GetWorldOBB(obb); + + cci.mat=TranslateMatrix(obb.GetCenter()) * + obb.GetRotationMatrix() * + ScaleMatrix(obb.GetHalfExtend()*2.0f); //*2.0f并不是因为OBB尺寸不对,是因为CUBE的原始尺寸就是1 CreateComponent(&cci,rm_box->cdp); diff --git a/inc/hgl/component/MeshComponent.h b/inc/hgl/component/MeshComponent.h index d10d0469..179c9924 100644 --- a/inc/hgl/component/MeshComponent.h +++ b/inc/hgl/component/MeshComponent.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -101,7 +101,7 @@ public: return mcd->mesh; } - const bool GetBoundingBox(AABB &box) const override + const bool GetLocalAABB(AABB &box) const override { Mesh *mesh=GetMesh(); diff --git a/inc/hgl/component/PrimitiveComponent.h b/inc/hgl/component/PrimitiveComponent.h index 678f1750..e3f5d3e5 100644 --- a/inc/hgl/component/PrimitiveComponent.h +++ b/inc/hgl/component/PrimitiveComponent.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -18,13 +18,13 @@ public: virtual ~PrimitiveComponent()=default; - virtual const bool GetBoundingBox(AABB &box) const =0; + virtual const bool GetLocalAABB(AABB &box) const=0; - const bool GetBoundingBox(OBB &box) + const bool GetWorldOBB(OBB &box) { AABB aabb; - if(!GetBoundingBox(aabb)) + if(!GetLocalAABB(aabb)) return false; box.Set(GetLocalToWorldMatrix(),aabb);