Archived

This topic is now archived and is closed to further replies.

gajraaj

Point Sprites and User Clip Planes

Recommended Posts

gajraaj    122
Im trying to write a small application that uses the method SetClipPlane, basically I want to experiment the following: 1) How SetClipPlane works 2) How to render a point sprite The code is given below, I have been able to render a point sprite and also used the xz plane and the yz plane to cut through it and see how it works but i cant seem to make it work for the xy plane.
HRESULT InitVB()
{
    // Initialize three vertices for rendering a triangle   

	CUSTOMVERTEX vertices[] =
	{		
		{ 0.0f, 0.5f, 0.5f, 0xff00ff00, },
	};
    // Create the vertex buffer. Here we are allocating enough memory

    // (from the default pool) to hold all our 3 custom vertices. We also

    // specify the FVF, so the vertex buffer knows what data it contains.

    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 1*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

    // Now we fill the vertex buffer. To do this, we need to Lock() the VB to

    // gain access to the vertices. This mechanism is required becuase vertex

    // buffers may be in device memory.

    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
    g_pVB->Unlock();

    return S_OK;
}

VOID Render()
{
    // Clear the backbuffer to a blue color

    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

	FLOAT PointSize = 50.0f;
	FLOAT PointSizeMax = 50.0f;
	D3DXPLANE  plane;
	

    // Begin the scene

    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );		
		g_pd3dDevice->SetRenderState(D3DRS_POINTSIZE, *((DWORD*)&PointSize));
		g_pd3dDevice->SetRenderState(D3DRS_POINTSIZE_MAX, *((DWORD*)&PointSizeMax));
		g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_POINT);
		g_pd3dDevice->SetRenderState(D3DRS_CLIPPING , TRUE);

		//	xz split halfway through the middle

		/*
		-------------
		|			|
		-------------
		|			|
		-------------
		*/
		/*
        D3DXVECTOR3 a(0.0f, 0.5f, 0.5f );
        D3DXVECTOR3 b(0.5f, 0.5f, 0.5f );
        D3DXVECTOR3 c(0.0f, 0.5f, -0.5f );
		*/
		//	yz split halfway through the middle

		/*
		-----------------
		|		|		|
		-----------------
		|		|		|
		-----------------
		*/
		/*
		D3DXVECTOR3 a(0.0f, 0.5f, 0.5f );
        D3DXVECTOR3 b(0.0f, 0.5f, 0.0f );
        D3DXVECTOR3 c(0.0f, -0.5f, 0.5f );
		*/
		
		//	xy split diaognallu through the middle

		/*
		===
		|/|
		===
		*/		
		D3DXVECTOR3 a(0.0f, 0.5f, 0.5f );
        D3DXVECTOR3 b(0.5f, -0.5f, 0.5f );
        D3DXVECTOR3 c(0.0f, -0.0f, 0.5f );

        D3DXPLANE plane;
        D3DXPlaneFromPoints( &plane, &a, &b, &c );
        
        g_pd3dDevice->SetClipPlane(0, plane );

        g_pd3dDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, D3DCLIPPLANE0 );	
		
        g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 1 );

        // End the scene

        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display

    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

Im weak in Mathematics and so far have difficulty in understanding how to come up with the right vectors for the method D3DXPlaneFromPoints(). 1)Can anyone please tell me what Im doing wrong. 2)How exactly do I compute the vertices for the plane equation ax+by+cz+d=0 3)should i change the vertex info for the point sprite itself? Thanks in advance [edited by - gajraaj on May 25, 2004 12:43:23 PM] [edited by - gajraaj on May 25, 2004 12:56:54 PM]

Share this post


Link to post
Share on other sites