📄 ground.cpp
字号:
// Ground.cpp: implementation of the CGround class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RayTrace.h"
#include "Ground.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//构造函数,初始化数据成员
CGround::CGround()
:
vecNormal (0.,0.,1.)
{
}
//析构函数
CGround::~CGround()
{
}
CVector CGround::GetNormalVec()
{
return vecNormal;
}
double CGround::Intersect()
{
double dintersect;
if( HitRay-> Direction.GetZ() == 0 )
dintersect = 0.;
else
{
dintersect = -HitRay->StartPoint.GetZ() / HitRay->Direction.GetZ();
if( dintersect < SMALL )
dintersect = 0.;
}
if( dintersect != 0.0 )
{
IntersectPoint = HitRay->Direction;
IntersectPoint *= dintersect;
IntersectPoint +=HitRay->StartPoint;
}
return dintersect;
}
CVector CGround::Mapping()
{
double x,y;
int xrange,yrange;
int tu,tv;
int tempu,tempv;
x = IntersectPoint.GetX();
y = IntersectPoint.GetY();
tu = (int)floor( (double)abs(x) );
tv = (int)floor( (double)abs(y) );
xrange = yrange = 250;//500
tempu = tu % xrange;
tu = tu - tempu;
tempv = tv % yrange;
tv = tv - tempv;
double u,v;
u = ( fabs(x) - (double)tu ) / (double)xrange;
v = ( fabs(y) - (double)tv ) / (double)yrange;
if( x < 0 )
u = 1.0 - u;
if( y < 0 )
v = 1.0 - v;
return Texture->GetColor(u,v);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -