Hi,
I'm developing an application which uses a webcam to retrieve co-ordinates through tcp, in real time. These co-ordinates are the location of a light that the webcam detects. All I need to do for now is plot these points in a Direct3D environment, on one plane where z=0.

I've written the client to retrive the co-ordinates via tcp. It works fine, and the co-ordinates are currently held in a buffer, recvbuf, which is filled when using the network recv() method:

Code:
//receive messages
	while(TRUE){
		iResult = recv(ConnectSocket,recvbuf,recvbuflen,0);
		if(iResult > 1){
			//printf("Bytes received: %d\n", iResult);
			printf("%*.*s\n", iResult ,iResult ,recvbuf);
					
				if(recievedFirstMessage==1){
					if(recvbuf[25]=='1'){
						printf("x: %c%c%c\n", recvbuf[17],recvbuf[18],recvbuf[19]);
						printf("y: %c%c%c\n", recvbuf[21],recvbuf[22],recvbuf[23]);
						printf("B: %c\n\n", recvbuf[25]);
					}
					else if(recvbuf[25]=='5'){
							printf("Bit errors\n\n");
					}
					else{
						printf("SERVER: Sending error\n\n");
					}
				}
			recievedFirstMessage=1;
		}
As the webcam has a resolution of 320x240, x can never exceed 320 and y can never exceed 240. I've also written a program to create a direct3D device, and populate it with multiple points.

The first problem: I want to create a rectangle by using a linelist (which the program currently does) but I want to also draw the pointlist (which is currently commented out) at the same time. At the moment, it can draw either, but not both!

Note: The transform method is just to spin the rectangle round to show off 3D co-ordinates in the future.

The second problem: At the moment, the pointlist or linelist are specified then the program is run. While the linelist (rectangle defining the 320x240 area) is fine hardcoded, the points must be able to appear on the fly. Does anyone have any clue as to how I would go about doing this? Code for the drawing class is below:

Code:
//FIREFLY: includes
#include "StdAfx.h"
#include "MyApp.h"
#include "d3d9.h"
#include "mmsystem.h"
#include <math.h>

//FIREFLY: definitions
const DWORD MY_VERTEX_TYPE = (  D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE | D3DFVF_TEX1 );
struct MyVertexType
{
	float x;
	float y;
	float z;
	D3DXVECTOR3 normal;
	DWORD color;
};


MyApp::MyApp(void)
{
}

MyApp::~MyApp(void)
{
}

MyApp::MyApp(HWND hWnd)
{
	this->hWnd = hWnd;
	g_pD3D = NULL;
	pDevice = NULL;
	pMesh = NULL;
	verBuff = NULL;
	inBuff = NULL;
}

//FIREFLY: initilisation, create device
HRESULT MyApp::Init()
{
	if( NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))){
		return E_FAIL;
	}

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed   = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &pDevice ) ) ){
		return E_FAIL;
	}
	D3DXVECTOR3 norm(0.5f,0.5f,0.5f); //define normal as middle of screen

	//CLIENT STUFF HERE?

	MyVertexType vertArray[] =
	{
		{0,0,0,norm ,D3DCOLOR_XRGB(0,255,255)}, //for rectangle
		{0,240,0,norm ,D3DCOLOR_XRGB(0,255,255)},
		{320,0,0,norm ,D3DCOLOR_XRGB(0,255,255)},
		{320,240,0,norm ,D3DCOLOR_XRGB(0,255,255)}, //end of rectangle

		{0,1,0,norm ,D3DCOLOR_XRGB(255,255,255)},
		{1,-1,0,norm ,D3DCOLOR_XRGB(255,255,255)},
		{-1,-1,0,norm ,D3DCOLOR_XRGB(255,255,255)},
	};


	unsigned int indexArray[] =
	{ 0,1,1,3,3,2,2,0 };

	if(FAILED(pDevice->CreateVertexBuffer(3*sizeof(MyVertexType),0,MY_VERTEX_TYPE,D3DPOOL_SYSTEMMEM,&verBuff,NULL)))
	{
		return E_FAIL;
	}

	if( FAILED(pDevice->CreateIndexBuffer(8*sizeof(MyVertexType),0,D3DFMT_INDEX32,D3DPOOL_SYSTEMMEM,&inBuff,NULL)))
	{
		return E_FAIL;
	}

	void *lockPoint;
	if( FAILED( verBuff->Lock( 0,sizeof(vertArray),(void**)&lockPoint,0 ) ) )
	{
		return E_FAIL;
	}

	memcpy( lockPoint,vertArray, sizeof(vertArray));
	verBuff->Unlock();

	if( FAILED( inBuff->Lock( 0,sizeof(indexArray),(void**)&lockPoint,0 ) ) )
	{
		return E_FAIL;
	}

	memcpy( lockPoint,indexArray, sizeof(indexArray));
	inBuff->Unlock();
	return D3D_OK;
}

