//----------------------------------------------------------------------------//
void Direct3D10RenderTarget::unprojectPoint(const GeometryBuffer& buff,
                                            const Vector2& p_in,
                                            Vector2& p_out) const
{
    if (!d_matrixValid)
        updateMatrix();

    const Direct3D10GeometryBuffer& gb =
        static_cast<const Direct3D10GeometryBuffer&>(buff);

    D3D10_VIEWPORT vp;
    setupViewport(vp);

    D3DXVECTOR3 in_vec;
    in_vec.z = 0.0f;

    // project points to create a plane orientated with GeometryBuffer's data
    D3DXVECTOR3 p1;
    D3DXVECTOR3 p2;
    D3DXVECTOR3 p3;
    in_vec.x = 0;
    in_vec.y = 0;
    D3DXVec3Project(&p1, &in_vec, &vp, &d_matrix, 0, gb.getMatrix()); 

    in_vec.x = 1;
    in_vec.y = 0;
    D3DXVec3Project(&p2, &in_vec, &vp, &d_matrix, 0, gb.getMatrix()); 

    in_vec.x = 0;
    in_vec.y = 1;
    D3DXVec3Project(&p3, &in_vec, &vp, &d_matrix, 0, gb.getMatrix()); 

    // create plane from projected points
    D3DXPLANE surface_plane;
    D3DXPlaneFromPoints(&surface_plane, &p1, &p2, &p3);

    // unproject ends of ray
    in_vec.x = vp.Width * 0.5f;
    in_vec.y = vp.Height * 0.5f;
    in_vec.z = -d_viewDistance;
    D3DXVECTOR3 t1;
    D3DXVec3Unproject(&t1, &in_vec, &vp, &d_matrix, 0, gb.getMatrix()); 

    in_vec.x = p_in.d_x;
    in_vec.y = p_in.d_y;
    in_vec.z = 0.0f;
    D3DXVECTOR3 t2;
    D3DXVec3Unproject(&t2, &in_vec, &vp, &d_matrix, 0, gb.getMatrix()); 

    // get intersection of ray and plane
    D3DXVECTOR3 intersect;
    D3DXPlaneIntersectLine(&intersect, &surface_plane, &t1, &t2);

    p_out.d_x = intersect.x;
    p_out.d_y = intersect.y;
}
Example #2
0
Vec3f VecProject(Vec3f obj, const D3D10_VIEWPORT& vp, const D3DXMATRIX& proj, const D3DXMATRIX& view, const D3DXMATRIX& model)
{
	D3DXVECTOR3 in(obj[0], obj[1], obj[2]);

	D3DXVECTOR3 out;
	D3DXVec3Project(&out, &in, &vp, &proj, &view, &model);
	return Vec3f(out.x, out.y, out.z);

//	Vec4f in = Vec4f(obj[0], obj[1], obj[2], 1) * model;
//	in = in * view;
//	in = in * proj;

#if 0
	D3DXVECTOR4 in(obj[0], obj[1], obj[2], 1);

	D3DXVECTOR4 out;
	D3DXVec4Transform(&out, &in, &model);
	D3DXVec4Transform(&in, &out, &view);
	D3DXVec4Transform(&out, &in, &proj);
	in = out;

//	transform_point_unaligned(out, in, model);
//	transform_point_unaligned(in, out, proj);

	if (in[3] == 0.0f)
	{
		// ??
		in[3] = 0.00001f;
	//	return GL_FALSE;
	}

	in[0] /= in[3];
	in[1] /= in[3];
	in[2] /= in[3];

    /* Map x, y and z to range 0-1 */
    in[0] = in[0] * 0.5 + 0.5;
    in[1] = in[1] * 0.5 + 0.5;
    in[2] = in[2] * 0.5 + 0.5;

    /* Map x,y to viewport */
	in[0] = in[0] * vp.Width + vp.TopLeftX;
	in[1] = in[1] * vp.Height + vp.TopLeftY;
//	in[2] = 1 -in[2];

	return Vec3f(in[0], in[1], in[2]);

	/*
	// window coordinates
	win[0] = viewport[0]+(1+in[0])*viewport[2]/2;
	win[1] = viewport[1]+(1+in[1])*viewport[3]/2;
//	win[1] = viewport[3] - win[1];
		
	// 0..1
	win[2] = (1+in[2])/2;
	*/
#endif
}
Example #3
0
void PhysXProject(float vx, float vy, float vz, int &xi, int &yi, float &depth)
{
	D3DXVECTOR3 output, input;

	input = D3DXVECTOR3(vx, vy, vz);

	D3DXVec3Project(&output, &input, &gViewPort, gViewerCamera.GetProjMatrix(), gViewerCamera.GetViewMatrix(), &gWorldMatrix);

	xi = output.x; yi = output.y; depth = output.z;
}
Example #4
0
void CGraphics::DrawText(CVector3 vecPosition, float fRange, unsigned long ulColor, float fScale, unsigned int fontIndex, unsigned long ulFormat, bool bShadow, const char * szFormat, ...)
{
	// Get the string arguments
	char szBuffer[ 2048 ];
	va_list vArgs;
	va_start(vArgs, szFormat);
	vsprintf(szBuffer, szFormat, vArgs);
	va_end(vArgs);

	// Calc function
	Vector2 vecScreen;

	// Define viewport pointer
	D3DVIEWPORT9 Viewport;

	// Out (2d) position.
	D3DXVECTOR3 Out;

	// Grab 3d position.
	D3DXVECTOR3 Position;
	Position.x = vecPosition.fX;
	Position.y = vecPosition.fY;
	Position.z = vecPosition.fZ;

	// Define all matrix's
	D3DXMATRIX matIdent, matProj, matView;

	// Calculate position.
	D3DXMatrixIdentity(&matIdent);
	m_pDevice->GetViewport(&Viewport);
	m_pDevice->GetTransform(D3DTS_PROJECTION, &matProj);
	m_pDevice->GetTransform(D3DTS_VIEW, &matView);

	D3DXVec3Project(&Out, &Position, &Viewport, &matProj, &matView, &matIdent);

	// Wrap out positions for vector.
	vecScreen.fX = Out.x; vecScreen.fY = Out.y;

	// Calculating range.
	float _fRange = 1.0f;
	CVector3 vecLocalPos;		
	g_pCore->GetGame()->GetLocalPlayer()->GetPosition(vecLocalPos);

	// Check range status. (Is -1 disabled)
	if(fRange != -1.0f)
		_fRange = abs(sqrt((vecLocalPos.fX*vecPosition.fX)+(vecLocalPos.fY*vecPosition.fY)+(vecLocalPos.fZ*vecPosition.fZ)));

	// Draw the text
	if(_fRange >= fRange)
		DrawText((unsigned int)vecScreen.fX, (unsigned int)vecScreen.fY, (unsigned int)vecScreen.fX, (unsigned int)vecScreen.fY, ulColor, fScale, fScale, ulFormat, fontIndex, bShadow, szBuffer); 
}
Example #5
0
INTPOINT GetScreenPos(D3DXVECTOR3 pos, IDirect3DDevice9* Device)
{
	D3DXVECTOR3 screenPos;
	D3DVIEWPORT9 Viewport;
	D3DXMATRIX Projection, View, World;

	Device->GetViewport(&Viewport);
	Device->GetTransform(D3DTS_VIEW, &View);
	Device->GetTransform(D3DTS_PROJECTION, &Projection);
	D3DXMatrixIdentity(&World);
	D3DXVec3Project(&screenPos, &pos, &Viewport, &Projection, &View, &World);

	return INTPOINT((int)screenPos.x, (int)screenPos.y);
}
Example #6
0
File: math.c Project: devyn/wine
/*************************************************************************
 * D3DXVec3ProjectArray
 *
 * Projects an array of vectors to the screen.
 */
D3DXVECTOR3* WINAPI D3DXVec3ProjectArray(
    D3DXVECTOR3* out, UINT outstride, CONST D3DXVECTOR3* in, UINT instride,
    CONST D3DVIEWPORT9* viewport, CONST D3DXMATRIX* projection,
    CONST D3DXMATRIX* view, CONST D3DXMATRIX* world, UINT elements)
{
    UINT i;
    TRACE("\n");
    for (i = 0; i < elements; ++i) {
        D3DXVec3Project(
            (D3DXVECTOR3*)((char*)out + outstride * i),
            (CONST D3DXVECTOR3*)((const char*)in + instride * i),
            viewport, projection, view, world);
    }
    return out;
}
Vector3f Camera::projectPosition(const Vector3f& position)
{
    assert( _frame );
    _frame->getLTM();

    Vector p = wrap( position );
    Vector s;
    Matrix v;

    // view matrix
    D3DXMatrixInverse( &v, NULL, &_frame->LTM );
    // projection routine
    D3DXVec3Project( &s, &p, &_viewPort, &_projection, &v, &identity );

    return wrap( s );
}
void CMglMatrixManager::ConvertToScreenVector(D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pInVector)
{
	InitCheck();

	_D3DVIEWPORTx vp;
	vp.X = 0;
	vp.Y = 0;
	vp.Width = m_myudg->GetWidth();
	vp.Height = m_myudg->GetHeight();
	vp.MinZ = 0.0f;
	vp.MaxZ = 1.0f;
	
	D3DXVec3Project(pOut, pInVector, &vp,
		&(GetProjectionMatrix()),
		&(GetViewMatrix()),
		+&(m_pWorldMgr->GetMatrix()));
}
Example #9
0
int Sound::HitTest(const D3DXMATRIX& projection, const D3DXMATRIX& view, const D3DXMATRIX& model, const D3D10_VIEWPORT& vp, int type, Vec2f mousepos, Vec3f pos, IHitTest* hitTest)
{
	D3DXVECTOR3 location(m_location->getValue());
//	D3DXVECTOR4 v;

//	D3DXVec3Transform(&v, &location, &modelView);

	D3DXVECTOR3 out;
	D3DXVec3Project(&out, &location, &vp, &projection, &view, &model);

	if (fabs(mousepos[0]-out.x) < 3 &&
		fabs(mousepos[1]-out.y) < 3)
	{
		hitTest->OnHit(this, type, *(Vec3f*)&out);
		return 1;
	}

	return 0;
}
Example #10
0
Vector3 RenderTargetD3D9::project(const Vector3 & v)
{
    //world matrix
    D3DXMATRIX matWorldD3D ( MappingsD3D9::getMatrix( m_RenderState.m_mtxWorld ) );
    //view matrix
    xs::Matrix4 matView( m_RenderState.m_mtxView );
    matView[2][0] = -matView[2][0];
    matView[2][1] = -matView[2][1];
    matView[2][2] = -matView[2][2];
    matView[2][3] = -matView[2][3];
    D3DXMATRIX matViewD3D( MappingsD3D9::getMatrix( matView ) );
    //projection matrix
    xs::Matrix4 matProj;
    convertProjectionMatrix(m_RenderState.m_mtxProjection, matProj, false);
    D3DXMATRIX matProjD3D( MappingsD3D9::getMatrix( matProj) );

    D3DXVECTOR3 vin(v.x, v.y, v.z);
    D3DXVECTOR3 vout;
    D3DXVec3Project(&vout, &vin, &m_viewport, &matProjD3D, &matViewD3D, &matWorldD3D);
    return Vector3(vout.x, vout.y, vout.z);
}
Example #11
0
void GERendering::worldToScreen(const GEVector* PositionWorld, GEVector* PositionScreen)
{
    D3DXMATRIX matProjection;
    d3ddev->GetTransform(D3DTS_PROJECTION, &matProjection);

    D3DXMATRIX matView;
    d3ddev->GetTransform(D3DTS_VIEW, &matView);

    D3DXMATRIX matIdentity;
    D3DXMatrixIdentity(&matIdentity);
    
    D3DVIEWPORT9 vPort;
    d3ddev->GetViewport(&vPort);

    D3DXVECTOR3 vPositionWorld(PositionWorld->X, PositionWorld->Y, PositionWorld->Z);

    D3DXVECTOR3 vPositionScreen;
    D3DXVec3Project(&vPositionScreen, &vPositionWorld, &vPort, &matProjection, &matView, &matIdentity);

    PositionScreen->X = vPositionScreen.x;
    PositionScreen->Y = vPositionScreen.y;
    PositionScreen->Z = vPositionScreen.z;  // if < 1.0f, then the world position is in the screen
}
Example #12
0
void Screen3D::GetScreenCoordinates( Vector3D* Out, Vector3D& Input )
{

	//Declarations
	D3DXVECTOR3 out,  in;
	D3DVIEWPORT9 viewport;
	D3DXMATRIX mView, mWorld, mProjection, mInvertedView ;


	//Get the variables we need
	in = Input;
	D3DDevice->GetViewport( &viewport);
	D3DDevice->GetTransform( D3DTS_VIEW, &mView );
	D3DDevice->GetTransform( D3DTS_WORLD, &mWorld );
	D3DDevice->GetTransform( D3DTS_PROJECTION, &mProjection );

	
	//project the vector
	D3DXVec3Project(&out, &in, &viewport, &mProjection, &mView, &mWorld );

	//done! We now have the projected (screen) coordinates
	*Out = out;
}
Example #13
0
void LensFlare::render(ICamera *cam, Vec3 sunPos)
{
	Vec3 sunPosScreen;
	Vec2 vecSunToCenter;
	Mat world;
	Vec2 screenCenter;
	D3DVIEWPORT9 viewport;
	gEngine.device->getDev()->GetViewport(&viewport);
	D3DXMatrixTranslation(&world, 0, 0, 0);
	D3DXVec3Project(&sunPosScreen, &sunPos, &viewport, cam->getProjectionMat(), cam->getViewMat(), &world);
	//gEngine.renderer->addTxt("%.3f %.3f %.3f", sunPosScreen.x, sunPosScreen.y, sunPosScreen.z);
	screenCenter.x = viewport.Width/2;
	screenCenter.y = viewport.Height/2;
	vecSunToCenter = screenCenter - Vec2(sunPosScreen);

	Vec3 sunToCam = sunPos - *cam->getPosition();
	D3DXVec3Normalize(&sunToCam, &sunToCam);
	if(acos(D3DXVec3Dot(&sunToCam, cam->getViewDirection())) < cam->getFOV())

	for(int i = 0; i < 11; i++)
	{
		if(m_flares[i].texture)
		{
			//Vec2 flarePos = vecSunToCenter * m_flares[i].distance + Vec2(sunPosScreen.x, sunPosScreen.y);
			Vec2 flarePos = vecSunToCenter * m_flares[i].distance + Vec2(sunPosScreen.x, sunPosScreen.y);
			gEngine.renderer->r2d->drawQuad(m_flares[i].texture, flarePos.x - m_flares[i].texture->width/2,
																 flarePos.y - m_flares[i].texture->height/2, 
																 flarePos.x + m_flares[i].texture->width/2, 
																 flarePos.y + m_flares[i].texture->height/2, 
																 D3DCOLOR_ARGB(255, 255, 255, 255), 
																 D3DCOLOR_ARGB(255, 255, 255, 255),
																 D3DCOLOR_ARGB(255, 255, 255, 255),
																 D3DCOLOR_ARGB(255, 255, 255, 255));
		}
	}
}
	//=============================================================================================================
	void CLensFlareRenderer9::Draw()
	{
		if( !CanBeApplied() )
			return;

		// a nézeti mátrix elsö oszlopa a nézési irány
		viewdir.x = View._13;
		viewdir.y = View._23;
		viewdir.z = View._33;

		lightpos = Eye + Sun;
		vdotl = D3DXVec3Dot(&viewdir, &lightpos);

		// ha háttal vagyunk a fénynek akkor nincs mit rajzolni
		if( vdotl / D3DXVec3Length(&lightpos) < 0 ) return;
		D3DXVec3Project(&lightpos, &lightpos, &viewport, &Projection, &View, &id);

		ctol.x = lightpos.x - center.x;
		ctol.y = lightpos.y - center.y;

		length = D3DXVec2Length(&ctol);
		alpha = 1.0f - (length / halfdiagonal);

		// ha valami eltakarja a fényforrást
		etos = Sun;
		D3DXVec3Normalize(&etos, &etos);

		for( occluderlist::iterator it = occluders.begin(); it != occluders.end(); ++it )
		{
			etoc = it->center - Eye;
			dist = D3DXVec3Length(&etoc);

			D3DXVec3Normalize(&etoc, &etoc);
			cosa = D3DXVec3Dot(&etoc, &etos);

			x = cosa * dist;
			rad = dist * dist - x * x;

			rad /= (it->radius * it->radius);
			alpha *= min(1, rad * rad);
		}

		color.a = min(1, alpha);
		D3DXVec2Normalize(&ctol, &ctol);

		// render
		manager->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
		manager->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		manager->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

		for( int i = 0; i < _FLARECOUNT_; ++i )
		{
			scaleddir = center + ctol * length * flares[i].scale;

			D3DXMatrixScaling(&scale, flares[i].size, flares[i].size, 1);
			D3DXMatrixTranslation(&translate, scaleddir.x - flares[i].size * 0.5f, scaleddir.y - flares[i].size * 0.5f, 0);
			D3DXMatrixMultiply(&transform, &scale, &translate);

			manager->SetTexture(0, lens[flares[i].index]);
			game->DrawImage(transform, color);
		}

		manager->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
	}
