STRUCT lpDrawItemStruct, CDC *pDC)
{
m_iWidth = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left;
m_iHeight = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top;
m_bmpBuffer.CreateCompatibleBitmap (pDC, m_iWidth, m_iHeight);
m_bBmpCreated = TRUE;
m_dcMem.CreateCompatibleDC (pDC);
m_pOldBitmap = m_dcMem.SelectObject (&m_bmpBuffer);
SetRadius (max (min (m_iWidth, m_iHeight) - 2, 0) / 2);
SetCenter (m_iWidth / 2, m_iHeight / 2);
CreateBackground ();
}
// Set new specular intensity
BOOL CVectorCtl::SetSpecularExponent (double dExp)
{
if (dExp < 1.0 || dExp > 200.0)
return FALSE;
m_dSpecularExponent = dExp;
Redraw ();
return TRUE;
}
// Rotate our vector around the X and Y axis
void CVectorCtl::RotateByXandY (double XRot, double YRot)
{ // Angles are in radians
if (XRot == 0.0 && YRot == 0.0)
return;
double cx = cos(XRot),
sx = sin(XRot),
cy = cos(YRot),
sy = sin(YRot),
dx = m_dVec[0] * cy + m_dVec[1] * sx * sy + m_dVec[2] * cx * sy,
dy = m_dVec[1] * cx - m_dVec[2] * sx,
dz = -m_dVec[0] * sy + m_dVec[1] * sx * cy + m_dVec[2] * cx * cy;
if (!m_bFrontVector || dz >= 0.0) { // Vector is bounds free
m_dVec[0] = dx;
m_dVec[1] = dy;
m_dVec[2] = dz;
} else { // Otherwise, do not allow Z to be negative (light shines from behind)
m_dVec[2] = 0.0;
m_dVec[0] = dx;
m_dVec[1] = dy;
Normalize ();
}
Redraw ();
}
void CVectorCtl::UpdateAxisControls ()
{
CString cs;
for (int i=0; i<3; i++)
if (pCtl[i]) {
cs.Format ("%+1.5f",m_dVec[i]);
pCtl[i]->SetWindowText (cs);
}
}
void CVectorCtl::SetAxisControl (int nXCtl, int nYCtl, int nZCtl)
{
pCtl[0] = GetParent()->GetDlgItem(nXCtl);
pCtl[1] = GetParent()->GetDlgItem(nYCtl);
pCtl[2] = GetParent()->GetDlgItem(nZCtl);
}
void CVectorCtl::SetRadius (UINT uRadius)
{
m_iRadius = uRadius;
m_iSqrRadius = m_iRadius * m_iRadius;
CreateBackground ();
Redraw (TRUE);
}
void CVectorCtl::SetCenter (UINT uHorizPos, UINT uVertPos)
{
m_iXCenter = uHorizPos;
m_iYCenter = uVertPos;
CreateBackground ();
Redraw (TRUE);
}
void CVectorCtl::SetAxis (double d, int nAxis)
{
if (fabs(d)>=1.0) {
m_dVec[nAxis]=d > 1.0 ? 1.0 : -1.0;
m_dVec[(nAxis+1) %3]=m_dVec[(nAxis+2) %3]=0.0;
Redraw ();
return;
}
m_dVec[nAxis] = d;
Normalize ();
Redraw ();
}
void CVectorCtl::SetVector (double dx, double dy, double dz)
{
m_dVec[0] = dx;
m_dVec[1] = dy;
m_dVec[2] = dz;
Normalize ();
Redraw ();
}
void CVectorCtl::SetBackgroundColor (COLORREF clrStart, COLORREF clrEnd)
{
ClearBackgroundBitmap ();
m_clrBackgroundStart = clrStart;