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
;
}
查看全文
相关阅读:
win7下安装Linux实现双系统全攻略
Dreamweaver_CS6安装与破解,手把手教程
windows Server 2008各版本有何区别?
如何查看路由器中的pppoe拨号密码?
xp远程桌面连接最大用户数怎么设置?
网站的盈利模式
linux 下安装mysql-5.7.16
GNS3连接虚拟机
cain使用教程
数据中心网络架构的问题与演进 — CLOS 网络与 Fat-Tree、Spine-Leaf 架构
原文地址:https://www.cnblogs.com/len3d/p/202305.html
最新文章
写一个迷你版Smarty模板引擎,对认识模板引擎原理非常好(附代码)
Yii2.0官方高级模板的目录结构分析
Yii2.0官方高级模板的目录结构分析
iOS UILabel显示HTML文本
图片服务器设计
图片服务器设计
iOS: How To Make AutoLayout Work On A ScrollView
iOS学习之Autolayout
iOS学习之Autolayout
JDBC
热门文章
MyBatis
Linux
ActiveMQ
设计模式系列之----原型模式
设计模式系列之----观察者模式
JavaWeb基础
Java基础
SQL题
多线程题
用Python语言设计GUI界面
Copyright © 2011-2022 走看看