Example #15
0
void SpherePopup::Update()
{
	D3DXVECTOR3 t;
	auto vp = GraphicsEngine::GetViewport();
	viewport.Width = vp.Width;
	viewport.Height = vp.Height;
	D3DXVec3Project(&t, &worldPos, &viewport, &projection, &view, &world);
	windowWP.x = t.x;
	windowWP.y = t.y;

	D3DXVECTOR4 t4;
	t = worldPos;
	t.y = 0;
	D3DXVec3Normalize(&t, &t);
	D3DXVec3Transform(&t4, &t, &world);
	
	if (animationState > .99f && t4.z <= .5f)
	{
		animationMultiplier = -1;
	}

	if (animationState < 0)
		isDead = true;

	if (animationState < 0.3333f)
	{
		if (windowPos.x < Window::GetWidth() / 2)//line should go to the right top corner
			animationState += animationMultiplier * .3333f * 10 / D3DXVec2Length(&(windowWP - windowPos2));
		else
			animationState += animationMultiplier * .3333f * 10 / D3DXVec2Length(&(windowWP - windowPos));
	}
	else if (animationState < 0.6666f)
	{
		animationState += animationMultiplier * .3333f * 10 / 192;
	}
	else
	{
		animationState += animationMultiplier * .3333f * 10 / 128;
		if (animationState > 1)
		{
			animationState = 1;
			animationMultiplier = 0;
		}
	}

	float s1 = animationState * 3,
		s2 = animationState * 3 - 1,
		s3 = animationState * 3 - 2;

	vLines[0] = windowWP.x;
	vLines[1] = windowWP.y;
	vLines[3] = lerp(windowWP.y, windowPos.y, s1);
	vLines[5] = vLines[7] = vLines[9] = vLines[19] = vWindow[1] = vWindow[5] = windowPos.y;
	vLines[11] = vLines[13] = vLines[15] = vLines[17] = vWindow[3] = vWindow[7] = lerp(windowPos.y, windowPos2.y, s3);

	if (windowPos.x < Window::GetWidth() / 2)//line should go to the right top corner
	{
		vLines[2] = lerp(windowWP.x, windowPos2.x, s1);
		vLines[4] = vLines[14] = vLines[16] = vLines[18] = vWindow[4] = vWindow[6] = windowPos2.x;
		vLines[6] = vLines[8] = vLines[10] = vLines[12] = vWindow[0] = vWindow[2] = lerp(windowPos2.x, windowPos.x, s2);
	}
	else
	{
		vLines[2] = lerp(windowWP.x, windowPos.x, s1);
		vLines[4] = vLines[14] = vLines[16] = vLines[18] = vWindow[0] = vWindow[2] = windowPos.x;
		vLines[6] = vLines[8] = vLines[10] = vLines[12] = vWindow[4] = vWindow[6] = lerp(windowPos.x, windowPos2.x, s2);
	}

	if (s3 > 0)
	{
		vWindow[3]--;
		vWindow[4]--;
		vWindow[6]--;
		vWindow[7]--;
	}

	meshLines->SetRawData(vLines, 20, 20 * sizeof(float), 2 * sizeof(float));
	meshWindow->SetRawData(vWindow, 8, 8 * sizeof(float), 2 * sizeof(float));
}
void ToolDoorEdit::DrawSelected(void)
{
	DWORD dwSelCount = (DWORD)m_vSelGridIndexArray.size();
	if (!dwSelCount) return;
	render::Interface::Layer3D *pLayer3D = render::Interface::GetInstance()->GetLayer3D();
	render::Interface::Layer2D *pLayer2D = render::Interface::GetInstance()->GetLayer2D();

	D3DVIEWPORT9 tViewport;
	render::Interface::GetInstance()->GetDevice()->GetViewport(&tViewport);
	D3DXMATRIX matWrold;
	D3DXMatrixIdentity(&matWrold);

	//循环可见格子
	EditMap *pMap = CommDB::GetInstance()->GetMap();
	Grid	*pMapGrid(NULL);
	TerrainMesh *pMesh = CommDB::GetInstance()->GetTerrainMesh();
	TerrainMesh::_tagGrid *pGrid(NULL);
	TerrainMesh::_tagVertex *pVertexArray = pMesh->GetVertexList();
	
	static D3DXVECTOR3 pos[4],vCenter;;
	
	WndDoorEdit *pWndDoorEdit = CommUI::GetInstance()->GetEditWnd()->GetWndDoorEdit();
	render::Camera *pCamera = CommUI::GetInstance()->GetEditWnd()->GetCamera();
	for(DWORD n = 0;n < dwSelCount; n++)
	{
		DWORD dwGridIndex = m_vSelGridIndexArray[n];
		pMapGrid = pMap->GetGrid(dwGridIndex);
		pMap->GetGridPosition(dwGridIndex,pos,&vCenter);
		pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[1],&pos[2],0xa077ff77);
		pLayer3D->_DEBUG_DrawTriangle(&pos[0],&pos[2],&pos[3],0xa077ff77);
		//画名字
		int iDoorIndex = pMapGrid->GetDoorIndex() - 1;
		if (iDoorIndex >= 0)
		{
			D3DXVec3Project(&vCenter,&vCenter,&tViewport,pCamera->GetProjectionMatrix(),
				pCamera->GetViewMatrix(),&matWrold);
			tagDoor *pDoor = pWndDoorEdit->GetDoor(iDoorIndex);
			int iTexLen = lstrlen(pDoor->szName);

			int iTextWidth = pLayer2D->CalcTextWidth(pDoor->szName,iTexLen);
			int iTextHeight= pLayer2D->GetFontSize();

			int iWidth = iTextWidth + 16;	

			int iStartX = (int)vCenter.x - iWidth / 2;
			int iStartY = (int)vCenter.y - iTextHeight/2;

			pLayer2D->DrawSolidQuad(iStartX - 2,iStartY ,iTextWidth + 8,iTextHeight + 2 ,0x80bbc5ff);

			ui::Wnd::SetUIRendState();
			pLayer2D->OutPutText(iStartX + 1,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX + 1,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX + 1,iStartY,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX - 1,iStartY,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX,iStartY + 1,pDoor->szName,iTexLen,FWC_BLACK);
			pLayer2D->OutPutText(iStartX,iStartY - 1,pDoor->szName,iTexLen,FWC_BLACK);  
			pLayer2D->OutPutText(iStartX,iStartY,pDoor->szName,iTexLen,0xFF44FF55);  

		}
	}
}
Example #17
0
void EFFECT_LENSFLARE::Render()
{
	if(sprite == NULL || lensflareTexture == NULL)return;

	RECT sourceRectangles[7] = {{0, 0, 128, 128},
								{128, 0, 256, 128},
								{0, 128, 128, 256},
								{128, 128, 192, 192},
								{192, 128, 256, 192},
								{128, 192, 192, 256},
								{192, 192, 256, 256}};

	//Calculate screen position of light source
	D3DXVECTOR3 screenPos;
	D3DVIEWPORT9 Viewport;
	D3DXMATRIX Projection, View, World;
	m_pDevice->GetViewport(&Viewport);
	m_pDevice->GetTransform(D3DTS_VIEW, &View);
	m_pDevice->GetTransform(D3DTS_PROJECTION, &Projection);
	D3DXMatrixIdentity(&World);
	D3DXVec3Project(&screenPos, &m_position, &Viewport, &Projection, &View, &World);

	//Get viewport
	D3DVIEWPORT9 v;
	m_pDevice->GetViewport(&v);

	//Check that light source is within or without the screen bounds
	if(screenPos.x < 0 || screenPos.x > v.Width ||
	   screenPos.y < 0 || screenPos.y > v.Height || screenPos.z > 1.0f)
		m_inScreen = false;
	else m_inScreen = true;

	//Lensflares aren't visible so exit function...
	if(m_mainAlpha <= 0.0f)return;
	
	//Calculate the ray from the screen center to the light source
	D3DXVECTOR2 lightSource = D3DXVECTOR2(screenPos.x, screenPos.y);
	D3DXVECTOR2 screenCenter = D3DXVECTOR2(v.Width * 0.5f, v.Height * 0.5f);
	D3DXVECTOR2 ray = screenCenter - lightSource;

	//Draw the different flares
	D3DXMATRIX sca;
	sprite->Begin(D3DXSPRITE_ALPHABLEND);
	for(int i=0;i<(int)m_flares.size();i++)
	{
		//Calculate Flare position in screen coordinates
		RECT r = sourceRectangles[m_flares[i].sourceFlare];
		D3DXVECTOR2 offset = D3DXVECTOR2((r.right - r.left) / 2.0f, (r.bottom - r.top) / 2.0f) * m_flares[i].scale;
		D3DXVECTOR2 flarePos = lightSource + ray * m_flares[i].place - offset;

		//Scale
		D3DXMatrixScaling(&sca, m_flares[i].scale, m_flares[i].scale, 1.0f);

		//Calculate flare alpha
		D3DXCOLOR m_color = m_flares[i].m_color;
		float alpha = (D3DXVec2Length(&((flarePos + offset) - screenCenter)) + 150.0f) / (float)v.Height;
		if(alpha > 1.0f)alpha = 1.0f;
		m_color.a = alpha * m_mainAlpha * 1.5f;

		//Draw Flare
		sprite->SetTransform(&sca);
		sprite->Draw(lensflareTexture, &r, NULL, &D3DXVECTOR3(flarePos.x / m_flares[i].scale, flarePos.y / m_flares[i].scale, 0.0f), m_color);
	}
	sprite->End();

	D3DXMatrixIdentity(&sca);
	sprite->SetTransform(&sca);
}
Example #18
0
void CDialogMsg::Render( C2DRender* p2DRender )
{
	CSize size;	
	LPCUSTOMTEXT lpCustomText;

//	CD3DFont* pOldFont = p2DRender->GetFont();
//	p2DRender->SetFont( CWndBase::m_Theme.m_pFontWndTitle );
	
	LPDIRECT3DDEVICE9 pd3dDevice = p2DRender->m_pd3dDevice;
	
	pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU, 1 );
	pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV, 1 );
	pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );		
	pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );		
	
	pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );	
	pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
	
	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR  );
	
	TEXTUREVERTEX vertex[ 4 * 18 ];
	CPoint point;
	int nIndex;
		
	for( int i = 0; i < m_textArray.GetSize(); i++ )
	{
		lpCustomText = (LPCUSTOMTEXT) m_textArray.GetAt( i );
		TEXTUREVERTEX* pVertices = vertex; 
		if( !lpCustomText->m_bInfinite && lpCustomText->m_timer.TimeOut() )
		{
			// 퀘스트 이모티콘을 다시 보이게 한다.
			if( lpCustomText->m_pObj->GetType() == OT_MOVER )
				((CMover*)lpCustomText->m_pObj)->m_bShowQuestEmoticon = TRUE;
			safe_delete( lpCustomText );
			m_textArray.RemoveAt( i );
			i --;
		}
		else
		{
			CObj* pObj = lpCustomText->m_pObj;
			if( lpCustomText->m_pTexture )
			{
				if( pObj->IsCull() == FALSE )
				{
					// 월드 좌표를 스크린 좌표로 프로젝션 한다.
					D3DXVECTOR3 vOut, vPos = pObj->GetPos(), vPosHeight;
					D3DVIEWPORT9 vp;
					const BOUND_BOX* pBB;
					
					if( pObj->m_pModel )
						pBB	= pObj->m_pModel->GetBBVector();
					else
						return;

					pd3dDevice->GetViewport( &vp );

					D3DXMATRIX matTrans;
					D3DXMATRIX matWorld;
					D3DXMatrixIdentity(&matWorld);
					D3DXMatrixTranslation( &matTrans, vPos.x, vPos.y , vPos.z);

					D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixScale() );
					D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixRotation() );
					D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

					vPosHeight = pBB->m_vPos[0];
					vPosHeight.x = 0;
					vPosHeight.z = 0;
					
					D3DXVec3Project( &vOut, &vPosHeight, &vp, &pObj->GetWorld()->m_matProj,
						&pObj->GetWorld()->m_pCamera->m_matView, &matWorld);

					CPoint point;
					point.x = (LONG)( vOut.x - 32 / 2 );
					point.y = (LONG)( vOut.y - 32 );
					
					MakeEven( point.x );			
	
					p2DRender->RenderTexture( point, lpCustomText->m_pTexture );
				}
			}
			else
			{
			LPCTSTR lpStr = lpCustomText->m_string;
			lpCustomText->m_pFont->GetTextExtent( (TCHAR*)lpStr, &size );
			if( pObj->IsCull() == FALSE )
			{
				int nAlpha = 200;
				if( !lpCustomText->m_bInfinite && lpCustomText->m_timer.GetLeftTime() > 4000 )
					nAlpha = (int)( 200 - ( ( lpCustomText->m_timer.GetLeftTime() - 4000 )* 200 / 1000 ) );
	
				// 월드 좌표를 스크린 좌표로 프로젝션 한다.
				D3DXVECTOR3 vOut, vPos = pObj->GetPos(), vPosHeight;
				D3DVIEWPORT9 vp;
				const BOUND_BOX* pBB;
				
				if( pObj->m_pModel )
					pBB	= pObj->m_pModel->GetBBVector();
				else
					return;

				pd3dDevice->GetViewport( &vp );

				D3DXMATRIX matTrans;
				D3DXMATRIX matWorld;
				D3DXMatrixIdentity(&matWorld);
				D3DXMatrixTranslation( &matTrans, vPos.x, vPos.y , vPos.z);

				D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixScale() );
				D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixRotation() );
				D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

				vPosHeight = pBB->m_vPos[0];
				vPosHeight.x = 0;
				vPosHeight.z = 0;
				
				D3DXVec3Project( &vOut, &vPosHeight, &vp, &pObj->GetWorld()->m_matProj,
					&pObj->GetWorld()->m_pCamera->m_matView, &matWorld);
			
				CRect rect = lpCustomText->m_rect;
				vOut.x -= rect.Width() / 2;
				vOut.y -= rect.Height();
				CPoint ptOrigin = p2DRender->GetViewportOrg();

				vOut.y *= 0.9f;

				FLOAT x = vOut.x;
				FLOAT y = vOut.y;

				int nHeight = rect.Height() / 8;
				int nWidth  = rect.Width()  / 8;
				CTexture* pTexture;

				FLOAT fEdge  = 8.0f;
				FLOAT fWidth = ( nWidth <= 5 ) ? rect.Width() * 0.7f : rect.Width() * 0.9f;
				FLOAT fHeight = rect.Height() * 0.75f;

				FLOAT fOffsetX = 0;
				FLOAT fOffsetY = 0;
				
				nIndex = 0;

				int i;
				

				if( lpCustomText->m_nKind == CHAT_SHOUT )
				{
					char buffer[256] = { 0 };
					
					// 텍스쳐렌더 버그 관련 수정
					CTexture* pShoutTex = NULL;

					int nlen = _tcsclen(lpStr);

					if( nlen >= 1 && nlen <= 1 )
						strcpy( buffer, "texDialogBoxShout00.bmp" );
					else
						if( nlen >= 2 && nlen <= 3 )
							strcpy( buffer, "texDialogBoxShout01.bmp" );
						else
							if( nlen >= 4 && nlen <= 5 )
								strcpy( buffer, "texDialogBoxShout02.bmp" );
							else
								if( nlen >= 6 && nlen <= 9 )
									strcpy( buffer, "texDialogBoxShout03.bmp" );
								else
									if( nlen >= 10 && nlen <= 20 )
										strcpy( buffer, "texDialogBoxShout04.bmp" );
									else
										if( nlen >= 21 && nlen <= 40 )
											strcpy( buffer, "texDialogBoxShout05.bmp" );
										else
											if( nlen >= 41 && nlen <= 60 )
												strcpy( buffer, "texDialogBoxShout06.bmp" );
											else
												if( nlen >= 61 )
													strcpy( buffer, "texDialogBoxShout07.bmp" );

					pShoutTex = CWndBase::m_textureMng.AddTexture( g_Neuz.m_pd3dDevice, MakePath( DIR_THEME, buffer ), 0xffff00ff );
					if( pShoutTex )
					{
						p2DRender->RenderTextureEx( CPoint( (int)( x-20 ), (int)( y-20 ) ), CPoint( (int)( fWidth+50.0f ), (int)( fHeight+40.0f ) ), pShoutTex, nAlpha, 1.0f, 1.0f, FALSE );
						goto g_ShoutChat;
					}
				}


				for( i=0; i<3; i++ )
				{
					if( i==0 || i==2 )
						fOffsetY=fEdge;
					else
						fOffsetY=fHeight;
					
					fOffsetX = 0;

					for( int j=0; j<3; j++ )
					{
						if( j==0 || j==2 )
							fOffsetX = fEdge;
						else
							fOffsetX = fWidth;

						pTexture = m_texPack_ex[lpCustomText->m_nKind].GetAt( nIndex );

						SetTextureVertex( pVertices, x, y, pTexture->m_fuLT, pTexture->m_fvLT );
						pVertices++;
						SetTextureVertex( pVertices, x+fOffsetX, y, pTexture->m_fuRT, pTexture->m_fvRT );
						pVertices++;
						SetTextureVertex( pVertices, x, y+fOffsetY, pTexture->m_fuLB, pTexture->m_fvLB );
						pVertices++;
						SetTextureVertex( pVertices, x, y+fOffsetY, pTexture->m_fuLB, pTexture->m_fvLB );
						pVertices++;
						SetTextureVertex( pVertices, x+fOffsetX, y, pTexture->m_fuRT, pTexture->m_fvRT );
						pVertices++;
						SetTextureVertex( pVertices, x+fOffsetX, y+fOffsetY, pTexture->m_fuRB, pTexture->m_fvRB );
						pVertices++;

						x+=fOffsetX;			

						nIndex++;
					}

					x = vOut.x;
					
					y+=fOffsetY;

				}

				// 꼬랑지 출력 
				if( nWidth >= 6 )
				{
					point =  CPoint( (int)( x + ( 3 * nWidth / 5 ) * 8 ), (int)( y ) );
					nIndex = 9;
				}
				else
				if( nWidth == 4 || nWidth == 5 ) 
				{
					point =  CPoint( (int)( x + 3 * 8 ), (int)( y ) );
					nIndex = 9;
				}
				else
				if( nWidth == 3 ) 
				{
					point =  CPoint( (int)( x + 1 * 8 ), (int)( y ) );
					nIndex = 9;
				}
				pTexture = m_texPack_ex[lpCustomText->m_nKind].GetAt( nIndex );

				SetTextureVertex( pVertices, (FLOAT)( point.x ), (FLOAT)( point.y ), pTexture->m_fuLT, pTexture->m_fvLT );
				pVertices++;
				SetTextureVertex( pVertices, (FLOAT)( point.x + 8.0f ), (FLOAT)( point.y ), pTexture->m_fuRT, pTexture->m_fvRT);
				pVertices++;
				SetTextureVertex( pVertices, (FLOAT)( point.x ), (FLOAT)( point.y + 8.0f ), pTexture->m_fuLB, pTexture->m_fvLB);
				pVertices++;
				
				SetTextureVertex( pVertices, (FLOAT)( point.x + 8.0f ), (FLOAT)( point.y ), pTexture->m_fuRT, pTexture->m_fvRT);
				pVertices++;
				SetTextureVertex( pVertices, (FLOAT)( point.x ), (FLOAT)( point.y + 8.0f ), pTexture->m_fuLB, pTexture->m_fvLB);
				pVertices++;
				SetTextureVertex( pVertices, (FLOAT)( point.x + 8.0f ), (FLOAT)( point.y + 8.0f ), pTexture->m_fuRB, pTexture->m_fvRB);
				pVertices++;

				pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( nAlpha, 0, 0, 0 ) );
				pd3dDevice->SetVertexShader( NULL );

				pd3dDevice->SetTexture( 0, m_texPack_ex[lpCustomText->m_nKind].GetAt( 0 )->m_pTexture );
				
				pd3dDevice->SetFVF( D3DFVF_TEXTUREVERTEX );
				pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 20, vertex, sizeof( TEXTUREVERTEX ) );

