📄 spherelight.cpp
字号:
// SphereLight.cpp: implementation of the CSphereLight class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RayTrace.h"
#include "SphereLight.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//构造函数,初始化成员变量
CSphereLight::CSphereLight
(
CVector location,
CVector intensity,
BOOL reflectable,
double radius
)
:
CLight( location, intensity,"SPHERELIGHT",reflectable),
dRadius ( radius )
{
}
//析构函数
CSphereLight::~CSphereLight()
{
}
/*************************************************************************
*
* 函数名称:
* CSphereLight::Intersect()
*
* 参数:
* 无
*
* 返回值:
* double - 返回与景物的交点参数值
*
* 说明:
* 计算与景物的交点参数值。
*
************************************************************************/
double CSphereLight::Intersect()
{
//求交测试,场景原点O(0,0,0),入射光线HitRay方向向量为单位向量
double dintersect;
double I_b,I_c,I_disc;
CVector temp = vecLocation;
temp -= HitRay->StartPoint;
I_b = -2.0 * ( temp * HitRay->Direction );
I_c = temp*temp - dRadius*dRadius;
I_disc = I_b*I_b - 4.0*I_c;
if( !(I_disc>0.0) )
dintersect=0.0;
else
{
double I_sqrt,I_t1,I_t2;
I_sqrt = sqrt(I_disc);
I_t1 = ( -I_b - I_sqrt ) * 0.5;
I_t2 = ( -I_b + I_sqrt ) * 0.5;
if((!(I_t1>SMALL)) && (!(I_t2>SMALL)))
dintersect=0.0;
else
{
if(I_t1>I_t2)
{
if(I_t2<SMALL)
I_t2=I_t1;
}
else
{
if(I_t1>SMALL)
I_t2=I_t1;
}
dintersect=I_t2;
}
}
return dintersect;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -