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
;
}
查看全文
相关阅读:
C++静态库与动态库(转)
Tornado异步
Yacc与Lex
云数据库
linux如何查看端口被谁占用
Innodb Double Write
MySQL GTIDs(global transaction identifiers)
Java并发编程:线程池的使用
Oracle 建立索引及SQL优化
解决redhat linux下IP地址可以ping通,域名无法ping通问题
原文地址:https://www.cnblogs.com/len3d/p/229157.html
最新文章
3 触发器报警-->远程执行命令
3 监控项、触发器-执行动作、web监控、nginx监控
2 zabbix安装与部署
1 监控概述
06 saltstack生产实例-需求
6 RESTful规范
5 解析器、url路由控制、分页、渲染器和版本
2017.07.25 Python网络爬虫之其他模块
2017.07.26 Python网络爬虫之Scrapy爬虫实战之今日影视
2017.07.26 Python网络爬虫之Scrapy爬虫框架
热门文章
2017.07.24 Python网络爬虫之logging模块
2017.07.24 Python网络爬虫之urllib2修改Header
2017.07.23 Python网络爬虫之爬虫常用模块
2017.07.22 Python网络爬虫之简单的Python脚本
2017.07.21 Python网络爬虫之Python代码格式
2017.07.20 Python网络爬虫之Python函数和类
2017.07.19 Python网络爬虫之Python语句
Ubuntu初始化设置
swig
python调用c代码2
Copyright © 2011-2022 走看看