g_ShoutChat:

				/*
				CPoint point;
				point.x = vOut.x + 8;;		
				point.y = vOut.y + 8;;		
				*/

				x = vOut.x + 8;
				y = vOut.y + 8;
				x -= ptOrigin.x;
				y -= ptOrigin.y;
				/*
				point.x -= ptOrigin.x;
				MakeEven( point.x );
				point.y -= ptOrigin.y;
				*/
				
				lpCustomText->m_string.SetAlpha( nAlpha );
//				p2DRender->TextOut_EditString( point.x, point.y, lpCustomText->m_string, 0, 0, 0 );
				p2DRender->TextOut_EditString( (int)( x ), (int)( y ), lpCustomText->m_string, 0, 0, 0 );
			}
			}
		}
	}
	
	for( i = 0; i < m_VendortextArray.GetSize(); i++ )
	{
		lpCustomText = (LPCUSTOMTEXT) m_VendortextArray.GetAt( i );
		TEXTUREVERTEX* pVertices = vertex; 

		LPCTSTR lpStr = lpCustomText->m_string;
		lpCustomText->m_pFont->GetTextExtent( (TCHAR*)lpStr, &size );
		CObj* pObj = lpCustomText->m_pObj;
		if( pObj->IsCull() == FALSE )
		{
			int nAlpha = 200;

			// 월드 좌표를 스크린 좌표로 프로젝션 한다.
			D3DXVECTOR3 vOut, vPos = pObj->GetPos(), vPosHeight;
			D3DVIEWPORT9 vp;
			const BOUND_BOX* pBB;
			
			if( pObj->m_pModel )
				pBB	= pObj->m_pModel->GetBBVector();
			else
				return;

			pd3dDevice->GetViewport( &vp );

			D3DXMATRIX matTrans;
			D3DXMATRIX matWorld;
			D3DXMatrixIdentity(&matWorld);
			D3DXMatrixTranslation( &matTrans, vPos.x, vPos.y , vPos.z);

			D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixScale() );
			D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixRotation() );
			D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

			vPosHeight = pBB->m_vPos[0];
			vPosHeight.x = 0;
			vPosHeight.z = 0;
			
			D3DXVec3Project( &vOut, &vPosHeight, &vp, &pObj->GetWorld()->m_matProj,
				&pObj->GetWorld()->m_pCamera->m_matView, &matWorld);
		
			CRect rect = lpCustomText->m_rect;
			vOut.x -= rect.Width() / 2;
			vOut.y -= rect.Height();
			DWORD dwMaxHeight = lpCustomText->m_pFont->GetMaxHeight();
			CPoint ptOrigin = p2DRender->GetViewportOrg();

			int x = (int)( vOut.x );
			int y = (int)( vOut.y );
			int nHeight = rect.Height() / 8;
			int nWidth  = rect.Width()  / 8;

			FLOAT fGap    = 40;
			FLOAT fWidth  = (FLOAT)( rect.Width() );
			FLOAT fHeight = rect.Height()*0.8f;

			fGap += 2.0f;

			CPoint ptTex1;
			CPoint ptTex2;
			
			ptTex1.x = (LONG)( vOut.x-24 );
			ptTex1.y = (LONG)( vOut.y-fGap );
			
			p2DRender->RenderTexture(ptTex1, m_pTex[0], nAlpha, 1.0f, 1.0f );

			ptTex1.x = (LONG)( vOut.x+8 );
			ptTex1.y = (LONG)( vOut.y-fGap );
				
			ptTex2.x = (int)fWidth;
			ptTex2.y = 32;
			p2DRender->RenderTextureEx( ptTex1, ptTex2, m_pTex[1], nAlpha, 1.0f, 1.0f );

			ptTex1.x = (LONG)( (int)(vOut.x+8)+ptTex2.x );
			ptTex1.y = (LONG)( vOut.y-fGap );
				
			p2DRender->RenderTexture(ptTex1, m_pTex[2], nAlpha, 1.0f, 1.0f );

			fGap -= 2.0f;
			x = (int)( vOut.x + 8 );
			y = (int)( vOut.y + 8 );
			x -= ptOrigin.x;
			y -= ptOrigin.y;
			lpCustomText->m_string.SetAlpha( 250 );
			p2DRender->TextOut_EditString( x, (int)( y-fGap ), lpCustomText->m_string, 0, 0, 0 );
		}
	}
}
Example #19
0
void CDialogMsg::Render( C2DRender* p2DRender )
{
	CSize size;	
	LPCUSTOMTEXT lpCustomText;
	for( int i = 0; i < m_textArray.GetSize(); i++ )
	{
		lpCustomText = (LPCUSTOMTEXT) m_textArray.GetAt( i );
		if( lpCustomText->m_timer.TimeOut() )
		{
			// 퀘스트 이모티콘을 다시 보이게 한다.
			if( lpCustomText->m_pObj->GetType() == OT_MOVER )
				((CMover*)lpCustomText->m_pObj)->m_bShowQuestEmoticon = TRUE;
			safe_delete( lpCustomText );
			m_textArray.RemoveAt( i );
			i --;
		}
		else
		{
			LPCTSTR lpStr = lpCustomText->m_string;
			lpCustomText->m_pFont->GetTextExtent( (TCHAR*)lpStr, &size );
			CObj* pObj = lpCustomText->m_pObj;

			if( pObj->IsCull() == FALSE )
			{
				int nAlpha = 200;
				if( lpCustomText->m_timer.GetLeftTime() > 4000 )
					nAlpha = 200 - ( ( lpCustomText->m_timer.GetLeftTime() - 4000 )* 200 / 1000 );
				LPDIRECT3DDEVICE9 pd3dDevice = p2DRender->m_pd3dDevice;

				// 월드 좌표를 스크린 좌표로 프로젝션 한다.
				D3DXVECTOR3 vOut, vPos = pObj->GetPos(), vPosHeight;
				D3DVIEWPORT9 vp;
				const BOUND_BOX* pBB = pObj->m_pModel->GetBBVector();

				pd3dDevice->GetViewport( &vp );

				D3DXMATRIX matTrans;
				D3DXMATRIX matWorld;
				D3DXMatrixIdentity(&matWorld);
				D3DXMatrixTranslation( &matTrans, vPos.x, vPos.y , vPos.z);

				D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixScale() );
				D3DXMatrixMultiply( &matWorld, &matWorld, &pObj->GetMatrixRotation() );
				D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

				vPosHeight = pBB->m_vPos[0];
				vPosHeight.x = 0;
				vPosHeight.z = 0;
				
				D3DXVec3Project( &vOut, &vPosHeight, &vp, &pObj->GetWorld()->m_matProj,
					&pObj->GetWorld()->m_pCamera->m_matView, &matWorld);
			
				CRect rect = lpCustomText->m_rect;
				vOut.x -= rect.Width() / 2;
				vOut.y -= rect.Height();
				CRectClip rectClip = p2DRender->m_clipRect;
				DWORD dwLineCount = lpCustomText->m_string.GetLineCount();
				DWORD dwMaxHeight = lpCustomText->m_pFont->GetMaxHeight();
				CPoint ptOrigin = p2DRender->GetViewportOrg();
				p2DRender->SetViewportOrg( 0, 0 );
				int x = vOut.x;
				int y = vOut.y;
				int nHeight = rect.Height() / 8;
				int nWidth  = rect.Width()  / 8;

				for( int i = 0; i < nHeight; i++)
				{
					int nIndex;
					if( i == 0 ) 
						nIndex = 0; 
					else if( i != nHeight - 1 ) 
						nIndex = 3;
					else 
						nIndex = 6;
					for( int j = 0; j < nWidth; j++)
					{
						CPoint point = CPoint( x + j * 8, y + i * 8);
						if( j == 0 )
							m_texPack.Render( p2DRender, point, nIndex, nAlpha ); 
						else
						if( j != nWidth - 1 )
						{
							// 맨 밑쪽 
							/*
							if( i == nHeight - 1 ) 
							{
								if( nWidth >= 6 && ( j == 3 * nWidth / 5 || j == 3 * nWidth / 5 + 1) )
								{ m_texPack.Render( p2DRender, point, 4); continue; } // 5 : 3 = 10 : 6 
								else
								if( nWidth == 5 && ( j == 2 || j == 3 ) )
								{ m_texPack.Render( p2DRender, point, 4); continue; }
								else
								if( nWidth == 4 && j == 2 )
								{ m_texPack.Render( p2DRender, point, 4); continue; }
								else
								if( nWidth == 3 && j == 1 )
								{ m_texPack.Render( p2DRender, point, 4); continue; }
							}*/
							m_texPack.Render( p2DRender, point, nIndex + 1, nAlpha); 
						}
						else
							m_texPack.Render( p2DRender, point, nIndex + 2, nAlpha); 
					}
				}
				// 꼬랑지 출력 
				if( nWidth >= 6 )
					m_texPack.Render( p2DRender, CPoint( x + ( 3 * nWidth / 5 ) * 8, y + i * 8 - 1),  9, nAlpha ); 
				else
				if( nWidth == 5 ) 
					m_texPack.Render( p2DRender, CPoint( x + 2 * 8, y + i * 8 - 1), 9, nAlpha ); 
				else
				if( nWidth == 4 ) 
					m_texPack.Render( p2DRender, CPoint( x + 2 * 8, y + i * 8 - 1),  11, nAlpha ); 
				else
				if( nWidth == 3 ) 
					m_texPack.Render( p2DRender, CPoint( x + 1 * 8, y + i * 8 - 1),  11 , nAlpha); 
				p2DRender->SetViewportOrg( ptOrigin );

				x = vOut.x + 8;
				y = vOut.y + 8;
				p2DRender->TextOut_EditString( x, y, lpCustomText->m_string, 0, 0, 0 );
				/*
				for( i = 0; i < dwLineCount; i++)
				{
					CString string = lpCustomText->m_string.GetLine( i );
					DWORD dwOffset = lpCustomText->m_string.GetLineOffset( i );
					LPCTSTR lpszStr = string;
					int nLength = string.GetLength();
					DWORD dwCurOffset;
					TCHAR strHan[ 3 ];
					x = vOut.x + 8;;
					for( int j = 0; j < nLength; j++)
					{
						if( IsHangul( string[j] ) )
						{
							strHan[0] = string[j++];
							strHan[1] = string[j];
							strHan[2] = '\0';
							dwCurOffset = dwOffset + (j - 1);
						}
						else
						{
							strHan[0] = string[j];
							strHan[1] = '\0';
							dwCurOffset = dwOffset + j;
						}
						CSize size = lpCustomText->m_pFont->GetTextExtent(strHan);
						DWORD dwColor = lpCustomText->m_string.m_adwColor[dwCurOffset];
						DWORD dwStyle = lpCustomText->m_string.m_abyStyle[dwCurOffset];
						
						//p2DRender->TextOut( dwBegin, 0 + y * dwMaxHeight, strHan, dwColor);
						lpCustomText->m_pFont->DrawText( x, y, dwColor, (TCHAR*) strHan );
						if( dwStyle & ESSTY_BOLD )
							lpCustomText->m_pFont->DrawText( x + 1, y, dwColor, (TCHAR*) strHan );
						if( dwStyle & ESSTY_UNDERLINE )
							p2DRender->RenderLine( CPoint( x, y + size.cy ), CPoint( x + size.cx, y + size.cy ), dwColor );
							
						x+= size.cx;
					}	
					//lpCustomText->m_pFont->DrawText( x, y, D3DCOLOR_ARGB( nAlpha, 0, 0, 0 ), (TCHAR*) lpszStr );
					y += dwMaxHeight;
				}
				*/
			}
		}
	}
}
Example #20
0
int Transform::HitTest(const D3DXMATRIX& projection, const D3DXMATRIX& view, const D3DXMATRIX& model, const D3D10_VIEWPORT& vp, int type, Vec2f mousepos, Vec3f pos, IHitTest* hitTest)
{
	D3DXMATRIX transform = GetTransform();

	D3DXMATRIX model2 = model * transform;

//	D3DXVECTOR3 location(0,0,0);
//	D3DXVECTOR4 v;
//	D3DXVec3Transform(&v, &location, &transform);

	float scale = 10;

	D3DXVECTOR3 out;

	D3DXVECTOR3 _obj = *D3DXVec3Project(&out, &D3DXVECTOR3(0,0,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _xaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(scale,0,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _yaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(0,scale,0), &vp, &projection, &view, &model2);
	D3DXVECTOR3 _zaxis = *D3DXVec3Project(&out, &D3DXVECTOR3(0,0,scale), &vp, &projection, &view, &model2);

	Vec3f obj = VecProject(Vec3f(0,0,0), vp, projection, view, model2);
	Vec3f xaxis = VecProject(Vec3f(scale,0,0), vp, projection, view, model2);
	Vec3f yaxis = VecProject(Vec3f(0,scale,0), vp, projection, view, model2);
	Vec3f zaxis = VecProject(Vec3f(0,0,scale), vp, projection, view, model2);

	if (fabs(mousepos[0]-obj[0]) < 3 &&
		fabs(mousepos[1]-obj[1]) < 3)
	{
		hitTest->OnHit(this, type, *(Vec3f*)&obj);
		return 1;
	}
	else
	{
	//

		int axis = 0;

		double t;
		if (point_near_line_2d(obj, xaxis, mousepos, &t))
		{
			axis = 1;
		}
		else if (point_near_line_2d(obj, yaxis, mousepos, &t))
		{
			axis = 2;
		}
		else if (point_near_line_2d(obj, zaxis, mousepos, &t))
		{
			axis = 3;
		}

		if (axis)
		{
			hitTest->OnHit(this, type, obj, axis, t);

#if 0
			SelectedObject* p = object->m_selectedObject;
		//	p->m_object = object;
			p->m_wtransform = model;

			// ??
			if (m_document->m_objectMode == Mode_Model || m_document->m_objectMode == Mode_Axis)
				p->m_startTransform = object->m_transform->m_matrix;
			else
				p->m_startTransform = LDraw::matrix4f::getIdentity();

			p->m_z = obj[2];

			p->m_axis = axis;
			p->m_axis_t = t;

			selectedObjects.Add(p);
#endif
		}
	}

	return 0;
}