Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
魔术师Dix
Unity几何库:木蝴蝶
提交
dd0ba84c
Unity几何库:木蝴蝶
项目概览
魔术师Dix
/
Unity几何库:木蝴蝶
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Unity几何库:木蝴蝶
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dd0ba84c
编写于
11月 10, 2022
作者:
魔术师Dix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新3d直线与Box3d的相交检测,并优化部分代码;
上级
ce3c2002
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
134 addition
and
16 deletion
+134
-16
Intersection/IntrLine2dBox2d.cs
Intersection/IntrLine2dBox2d.cs
+3
-10
Intersection/IntrLine3dBox3d.cs
Intersection/IntrLine3dBox3d.cs
+116
-3
Math/Box3d.cs
Math/Box3d.cs
+9
-0
Math/Line2d.cs
Math/Line2d.cs
+6
-3
未找到文件。
Intersection/IntrLine2dBox2d.cs
浏览文件 @
dd0ba84c
...
...
@@ -25,22 +25,15 @@ namespace Oroxylum
public
IntrLine2dBox2d
(
Line2d
line
,
Box2d
box
)
{
LineParam0
=
0
;
LineParam1
=
0
;
LineParam0
=
-
float
.
MaxValue
;
LineParam1
=
float
.
MaxValue
;
Point0
=
0
;
Point1
=
0
;
Result
=
E_IntersectionResult
.
NotComputed
;
Type
=
E_IntersectionType
.
Empty
;
Quantity
=
0
;
float2
direction
=
line
.
Direction
;
if
(!
direction
.
IsNormalized
())
direction
=
math
.
normalize
(
direction
);
LineParam0
=
-
float
.
MaxValue
;
LineParam1
=
float
.
MaxValue
;
DoClipping
(
ref
LineParam0
,
ref
LineParam1
,
line
.
Origin
,
direction
,
box
,
DoClipping
(
ref
LineParam0
,
ref
LineParam1
,
line
.
Origin
,
line
.
Direction
,
box
,
true
,
ref
Quantity
,
ref
Point0
,
ref
Point1
,
ref
Type
);
Result
=
(
Type
!=
E_IntersectionType
.
Empty
)
?
...
...
Intersection/IntrLine3dBox3d.cs
浏览文件 @
dd0ba84c
...
...
@@ -8,14 +8,127 @@
*/
using
Unity.Mathematics
;
namespace
Oroxylum
{
/// <summary>
/// 相交计算结果:3d直线与3dBox
/// </summary>
public
class
IntrLine3dBox3d
public
struct
IntrLine3dBox3d
{
public
int
Quantity
;
public
E_IntersectionResult
Result
;
public
E_IntersectionType
Type
;
public
float
LineParam0
,
LineParam1
;
public
float3
Point0
;
public
float3
Point1
;
public
IntrLine3dBox3d
(
Line3d
line
,
Box3d
box
)
{
Result
=
E_IntersectionResult
.
NotComputed
;
Type
=
E_IntersectionType
.
Empty
;
LineParam0
=
-
float
.
MaxValue
;
LineParam1
=
float
.
MaxValue
;
Point0
=
0
;
Point1
=
1
;
Quantity
=
0
;
DoClipping
(
ref
LineParam0
,
ref
LineParam1
,
line
.
Origin
,
line
.
Direction
,
box
,
true
,
ref
Quantity
,
ref
Point0
,
ref
Point1
,
ref
Type
);
Result
=
(
Type
!=
E_IntersectionType
.
Empty
)
?
E_IntersectionResult
.
Intersects
:
E_IntersectionResult
.
NoIntersection
;
}
public
static
bool
DoClipping
(
ref
float
t0
,
ref
float
t1
,
float3
origin
,
float3
direction
,
Box3d
box
,
bool
solid
,
ref
int
quantity
,
ref
float3
point0
,
ref
float3
point1
,
ref
E_IntersectionType
intrType
)
{
// Convert linear component to box coordinates.
float3
diff
=
origin
-
box
.
Center
;
float3
BOrigin
=
new
float3
(
diff
.
Dot
(
box
.
AxisX
),
diff
.
Dot
(
box
.
AxisY
),
diff
.
Dot
(
box
.
AxisZ
)
);
float3
BDirection
=
new
float3
(
direction
.
Dot
(
box
.
AxisX
),
direction
.
Dot
(
box
.
AxisY
),
direction
.
Dot
(
box
.
AxisZ
)
);
double
saveT0
=
t0
,
saveT1
=
t1
;
bool
notAllClipped
=
Clip
(+
BDirection
.
x
,
-
BOrigin
.
x
-
box
.
Extent
.
x
,
ref
t0
,
ref
t1
)
&&
Clip
(-
BDirection
.
x
,
+
BOrigin
.
x
-
box
.
Extent
.
x
,
ref
t0
,
ref
t1
)
&&
Clip
(+
BDirection
.
y
,
-
BOrigin
.
y
-
box
.
Extent
.
y
,
ref
t0
,
ref
t1
)
&&
Clip
(-
BDirection
.
y
,
+
BOrigin
.
y
-
box
.
Extent
.
y
,
ref
t0
,
ref
t1
)
&&
Clip
(+
BDirection
.
z
,
-
BOrigin
.
z
-
box
.
Extent
.
z
,
ref
t0
,
ref
t1
)
&&
Clip
(-
BDirection
.
z
,
+
BOrigin
.
z
-
box
.
Extent
.
z
,
ref
t0
,
ref
t1
);
if
(
notAllClipped
&&
(
solid
||
t0
!=
saveT0
||
t1
!=
saveT1
))
{
if
(
t1
>
t0
)
{
intrType
=
E_IntersectionType
.
LineSegment
;
quantity
=
2
;
point0
=
origin
+
t0
*
direction
;
point1
=
origin
+
t1
*
direction
;
}
else
{
intrType
=
E_IntersectionType
.
Point
;
quantity
=
1
;
point0
=
origin
+
t0
*
direction
;
}
}
else
{
quantity
=
0
;
intrType
=
E_IntersectionType
.
Empty
;
}
return
intrType
!=
E_IntersectionType
.
Empty
;
}
private
static
bool
Clip
(
float
denom
,
float
numer
,
ref
float
t0
,
ref
float
t1
)
{
// Return value is 'true' if line segment intersects the current test
// plane. Otherwise 'false' is returned in which case the line segment
// is entirely clipped.
if
(
denom
>
0
)
{
if
(
numer
-
denom
*
t1
>
OMath
.
ZeroTolerance
)
{
return
false
;
}
if
(
numer
>
denom
*
t0
)
{
t0
=
numer
/
denom
;
}
return
true
;
}
else
if
(
denom
<
0
)
{
if
(
numer
-
denom
*
t0
>
OMath
.
ZeroTolerance
)
{
return
false
;
}
if
(
numer
>
denom
*
t1
)
{
t1
=
numer
/
denom
;
}
return
true
;
}
else
{
return
numer
<=
0
;
}
}
}
}
}
\ No newline at end of file
Math/Box3d.cs
浏览文件 @
dd0ba84c
...
...
@@ -8,6 +8,8 @@
*/
using
Unity.Mathematics
;
namespace
Oroxylum
{
/// <summary>
...
...
@@ -15,6 +17,13 @@ namespace Oroxylum
/// </summary>
public
struct
Box3d
{
public
float3
Center
;
public
float3
Extent
;
public
float3
AxisX
=>
new
float3
(
1.0f
,
0.0f
,
0.0f
);
public
float3
AxisY
=>
new
float3
(
0.0f
,
1.0f
,
0.0f
);
public
float3
AxisZ
=>
new
float3
(
0.0f
,
0.0f
,
1.0f
);
}
...
...
Math/Line2d.cs
浏览文件 @
dd0ba84c
...
...
@@ -18,13 +18,16 @@ namespace Oroxylum
public
struct
Line2d
{
public
float2
Origin
;
public
float2
Direction
;
/// <summary>
/// 直线方向,已经 normalize
/// </summary>
public
float2
Direction
;
public
Line2d
(
float2
origin
,
float2
direction
)
{
this
.
Origin
=
origin
;
this
.
Direction
=
direction
;
this
.
Direction
=
math
.
normalize
(
direction
)
;
}
public
static
Line2d
FromPoints
(
float2
p0
,
float2
p1
)
...
...
@@ -37,7 +40,7 @@ namespace Oroxylum
public
float2
ClosestPoint
(
float2
p
)
{
float
t
=
(
p
-
Origin
).
Dot
(
Direction
);
return
Origin
+
t
*
Direction
;
return
Origin
+
(
t
*
Direction
)
;
}
public
double
DistanceSquared
(
float2
p
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录