📄 ray.cpp
字号:
// ray.cpp: implementation of the ray class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "p_r.h"
#include "ray.h"
#include"globalExt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include"math.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ray::ray()
{
m_iXBegin=0;
m_iYBegin=0;
m_iXSec =0;
m_iYSec =0;
m_dEnergy=1.0;
m_dAngle=0;
m_dTime=0;
m_oLChild=NULL;
m_oRChild=NULL;
}
ray ray::operator=(const ray &M)
{
if(this==&M)
return *this;
m_iXBegin=M.m_iXBegin;
m_iYBegin=M.m_iYBegin;
m_iXSec =M.m_iXSec;
m_iYSec =M.m_iYSec;
m_dAngle=M.m_dAngle;
m_oLChild=M.m_oLChild;
m_oRChild=M.m_oRChild;
m_dTime =M.m_dTime;
m_dEnergy=M.m_dEnergy;
return *this;
}
ray::ray(int beginx,int beginy,int secx,int secy)
{
//double m_dAngle;//与X正半轴逆时针
m_iXBegin=beginx;
m_iYBegin=beginy;
m_iXSec =secx;
m_iYSec =secy;
m_dEnergy=1;
m_dTime=0;
m_dAngle=atan(float(secy-beginy)/float(secx-beginx));
m_oLChild=NULL;
m_oRChild=NULL;
}
ray::~ray()
{
}
bool ray::PointInRay(int x,int y)
{
float tag1=float((y-m_iYBegin))/float(x-m_iXBegin);
float tag2=float((m_iYSec-m_iYBegin))/float(m_iXSec-m_iXBegin);
if(tag1!=tag2) return false;
if((y-m_iYBegin)*(m_iYSec-m_iYBegin)>0 && (x-m_iXBegin)*(m_iXSec-m_iXBegin)>0)
return true;
return false;
}
void ray::PrintPo(CDC* pDC,int x,int y,double ZOOM)
{
if(PointInRay(x,y))
{
double Dis=sqrt((m_iXBegin-x)*(m_iXBegin-x)+(m_iYBegin-y)*(m_iYBegin-y));
m_dTime=Dis/g_fVUp;
//m_dEnergy=1;
m_dEnergy=1.0/Dis;
int color=255-int(m_dEnergy/ZOOM*255);
pDC->SetPixel(x,int(m_dTime*2000),RGB(color,color,color));
}
}
bool ray::MakeNew(CDC* pDC,Terrain temp,int &x,int &y)
{
float km,bm,kn,bn;
km=float(temp.m_iYEnd-temp.m_iYBegin)/float(temp.m_iXEnd-temp.m_iXBegin);
bm=temp.m_iYBegin - km * temp.m_iXBegin;
kn=float(m_iYSec-m_iYBegin)/float(m_iXSec-m_iXBegin);
bn=m_iYBegin - kn * m_iXSec;
int tempx,tempy;
if(km==kn) return false;
tempx=int((bn-bm)/(km-kn));
tempy=int((km*bn+bm*kn)/(kn-km));
int max=temp.m_iYBegin < temp.m_iYEnd ? temp.m_iYEnd : temp.m_iYBegin;
int min=temp.m_iYBegin > temp.m_iYEnd ? temp.m_iYEnd : temp.m_iYBegin;
// if(temp.m_iYBegin<temp.m_iYEnd)
if ((tempx <= temp.m_iXBegin) && (tempx >= temp.m_iXEnd)&&
(tempy <= min) && (tempy >= max))
{
if(PointInRay(tempx,tempy))
{
CBrush b;
b.CreateSolidBrush(RGB(255,0,0)); // 创建填充色画刷
CBrush* pOldBrush=(CBrush*)pDC->SelectObject(&b);//选择对象进DC
pDC->Ellipse(tempx-5,tempy-5,tempx+5,tempy+5);//画点(以圆代替点)
pDC->SelectObject(pOldBrush);//恢复原始画刷
b.DeleteObject();
x=tempx;
y=tempy;
return true;
}
else
return false;
}
else
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -