Converting from transformed to untransformed verticies

Started by
3 comments, last by Dwiel 21 years, 8 months ago
hey, ive got my code to draw some stars.....
  
struct FVF_XYZ_PSIZE_DIFFUSE
{
	float    x, y, z;
	float    rhw;
	float    psize;
	D3DCOLOR diffuse;
};

const DWORD D3DFVF_XYZ_PSIZE_DIFFUSE = D3DFVF_XYZRHW | D3DFVF_PSIZE | D3DFVF_DIFFUSE;

void GalaxyScreen::GetViewport()
{
	d3d_device->GetViewport(&vp);
}

void GalaxyScreen::InitScene()
{
	GetViewport();

	FVF_XYZ_PSIZE_DIFFUSE *verts = new FVF_XYZ_PSIZE_DIFFUSE[galaxy.numofstars];

	for (int a = 0; a < galaxy.numofsystems; a++)
	{
		verts[a].x = galaxy.SolarSystems[a].pos.x + galaxy.SolarSystems[a].sun.pos.x;
		verts[a].y = galaxy.SolarSystems[a].pos.y + galaxy.SolarSystems[a].sun.pos.y;
		verts[a].z = 1.0f;
//		verts[a].rhw = 0.5f;

		verts[a].diffuse = galaxy.SolarSystems[a].sun.color;
		verts[a].psize = 1.0f;
	}

	UINT numofverts = galaxy.numofsystems;
	UINT sizeofverts = sizeof(FVF_XYZ_PSIZE_DIFFUSE) * numofverts;
	if (FAILED( d3d_device->CreateVertexBuffer( sizeofverts, 0, D3DFVF_XYZ_PSIZE_DIFFUSE, D3DPOOL_MANAGED, &VB)))
		FatalError("Vertex Buffer could not be made!");
	
	void* Verticies;
	
	if (FAILED(VB->Lock(0, sizeofverts, (BYTE**)&Verticies, 0)))
		FatalError("Could not lock Vertex Buffer");

	memcpy(Verticies, verts, sizeofverts);

	VB->Unlock();
	delete [] verts;
}

void GalaxyScreen::KillScene()
{
	SAFE_RELEASE(VB);
}

void GalaxyScreen::Render()
{
	d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 100), 1.0f, 0);

	if(SUCCEEDED(d3d_device->BeginScene()))
	{
		UINT numofverts = galaxy.numofsystems;
		d3d_device->SetStreamSource(0, VB, sizeof(FVF_XYZ_PSIZE_DIFFUSE));
		d3d_device->SetVertexShader(D3DFVF_XYZ_PSIZE_DIFFUSE);
		d3d_device->DrawPrimitive(D3DPT_POINTLIST, 0, numofverts);
		d3d_device->EndScene();
	}

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

  
This works... I didnt include the functions to scale the points, but it displays one quadrant of the points... This is what I changed it to to try to get rid of the rhw component... what did I do wrong?
  
struct FVF_XYZ_PSIZE_DIFFUSE
{
	float    x, y, z;
//	float    rhw;

	float    psize;
	D3DCOLOR diffuse;
};

const DWORD D3DFVF_XYZ_PSIZE_DIFFUSE = D3DFVF_XYZ | D3DFVF_PSIZE | D3DFVF_DIFFUSE;

void GalaxyScreen::GetViewport()
{
	d3d_device->GetViewport(&vp);
}

void GalaxyScreen::InitScene()
{
	GetViewport();

	D3DXVECTOR3 EyePt = D3DXVECTOR3(0.0f, 0.0f, 2.0f);
	D3DXVECTOR3 LookatPt = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 UpVec = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
	D3DXMATRIX matWorld, matView, matProj;
	D3DXMatrixIdentity(&matWorld);
	D3DXMatrixLookAtLH(&matView, &EyePt, &LookatPt, &UpVec);
	FLOAT fAspect = vp.Width / (float)vp.Height;
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, fAspect, 1.0f, 500.0f);
	d3d_device->SetTransform(D3DTS_WORLD, &matWorld);
	d3d_device->SetTransform(D3DTS_VIEW, &matView);
	d3d_device->SetTransform(D3DTS_PROJECTION, &matProj);

	FVF_XYZ_PSIZE_DIFFUSE *verts = new FVF_XYZ_PSIZE_DIFFUSE[galaxy.numofstars];

	for (int a = 0; a < galaxy.numofsystems; a++)
	{
		verts[a].x = galaxy.SolarSystems[a].pos.x + galaxy.SolarSystems[a].sun.pos.x;
		verts[a].y = galaxy.SolarSystems[a].pos.y + galaxy.SolarSystems[a].sun.pos.y;
		verts[a].z = 1.0f;
//		verts[a].rhw = 0.5f;

		verts[a].diffuse = galaxy.SolarSystems[a].sun.color;
		verts[a].psize = 1.0f;
	}

	UINT numofverts = galaxy.numofsystems;
	UINT sizeofverts = sizeof(FVF_XYZ_PSIZE_DIFFUSE) * numofverts;
	if (FAILED( d3d_device->CreateVertexBuffer( sizeofverts, 0, D3DFVF_XYZ_PSIZE_DIFFUSE, D3DPOOL_MANAGED, &VB)))
		FatalError("Vertex Buffer could not be made!");
	
	void* Verticies;
	
	if (FAILED(VB->Lock(0, sizeofverts, (BYTE**)&Verticies, 0)))
		FatalError("Could not lock Vertex Buffer");

	memcpy(Verticies, verts, sizeofverts);

	VB->Unlock();
	delete [] verts;
}

void GalaxyScreen::KillScene()
{
	SAFE_RELEASE(VB);
}

void GalaxyScreen::Render()
{
	d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 100), 1.0f, 0);

	if(SUCCEEDED(d3d_device->BeginScene()))
	{
		UINT numofverts = galaxy.numofsystems;
		d3d_device->SetStreamSource(0, VB, sizeof(FVF_XYZ_PSIZE_DIFFUSE));
		d3d_device->SetVertexShader(D3DFVF_XYZ_PSIZE_DIFFUSE);
		d3d_device->DrawPrimitive(D3DPT_POINTLIST, 0, numofverts);
		d3d_device->EndScene();
	}

	d3d_device->Present(NULL, NULL, NULL, NULL);
}
  
Ive been stumped for ever and would really like some help! thanx a lot! Dwiel ~ tazzel3d
Advertisement
One thing i noticed is that you used
	FVF_XYZ_PSIZE_DIFFUSE *verts = new FVF_XYZ_PSIZE_DIFFUSE[galaxy.numofstars]; 

but for everything else you used galaxy.numofsystems (not numofstars) I dont know if this is deliberate or not.

Other than that I can''t notice any obvious mistakes. How exactly isn''t it working? Do you get any any output in the debug window?
--24 Beers in a Case.24 Hours in a Day.Coincedence? I think not!www.gramb0.co.uk
Yeah I forgot to fix that... They are the same because every solar system has (currently) only 1 sun/star...

in the debug window, it tells me that I have a lot of unfreed memory.. not sure from what... but I dont think that would be the problem... Ill fix the unfreed memory as soon as it actually starts working...

tazzel3d ~ dwiel
Also, all of my points are within a n units of the origin... ive tried n at 10 and 500.... all to no avail....

I do get the dark blue background, just no points...

tazzel3d ~ dwiel
wow... I had the verts on the wrong side of the camera!!!!!!!!! ahhh!!!! im really sry for wasting your guys'' time... thanx for tring though!!!!!

dwiel ~ tazzel3d

This topic is closed to new replies.

Advertisement