Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
typed-geometry
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
8
Issues
8
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Philip Trettner
typed-geometry
Commits
1e026322
Commit
1e026322
authored
Nov 18, 2020
by
Julian Schakib
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
frustum from proj-view (or planes), intersection with aabb (as a
comment)
parent
41065333
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
0 deletions
+118
-0
src/typed-geometry/functions/objects/intersection.hh
src/typed-geometry/functions/objects/intersection.hh
+42
-0
src/typed-geometry/types/objects/frustum.hh
src/typed-geometry/types/objects/frustum.hh
+76
-0
No files found.
src/typed-geometry/functions/objects/intersection.hh
View file @
1e026322
...
...
@@ -759,6 +759,48 @@ template <int D, class ScalarT>
return
intersects
(
b
,
a
);
}
/*
template <int D, class ScalarT>
[[nodiscard]] constexpr bool intersects(plane<D, ScalarT> const& p, aabb<D, ScalarT> const& b)
{
#warning not tested whatsoever
// see https://gdbooks.gitbooks.io/3dcollisions/content/Chapter2/static_aabb_plane.html
// convert aabb to center-extents representation
auto c = (b.max + b.min) * 0.5f; // aabb center
auto e = b.max - c; // positive extents
// compute the projection interval radius of b onto L(t) = b.c + t * p.n
float r = e.x * abs(p.normal.x) + e.y * abs(p.normal.y) + e.z * abs(p.normal.z);
// compute distance of box center from plane
float s = dot(p.normal, c) - p.dis;
// intersection occurs when distance s falls within [-r,+r] interval
return abs(s) <= r;
}
template <int D, class ScalarT>
[[nodiscard]] constexpr bool intersects(aabb<D, ScalarT> const& a, plane<D, ScalarT> const& b)
{
return intersects(b, a);
}*/
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
bool
intersects
(
frustum
<
ScalarT
>
const
&
a
,
aabb
<
D
,
ScalarT
>
const
&
b
)
{
for
(
auto
const
&
p
:
a
.
planes
)
if
(
intersects
(
b
,
p
))
return
true
;
return
false
;
}
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
bool
intersects
(
aabb
<
D
,
ScalarT
>
const
&
a
,
frustum
<
ScalarT
>
const
&
b
)
{
return
intersects
(
b
,
a
);
}
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
optional
<
segment
<
D
,
ScalarT
>>
intersection
(
segment
<
D
,
ScalarT
>
const
&
a
,
sphere
<
D
,
ScalarT
>
const
&
b
)
{
...
...
src/typed-geometry/types/objects/frustum.hh
View file @
1e026322
#pragma once
#include <typed-geometry/feature/assert.hh>
#include <typed-geometry/functions/swizzling/swizzling-basic.hh>
#include <typed-geometry/functions/vector/dot.hh>
#include <typed-geometry/functions/vector/length.hh>
#include <typed-geometry/functions/vector/normalize.hh>
#include <typed-geometry/types/scalars/default.hh>
#include "../pos.hh"
#include "../vec.hh"
#include "plane.hh"
namespace
tg
{
template
<
class
ScalarT
>
struct
frustum
;
// Common frustum types
using
ffrustum
=
frustum
<
f32
>
;
using
dfrustum
=
frustum
<
f64
>
;
// ======== IMPLEMENTATION ========
template
<
class
ScalarT
>
struct
frustum
{
// frustum represented by 6 planes
array
<
tg
::
plane
<
3
,
ScalarT
>
,
6
>
planes
;
constexpr
frustum
()
=
default
;
explicit
constexpr
frustum
(
array
<
tg
::
plane
<
3
,
ScalarT
>
,
6
>
const
&
planes
)
:
planes
(
planes
)
{
/* TG_CONTRACT(..); */
}
// extract frustum from a view-projection-matrix
explicit
constexpr
frustum
(
mat
<
4
,
4
,
ScalarT
>
const
&
m
)
{
// computing planes in order: left, right, bottom, top, near, far
for
(
auto
i
=
0u
;
i
<
3
;
++
i
)
for
(
auto
j
=
0u
;
j
<
2
;
++
j
)
{
// plane parameters from matrix (see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf)
vec4
abcd
;
for
(
auto
k
=
0
;
k
<
4
;
++
k
)
abcd
[
k
]
=
j
==
0
?
m
[
k
][
3
]
+
m
[
k
][
i
]
:
m
[
k
][
3
]
-
m
[
k
][
i
];
#warning normalization correct?
#warning -d due to tg representation of planes, right?
auto
n
=
vec3
(
abcd
);
auto
l
=
length
(
n
);
planes
[
2
*
i
+
j
]
=
plane3
(
dir3
(
n
/
l
),
-
abcd
.
w
/
l
);
}
}
[[
nodiscard
]]
bool
operator
==
(
frustum
const
&
rhs
)
const
{
for
(
auto
i
=
0u
;
i
<
planes
.
size
();
++
i
)
{
if
(
planes
[
i
]
!=
rhs
.
planes
[
i
])
return
false
;
}
return
true
;
}
[[
nodiscard
]]
bool
operator
!=
(
frustum
const
&
rhs
)
const
{
return
!
operator
==
(
rhs
);
}
};
template
<
class
I
,
int
D
,
class
ScalarT
,
class
TraitsT
>
constexpr
void
introspect
(
I
&&
i
,
frustum
<
ScalarT
>&
v
)
{
i
(
v
.
planes
,
"planes"
);
}
}
// namespace tg
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment