Example #1
0
void LFO::Process(UnsignedType SampleCount) 
{
	UnsignedType type = m_Type->Value();
	FloatType freq =m_Freq->Value();
	FloatType Incr, CyclePos, Pos;

	CyclePos = StateValue(m_CyclePosInd)->AsFloat;

	for (UnsignedType n=0; n<SampleCount; n++) 
	{
		Incr = freq * (DEFAULT_TABLE_LEN / (FloatType)SampleRate());

		// Raw Output
		CyclePos = AdjustPos (CyclePos + Incr);
		SetOutput (output[0], n, (*ClassObject()->Table(type))[CyclePos]);

		// 'Cosine' Output
		Pos = AdjustPos (CyclePos + (DEFAULT_TABLE_LEN * 0.25f));
		SetOutput (output[1], n, (*ClassObject()->Table(type))[Pos]);

		// Inverted Output
		Pos = AdjustPos (DEFAULT_TABLE_LEN - CyclePos);
		SetOutput (output[2], n, (*ClassObject()->Table(type))[Pos]);
	}
}
bool TextFormatter::FormatFwd(CFDC& dc, FilePos start)
{
    AdjustPos(start); // just to be safe
    if (start.para >= m_tf->Length(start.docid))
        return false; // at eof
    m_lines.RemoveAll();
    m_top = start;
    bool header = true;
    for (int page = 0; page < m_pages; ++page)
    {
        int h = 0;
        int beg = m_lines.GetSize();
        while (h < m_height && start.para < m_tf->Length(start.docid))
        {
            Paragraph para(m_tf->GetParagraph(start.docid, start.para));
            bool empty = para.len == 0 || para.len == 1 && para.str[0] == _T(' ');
            if (h == 0 && empty)
            {
                start.off = para.len;
                AdjustPos(start);
                continue;
            }
            if (para.flags & Paragraph::header)
            {
                if (!header)
                    break;
            }
            else
                if (!empty && !(para.flags & Paragraph::image))
                    header = false;
            int lh = WrapLine(dc, para, start, m_lines, h, m_height - h);
            if (lh < 0)
                break;
            AdjustPos(start);
            h += lh;
        }
        m_pagelen.SetAtGrow(page, m_lines.GetSize() - beg);
    }
    m_bot = start;
    Highlight();
    // add one dummy line always
    Line l;
    l.pos = m_bot;
    m_lines.Add(l);
    return true;
}
bool TextFormatter::FormatFwdAdj(CFDC& dc)
{
    // if an image crosses the bottom of the window, and does not start
    // at the top of window, then move down only until the image is
    // fully visible
    AdjustPos(m_bot);
    Paragraph p(m_tf->GetParagraph(m_bot.docid, m_bot.para));
    if (p.flags&Paragraph::image && // image
        m_bot.off > 0 && // crosses window border
        (m_top.docid != m_bot.docid || m_top.para != m_bot.para)) // is not visible at top
        // then do a partial move forward to show a whole image
        m_bot.off = 0;
    return FormatFwd(dc, m_bot);
}
Example #4
0
void Stable(void)
{
	static double gval[3];
	static double pre_pitch, pitch, pre_roll, roll;
	int i;
	if(timer_nowtime() - STABLETIMER > FRESHTIME)
	{
		ReadGSensor();
		gval[0] = (double)(G_AXIS_VALUE[0]);
		gval[1] = (double)(G_AXIS_VALUE[1]);
		gval[2] = (double)(G_AXIS_VALUE[2]);
		pitch = (GetPitch(gval)- 5.0*DEG_TO_RAD)*0.5 + pre_pitch*0.5;
		roll = (GetRoll(gval) - 4.5*DEG_TO_RAD)*0.5 + pre_roll*0.5;
	
	
		BODY_PITCH = BODY_PITCH + STABLE_P*pitch + (pitch - pre_pitch)*STABLE_D/FRESHTIME;
		BODY_ROLL = BODY_ROLL + STABLE_P*roll + (roll - pre_roll)*STABLE_D/FRESHTIME;

		if(BODY_PITCH > 60.0*DEG_TO_RAD)
			BODY_PITCH = 60.0*DEG_TO_RAD;
		else if(BODY_PITCH < -60.0*DEG_TO_RAD)
			BODY_PITCH = -60.0*DEG_TO_RAD;
		if(BODY_ROLL > 60.0*DEG_TO_RAD)
			BODY_ROLL = 60.0*DEG_TO_RAD;
		else if(BODY_ROLL < -60.0*DEG_TO_RAD)
			BODY_ROLL = -60.0*DEG_TO_RAD;
			
		
		for(i =0 ; i < 6; i++ )
		{
			LEGPOS[0] = LEGGOAL[3*i] - cos(J3MAP[i])*20.0;
			LEGPOS[1] = LEGGOAL[3*i+1] - sin(J3MAP[i])*20.0;
			LEGPOS[2] = LEGGOAL[3*i+2];
			Transform(BODY_YAW, BODY_PITCH, BODY_ROLL, LEGPOS);
			AdjustPos(POS_GAIN, LEGPOS);
			CenterToJoint3(LEGPOS,i,J3GOAL);
			Joint3ToJoint2(J3GOAL, J2GOAL);
			JointAngle(LEGPOS, J2GOAL,i,JANGLE);
			SetJoint(JANGLE,i);	
			rcservo_SetAction(POSITION, STABLETIME);
			STABLETIMER = timer_nowtime(); 
		}
		pre_pitch = pitch;
		pre_roll = roll;
	}
	rcservo_PlayAction();
}
Example #5
0
bool SetSelected(ODynamicObj* p_poObj, f32 p_fRadius, const Vec3& p_vMousePos)
{
	Vec3 vPlayerPos = p_poObj->GetPosition();
	vPlayerPos = AdjustPos(vPlayerPos);
	vPlayerPos *= kPIXEL_PER_METER;
	vPlayerPos.x += kCANVAS_START_X;
	vPlayerPos.y += kCANVAS_START_Y;
	vPlayerPos.z = 0;
	Vec3 vMousePos = p_vMousePos;
	Vec3 vDiff = vMousePos - vPlayerPos;
	if(vDiff.LengthSq() < p_fRadius * kPIXEL_PER_METER * p_fRadius * kPIXEL_PER_METER)	
	{
		if(g_WatchPlayer)
			g_WatchPlayer->SetShowDetailed(false);
		p_poObj->SetShowDetailed(true);
		g_WatchPlayer = p_poObj;
		return true;
	}
	return false;
}
Example #6
0
void Idle(void)
{
	int i;
	double temp_p, temp_r;
	if(rcservo_PlayAction() == RCSERVO_PLAYEND)
	{
		for(i =0 ; i < 6; i++ )
		{
			LEGPOS[0] = LEGGOAL[3*i];
			LEGPOS[1] = LEGGOAL[3*i+1];
			LEGPOS[2] = LEGGOAL[3*i+2];
			if(SWING == 1)
			{
				ALPHA = ALPHA + PI/36.0;
				if(ALPHA >= 2*PI - PI/36.0)
					ALPHA = 0.0;
				temp_p = BODY_PITCH + gain_p*sin(ALPHA)*DEG_TO_RAD;
				temp_r = BODY_ROLL+ gain_r*sin(ALPHA+PI/2)*DEG_TO_RAD;
			}
			else
			{
				temp_p = BODY_PITCH;
				temp_r = BODY_ROLL;
			}
			Transform(BODY_YAW, temp_p, temp_r, LEGPOS);
			AdjustPos(POS_GAIN, LEGPOS);
			CenterToJoint3(LEGPOS,i,J3GOAL);
			Joint3ToJoint2(J3GOAL, J2GOAL);
			JointAngle(LEGPOS, J2GOAL,i,JANGLE);
			SetJoint(JANGLE,i);	
			rcservo_SetAction(POSITION, IDLEPLAYTIME);
			
		}
		IDLEFRAME = 0;
	}
	rcservo_PlayAction();
}
Example #7
0
void SetMotion(int num)
{
	double temp_p, temp_r;
	GetLegMotion(LEGOPPOSITE, LEGGOAL, num, LEGFRAME[num],LEGPOS);
	if(SWING == 1)
	{
		ALPHA = ALPHA + PI/36.0;
		if(ALPHA >= 2*PI - PI/36.0)
			ALPHA = 0.0;
		temp_p = BODY_PITCH + gain_p*sin(ALPHA)*DEG_TO_RAD;
		temp_r = BODY_ROLL+ gain_r*sin(ALPHA+PI/2)*DEG_TO_RAD;
	}
	else
	{
		temp_p = BODY_PITCH;
		temp_r = BODY_ROLL;
	}
	Transform(BODY_YAW, temp_p, temp_r, LEGPOS);
	AdjustPos(POS_GAIN, LEGPOS);
	CenterToJoint3(LEGPOS,num,J3GOAL);
	Joint3ToJoint2(J3GOAL, J2GOAL);
	JointAngle(LEGPOS, J2GOAL,num,JANGLE);
	SetJoint(JANGLE,num);	
}
Example #8
0
	INT_PTR CAboutDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{
		switch (uMsg) {
		case WM_INITDIALOG:
			{
				SetItemText(IDC_ABOUT_VERSION,
							APP_NAME_W L" ver." APP_VERSION_TEXT_W L" (" APP_PLATFORM_W L")");

				m_pLogoImage=m_Core.GetGraphicSystem().CreateImage();
				m_pLogoImage->LoadFromResource(m_hinst,MAKEINTRESOURCE(ID_PNG_LOGO),L"PNG");

				m_fTransparentLogo=false;
				BOOL fCompositionEnabled;
				if (::DwmIsCompositionEnabled(&fCompositionEnabled)==S_OK && fCompositionEnabled) {
					HWND hwndLogo=GetItemHandle(IDC_ABOUT_LOGO);
					RECT rc;
					::GetWindowRect(hwndLogo,&rc);
					MARGINS Margins={rc.right-rc.left,0,0,0};
					if (::DwmExtendFrameIntoClientArea(hDlg,&Margins)==S_OK)
						m_fTransparentLogo=true;
				}

				AdjustPos();
			}
			return TRUE;

		case WM_PAINT:
			{
				PAINTSTRUCT ps;
				RECT rcLogo,rcClient;

				::BeginPaint(hDlg,&ps);

				Graphics::CCanvas *pCanvas=m_Core.GetGraphicSystem().CreateCanvas(ps.hdc);
				if (m_fTransparentLogo)
					pCanvas->Clear(Graphics::Color(0,0,0,0));
				::GetWindowRect(::GetDlgItem(hDlg,IDC_ABOUT_LOGO),&rcLogo);
				::OffsetRect(&rcLogo,-rcLogo.left,-rcLogo.top);
				::GetClientRect(hDlg,&rcClient);
				rcClient.left=rcLogo.right;
				pCanvas->FillRect(rcClient,Graphics::Color(::GetSysColor(COLOR_3DFACE)));
				if (!m_fTransparentLogo)
					pCanvas->FillRect(rcLogo,Graphics::Color(255,255,255));
				if (m_pLogoImage!=nullptr) {
					pCanvas->DrawImage((rcLogo.right-m_pLogoImage->GetWidth())/2,
									   (rcLogo.bottom-m_pLogoImage->GetHeight())/2,
									   m_pLogoImage);
				}
				delete pCanvas;

				::EndPaint(hDlg,&ps);
			}
			return TRUE;

		case WM_DWMCOMPOSITIONCHANGED:
			m_fTransparentLogo=false;
			return TRUE;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
			case IDOK:
			case IDCANCEL:
				//::EndDialog(hDlg,LOWORD(wParam));
				Destroy();
				return TRUE;
			}
			return TRUE;

		case WM_DESTROY:
			TSTask::SafeDelete(m_pLogoImage);
			m_Core.RemoveModelessDialog(this);
			return TRUE;
		}

		return FALSE;
	}
