示例#1
0
文件: XMyD3DView.cpp 项目: xahgo/tama
void XMyD3DView::OnDraw(CDC* pDC)
{
//	CPaintDC dc(this); // device context for painting
	// TODO: 여기에 메시지 처리기 코드를 추가합니다.
	// 그리기 메시지에 대해서는 __super::OnPaint()을(를) 호출하지 마십시오.
	if( GetChain() )
	{
		LPDIRECT3DDEVICE9 pd3dDevice = GRAPHICS_D3D->GetDevice();
		LPDIRECT3DSURFACE9 pBackBuffer = NULL;
		GetChain()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
		if( pBackBuffer )
		{
			CRect rect;
			GetClientRect( &rect );
			XE::VEC2 vRectSize = XE::VEC2( (float)rect.right - rect.left, (float)rect.bottom - rect.top );
			XE::SetProjection( rect.right-rect.left, rect.bottom-rect.top );
			pd3dDevice->SetRenderTarget( 0, pBackBuffer );
			pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, XCOLOR_GRAY, 1.0f, 0 );
//			D3DRECT rectClear={0, 29, rect.right, rect.bottom};
//			pd3dDevice->Clear( 1, &rectClear, D3DCLEAR_TARGET, XCOLOR_GRAY, 1.0f, 0 );
			if(SUCCEEDED(pd3dDevice->BeginScene()))
			{
				Draw();
				pd3dDevice->EndScene();
			}
			GetChain()->Present( NULL, NULL, GetSafeHwnd(), NULL, 0 );
			pBackBuffer->Release();
		} // pBackBuffer
	}

}
CMarkovWordGenerator::SFragHead *CMarkovWordGenerator::AllocFrag (char *pFrag, char chChar, DWORD dwFlags)

//	AllocFrag
//
//	Allocates a new fragment

	{
	SFragHead *pNewFrag = (SFragHead *) new char [sizeof(SFragHead) + 2 * sizeof(SChainChar)];
	pNewFrag->sFrag[0] = pFrag[0];
	pNewFrag->sFrag[1] = pFrag[1];
	pNewFrag->sFrag[2] = pFrag[2];
	pNewFrag->sFrag[3] = '\0';
	pNewFrag->dwFlags = dwFlags;
	pNewFrag->dwCount = 1;

	SChainChar *pChain = GetChain(pNewFrag);
	pChain->chChar = chChar;
	pChain->dwCount = 1;

	pChain++;
	pChain->chChar = '\0';
	pChain->dwCount = 0;

	return pNewFrag;
	}
示例#3
0
std::vector<int> CPlanarGraph::ExtractDeepestFaceOrChain(bool& flagCyclic, bool flagSmallFaceFirst)
{
	if ( VisitedNoNode() == true && HasFixedNode() == true )
	{
		// Handle the fixed nodes first...
		std::vector<int> indices = GetFixedNodes();
		return indices;
	}
	if ( m_chains.empty() == false )
	{
		for ( int i=0; i<int(m_chains.size()); i++ )
		{
			CGraphChain& chain = GetChain(i);
#if 0 // Before 09/23/2013, which is NOT suitable for ghost cases
			int idx0 = chain.GetIndices()[0];
			if ( GetNode(idx0).GetFlagVisited() == true )
			{
				continue;
			}
#else
			bool flagAllVisited = true;
			for ( int j=0; j<chain.GetChainSize(); j++ )
			{
				if ( GetNode(chain.GetIndices()[j]).GetFlagVisited() == false )
				{
					flagAllVisited = false;
					break;
				}
			}
			if ( flagAllVisited == true )
			{
				continue;
			}
#endif
			flagCyclic = chain.GetFlagCyclic();
			std::vector<int> indices = chain.GetIndices();
			return indices;
		}
	}
	std::vector<int> faceIndices = ExtractDeepestFace(flagSmallFaceFirst);
	if ( faceIndices.empty() == false && VisitedNoNode() == true )
	{
		flagCyclic = true;
		return faceIndices;
	}
	int faceConstraintCount = CountConstraints(faceIndices);
	std::vector<int> chainIndices = ExtractDeepestChainNew();
	int chainConstraintCount = CountConstraints(chainIndices);
	if ( faceIndices.empty() == false && faceConstraintCount > chainConstraintCount )
	{
		flagCyclic = true;
		return faceIndices;
	}
	else
	{
		flagCyclic = false;
		return chainIndices;
	}
}
ALERROR CMarkovWordGenerator::WriteAsXML (IWriteStream *pOutput)

//	WriteAsXML
//
//	Writes out the Markov chain data to an XML element

	{
	ALERROR error;
	int i;

	//	Open tag

	CString sData;
	sData = CONSTLIT("\t<WordGenerator>\r\n");
	if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	//	Fragments

	for (i = 0; i < m_Table.GetCount(); i++)
		{
		sData = CONSTLIT("\t\t<Syl>");
		if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;

		sData = strPatternSubst(CONSTLIT("%s;%d;%d;"), strToXMLText(CString(m_Table[i]->sFrag)), m_Table[i]->dwCount, m_Table[i]->dwFlags);
		if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;

		SChainChar *pChain = GetChain(m_Table[i]);
		while ((*(DWORD *)pChain) != 0)
			{
			char chChar[2];
			chChar[0] = pChain->chChar;
			chChar[1] = '\0';
			CString sChar = strToXMLText(CString(chChar, 1, true));
			sData = strPatternSubst(CONSTLIT("%s;%d;"), sChar, pChain->dwCount);

			if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
				return error;

			pChain++;
			}

		sData = CONSTLIT("</Syl>\r\n");
		if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
			return error;
		}

	//	Done

	//	Close tag

	sData = CONSTLIT("\t</WordGenerator>\r\n");
	if (error = pOutput->Write(sData.GetPointer(), sData.GetLength(), NULL))
		return error;

	return NOERROR;
	}
CMarkovWordGenerator::SFragHead *CMarkovWordGenerator::AppendChainChar (SFragHead *pFrag, char chChar, DWORD dwFlags)

//	AppendChainChar
//
//	Appends the character to the chain; frees the original fragment and
//	returns a newly allocated one.

	{
	DWORD *pChainStart = (DWORD *)GetChain(pFrag);
	DWORD *pChain = pChainStart;
	while (*pChain != 0)
		pChain++;

	int iChainCount = (pChain - pChainStart) + 1;

	//	Allocate the new fragment

	SFragHead *pNewFrag = (SFragHead *) new char [sizeof(SFragHead) + (iChainCount + 1) * sizeof(SChainChar)];
	*pNewFrag = *pFrag;
	if (dwFlags & FRAG_WORD_START)
		pNewFrag->dwFlags |= FRAG_WORD_START;

	//	Copy all but the last

	DWORD *pChainSrc = pChainStart;
	DWORD *pChainSrcEnd = pChainSrc + (iChainCount - 1);
	DWORD *pChainDest = (DWORD *)GetChain(pNewFrag);
	while (pChainSrc < pChainSrcEnd)
		*pChainDest++ = *pChainSrc++;

	//	Add the new char

	((SChainChar *)pChainDest)->chChar = chChar;
	((SChainChar *)pChainDest)->dwCount = 1;
	pChainDest++;

	//	Terminator

	*pChainDest = 0;

	//	Free original and return

	delete pFrag;
	return pNewFrag;
	}
示例#6
0
void
OOCEnv  ::
RemoveChain( const std::string  & name ){
	 ChainBase * c = GetChain(name);
	 RAssert( c != NULL);
	 c->RemoveAllChunks();		// remove all the chunks
	 chains.erase(name);	// remove the chain from the map of all the chains
	 c->PointedBy(-1);		// delete the datastructure
//	 SaveAT();				// save the updated allocation table
 }
bool CMarkovWordGenerator::FindChainChar (SFragHead *pFrag, char chChar, SChainChar **retpChain)

//	FindChainChar
//
//	Looks for the char in the chain and returns the SChainChar entry.

	{
	SChainChar *pChain = GetChain(pFrag);
	while ((*(DWORD *)pChain) != 0)
		{
		if (pChain->chChar == chChar)
			{
			*retpChain = pChain;
			return true;
			}

		pChain++;
		}

	return false;
	}
示例#8
0
void XViewSpline::Draw()
{
    // TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
    if( GetChain() )
    {
        LPDIRECT3DSURFACE9 pBackBuffer = nullptr;
        GetChain()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
        if( pBackBuffer )
        {
            D3DDEVICE->SetRenderTarget( 0, pBackBuffer );
            D3DDEVICE->Clear( 0, nullptr, D3DCLEAR_TARGET, XCOLOR_GRAY, 1.0f, 0 );
            RECT rect;
            GetClientRect( &rect );
            XE::SetProjection( rect.right-rect.left, rect.bottom-rect.top );
            if(SUCCEEDED(D3DDEVICE->BeginScene()))
            {
                // FrameMove
                FrameMove();
                //
                D3DXVECTOR2 v( 0, 0 );		//
                D3DXMATRIX mWorld, mRot, mTrans, mLocal;
                D3DXMatrixIdentity( &mWorld );
                D3DXMatrixTranslation( &mWorld, vCenter.x, vCenter.y, 0 );
                for( int i = 0; i < MAX_JOINT; ++i )
                {
                    JOINT *j = &m_listJoint[i];

                    // 관절부위에 원을 그림
                    D3DCOLOR col = XCOLOR_WHITE;
                    if( m_idxSelected == i )
                        col = XCOLOR_RED;
                    GRAPHICS->DrawCircle( j->m_vEnd.x, j->m_vEnd.y, 5.f, col );		// 관절끝 부위에 원을 그림
                    GRAPHICS->DrawLine( j->m_vStart.x, j->m_vStart.y, j->m_vEnd.x, j->m_vEnd.y, col );		// 관절 그림
                    // test
                    {
                        D3DXVECTOR2 vA;
                        vA = D3DXVECTOR2( m_vMouse.x, m_vMouse.y ) - s_vC;
                        float rDist = GetAngle( s_vB ) - GetAngle( vA );
                        if( rDist > D2R(180.f) )
                            rDist -= D2R(360.f);
                        else if( rDist < D2R(-180.f) )
                            rDist += D2R(360.f);

                        // draw
                        GRAPHICS->DrawLine( s_vC.x - 100.f, s_vC.y, s_vC.x + 100.f, s_vC.y, XCOLOR_BLUE );
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y - 100.f, s_vC.x, s_vC.y + 100.f, XCOLOR_BLUE );		// 십자선
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + s_vB.x, s_vC.y + s_vB.y, XCOLOR_RED );	// 목표벡터
                        GRAPHICS->DrawLine( s_vC.x, s_vC.y, s_vC.x + vA.x, s_vC.y + vA.y, XCOLOR_WHITE );	// 시작 벡터
                        SE::g_pFDBasic->DrawString( s_vC.x + 5.f, s_vC.y + 5.f, XCOLOR_WHITE, _T("%f(%f)"), R2D(rDist), rDist );

                    }

                    // info
                    SE::g_pFDBasic->DrawString( 5.f, 5.f, XCOLOR_WHITE, _T("%d-%d"), (int)m_vMouse.x, (int)m_vMouse.y );
                    /*					D3DXMatrixRotationZ( &mRot, j->m_rAngle );
                    					D3DXMatrixTranslation( &mTrans, j->m_vLocal.x, j->m_vLocal.y, 0 );
                    					mLocal = mRot * mTrans;
                    					mWorld = mLocal * mWorld;
                    					j->m_mWorld = mWorld;

                    					D3DXVECTOR2 v0 = D3DXVECTOR2( 0, 0 );			// 관절원점
                    					D3DXVECTOR2 v1 = D3DXVECTOR2( LEN_JOINT, 0 );		// 관절끝위치
                    					D3DXVECTOR2 v0T, v1T;
                    					D3DXVec2TransformCoord( &v0T, &v0, &mWorld );
                    					D3DXVec2TransformCoord( &v1T, &v1, &mWorld );
                    					// 관절부위에 원을 그림
                    					D3DCOLOR col = XCOLOR_WHITE;
                    					if( m_idxSelected == i )
                    						col = XCOLOR_RED;
                    					GRAPHICS->DrawCircle( v1T.x, v1T.y, 5.f, col );		// 관절부위에 원을 그림
                    					GRAPHICS->DrawLine( v0T.x, v0T.y, v1T.x, v1T.y, col );		// 관절 그림
                    					if( m_bDrawDebug )
                    					{
                    	//					SE::g_pFDBasic->DrawString( v1T.x + 20.f, v1T.y - 20.f, XCOLOR_WHITE, _T("%f"), j->dot );
                    						// normal
                    						D3DXVECTOR2 v2T;
                    						v1 = j->m_vNormal * 50.f + v0T;
                    				//		D3DXVec2TransformCoord( &v2T, &v1, &mWorld );
                    						GRAPHICS->DrawLine( v0T.x, v0T.y, v1.x, v1.y, XCOLOR_BLUE );		// 노말벡터
                    						// 힘벡터
                    						v1 = j->m_vForce * 300.f;
                    						v2T = v1T + v1;
                    						GRAPHICS->DrawLine( v1T.x, v1T.y, v2T.x, v2T.y, XCOLOR_GREEN );		// 노말벡터
                    					}
                    					*/
                }

                //
                D3DDEVICE->EndScene();
            }
            GetChain()->Present( nullptr, nullptr, GetSafeHwnd(), nullptr, 0 );
            pBackBuffer->Release();
        }
    }

}
CString CMarkovWordGenerator::Generate (void)

