Lagrange
Frustum.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/ui/api.h>
15#include <lagrange/ui/utils/math.h>
16#include <array>
17
18namespace lagrange {
19namespace ui {
20
21enum FrustumPlanes : unsigned int {
22 FRUSTUM_NEAR = 0,
23 FRUSTUM_FAR,
24 FRUSTUM_LEFT,
25 FRUSTUM_RIGHT,
26 FRUSTUM_TOP,
27 FRUSTUM_BOTTOM
28};
29
30enum FrustumVertices : unsigned int {
31 FRUSTUM_NEAR_LEFT_BOTTOM = 0,
32 FRUSTUM_FAR_LEFT_BOTTOM,
33 FRUSTUM_NEAR_RIGHT_BOTTOM,
34 FRUSTUM_FAR_RIGHT_BOTTOM,
35 FRUSTUM_NEAR_LEFT_TOP,
36 FRUSTUM_FAR_LEFT_TOP,
37 FRUSTUM_NEAR_RIGHT_TOP,
38 FRUSTUM_FAR_RIGHT_TOP
39};
40
42class LA_UI_API Frustum
43{
44public:
45 using Plane = Eigen::Hyperplane<float, 3>;
46
47 std::array<Eigen::Vector3f, 8> vertices;
48 std::array<Plane, 6> planes;
49
50 Frustum transformed(const Eigen::Affine3f& T) const;
51
52 bool intersects(const Eigen::AlignedBox3f& bb, bool& fully_inside) const;
53 bool intersects(const Eigen::Vector3f& a, const Eigen::Vector3f& b, const Eigen::Vector3f& c)
54 const;
55
56 bool is_backfacing(const Eigen::Vector3f& a, const Eigen::Vector3f& b, const Eigen::Vector3f& c)
57 const;
58
59 bool intersects(const Eigen::Vector3f& a, const Eigen::Vector3f& b) const;
60
61 Eigen::Vector3f get_edge(FrustumVertices a, FrustumVertices b) const;
62 Eigen::Vector3f get_normalized_edge(FrustumVertices a, FrustumVertices b) const;
63
64
65 bool contains(const Eigen::Vector3f& a) const;
66};
67
68
69} // namespace ui
70} // namespace lagrange
Frustum defined using 6 planes.
Definition: Frustum.h:43
Lagrange UI Viewer and mini 3D engine.
Definition: AcceleratedPicking.h:22
Main namespace for Lagrange.
Definition: AABBIGL.h:30