示例#1
0
//-----------------------------------------------------------------------------
// Purpose: Tesla effect
//-----------------------------------------------------------------------------
void FX_BuildTeslaZap( const CEffectData &data )
{
	// Build the tesla, only works on entities
	C_BaseEntity *pEntity = data.GetEntity();
	if ( !pEntity )
		return;

	Vector vColor( 1, 1, 1 );

	BeamInfo_t beamInfo;
	beamInfo.m_nType = TE_BEAMTESLA;
	beamInfo.m_pStartEnt = pEntity;
	beamInfo.m_nStartAttachment = data.m_nAttachmentIndex;
	beamInfo.m_pEndEnt = NULL;
	beamInfo.m_vecEnd = data.m_vOrigin;
	beamInfo.m_pszModelName = "sprites/physbeam.vmt";
	beamInfo.m_flHaloScale = 0.0;
	beamInfo.m_flLife = 0.3f;
	beamInfo.m_flWidth = data.m_flScale;
	beamInfo.m_flEndWidth = 1;
	beamInfo.m_flFadeLength = 0.3;
	beamInfo.m_flAmplitude = 16;
	beamInfo.m_flBrightness = 200.0;
	beamInfo.m_flSpeed = 0.0;
	beamInfo.m_nStartFrame = 0.0;
	beamInfo.m_flFrameRate = 1.0;
	beamInfo.m_flRed = vColor.x * 255.0;
	beamInfo.m_flGreen = vColor.y * 255.0;
	beamInfo.m_flBlue = vColor.z * 255.0;
	beamInfo.m_nSegments = 20;
	beamInfo.m_bRenderable = true;
	beamInfo.m_nFlags = 0;
	
	beams->CreateBeamEntPoint( beamInfo );
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pInParticle - 
//			*pDraw - 
//			&sortKey - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool C_PerfTest::SimulateAndRender(Particle *pInParticle, ParticleDraw *pDraw, float &sortKey)
{
	PerfTestParticle *pParticle = (PerfTestParticle*)pInParticle;

	// Render.
	Vector tPos;
	TransformParticle(m_pParticleMgr->GetModelView(), pParticle->m_Pos, tPos);
	sortKey = tPos.z;

	Vector vColor( 0, 0, 0 );
	for( int i=0; i < NUM_LIGHTS; i++ )
	{
		float fDist = pParticle->m_Pos.DistToSqr( m_LightPos[i] );
		float fAmt;
		if( fDist > 0.0001f )
			fAmt = m_LightIntensity[i] / fDist;
		else
			fAmt = 1000;

		vColor += m_LightColor[i] * fAmt;
	}
	vColor = vColor.Min( Vector(255.1,255.1,255.1) );

	RenderParticle_Color255Size(
		pDraw,
		tPos,
		vColor,		// color
		255,		// alpha
		1			// size
		);

	return true;
}
示例#3
0
//-----------------------------------------------------------------------------
// Purpose: Tesla effect
//-----------------------------------------------------------------------------
void FX_BuildTeslaHitbox( const CEffectData &data )
{
	Vector vColor( 1, 1, 1 );

	C_BaseEntity *pEntity = ClientEntityList().GetEnt( data.entindex() );
	C_BaseAnimating *pAnimating = pEntity ? pEntity->GetBaseAnimating() : NULL;
	if (!pAnimating)
		return;

	studiohdr_t *pStudioHdr = modelinfo->GetStudiomodel( pAnimating->GetModel() );
	if (!pStudioHdr)
		return;

	mstudiohitboxset_t *set = pStudioHdr->pHitboxSet( pAnimating->GetHitboxSet() );
	if ( !set )
		return;

	matrix3x4_t	*hitboxbones[MAXSTUDIOBONES];
	if ( !pAnimating->HitboxToWorldTransforms( hitboxbones ) )
		return;

	int nBeamCount = (int)(data.m_flMagnitude + 0.5f);
	for ( int i = 0; i < nBeamCount; ++i )
	{
		int nStartHitBox = random->RandomInt( 1, set->numhitboxes );
		int nEndHitBox = random->RandomInt( 1, set->numhitboxes );
		FX_BuildTeslaHitbox( pEntity, nStartHitBox, nEndHitBox, data.m_flScale, vColor, random->RandomFloat( 0.05f, 0.2f ) );
	}
}
示例#4
0
void C_Sun::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	// Setup all our parameters.
	Vector vColor(
		m_clrRender->r / 255.0f,
		m_clrRender->g / 255.0f,
		m_clrRender->b / 255.0f );

	float sizeMul[] = {0.5, 0.3, 0.2, 0.1};

	m_Overlay.m_vDirection = m_vDirection;

	m_Overlay.m_nSprites = min( m_nLayers, CGlowOverlay::MAX_SPRITES );
	for( int i=0; i < m_Overlay.m_nSprites; i++ )
	{
		m_Overlay.m_Sprites[i].m_vColor = vColor;
		m_Overlay.m_Sprites[i].m_flHorzSize = (m_HorzSize / 100.0f) * sizeMul[i];
		m_Overlay.m_Sprites[i].m_flVertSize = (m_VertSize / 100.0f) * sizeMul[i];
	}

	// Either activate or deactivate.
	if( m_bOn )
		m_Overlay.Activate();
	else
		m_Overlay.Deactivate();
}
示例#5
0
static LTVector GetNodeModelColor(ModelsDB::HNODE hModelNode)
{
	LTVector vColor(1, 1, 1);

	switch ( g_pModelsDB->GetNodeLocation( hModelNode ))
	{
		case HL_HEAD :
			vColor = LTVector(1, 0, 0);
		break;

		case HL_TORSO :
			vColor = LTVector(1, 1, 0);
		break;

		case HL_ARM_LEFT :
		case HL_ARM_RIGHT :
			vColor = LTVector(0, 1, 0);
		break;

		case HL_LEG_LEFT :
		case HL_LEG_RIGHT :
			vColor = LTVector(0, 0, 1);
		break;
	}

	return vColor;
}
void C_LightGlow::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	m_Glow.m_vPos = GetAbsOrigin();

	if( updateType == DATA_UPDATE_CREATED )
	{
		// Setup our flare.
		Vector vColor(
			m_clrRender->r / 255.0f,
			m_clrRender->g / 255.0f,
			m_clrRender->b / 255.0f );

		m_Glow.m_nSprites = 2;

		m_Glow.m_Sprites[0].m_flHorzSize = m_Glow.m_Sprites[0].m_flVertSize = (float)m_Size / 100;
		m_Glow.m_Sprites[0].m_vColor = vColor;

		m_Glow.m_Sprites[1].m_flHorzSize = m_Glow.m_Sprites[1].m_flVertSize = (float)m_Size / 200;
		m_Glow.m_Sprites[1].m_vColor = vColor;

		m_Glow.Activate();
	}
}
示例#7
0
/*!
 * this is the heart of the application and user-controlled drawing of a 
 * 3ds max mesh with a specific shader.
 *
 * @param *d3dgw : 
 * @param numPass : 
 *
 * @return HRESULT  : 
 */