//	Generate
//
//	Generates a random word

	{
	int i;

	if (!InitStart())
		return NULL_STR;

	//	Allocate a result buffer

	char szBuffer[1024];
	int iLength = 0;

	//	Start by picking a random fragment

	DWORD dwRoll = (DWORD)mathRandom(1, m_dwStartCount);
	for (i = 0; i < m_Start.GetCount() && dwRoll > m_Start[i]->dwCount; i++)
		dwRoll -= m_Start[i]->dwCount;

	SFragHead *pFrag = m_Start[i];
	szBuffer[0] = pFrag->sFrag[0];
	szBuffer[1] = pFrag->sFrag[1];
	szBuffer[2] = pFrag->sFrag[2];
	char *pPosFrag = szBuffer;
	char *pPos = szBuffer + 3;
	char *pPosEnd = szBuffer + sizeof(szBuffer);

	while (true)
		{
		//	Bounds check

		if (pPos + 1 == pPosEnd)
			{
			*pPos = '\0';
			return CString(szBuffer);
			}

		//	Pick a random character for this fragment

		dwRoll = (DWORD)mathRandom(1, pFrag->dwCount);
		SChainChar *pChain = GetChain(pFrag);
		while ((*(DWORD *)pChain) != 0)
			{
			if (dwRoll <= pChain->dwCount)
				break;

			dwRoll -= pChain->dwCount;
			pChain++;
			}

		//	Are we done?

		if (pChain->chChar == '\0')
			{
			*pPos = '\0';
			return CString(szBuffer);
			}

		//	Add the character

		*pPos++ = pChain->chChar;
		pPosFrag++;

		//	Look for the new fragment

		int iPos;
		if (Find(pPosFrag, &iPos))
			pFrag = m_Table[iPos];
		else
			{
			*pPos = '\0';
			return CString(szBuffer);
			}
		}

	return NULL_STR;
	}