zoukankan
html css js c++ java
光线与球的求交代码
//
-------------------------------------------------------------------------
eiBool eiSphere::intersect(eiRay
*
ray, eiObject
*
po, eiFloat
&
oldt,
eiPrimitive
* &
ret_pri, eiFloat
*
cust_data,
HitParam
*
hparam)
{
if
( oldt
==
0.0f
||
ray_box( ray
->
src, hparam
->
hitPoint )
{
//
compute intersecting point
eiVector oc
=
add( ray
->
src,
-
center );
eiFloat oc_len
=
dist( oc );
if
( oc_len
>
radius
||
po
->
material
->
doubleSide )
{
eiFloat a
=
dot( ray
->
dir, ray
->
dir );
eiFloat b
=
2.0f
*
dot( oc, ray
->
dir);
eiFloat c
=
dot( oc, oc )
-
RR;
eiFloat dt
=
b
*
b
-
4.0f
*
a
*
c;
eiFloat t;
if
(a
==
0.0f
||
dt
<
0.0f
)
return
false
;
else
if
(dt
==
0.0f
)
{
t
=
-
b
/
a
*
0.5f
;
if
(t
<
0.0f
)
return
false
;
}
else
{
a
=
0.5f
/
a;
eiFloat t1
=
(
-
b
+
sqrtf( dt ))
*
a;
eiFloat t2
=
(
-
b
-
sqrtf( dt ))
*
a;
if
(t1
>
0.0f
&&
t2
<
0.0f
)
t
=
t1;
else
if
(t1
<
0.0f
&&
t2
>
0.0f
)
t
=
t2;
else
if
(t1
>
0.0f
&&
t2
>
0.0f
)
t
=
(t1
<
t2)
?
t1 : t2;
else
return
false
;
}
eiVector tmpIntersection
=
add(ray
->
src, mulvf(ray
->
dir,t));
//
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
return
true
;
}
}
}
return
false
;
}
查看全文
相关阅读:
Mysql基础
Mysql基础2
Windows CMD命令大全
python 调试方法
LDAP
Linux 内核与模块调试
Linux tee命令
Linux kgdb命令
OpenSSL基础知识
Linux top命令
原文地址:https://www.cnblogs.com/len3d/p/202305.html
最新文章
使用BasicDataSource连接池连接oracle数据库报错ORA-12505
dubbox部署到jdk1.7环境,启动:java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()
dubbox消费者启动成功,却无法连接注册中心
数据结构和算法 – 9.二叉树和二叉查找树
数据结构和算法 – 8.链表
数据结构和算法 – 7.散列和 Hashtable 类
数据结构和算法 – 6.构建字典: DictionaryBase 类和 SortedList 类
数据结构和算法 – 5.模式匹配和文本处理
数据结构和算法 – 4.字符串、 String 类和 StringBuilder 类
数据结构和算法 – 3.堆栈和队列
热门文章
数据结构和算法 – 番外篇.时间测试类Timing
数据结构和算法 c#– 1.单项链表
SQLSERVER查询连接数
Notepad++插件Emmet和Python Script的安装
zen-Coding在Notepad++中的使用
Notepad++ 快捷键 大全
bootstarp v3 学习简记
Bootstarp学习教程(7) 表单
git移除某文件夹的版本控制
更改git bash默认的路径
Copyright © 2011-2022 走看看