Hallo zusammen,
habe mich erneut mit dem Thema Ebenen und Umgebungsquader befasst und festgestellt, dass ich es mir unnötig umständlich und noch dazu etwas falsch gemacht habe.
Der Umgebungsquader umschließt das Objekt vollständig ein und ist in meinem Fall immer entlang der Achsen ausgerichtet(AABB).
Das bedeutet gleichzeitig, dass keine besonderen Rechnungen notwendig sind, um die Ebenen des Umgebungsquaders anzulegen.
Die linke Ebene kann sich nur auf der X-Achse bewegen und der Normalvektor bei der linken Ebene zeigt immer in die negative Richtung.
Der Normalvektor kann also ruhig mit -1.0f per Hand festgelegt werden.
Die Distanz der linken Ebene kann zu Beginn auch per Hand festgelegt werden, mithilfe des minimalen Vektors(BoundingBoxMin).
Die Distanz der linken Ebene vom Umgebungsquader ist immer die X-Komponente des Vektors BoundingBoxMin.
Der alte Code:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
// Ermittle die 8 Ecken eines AABBs(Axis Aligned Bounding Box)
glm::vec3 ohl = glm::vec3(object->vec3_BoundingBoxMin.x, object->vec3_BoundingBoxMax.y, object->vec3_BoundingBoxMin.z); // ECKE - OBEN - HINTEN LINKS
glm::vec3 ohr = glm::vec3(object->vec3_BoundingBoxMax.x, object->vec3_BoundingBoxMax.y, object->vec3_BoundingBoxMin.z); // ECKE - OBEN - HINTEN RECHTS
glm::vec3 ovl = glm::vec3(object->vec3_BoundingBoxMin.x, object->vec3_BoundingBoxMax.y, object->vec3_BoundingBoxMax.z); // ECKE - OBEN - VORNE LINKS
glm::vec3 ovr = object->vec3_BoundingBoxMax; // ECKE - OBEN - VORNE RECHTS
glm::vec3 uhl = object->vec3_BoundingBoxMin; // ECKE - UNTEN - HINTEN LINKS
glm::vec3 uhr = glm::vec3(object->vec3_BoundingBoxMax.x, object->vec3_BoundingBoxMin.y, object->vec3_BoundingBoxMin.z); // ECKE - UNTEN - HINTEN RECHTS
glm::vec3 uvl = glm::vec3(object->vec3_BoundingBoxMin.x, object->vec3_BoundingBoxMin.y, object->vec3_BoundingBoxMax.z); // ECKE - UNTEN - VORNE LINKS
glm::vec3 uvr = glm::vec3(object->vec3_BoundingBoxMax.x, object->vec3_BoundingBoxMin.y, object->vec3_BoundingBoxMax.z); // ECKE - UNTEN - VORNE RECHTS
// Erstelle die 6 Ebenen mithilfe der Ecken
object->plane_left.Create(ohl, uhl, ovl);
object->plane_front.Create(ovl, uvl, ovr);
object->plane_right.Create(ovr, uvr, ohr);
object->plane_back.Create(ohr, uhr, ohl);
object->plane_top.Create(ohl, ovl, ohr);
object->plane_bottom.Create(uvl, uhl, uvr);
|
Der alte Code wurde nun mit dem folgenden neuen Code ersetzt:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
object->SetBoundingBoxMin();
object->SetBoundingBoxMax();
object->plane_left.normal = glm::vec3(-1.0f, 0.0f, 0.0f);
object->plane_left.w = object->vec3_BoundingBoxMin.x;
object->plane_right.normal = glm::vec3(1.0f, 0.0f, 0.0f);
object->plane_right.w = object->vec3_BoundingBoxMax.x;
object->plane_front.normal = glm::vec3(0.0f, 0.0f, 1.0f);
object->plane_front.w = object->vec3_BoundingBoxMax.z;
object->plane_back.normal = glm::vec3(0.0f, 0.0f, -1.0f);
object->plane_back.w = object->vec3_BoundingBoxMin.z;
object->plane_top.normal = glm::vec3(0.0f, 1.0, 0.0f);
object->plane_top.w = object->vec3_BoundingBoxMax.y;
object->plane_bottom.normal = glm::vec3(0.0f, -1.0f, 0.0);
object->plane_bottom.w = object->vec3_BoundingBoxMin.y;
|
Jetzt scheint alles in Ordnung zu sein:
Ist es denn jetzt richtig oder habe ich es schon wieder falsch verstanden?
Gruß
Erdem