bool TextFormatter::AtEof()
{
    FilePos p(m_bot);
    AdjustPos(p);
    return p.para >= m_tf->Length(p.docid);
}
Example #10
0
bool TextFormatter::AtTop()
{
    FilePos p(m_top);
    AdjustPos(p, true);
    return p.off == 0 && p.para == 0;
}
Example #11
0
bool TextFormatter::FormatBack(CFDC& dc, FilePos start, FilePos prev_top)
{
    AdjustPos(start, true);
    if (start.para == 0 && start.off == 0)
        return false; // at the top
    m_lines.RemoveAll();
    m_bot = start;
    for (int page = m_pages - 1; page >= 0; --page)
    {
        LineArray tmp;
        FilePos pos = start;
        int h = 0;
        // while there are still paragrahs before
        while (h < m_height && (pos.para>0 || pos.off > 0))
        {
            // format entire paragraph
            LineArray cp;
            Paragraph para(m_tf->GetParagraph(pos.docid, pos.para));
            if (pos.off < para.len) // double check args
                para.len = pos.off;
            else
                pos.off = para.len;
            FilePos fp = FilePos(pos.para, 0, pos.docid);
            WrapLine(dc, para, fp, cp, 0, 32768);
            // insert the formatted paragraph at start of list
            tmp.InsertAt(0, &cp);
            for (int i = 0; i < cp.GetSize(); ++i)
                h += cp[i].height;
            pos.off = 0;
            AdjustPos(pos, true);
        }
        // delete extra lines
        int j;
        // remove top lines
        for (h = 0, j = tmp.GetUpperBound(); j >= 0 && h + tmp[j].height <= m_height; --j)
            h += tmp[j].height;
        if (j < tmp.GetUpperBound())
        {
            if (j >= 0 && prev_top != 0 && tmp[j + 1].pos >= prev_top)
            {
                --j;
                tmp.RemoveAt(0, j + 1);
                // now remove bottom lines
                for (h = j = 0; j < tmp.GetSize() && h + tmp[j].height <= m_height; ++j)
                    h += tmp[j].height;
                if (j < tmp.GetSize())
                    tmp.RemoveAt(j, tmp.GetSize() - j);
            }
            else
            {
                tmp.RemoveAt(0, j + 1);
            }
        }
        // save lines
        m_lines.InsertAt(0, &tmp);
        m_pagelen.SetAtGrow(page, tmp.GetSize());
        start = m_lines[0].pos;
        if (start.para == 0 && start.off == 0) // we reached the top of file
            return FormatFwd(dc, FilePos(0, 0, start.docid));
    }
    // save positions
    m_top = m_lines[0].pos;
    Highlight();
    // add one dummy line always
    Line l;
    l.pos = m_bot;
    m_lines.Add(l);
    return true;
}
Example #12
0
	INT_PTR CSettingsDialog::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
	{
		switch (uMsg) {
		case WM_INITDIALOG:
			{
				::SetWindowText(hDlg,GetTitle());

				DeleteAllPages();
				for (int i=0;;i++) {
					CPage *pPage=CreatePage(i);
					if (pPage==nullptr)
						break;

					m_PageList.push_back(pPage);

					::SendDlgItemMessage(hDlg,IDC_SETTINGS_LIST,LB_ADDSTRING,0,i);
				}

				int Page=0;
				if (m_StartPage>=0 && m_StartPage<(int)m_PageList.size())
					Page=m_StartPage;
				else if (m_CurrentPage>=0 && m_CurrentPage<(int)m_PageList.size())
					Page=m_CurrentPage;
				m_CurrentPage=-1;

				if (SetPage(Page)) {
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_LIST,LB_SETCURSEL,Page,0);
				}

				m_himlIcons=::ImageList_LoadImage(m_hinst,MAKEINTRESOURCE(IDB_SETTINGS),16,1,
												  CLR_NONE,IMAGE_BITMAP,LR_CREATEDIBSECTION);

				LRESULT ItemHeight=::SendDlgItemMessage(hDlg,IDC_SETTINGS_LIST,LB_GETITEMHEIGHT,0,0);
				if (ItemHeight<16+8)
					::SendDlgItemMessage(hDlg,IDC_SETTINGS_LIST,LB_SETITEMHEIGHT,0,16+8);

				AdjustPos();
			}
			return TRUE;

		case WM_DRAWITEM:
			{
				LPDRAWITEMSTRUCT pdis=reinterpret_cast<LPDRAWITEMSTRUCT>(lParam);

				if (wParam==IDC_SETTINGS_LIST) {
					if (pdis->itemData>=m_PageList.size())
						break;

					const CPage *pPage=m_PageList[pdis->itemData];
					const bool fSelected=(pdis->itemState&ODS_SELECTED)!=0;
					COLORREF crText,crOldText;
					int OldBkMode;
					RECT rcBack,rcText;

					rcBack=pdis->rcItem;
					rcBack.left+=4+16+4;
					if (fSelected) {
						RECT rc=pdis->rcItem;
						rc.right=rcBack.left;
						::FillRect(pdis->hDC,&rc,
								   reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
						FillGradient(pdis->hDC,rcBack,
									 RGB(0,0,0),pPage->GetTitleColor());
						crText=RGB(255,255,255);
					} else {
						::FillRect(pdis->hDC,&pdis->rcItem,
								   reinterpret_cast<HBRUSH>(COLOR_WINDOW+1));
						crText=::GetSysColor(COLOR_WINDOWTEXT);
					}
					::ImageList_Draw(m_himlIcons,pPage->GetIcon(),pdis->hDC,
									 pdis->rcItem.left+4,
									 rcBack.top+((rcBack.bottom-rcBack.top)-16)/2,
									 ILD_TRANSPARENT);
					rcText=rcBack;
					rcText.left+=4;
					rcText.right-=4;
					crOldText=::SetTextColor(pdis->hDC,crText);
					OldBkMode=::SetBkMode(pdis->hDC,TRANSPARENT);
					::DrawText(pdis->hDC,pPage->GetTitle(),-1,
							   &rcText,DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
					::SetTextColor(pdis->hDC,crOldText);
					::SetBkMode(pdis->hDC,OldBkMode);
					if ((pdis->itemState & (ODS_FOCUS | ODS_NOFOCUSRECT))==ODS_FOCUS) {
						::DrawFocusRect(pdis->hDC,&rcBack);
					}
				} else if (wParam==IDC_SETTINGS_TITLE) {
					if (m_CurrentPage<0 || (size_t)m_CurrentPage>=m_PageList.size())
						break;

					CPage *pPage=m_PageList[m_CurrentPage];
					RECT rc;

					FillGradient(pdis->hDC,pdis->rcItem,
								 RGB(0,0,0),pPage->GetTitleColor());
					LOGFONT lf;
					::GetObject(reinterpret_cast<HFONT>(::SendMessage(hDlg,WM_GETFONT,0,0)),sizeof(lf),&lf);
					lf.lfWeight=FW_BOLD;
					HFONT hfont=::CreateFontIndirect(&lf);
					HFONT hfontOld=SelectFont(pdis->hDC,hfont);
					COLORREF crOldText=::SetTextColor(pdis->hDC,RGB(255,255,255));
					int OldBkMode=::SetBkMode(pdis->hDC,TRANSPARENT);
					rc.left=pdis->rcItem.left+2;
					rc.top=pdis->rcItem.top;
					rc.right=pdis->rcItem.right-2;
					rc.bottom=pdis->rcItem.bottom;
					::DrawText(pdis->hDC,pPage->GetTitle(),-1,
							   &rc,DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
					SelectFont(pdis->hDC,hfontOld);
					::DeleteObject(hfont);
					::SetTextColor(pdis->hDC,crOldText);
					::SetBkMode(pdis->hDC,OldBkMode);
				}
			}
			return TRUE;

		case WM_COMMAND:
			switch (LOWORD(wParam)) {
			case IDC_SETTINGS_LIST:
				if (HIWORD(wParam)==LBN_SELCHANGE) {
					int Page=(int)::SendDlgItemMessage(hDlg,IDC_SETTINGS_LIST,LB_GETCURSEL,0,0);

					if (Page>=0)
						SetPage(Page);
				}
				return TRUE;

			case IDOK:
				if (QueryOK() && OnOK()) {
					End(IDOK);
				}
				return TRUE;

			case IDCANCEL:
				OnCancel();
				End(IDCANCEL);
				return TRUE;
			}
			return TRUE;

		case WM_APP_SET_PAGE:
			SetPage((int)wParam);
			return TRUE;

		case WM_DESTROY:
			{
				m_StartPage=m_CurrentPage;

				DeleteAllPages();

				if (m_himlIcons!=nullptr) {
					::ImageList_Destroy(m_himlIcons);
					m_himlIcons=nullptr;
				}

				m_Core.RemoveModelessDialog(this);
			}
			return TRUE;
		}

		return FALSE;
	}
Example #13
0
	int OnWndOther(WPARAM wParam,LPARAM lParam,BOOL *pbHandled)
	{
		AdjustPos();
		return 0;
	}