Пример #1
0
void CGras::DrawUI(LPDIRECT3DDEVICE7 lpDevice)
{
	if (lpVertices==NULL)return;
	if (game->lpTexture[40]==NULL)
	{	// Gras Textur nachladen
		game->lpTexture[40]=CreateTextureFromResource(lpDevice,game->lpDD,NULL,"grass.bmp",4,FALSE,TRUE); 
		MakeTransparent(game->lpTexture[40],FALSE);	// Gras
	}

	lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);

	DWORD old;
	lpDevice->GetRenderState(D3DRENDERSTATE_CULLMODE,&old);
	lpDevice->SetRenderState(D3DRENDERSTATE_CULLMODE,D3DCULL_NONE);
	if (Config.alpha)
	{
		lpDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,192);
		lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATEREQUAL);
	}

	lpDevice->SetTexture(0,game->lpTexture[40]);

	D3DMATRIX m;
	D3DUtil_SetIdentityMatrix(m);
	lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&m);

	for (int i=0;i<vertexbuffers;i++)
		lpDevice->DrawIndexedPrimitiveVB(D3DPT_TRIANGLELIST,lpVertices[i],0,vertexnum[i],Indices,vertexnum[i]/4*6,0);

	lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,0);
	lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
	lpDevice->SetRenderState(D3DRENDERSTATE_CULLMODE,old);
}
Пример #2
0
//-----------------------------------------------------------------------------
// Name: D3DUtil_SetRotateZMatrix()
// Desc: Create Rotation matrix about Z axis
//-----------------------------------------------------------------------------
VOID D3DUtil_SetRotateZMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DUtil_SetIdentityMatrix( mat );
    mat._11  =  cosf( fRads );
    mat._12  =  sinf( fRads );
    mat._21  = -sinf( fRads );
    mat._22  =  cosf( fRads );
}
Пример #3
0
//-----------------------------------------------------------------------------
// Name: D3DUtil_SetRotateYMatrix()
// Desc: Create Rotation matrix about Y axis
//-----------------------------------------------------------------------------
VOID D3DUtil_SetRotateYMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DUtil_SetIdentityMatrix( mat );
    mat._11 =  cosf( fRads );
    mat._13 = -sinf( fRads );
    mat._31 =  sinf( fRads );
    mat._33 =  cosf( fRads );
}
Пример #4
0
//-----------------------------------------------------------------------------
// Name: D3DUtil_SetRotateXMatrix()
// Desc: Create Rotation matrix about X axis
//-----------------------------------------------------------------------------
VOID D3DUtil_SetRotateXMatrix( D3DMATRIX& mat, FLOAT fRads )
{
    D3DUtil_SetIdentityMatrix( mat );
    mat._22 =  cosf( fRads );
    mat._23 =  sinf( fRads );
    mat._32 = -sinf( fRads );
    mat._33 =  cosf( fRads );
}
Пример #5
0
//-----------------------------------------------------------------------------
// Name: D3DUtil_SetViewMatrix()
// Desc: Given an eye point, a lookat point, and an up vector, this
//       function builds a 4x4 view matrix.
//-----------------------------------------------------------------------------
HRESULT D3DUtil_SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom,
                               D3DVECTOR& vAt, D3DVECTOR& vWorldUp )
{
    // Get the z basis vector, which points straight ahead. This is the
    // difference from the eyepoint to the lookat point.
    D3DVECTOR vView = vAt - vFrom;

    FLOAT fLength = Magnitude( vView );
    if( fLength < 1e-6f )
        return E_INVALIDARG;

    // Normalize the z basis vector
    vView /= fLength;

    // Get the dot product, and calculate the projection of the z basis
    // vector onto the up vector. The projection is the y basis vector.
    FLOAT fDotProduct = DotProduct( vWorldUp, vView );

    D3DVECTOR vUp = vWorldUp - fDotProduct * vView;

    // If this vector has near-zero length because the input specified a
    // bogus up vector, let's try a default up vector
    if( 1e-6f > ( fLength = Magnitude( vUp ) ) )
    {
        vUp = D3DVECTOR( 0.0f, 1.0f, 0.0f ) - vView.y * vView;

        // If we still have near-zero length, resort to a different axis.
        if( 1e-6f > ( fLength = Magnitude( vUp ) ) )
        {
            vUp = D3DVECTOR( 0.0f, 0.0f, 1.0f ) - vView.z * vView;

            if( 1e-6f > ( fLength = Magnitude( vUp ) ) )
                return E_INVALIDARG;
        }
    }

    // Normalize the y basis vector
    vUp /= fLength;

    // The x basis vector is found simply with the cross product of the y
    // and z basis vectors
    D3DVECTOR vRight = CrossProduct( vUp, vView );

    // Start building the matrix. The first three rows contains the basis
    // vectors used to rotate the view to point at the lookat point
    D3DUtil_SetIdentityMatrix( mat );
    mat._11 = vRight.x;    mat._12 = vUp.x;    mat._13 = vView.x;
    mat._21 = vRight.y;    mat._22 = vUp.y;    mat._23 = vView.y;
    mat._31 = vRight.z;    mat._32 = vUp.z;    mat._33 = vView.z;

    // Do the translation values (rotations are still about the eyepoint)
    mat._41 = - DotProduct( vFrom, vRight );
    mat._42 = - DotProduct( vFrom, vUp );
    mat._43 = - DotProduct( vFrom, vView );

    return S_OK;
}
Пример #6
0
void CSprite::DrawSmooth(LPDIRECT3DDEVICE7 lpDevice,const D3DVECTOR pos,const float w,const float h,const DWORD color,const int spritenr)
{
    D3DVECTOR rightVect,upVect;
    D3DMATRIX mat;
    {
        lpDevice->GetTransform(D3DTRANSFORMSTATE_VIEW,&mat);
        rightVect=Normalize(D3DVECTOR(mat._11,mat._21,mat._31))*w*0.5f;
        upVect=Normalize(D3DVECTOR(mat._12,mat._22,mat._32))*h*0.5f;
    }

    const D3DVECTOR n=D3DVECTOR(0,0,0);
    D3DLVERTEX verts[4]=
    {
        D3DLVERTEX(pos-rightVect+upVect, color,0, 1.0f, 0.0f),
        D3DLVERTEX(pos+rightVect+upVect, color,0, 0.0f, 0.0f),
        D3DLVERTEX(pos-rightVect-upVect, color,0, 1.0f, 1.0f),
        D3DLVERTEX(pos+rightVect-upVect, color,0, 0.0f, 1.0f)
    };

    D3DUtil_SetIdentityMatrix(mat);

    lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&mat);

    if (Config.alpha)
    {
        lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,FALSE);

        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,   TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
        lpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1,         D3DTA_TEXTURE);
        lpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,           D3DTOP_SELECTARG1);
        lpDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);

        lpDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCCOLOR);
        lpDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCCOLOR);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,0x08);
    }

    lpDevice->SetTexture(0,GetSurface(spritenr));
    lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_LVERTEX,verts,4,0);
    lpDevice->SetTexture(0,NULL);

    if (Config.alpha)
    {
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,   FALSE);
        lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,FALSE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE);
    }
}