-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOctreeLeaf.cs
104 lines (91 loc) · 2.97 KB
/
OctreeLeaf.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using UnityEngine;
public struct OctreeLeaf : IEquatable<OctreeLeaf>, IComparable<OctreeLeaf>
{
Int64 _trace;
public OctreeLeaf(byte trace)
{
_trace = (trace & 0xF);
level = 1;
}
private OctreeLeaf(Int64 trace, byte level)
{
_trace = trace;
this.level = level;
}
public Vector3 Position(Vector3 orig, float origLen)
{
Vector3 result = orig;
float len = origLen/(1<<Level);
for (int i = 0; i < Level; i++)
{
byte childNum = (byte)((_trace >> (i * 3)) & 7);
result = Octree.GetChildPos(result, len, childNum);
len *= 2;
}
return result;
}
byte level;
public byte Level
{
get
{
return level;
}
}
public OctreeLeaf GetChild(byte childNum)
{
Int64 ranged = ((Int64)(childNum & 7));
//keeps childNum valid without throwing
//Int64 appendix = (ranged | 0x8) << (4 * Level);
//Int64 mask = -1 << ((4 * Level) - 1);
Int64 newTrace = (_trace << 3) | ranged;
return new OctreeLeaf(newTrace,(byte)(Level+1));
}
/*public static implicit operator OctreeLeaf(Int64 t)
{
return new OctreeLeaf(t);
}*/
public static implicit operator OctreeLeaf(byte t)
{
return new OctreeLeaf(t);
}
public bool Equals(OctreeLeaf other)
{
return (this.Level == other.Level && this._trace == other._trace);
}
public int CompareTo(OctreeLeaf other)
{
int levelCheck = (this.Level - other.Level);
int absLevelCheck = (levelCheck + (levelCheck >> 31)) ^ (levelCheck >> 31);
int rangedLevelCheck = (levelCheck+(1-(levelCheck&int.MinValue)>>30))/(1+((levelCheck + (levelCheck >> 31)) ^ (levelCheck >> 31))); //Brings to -1/0/+1
Int64 traceCheck = (this._trace - other._trace);
int rangedTraceCheck = (int)(((rangedLevelCheck & 1) ^ 1) * (1 + traceCheck) / (1 + ((traceCheck + (traceCheck >> 63)) ^ (traceCheck >> 63))));//Brings to -1/0/1 then times by 1 if zero and 0 if not zero
return rangedTraceCheck;
}
public static bool operator >(OctreeLeaf l1, OctreeLeaf l2)
{
return l1.Level>l2.Level && l1._trace > l2._trace;
}
public static bool operator <(OctreeLeaf l1, OctreeLeaf l2)
{
return l1.Level < l2.Level && l1._trace < l2._trace;
}
public static bool operator ==(OctreeLeaf l1, OctreeLeaf l2)
{
return (l1.Level == l2.Level && l1._trace == l2._trace);
}
public static bool operator !=(OctreeLeaf l1, OctreeLeaf l2)
{
return (l1.Level != l2.Level && l1._trace != l2._trace);
}
}