void MyApp::Render()
{
	D3DCOLOR background = 0x000000; //set background colour

	if (pDevice)
	{
		pDevice->Clear(0,0,(D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER),background,1.0f,0);
		pDevice->BeginScene();

		pDevice->SetStreamSource(0,verBuff,0,sizeof(MyVertexType));
		pDevice->SetIndices( inBuff );
		pDevice->SetFVF(MY_VERTEX_TYPE);

		//moves camera around
		Transforms();

		//what factors to render with
		RenderStates();

		//draw a basic triangle
		
		//pDevice->DrawPrimitive(D3DPT_LINELIST,0,4);
		pDevice->DrawIndexedPrimitive(D3DPT_LINELIST,0,0,4,0,4); //this draws the rectangle
		//pDevice->DrawPrimitive(D3DPT_POINTLIST,4,13); //or alternatively, this draws the pointlist

		//draw a basic poly
		//pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,4,0,2);

		//draw a mesh
		//pMesh->DrawSubset(0);

		pDevice->EndScene();
		pDevice->Present(0,0,0,0);
	}
}

void MyApp::RenderStates()
{
	pDevice->SetRenderState(D3DRS_CULLMODE,false );
	pDevice->SetRenderState(D3DRS_LIGHTING,false );
	pDevice->SetRenderState( D3DRS_AMBIENT, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) );
	pDevice->SetRenderState(D3DRS_SHADEMODE,3 );
	pDevice->SetRenderState(D3DRS_SPECULARENABLE,false);
	pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

}

void MyApp::Lighting()
{
}

void MyApp::Materials()
{
}

void MyApp::Transforms()
{
	D3DXMATRIX pMatrix;
	D3DXMATRIX RotMatrix;
	D3DXVECTOR3 lookat(0,120,0); //where the camera starts
	D3DXVECTOR3 up (0,1,0);
	D3DXVECTOR3 eye(0, 0, -500); //how far away the camera is

	//D3DXMatrixRotationX( &RotMatrix,D3DXToRadian(90) );
	D3DXMatrixRotationY( &pMatrix,timeGetTime()/1000.0F);
	//pMatrix = RotMatrix * pMatrix; 
	pDevice->SetTransform( D3DTS_WORLD, &pMatrix );

	D3DXMatrixLookAtLH( &pMatrix,&eye,&lookat,&up);
	pDevice->SetTransform( D3DTS_VIEW , &pMatrix );

	D3DXMatrixPerspectiveFovLH( &pMatrix,D3DXToRadian(90),640/480,1.0f,1000.0f);
	pDevice->SetTransform( D3DTS_PROJECTION , &pMatrix );


}
void MyApp::Shutdown()
{
	g_pD3D->Release();
	pDevice->Release();
	//pMesh->Release();
	verBuff->Release();
	//inBuff->Release();
}
Here is an example of what it draws at present:
http://b.imagehost.org/view/0228/rectangle.jpg