HRESULT SampleShaderPluginVertexShader::SetVertexShader(ID3DGraphicsWindow *d3dgw, int numPass)
{
	
   	HRESULT hr = S_OK;

	// Set matrices for the vertex shader
	D3DXMATRIX matWorld, matView, matProj, matAll, matAllTranspose;
	pd3dDevice->GetTransform( D3DTS_WORLD,&matWorld );
	pd3dDevice->GetTransform( D3DTS_VIEW,&matView );
	pd3dDevice->GetTransform( D3DTS_PROJECTION,&matProj );
	D3DXMatrixMultiply( &matAll, &matWorld,&matView );
	D3DXMatrixMultiply( &matAll, &matAll,&matProj );
	D3DXMatrixTranspose( &matAll, &matAll );
	pd3dDevice->SetVertexShaderConstant( 4, &matAll, 4 );
	
	// ********************************************************************************
	// Setting up the stages and vertex shaders per pass
	// ********************************************************************************

		// Set default states
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		pd3dDevice->SetRenderState( D3DRS_ZENABLE,     TRUE );
		pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
		pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,  FALSE );
		pd3dDevice->SetRenderState( D3DRS_LIGHTING,    TRUE );
		pd3dDevice->SetRenderState( D3DRS_AMBIENT,     0xffffffff );
		// Set filtering to point sampling; otherwise we lose the sharp
		// transistions in the lighting that we wanted.
		pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_POINT );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_POINT );
		
		// Set the texture coordinates to be clamped so we do not have to clamp the
		// result of the dot product in the texture gen code. We only really need
		// to clamp U because V is fixed at 0.0.
		pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP );
		
		// Draw the first pass, the textured visible polygons. We want to modulate 
		// the texture with the diffuse at stage 0. The texture is a banded gray 
		// scale to give the lighting and the diffuse is used as specified in the
		// vertex because vertex lighting is disabled. This is a useful way to set
		// things up because the base color can be changed without having to
		// change render state and therefore without having to break primitives.
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT1 );
		

		pd3dDevice->SetVertexShader( dwVertexShader );
		
		// Set constants for the vertex shader
		D3DXVECTOR4 vColor( m_MtlColor.r, m_MtlColor.g,m_MtlColor.b, 0.0f );
		pd3dDevice->SetVertexShaderConstant( 0, &vColor, 1 );

	return S_OK;
}
示例#8
0
void ModelDraw::StaticLightCB(WorldTreeObj *pObj, void *pUser)
{
	ASSERT(pObj->GetObjType() == WTObj_Light);

	SStaticLightCallbackData *pData	 = (SStaticLightCallbackData*)pUser;
	StaticLight *pStaticLight		 = (StaticLight*)pObj;

	//sanity check
	assert(pData);
	assert(pData->m_pInstance);
	assert(pData->m_pLightList);

	//figure out the color for this light
	LTVector vColor(pStaticLight->m_Color);
	if(pStaticLight->m_pLightGroupColor)
	{
		vColor.x *= pStaticLight->m_pLightGroupColor->x;
		vColor.y *= pStaticLight->m_pLightGroupColor->y;
		vColor.z *= pStaticLight->m_pLightGroupColor->z;
	}

	//early out if the light isn't going to contribute anything of value (fairly common when
	//lightgroups are turned off)
	if((vColor.x < 1.0f) && (vColor.y < 1.0f) && (vColor.z < 1.0f))
		return;

	LTVector vPos = pStaticLight->m_Pos;
	LTVector vDir = pStaticLight->m_Dir;

	if (pData->m_pInstance->m_Flags & FLAG_REALLYCLOSE)
	{
		// Put the lighting in our space
		vPos = g_ViewParams.m_mView * vPos;
		g_ViewParams.m_mView.Apply3x3(vDir);
	}

	CRenderLight RenderLight;

	if(pStaticLight->m_FOV > -0.99f)
	{
		RenderLight.SetupSpotLight(	vPos, vDir, vColor,
									pStaticLight->m_AttCoefs, 
									pStaticLight->m_Radius,
									pStaticLight->m_FOV,
									pStaticLight->m_eAttenuation,
									pStaticLight->m_Flags);
	}
	else
	{
		RenderLight.SetupPointLight(	vPos, vColor,
										pStaticLight->m_AttCoefs, pStaticLight->m_Radius,
										pStaticLight->m_eAttenuation,
										pStaticLight->m_Flags);
	}
	pData->m_pLightList->InsertLight(RenderLight, pStaticLight->m_fConvertToAmbient);
}
示例#9
0
//--------------------------------------------------------------------------------------
// Render the Fluid
//--------------------------------------------------------------------------------------
void RenderFluid( ID3D11DeviceContext* pd3dImmediateContext )
{
	DirectX::XMMATRIX proj = DirectX::XMMatrixOrthographicOffCenterLH(0, FLUID->Width(), FLUID->Height(), 0, 0, 1);
	proj = DirectX::XMMatrixTranspose(proj);

	D3D11_MAPPED_SUBRESOURCE MappedResource = {};
	pd3dImmediateContext->Map( g_pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource );
	ConstantBuffer* pCB = reinterpret_cast<ConstantBuffer*>(MappedResource.pData);
	DirectX::XMStoreFloat4x4A( &pCB->mViewProjection, proj );
	pCB->fParticleSize = PARTICLE_SIZE;
	pd3dImmediateContext->Unmap( g_pConstantBuffer, 0 );

	pd3dImmediateContext->VSSetShader( g_pVertexShader, NULL, 0 );
	pd3dImmediateContext->GSSetShader( g_pGeometryShader, NULL, 0 );
	pd3dImmediateContext->PSSetShader( g_pPixelShader, NULL, 0 );

	pd3dImmediateContext->GSSetConstantBuffers(0, 1, &g_pConstantBuffer);
	
	pd3dImmediateContext->IASetInputLayout( g_pVertexLayout );
	pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_POINTLIST );
	
	for (unsigned int i = 0; i < FLUID->Size(); i += FluidVertexBufferSize)
	{
		pd3dImmediateContext->Map(g_pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedResource);
		ParticleVertex* pVertices = reinterpret_cast<ParticleVertex*>(MappedResource.pData);

		// Render each particle
		unsigned int j = 0;
		for (; j < FluidVertexBufferSize && i + j < FLUID->Size(); j++) {
			float color = (float)(0.5f * FLUID->density[i + j] / FluidRestDensity);
			color = (color > 1.0f) ? 1.0f : color;
			DirectX::XMFLOAT4 vColor(1.0f - color, 1.0f - color, 1.0f, 1.0f);
			DirectX::XMFLOAT2 vPosition(FLUID->pos[i + j].x, FLUID->pos[i + j].y);
			pVertices[j].position = vPosition;
			pVertices[j].color = vColor;
		}

		pd3dImmediateContext->Unmap(g_pVertexBuffer, 0);

		UINT stride = sizeof(ParticleVertex);
		UINT offset = 0;
		pd3dImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);

		pd3dImmediateContext->Draw(j, 0);
	}
}
LTVector GameBase::GetBoundingBoxColor()
{
    LTVector vColor(1, 1, 1);
	switch (GetType())
	{
		case OT_MODEL :
			 vColor.Init(1, 0, 0);
		break;

		case OT_WORLDMODEL :
			 vColor.Init(0, 0, 1);
		break;

		case OT_NORMAL :
		default :
			 vColor.Init(1, 1, 1);
		break;
	}

	return vColor;
}
void CTEParticleRenderer::RenderParticles( CParticleRenderIterator *pIterator )
{
	const StandardParticle_t *pParticle = (const StandardParticle_t*)pIterator->GetFirst();
	while ( pParticle )
	{
		// Render.
		Vector tPos;
		TransformParticle(ParticleMgr()->GetModelView(), pParticle->m_Pos, tPos);
		float sortKey = tPos.z;

		Vector vColor(pParticle->m_Color[0]/255.9f, pParticle->m_Color[1]/255.9f, pParticle->m_Color[2]/255.9f);
		RenderParticle_ColorSize(
			pIterator->GetParticleDraw(),
			tPos,
			vColor,
			pParticle->m_Color[3]/255.9f,
			m_ParticleSize);

		pParticle = (const StandardParticle_t*)pIterator->GetNext( sortKey );
	}
}
示例#12
0
void wxToolTip::Create(
  const wxString&                   rsTip
)
{
    ULONG                           lStyle = ES_READONLY | ES_MARGIN | ES_CENTER;
    LONG                            lColor;
    char                            zFont[128];

    m_hWnd = ::WinCreateWindow( HWND_DESKTOP
                               ,WC_ENTRYFIELD
                               ,rsTip.c_str()
                               ,lStyle
                               ,0, 0, 0, 0
                               ,NULLHANDLE
                               ,HWND_TOP
                               ,1
                               ,NULL
                               ,NULL
                              );
    if (!m_hWnd)
    {
        wxLogError(wxT("Unable to create tooltip window"));
    }

    wxColour                        vColor( wxT("YELLOW") );
    lColor = (LONG)vColor.GetPixel();
    ::WinSetPresParam( m_hWnd
                      ,PP_BACKGROUNDCOLOR
                      ,sizeof(LONG)
                      ,(PVOID)&lColor
                     );
    strcpy(zFont, "8.Helv");
    ::WinSetPresParam( m_hWnd
                      ,PP_FONTNAMESIZE
                      ,strlen(zFont) + 1
                      ,(PVOID)zFont
                     );
} // end of wxToolTip::Create
示例#13
0
bool GenerateGrids(int x_grids, int y_grids, Vertex_VCN **ppVertices, int *pNum_Vertices, unsigned short **ppIndices, int *pNum_Indices, int *num_triangles)
{
	const int triangles_per_row = x_grids * 2;
	const int indices_per_row = triangles_per_row + 2;

	*num_triangles = triangles_per_row * y_grids;

	int num_vertices = (x_grids + 1) * (y_grids + 1);
	*pNum_Vertices = num_vertices;
	Vertex_VCN *pVertices = (Vertex_VCN *) Allocate16BytesAlignedMemory(sizeof(Vertex_VCN)*num_vertices);
	*ppVertices = pVertices;
	if ( pVertices==NULL )
		return false;

	int num_indices = indices_per_row * y_grids;
	*pNum_Indices = num_indices;
	unsigned short *pIndices = new unsigned short[num_indices];
	*ppIndices = pIndices;
	if ( pIndices==NULL )
	{
		Release16BytesAlignedMemory(pVertices);
		return false;
	}

	Vector4 vCorner(-0.5f, 0.5f, 0.0f, 1.0f);
	Vector4 vStep(1.0f/float(x_grids), -1.0f/float(y_grids), 0.0f, 0.0f);
	Vector4 vPosition = vCorner;
	Vector4 vNormal(0.0f, 0.0f, 1.0f);
	Vector4 vColor(1.0f, 1.0f, 1.0f, 1.0f);

	int x,y;
	int vertex_index = 0;

	for ( y=0; y<=y_grids; y++)
	{
		vPosition[0] = vCorner[0];
		for ( x=0; x<=x_grids; x++, vertex_index++)
		{
			pVertices[vertex_index].m_Position = vPosition;
			pVertices[vertex_index].m_Normal = vNormal;
			pVertices[vertex_index].m_Color = vColor;
			vPosition[0] += vStep[0];
		}
		vPosition[1] += vStep[1];
	}

	const int vertices_per_row = x_grids + 1;
	bool from_left_to_right = true;
	int index_index = 0;
	vertex_index = 0;

	for ( y=0; y<y_grids; y++ )
	{
		if ( from_left_to_right )
		{
			pIndices[index_index++] = y * vertices_per_row;
			pIndices[index_index++] = y * vertices_per_row + vertices_per_row;

			for ( x=0; x<x_grids; x++ )
			{
				vertex_index = y * vertices_per_row + x;
				pIndices[index_index++] = vertex_index + 1;
				pIndices[index_index++] = vertex_index + 1 + vertices_per_row;
			}
		}
		else
		{
			pIndices[index_index++] = y * vertices_per_row + x_grids;
			pIndices[index_index++] = (y+1) * vertices_per_row + x_grids;

			for ( x=x_grids; x>0; x-- )
			{
				vertex_index = y * vertices_per_row + x;
				pIndices[index_index++] = vertex_index - 1;
				pIndices[index_index++] = vertex_index - 1 + vertices_per_row;
			}
		}

		from_left_to_right = !from_left_to_right;
	}

	return true;
}
示例#14
0
void wxToolBar::DrawTool( wxDC& rDc, wxToolBarToolBase* pToolBase )
{
    wxToolBarTool* pTool = (wxToolBarTool *)pToolBase;
    wxColour gray85( 85,85,85 );
    wxPen vDarkGreyPen( gray85, 1, wxSOLID );
    wxBitmap vBitmap = pTool->GetNormalBitmap();
    bool bUseMask = false;
    wxMask* pMask = NULL;

    PrepareDC(rDc);

    if (!vBitmap.IsOk())
        return;
    if ((pMask = vBitmap.GetMask()) != NULL)
        if (pMask->GetMaskBitmap() != NULLHANDLE)
            bUseMask = true;

    if (!pTool->IsToggled())
    {
        LowerTool(pTool, FALSE);
        if (!pTool->IsEnabled())
        {
            wxColour vColor(wxT("GREY"));

            rDc.SetTextForeground(vColor);
            if (!pTool->GetDisabledBitmap().IsOk())
                pTool->SetDisabledBitmap(wxDisableBitmap( vBitmap
                                                         ,(long)GetBackgroundColour().GetPixel()
                                                        ));
            rDc.DrawBitmap( pTool->GetDisabledBitmap()
                           ,pTool->m_vX
                           ,pTool->m_vY
                           ,bUseMask
                          );
        }
        else
        {
            rDc.SetTextForeground(*wxBLACK);
            rDc.DrawBitmap( vBitmap
                           ,pTool->m_vX
                           ,pTool->m_vY
                           ,bUseMask
                          );
        }
        if (m_windowStyle & wxTB_3DBUTTONS)
        {
            RaiseTool(pTool);
        }
        if ( HasFlag(wxTB_TEXT) && !pTool->GetLabel().empty() )
        {
            wxCoord                 vX;
            wxCoord                 vY;
            wxCoord                 vLeft = pTool->m_vX - (int)(pTool->GetWidth()/2);

            rDc.SetFont(GetFont());
            rDc.GetTextExtent( pTool->GetLabel()
                              ,&vX
                              ,&vY
                             );
            if (pTool->GetWidth() > vX) // large tools
            {
                vLeft = pTool->m_vX + (pTool->GetWidth() - vX);
                GetSize(&vX, &vY);
                rDc.DrawText( pTool->GetLabel()
                             ,vLeft
                             ,vY - m_vTextY - 1
                            );
            }
            else  // normal tools
            {
                vLeft += (wxCoord)((m_vTextX - vX)/2);
                rDc.DrawText( pTool->GetLabel()
                             ,vLeft
                             ,pTool->m_vY + m_vTextY - 1 // a bit of margin
                            );
            }
        }
    }
    else
    {
        wxColour vColor(wxT("GREY"));

        LowerTool(pTool);
        rDc.SetTextForeground(vColor);
        if (!pTool->GetDisabledBitmap().IsOk())
            pTool->SetDisabledBitmap(wxDisableBitmap( vBitmap
                                                     ,(long)GetBackgroundColour().GetPixel()
                                                    ));
        rDc.DrawBitmap( pTool->GetDisabledBitmap()
                       ,pTool->m_vX
                       ,pTool->m_vY
                       ,bUseMask
                      );
        if ( HasFlag(wxTB_TEXT) && !pTool->GetLabel().empty() )
        {
            wxCoord                 vX;
            wxCoord                 vY;
            wxCoord                 vLeft = pTool->m_vX - (int)(pTool->GetWidth()/2);

            rDc.SetFont(GetFont());
            rDc.GetTextExtent( pTool->GetLabel()
                              ,&vX
                              ,&vY
                             );
            vLeft += (wxCoord)((m_vTextX - vX)/2);
            rDc.DrawText( pTool->GetLabel()
                         ,vLeft
                         ,pTool->m_vY + m_vTextY - 1 // a bit of margin
                        );
        }
    }
} // end of wxToolBar::DrawTool
示例#15
0
void ModelDraw::SetupModelLight(ModelInstance* pInstance, const ModelHookData& HookData, CRelevantLightList& LightList)
{
	//setup our light list information
	uint32 nMaxLights = LTMIN((uint32)g_CV_MaxModelLights, MAX_LIGHTS_SUPPORTED_BY_D3D);

	LTVector vInstancePosition;

	// Should we skip the root node and use it's first child node
	// for lighting consideration?
	if(g_CV_ModelLightingSkipRootNode)
	{
		// Index of the root node (should be 0)
		uint32 iRootNode = pInstance->NodeGetRootIndex();
		
		// How many children nodes does it have?
		uint32 iRootNodeNumKids = pInstance->NodeGetNumChildren( iRootNode );
		
		// Is there atleast one?
		if(iRootNodeNumKids > 0)
		{
		    // Just get the first one.
			// This assumes the the first child-node translates with the rest
			// of the mesh.
			uint32 iNode = pInstance->NodeGetChild( iRootNode, 0 );
			LTransform tf;
			pInstance->GetNodeTransform( iNode, tf, true );
		
			// Set our calculation position to the node's position
			vInstancePosition = tf.m_Pos;
		}
		else
		{
		    // If the root node doesn't have any children,
			// fall back to the root node's position.
			vInstancePosition = pInstance->GetPos();
		}
	}
	else // No? Then just use the root node position
	{
		//figure out the world position of this instance
		vInstancePosition = pInstance->GetPos();
	}

	LightList.ClearList();
	LightList.SetMaxLights(nMaxLights);
	LightList.SetObjectPos(vInstancePosition);
	LightList.SetObjectDims(pInstance->GetDims());

	// If they don't want lighting, set the values for no lighting and skip out
	if((g_CV_LightModels.m_Val == 0) || (HookData.m_ObjectFlags & FLAG_NOLIGHT))
	{
		LightList.AddAmbient(LTVector(255.0f, 255.0f, 255.0f));
		return;
	}

	//determine if we are in really close space
	bool bReallyClose = (HookData.m_ObjectFlags & FLAG_REALLYCLOSE) != 0;

	////////////////////////////////////////////////////////////////////
	// Add light from the environment.
	CRenderLight RenderLight;

	if(bReallyClose)
	{
		//this is really close, we need to transform it into the world
		g_ViewParams.m_mInvView.Apply(vInstancePosition);
	}

	// Global directional light dir.
	float fDirLightAmount = 0.0f;

	if (g_have_world && g_CV_ModelApplySun.m_Val && 
		(g_pStruct->m_GlobalLightColor.x || g_pStruct->m_GlobalLightColor.y || g_pStruct->m_GlobalLightColor.z))
	{
		// Use the previous lighting amount if it hasn't moved
		if ((pInstance->m_LastDirLightAmount >= 0.0f) &&
			(((pInstance->m_Flags2 & FLAG2_DYNAMICDIRLIGHT) == 0) ||
			(vInstancePosition.NearlyEquals(pInstance->m_LastDirLightPos, g_CV_ModelSunVariance.m_Val + 0.001f))))
		{
			fDirLightAmount = pInstance->m_LastDirLightAmount;
		}
		else
		{
			// Remember where we were last time we did this
			pInstance->m_LastDirLightPos = vInstancePosition;

			// Calculate the lighting
			fDirLightAmount = GetDirLightAmount(pInstance, vInstancePosition);

			// Remember the result
			pInstance->m_LastDirLightAmount = fDirLightAmount;
		}
		
		//setup the direction of the light
		LTVector vDirLightDir = g_pStruct->m_GlobalLightDir;
		if (bReallyClose)
		{
			// Put the lighting in our space
			g_ViewParams.m_mView.Apply3x3(vDirLightDir);
		}

		LTVector vScaledLightColor = g_pStruct->m_GlobalLightColor * fDirLightAmount;

		//add the directional light to the light list
		RenderLight.SetupDirLight(vDirLightDir, vScaledLightColor, FLAG_CASTSHADOWS);
		LightList.InsertLight(RenderLight, g_pStruct->m_GlobalLightConvertToAmbient);
	}

	// Ambient lighting
	if(g_have_world && g_CV_ModelApplyAmbient)
	{
		LTRGBColor ambientColor;
		w_DoLightLookup(world_bsp_shared->LightTable(), &vInstancePosition, &ambientColor);

		LTVector vAmbientLight;
		vAmbientLight.x = ambientColor.rgb.r;
		vAmbientLight.y = ambientColor.rgb.g;
		vAmbientLight.z = ambientColor.rgb.b;

		LightList.AddAmbient(vAmbientLight);
	}


	////////////////////////////////////////////////////////////////////
	// Figure out the lights that will be directionally lighting it.
	
	// Dynamic lights..
	for(uint32 i=0; i < g_nNumObjectDynamicLights; i++)
	{
		DynamicLight* pSrcLight = g_ObjectDynamicLights[i];

		if ((pSrcLight->m_Flags & FLAG_ONLYLIGHTWORLD) != 0)
			continue;

		LTVector vPos = pSrcLight->GetPos();
		if (bReallyClose)
		{
			// Put the lighting in our space
			vPos = g_ViewParams.m_mView * vPos;
		}

		LTVector vColor((float)pSrcLight->m_ColorR, (float)pSrcLight->m_ColorG, (float)pSrcLight->m_ColorB);
		LTVector vAttCoeff(1.0f, 0.0f, 19.0f/(pSrcLight->m_LightRadius*pSrcLight->m_LightRadius));
		RenderLight.SetupPointLight(vPos, vColor, vAttCoeff, pSrcLight->m_LightRadius, eAttenuation_D3D, 0);
		LightList.InsertLight(RenderLight, 0.0f);
	}

	// Static lights..
	if(g_have_world)
	{
		//fill out the callback data structure
		SStaticLightCallbackData CallbackData;
		CallbackData.m_pInstance	= pInstance;
		CallbackData.m_pLightList	= &LightList;

		//figure out what radius to use for this model
		float fModelRadius = pInstance->GetModelDB()->m_VisRadius;

		FindObjInfo foInfo;
		foInfo.m_iObjArray = NOA_Lights;
		foInfo.m_Min = vInstancePosition - LTVector(fModelRadius, fModelRadius, fModelRadius);
		foInfo.m_Max = vInstancePosition + LTVector(fModelRadius, fModelRadius, fModelRadius);
		foInfo.m_CB = &ModelDraw::StaticLightCB;
		foInfo.m_pCBUser = &CallbackData;

		world_bsp_client->ClientTree()->FindObjectsInBox2(&foInfo);
	}
}