zoukankan
html css js c++ java
光线与三角的求交代码
eiBool eiTriangle::intersect(eiRay
*
ray, eiObject
*
po, eiFloat
&
oldt,
eiPrimitive
*
&
ret_pri, eiFloat
*
cust_data, HitParam
*
hparam)
{
if
( clip
==
EI_BSP_PRIMITIVE
&&
( oldt
==
0.0f
||
ray_box( ray
->
src, hparam
->
hitPoint ) )
)
{
//
compute intersecting point
eiFloat vnd
=
dot(normal , ray
->
dir);
if
(ray
->
type
==
RAY_SHADOW)
vnd
=
-
vnd;
if
( vnd
<
0.0f
||
po
->
material
->
doubleSide )
{
eiFloat t,td1,td2,td3;
eiVector tmpIntersection;
if
(ray
->
type
==
RAY_SHADOW)
t
=
( dot( normal , ray
->
src)
+
d )
/
vnd;
else
t
=
-
( dot( normal , ray
->
src)
+
d )
/
vnd;
if
(t
<
0.0f
)
return
false
;
tmpIntersection
=
add(ray
->
src, mulvf(ray
->
dir,t));
//
make sure intersection in bound box
if
(
!
is_pos_in_box(tmpIntersection, box))
return
false
;
//
near and far clipping
if
(ray
->
type
==
RAY_EYE
&&
!
near_far_clip(tmpIntersection))
return
false
;
//
is in triangular area
td1
=
dot(tmpIntersection , la)
+
d1;
if
(td1
<
0.0f
||
td1
>
1.0f
)
return
false
;
td2
=
dot(tmpIntersection , lb)
+
d2;
if
(td2
<
0.0f
||
td2
>
1.0f
)
return
false
;
td3
=
dot(tmpIntersection , lc)
+
d3;
if
(td3
<
0.0f
||
td3
>
1.0f
)
return
false
;
//
affect shadow factor
if
(ray
->
type
==
RAY_SHADOW)
hparam
->
shadow_factor
*=
1.0f
-
po
->
material
->
opacity;
//
find nearest hit point
if
(oldt
==
0.0f
||
t
<
oldt)
{
hparam
->
hitPoint
=
tmpIntersection;
hparam
->
hitObj
=
po;
ret_pri
=
this
;
oldt
=
t;
//
fill custom data
cust_data[
0
]
=
td1;
cust_data[
1
]
=
td2;
cust_data[
2
]
=
td3;
return
true
;
}
}
}
return
false
;
}
查看全文
相关阅读:
csrf & xss
android_sqlite
android_error
oracle笔记
android_lesson_1
mysql 设置编码
前端进阶Event
前端进阶Position
chrome插件开发资料
dom4j selectNodes
原文地址:https://www.cnblogs.com/len3d/p/229157.html
最新文章
android_lesson_2
chrome中button的默认函数
前端进阶_IFrame
javascript判断两个块级元素是否重叠
servlet中请求action
css圣杯布局
jquery select 移动option <<转>>
android_adapter
js 测试题
j2ee项目中的乱码
热门文章
POI导出数据内存溢出问题《转》
chrome checkbox 偶尔不显示问题
前端进阶Style
javascript 获取选中文本
《javascript高级程序设计》第一版笔记
你不知道的5个HTML5 API
pullxml操作xml
JavaScript开发时的四个注意事项
前端进阶DOM
android_preference
Copyright © 2011-2022 走看看