Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MortonCode.h
Go to the documentation of this file.
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
#include <
Jolt/Geometry/AABox.h
>
8
9
JPH_NAMESPACE_BEGIN
10
11
class
MortonCode
12
{
13
public
:
16
static
uint32
sExpandBits
(
float
inV
)
17
{
18
JPH_ASSERT
(
inV
>= 0.0f &&
inV
<= 1.0f);
19
uint32
v
=
uint32
(
inV
* 1023.0f + 0.5f);
20
JPH_ASSERT
(
v
< 1024);
21
v
= (
v
* 0x00010001u) & 0xFF0000FFu;
22
v
= (
v
* 0x00000101u) & 0x0F00F00Fu;
23
v
= (
v
* 0x00000011u) & 0xC30C30C3u;
24
v
= (
v
* 0x00000005u) & 0x49249249u;
25
return
v
;
26
}
27
29
static
uint32
sGetMortonCode
(
Vec3Arg
inVector
,
const
AABox
&
inVectorBounds
)
30
{
31
// Convert to 10 bit fixed point
32
Vec3
scaled
= (
inVector
-
inVectorBounds
.mMin) /
inVectorBounds
.GetSize();
33
uint
x =
sExpandBits
(
scaled
.GetX());
34
uint
y =
sExpandBits
(
scaled
.GetY());
35
uint
z =
sExpandBits
(
scaled
.GetZ());
36
return
(x << 2) + (y << 1) + z;
37
}
38
};
39
40
JPH_NAMESPACE_END
AABox.h
uint
unsigned int uint
Definition
Core.h:439
JPH_NAMESPACE_END
#define JPH_NAMESPACE_END
Definition
Core.h:367
uint32
std::uint32_t uint32
Definition
Core.h:442
JPH_NAMESPACE_BEGIN
#define JPH_NAMESPACE_BEGIN
Definition
Core.h:361
JPH_ASSERT
#define JPH_ASSERT(...)
Definition
IssueReporting.h:33
Allocate
AllocateFunction Allocate
Definition
Memory.cpp:59
AABox
Axis aligned box.
Definition
AABox.h:16
MortonCode
Definition
MortonCode.h:12
MortonCode::sExpandBits
static uint32 sExpandBits(float inV)
Definition
MortonCode.h:16
MortonCode::sGetMortonCode
static uint32 sGetMortonCode(Vec3Arg inVector, const AABox &inVectorBounds)
Calculate the morton code for inVector, given that all vectors lie in inVectorBounds.
Definition
MortonCode.h:29
Vec3
Definition
Vec3.h:16
Jolt
Geometry
MortonCode.h
Generated by
1.10.0