Skip to main content
gamedev.net
🔒 Locked

Lighting problem

Started by nedemon 6 replies 850+ views
Original Post
nedemon
nedemon
Greeting, gentlemen. I use directional light and everything's ok, but once i tried changing it either to point or spot it just does nothing. Before that, i changed the position:

D3DXMATRIX g_Transform;
D3DXMatrixIdentity(&g_Transform);
D3DXMatrixTranslation(&g_Transform,-150.0f, -150.0f, -100.0f);	
g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_Transform);

And my material:

ZeroMemory(&g_Material, sizeof(D3DMATERIAL9));
g_Material.Diffuse.r = 1.0f;
g_Material.Diffuse.g = 1.0f;
g_Material.Diffuse.b = 1.0f;
g_pd3dDevice->SetMaterial(&g_Material);

Here's one light i tried

ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type       = D3DLIGHT_SPOT;
light.Diffuse.r  = 1.0f;
light.Diffuse.g  = 1.0f;
light.Diffuse.b  = 1.0f;
light.Position = D3DXVECTOR3(-150.0f, 150.0f, 100.0f);
light.Theta = D3DX_PI/4.0f; light.Phi = D3DX_PI/2.0f;
vecDir = D3DXVECTOR3(0.0f,0.0f,0.0f);
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
light.Range       = 1000.0f;
g_pd3dDevice->SetLight( 0, &light );
g_pd3dDevice->LightEnable( 0, TRUE );

The questions are: 1. How do i give the coordinates - do i assume that the world center is set in (150, 150, 100) or (0,0,0)? 2. What's wrong with the light?
matches81
matches81
how is a normalized 0-vector supposed to look? What I mean is in your code snippet for the light you have
vecDir = D3DXVECTOR3(0.0f,0.0f,0.0f);D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );

Essentially you´re trying to normalize a vector that has a length of 0, which is not going to work. So after all you should end up with a light.Direction of (0.0f, 0.0f, 0.0f), which should render the spot useless. Try some simple values for the direction (like (1.f, 0.f, 0.f), (0.f, 1.f, 0.f) and so on)... Perhaps that fixes both your problems because you might see whether the light is in the correct position or not.
jollyjeffers
jollyjeffers
One other thing - it doesn't look like you're configuring the 'attenuation' for your light source. I'm pretty sure 0-values for those 3 fields will cancel out any contribution of a spot/omni light.

You might find the Light Attenuation section of the Light Properties documentation useful.

light.Attenuation0 = 0.0f;
light.Attenuation1 = 1.0f;
light.Attenuation2 = 0.0f;


might be worth trying [smile]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
nedemon
nedemon
Well, it doesn't help. I mean, the directional is still here but the rest...
It's not with the normals, but it's weird. What do you set for spotlight which you don't set for directional?
DesignerX
DesignerX
Try att0 = 1, att1 = 0, att2 = 0
and change light type to POINT just to see that it works.

Also, what is your direction for the spot light ?
There is nothing that can't be solved. Just people that can't solve it. :)
nedemon
nedemon
Here it is:
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );	ZeroMemory( &light, sizeof(D3DLIGHT9) );	light.Type       = D3DLIGHT_POINT;	light.Diffuse.r  = 1.0f;	light.Ambient.r  = 1.0f;	light.Diffuse.g  = 1.0f;	light.Ambient.g  = 1.0f;	light.Diffuse.b  = 1.0f;	light.Ambient.b  = 1.0f;	light.Position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);	light.Attenuation0 = 0.0f;	light.Attenuation1 = 0.0f;	light.Attenuation2 = 1.0f;	vecDir = D3DXVECTOR3(0.0f,1.0f,0.0f);     //its from the spot	D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );	light.Range       = 1000.0f;	g_pd3dDevice->SetLight( 0, &light );	g_pd3dDevice->LightEnable( 0, TRUE );

Still not working.
nedemon
nedemon
Here's the whole prog for the ones who's interested
#include <Windows.h>#include <mmsystem.h>#include <d3dx9.h>#include <math.h>#include <d3dx9math.h>LPDIRECT3D9             g_pD3D       = NULL;LPDIRECT3DDEVICE9       g_pd3dDevice = NULL;LPDIRECT3DVERTEXBUFFER9 g_pVB        = NULL;LPDIRECT3DVERTEXBUFFER9 g_pVB1       = NULL;LPDIRECT3DVERTEXBUFFER9 g_pVB2       = NULL;LPDIRECT3DTEXTURE9      g_pTexture   = NULL;LPDIRECT3DINDEXBUFFER9	g_pIB        = NULL;#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL)#define D3DFVF_CUSTOMVERTEX1 (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE)struct CUSTOMVERTEX{	FLOAT x,y,z;	FLOAT nx,ny,nz;};struct CUSTOMVERTEX1{	FLOAT x,y,z;	FLOAT nx,ny,nz;	DWORD color;//	FLOAT tu,tv;};//-----------------Figure Stats--------------------------------------int SXpar = 30, SYpar = 30;int SNumV = (SXpar + 1) * (SYpar + 1);	int	SNumI  = 2 * SXpar * (SYpar + 1);int SNumP = SNumI - 2;//-------------------------------------------------------------FLOAT CHeight = 10.0f;FLOAT CRadius = 5.0f;int CPar = 30;int CSNumV = ((CPar + 1) * 4) + 2;	int CNumSP = CPar * 2;int CNumEP = CPar;int ThisTickCount = 0, LastTickCount = 0;float fAngle = 0;#include <fstream.h>ofstream out("out.txt");D3DVECTOR GetTriangeNormal(D3DXVECTOR3* vVertex1, D3DXVECTOR3* vVertex2						   , D3DXVECTOR3* vVertex3){    D3DXVECTOR3 vNormal;    D3DXVECTOR3 v1;    D3DXVECTOR3 v2;    D3DXVec3Subtract(&v1, vVertex2, vVertex1);    D3DXVec3Subtract(&v2, vVertex3, vVertex1);    D3DXVec3Cross(&vNormal, &v2, &v1);    D3DXVec3Normalize(&vNormal, &vNormal);    return vNormal;}HRESULT InitD3D( HWND hWnd ){    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )        return E_FAIL;	    D3DPRESENT_PARAMETERS d3dpp;    ZeroMemory( &d3dpp, sizeof(d3dpp) );    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;	d3dpp.EnableAutoDepthStencil = TRUE;      d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,        D3DCREATE_SOFTWARE_VERTEXPROCESSING,        &d3dpp, &g_pd3dDevice ) ) )    {        return E_FAIL;    }    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );	g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);  	return S_OK;}HRESULT InitGeometry(){    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 5000*sizeof(CUSTOMVERTEX1),                                                  0, D3DFVF_CUSTOMVERTEX1,                                                  D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )    {        return E_FAIL;    }	CUSTOMVERTEX1 vertices[5000];	D3DVECTOR n1,n2;	FLOAT dist[5] = {0, 30, 60, 90, 120};	DWORD colorz[5] = {		D3DCOLOR_XRGB(255,0,255), D3DCOLOR_XRGB(0,255,0), D3DCOLOR_XRGB(0,0,255),		D3DCOLOR_XRGB(255,255,0), D3DCOLOR_XRGB(0,255,255) 	};	FLOAT i,j,si,sj;	si = 20;	sj = 20;	int m;	long k = 0;	for(i = 50; i < 250; i+=si)		for(j = 50; j < 250; j+=sj)		{			vertices[k].x = i;		vertices[k+600].x = i;			vertices[k].y = j;		vertices[k+600].y = j;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i;		vertices[k+600].nx = i;			//vertices[k].ny = j;		vertices[k+600].ny = j;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if( ((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if( ((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = i+si;	vertices[k+600].x = i;			vertices[k].y = j;		vertices[k+600].y = j+sj;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i+si;	vertices[k+600].nx = i;			//vertices[k].ny = j;		vertices[k+600].ny = j+sj;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(255,255,0);			k++;			vertices[k].x = i;		vertices[k+600].x = i+si;			vertices[k].y = j+sj;	vertices[k+600].y = j;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i;		vertices[k+600].nx = i+si;			//vertices[k].ny = j+sj;	vertices[k+600].ny = j;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(255,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(255,255,0);n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;			k++;			vertices[k].x = i;		vertices[k+600].x = i;			vertices[k].y = j+sj;	vertices[k+600].y = j+sj;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i;	vertices[k+600].nx = -i;			//vertices[k].ny = j+sj;	vertices[k+600].ny = j+sj;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,255);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,255);			k++;			vertices[k].x = i+si;	vertices[k+600].x = i+si;			vertices[k].y = j;		vertices[k+600].y = j+sj;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i+si;	vertices[k+600].nx = i+si;			//vertices[k].ny = j;	vertices[k+600].ny = j+sj;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,0,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,0,255);			k++;			vertices[k].x = i+si;	vertices[k+600].x = i+si;			vertices[k].y = j+sj;	vertices[k+600].y = j;			vertices[k].z = 0.0f;	vertices[k+600].z = 200.0f;			//vertices[k].nx = i+si;	vertices[k+600].nx = i+si;			//vertices[k].ny = j+sj;	vertices[k+600].ny = j;			//vertices[k].nz = 1.0f;	vertices[k+600].nz = 200.0f-1;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].y-150)*(vertices[k].y-150)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].y-150)*(vertices[k+600].y-150)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;//			vertices[k].color = D3DCOLOR_XRGB(0,255,255);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,255);			k++;		}k+=600;	for(i = 0; i < 200; i+=si)		for(j = 50; j < 250; j+=sj)		{			vertices[k].x = j;		vertices[k+600].x = j;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i;		vertices[k+600].z = i;			vertices[k].nx = j;		vertices[k+600].nx = j;			vertices[k].ny = 51.0f;	vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i;		vertices[k+600].nz = i;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,255);//			vertices[k+600].color = D3DCOLOR_XRGB(255,255,0);			k++;			vertices[k].x = j;		vertices[k+600].x = j+sj;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i+si;	vertices[k+600].z = i+si;			vertices[k].nx = j;		vertices[k+600].nx = j+sj;			vertices[k].ny = 51.0f;	vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i+si;	vertices[k+600].nz = i+si;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,255);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,255);			k++;			vertices[k].x = j+sj;	vertices[k+600].x = j;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i+si;	vertices[k+600].z = i+si;			vertices[k].nx = j+sj;	vertices[k+600].nx = j;			vertices[k].ny = 51.0f;	vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i+si;	vertices[k+600].nz = i+si;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(255,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(255,255,0);n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;			k++;			vertices[k].x = j;		vertices[k+600].x = j;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i;		vertices[k+600].z = i;			vertices[k].nx = j;		vertices[k+600].nx = j;			vertices[k].ny = 51.0f;	vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i;		vertices[k+600].nz = i;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,255);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = j+sj;	vertices[k+600].x = j+sj;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i+si;	vertices[k+600].z = i;			vertices[k].nx = j+sj;	vertices[k+600].nx = j+sj;			vertices[k].ny = 51.0f;	vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i+si;	vertices[k+600].nz = i;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(255,0,0);//			vertices[k+600].color = D3DCOLOR_XRGB(255,0,0);			k++;			vertices[k].x = j+sj;	vertices[k+600].x = j+sj;			vertices[k].y = 50.0f;	vertices[k+600].y = 250.0f;			vertices[k].z = i;		vertices[k+600].z = i+si;			vertices[k].nx = j+sj;	vertices[k+600].nx = j+sj;			vertices[k].ny = 51.0f;vertices[k+600].ny = 250.0f-1;			vertices[k].nz = i;	vertices[k+600].nz = i+si;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].x-150)*(vertices[k].x-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[m];				}				if(sqrtf((vertices[k+600].x-150)*(vertices[k+600].x-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;			k++;		}k+=600;		for(i = 50; i < 250; i+=si)		for(j = 0; j < 200; j+=sj)		{			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i;		vertices[k+600].y = i;			vertices[k].z = j;		vertices[k+600].z = j;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i;		vertices[k+600].ny = i;			vertices[k].nz = j;		vertices[k+600].nz = j;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i+si;	vertices[k+600].y = i+si;			vertices[k].z = j;		vertices[k+600].z = j+sj;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i+si;	vertices[k+600].ny = i+si;			vertices[k].nz = j;		vertices[k+600].nz = j+sj;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i+si;	vertices[k+600].y = i+si;			vertices[k].z = j+sj;	vertices[k+600].z = j;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i+si;	vertices[k+600].ny = i+si;			vertices[k].nz = j+sj;	vertices[k+600].nz = j;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;			k++;			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i;		vertices[k+600].y = i;			vertices[k].z = j;		vertices[k+600].z = j;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i;	vertices[k+600].ny = i;			vertices[k].nz = j;	vertices[k+600].nz = j;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i+si;	vertices[k+600].y = i;			vertices[k].z = j+sj;	vertices[k+600].z = j+sj;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i+si;	vertices[k+600].ny = i;			vertices[k].nz = j+sj;	vertices[k+600].nz = j+sj;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);			k++;			vertices[k].x = 50.0f;	vertices[k+600].x = 250.0f;			vertices[k].y = i;		vertices[k+600].y = i+si;			vertices[k].z = j+sj;	vertices[k+600].z = j+sj;			vertices[k].nx = 51.0f;	vertices[k+600].nx = 250.0f-1;			vertices[k].ny = i;	vertices[k+600].ny = i+si;			vertices[k].nz = j+sj;	vertices[k+600].nz = j+sj;			for(m = 0; m < 5; m++)			{				if(sqrtf((vertices[k].y-150)*(vertices[k].y-150)+(vertices[k].z-100)*(vertices[k].z-100)) > dist[m])				{					vertices[k].color = colorz[4-m];				}				if(sqrtf((vertices[k+600].y-150)*(vertices[k+600].y-150)+(vertices[k+600].z-100)*(vertices[k+600].z-100)) > dist[m])				{					vertices[k+600].color = colorz[4-m];				}			}//			vertices[k].color = D3DCOLOR_XRGB(0,255,0);//			vertices[k+600].color = D3DCOLOR_XRGB(0,255,0);n1 = GetTriangeNormal(&D3DXVECTOR3(vertices[k-2].x, vertices[k-2].y, vertices[k-2].z),                               &D3DXVECTOR3(vertices[k-1].x, vertices[k-1].y, vertices[k-1].z),                               &D3DXVECTOR3(vertices[k].x, vertices[k].y, vertices[k].z));n2 = GetTriangeNormal(&D3DXVECTOR3(vertices[600+k-2].x, vertices[600+k-2].y, vertices[600+k-2].z),                               &D3DXVECTOR3(vertices[600+k-1].x, vertices[600+k-1].y, vertices[600+k-1].z),                               &D3DXVECTOR3(vertices[600+k].x, vertices[600+k].y, vertices[600+k].z));			vertices[k].nx = n1.x;	vertices[600+k].nx = n2.x;			vertices[k].ny = n1.y;	vertices[600+k].ny = n2.y;			vertices[k].nz = n1.z;	vertices[600+k].nz = n2.z;			vertices[k-1].nx = n1.x;vertices[600+k-1].nx = n2.x;			vertices[k-1].ny = n1.y;vertices[600+k-1].ny = n2.y;			vertices[k-1].nz = n1.z;vertices[600+k-1].nz = n2.z;			vertices[k-2].nx = n1.x;vertices[600+k-2].nx = n2.x;			vertices[k-2].ny = n1.y;vertices[600+k-2].ny = n2.y;			vertices[k-2].nz = n1.z;vertices[600+k-2].nz = n2.z;			k++;		}	VOID* pVertices;    if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )	{		return E_FAIL;	}	memcpy( pVertices, vertices, sizeof(vertices) );	g_pVB->Unlock();//------------------------------------------Sphere part------------------    if(FAILED(g_pd3dDevice->CreateVertexBuffer(SNumV * sizeof(CUSTOMVERTEX),                                               0, D3DFVF_CUSTOMVERTEX,                                               D3DPOOL_DEFAULT, &g_pVB1, NULL)))    {        return E_FAIL;    }	if(FAILED(g_pd3dDevice->CreateIndexBuffer(SNumI * sizeof(WORD), 											  0, D3DFMT_INDEX16, D3DPOOL_MANAGED,											  &g_pIB,NULL)))	{	    return E_FAIL;	}	WORD* pIndices;	CUSTOMVERTEX* pVertex; 	WORD wVertexIndex = 0;	int x;	int y;	D3DXVECTOR3 vNormal;	if(FAILED(g_pVB1->Lock(0, SNumV, (void**)&pVertex, 0)))	{		return E_FAIL;	}	//Lock the index buffer 	if(FAILED(g_pIB->Lock(0, SNumI, (void**)&pIndices, 0)))	{		return E_FAIL;	}	//Establish constants used in sphere generation	FLOAT fi = (D3DX_PI / SXpar);	FLOAT theta = (2.0f * D3DX_PI / SYpar);	//Generate the group of rings for the sphere	for(x = 0; x < SXpar + 1; x++)	{		FLOAT r0 = sinf(x * fi);		FLOAT y0 = cosf(x * fi);		//Generate the group of segments for the current ring		for(y = 0; y < SYpar + 1; y++)		{			FLOAT x0 = r0 * sinf(y * theta);			FLOAT z0 = r0 * cosf(y * theta);			vNormal.x = x0;			vNormal.y = y0;			vNormal.z = z0;				D3DXVec3Normalize(&vNormal, &vNormal);			//Add one vertex to the strip which makes up the sphere			pVertex->x = x0*49+100;			pVertex->y = y0*49+100;			pVertex->z = z0*49+100;			//out<<x0<<'\t'<<y0<<'\t'<<z0<<'\t'<<endl;			pVertex->nx = vNormal.x;			pVertex->ny = vNormal.y;			pVertex->nz = vNormal.z;//			pVertex->tu = 1.0f - ((FLOAT)y / (FLOAT)SYpar);//			pVertex->tv = (FLOAT)x / (FLOAT)SXpar;			//pVertex->color = D3DCOLOR_XRGB(255,255,255);			pVertex++;								//Add two indices except for the last ring 			if(x != SXpar) 			{				*pIndices = wVertexIndex; 				pIndices++;				*pIndices = wVertexIndex + (WORD)(SYpar + 1); 				pIndices++;								wVertexIndex++; 			}		}	}	if(FAILED(g_pIB->Unlock()))	{		return E_FAIL;	}	if(FAILED(g_pVB1->Unlock()))	{		return E_FAIL;	}//------------------------------------------Cyllinder part-----------			if(FAILED(g_pd3dDevice->CreateVertexBuffer(CSNumV * sizeof(CUSTOMVERTEX),                                               0, D3DFVF_CUSTOMVERTEX,                                               D3DPOOL_DEFAULT, &g_pVB2, NULL)))    {		return E_FAIL;    }	CUSTOMVERTEX* pVertex1; //	WORD wVertexIndex1 = 0;	//int y;	//Lock the vertex buffer	if(FAILED(g_pVB2->Lock(0, 0, (void**)&pVertex1, 0)))	{		return E_FAIL;	}		//float theta = (2.0f * D3DX_PI / CPar);	theta = (2.0f * D3DX_PI / CPar);	float SL = 1.0f / (float)CPar;	//int y = 0;	y = 0;	//Create the sides triangle strip	for(y = 0; y <= CPar; y++)	{		float x0 = CRadius * sinf(y * theta);		float z0 = CRadius * cosf(y * theta);		pVertex1->x = x0*5+200;		pVertex1->y = (0.0f + (CHeight / 2.0f))*5+80;		pVertex1->z = z0*5+100;		pVertex1->nx = x0;		pVertex1->ny = 0.0f;		pVertex1->nz = z0;//		pVertex1->tu = 1.0f - (SL * (float)y);//		pVertex1->tv = 0.0f;		pVertex1++;		pVertex1->x = x0*5+200;		pVertex1->y = (0.0f - (CHeight / 2.0f))*5+80;		pVertex1->z = z0*5+100;		pVertex1->nx = x0;		pVertex1->ny = 0.0f;		pVertex1->nz = z0;//		pVertex1->tu = 1.0f - (SL * (float)y);//		pVertex1->tv = 1.0f;		pVertex1++;	}		//Create the top triangle fan: Center	pVertex1->x = 0.0f*5+200;	pVertex1->y = (0.0f + (CHeight / 2.0f))*5+80;	pVertex1->z = 0.0f*5+100;	pVertex1->nx = 0.0f;	pVertex1->ny = 1.0f;	pVertex1->nz = 0.0f;//	pVertex1->tu = 0.5f;//	pVertex1->tv = 0.5f;	//pVertex1->color = D3DCOLOR_XRGB(255,0,0);	pVertex1++;	//Create the top triangle fan: Edges	for(y = 0; y <= CPar; y++)	{		float x0 = CRadius * sinf(y * theta);		float z0 = CRadius * cosf(y * theta);			pVertex1->x = x0*5+200;		pVertex1->y = (0.0f + (CHeight / 2.0f))*5+80;		pVertex1->z = z0*5+100;		pVertex1->nx = 0.0f;		pVertex1->ny = 1.0f;		pVertex1->nz = 0.0f;	//	pVertex1->color = D3DCOLOR_XRGB(255,0,0);		float tu0 = (0.5f * sinf(y * theta)) + 0.5f;		float tv0 = (0.5f * cosf(y * theta)) + 0.5f;//		pVertex1->tu = tu0;//		pVertex1->tv = tv0;		pVertex1++;	}	//Create the bottom triangle fan: Center	pVertex1->x = 0.0f*5+200;	pVertex1->y = (0.0f - (CHeight / 2.0f))*5+80;	pVertex1->z = 0.0f*5+100;	pVertex1->nx = 0.0f;	pVertex1->ny = -1.0f;	pVertex1->nz = 0.0f;//	pVertex1->tu = 0.5f;//	pVertex1->tv = 0.5f;	//pVertex1->color = D3DCOLOR_XRGB(255,0,0);	pVertex1++;	//Create the bottom triangle fan: Edges	for(y = CPar; y >= 0; y--)	{		float x0 = CRadius * sinf(y * theta);		float z0 = CRadius * cosf(y * theta);			pVertex1->x = x0*5+200;		pVertex1->y = (0.0f - (CHeight / 2.0f))*5+80;		pVertex1->z = z0*5+100;		pVertex1->nx = 0.0f;		pVertex1->ny = -1.0f;		pVertex1->nz = 0.0f;	//	pVertex1->color = D3DCOLOR_XRGB(255,0,0);		float tu0 = (0.5f * sinf(y * theta)) + 0.5f;		float tv0 = (0.5f * cosf(y * theta)) + 0.5f;//		pVertex1->tu = tu0;//		pVertex1->tv = tv0;		pVertex1++;	}	if(FAILED(g_pVB2->Unlock()))	{		return E_FAIL;	}	return S_OK;}VOID SetupMatrices(){	D3DXMATRIX g_Transform;	D3DXMatrixIdentity(&g_Transform);	D3DXMatrixTranslation(&g_Transform,-150.0f, -150.0f, -100.0f);	    g_pd3dDevice->SetTransform(D3DTS_WORLD, &g_Transform);/*	D3DXMATRIX g_View;	D3DXVECTOR3 Eye (150.0f, 150.0f, -250.0f);	D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);	D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);	D3DXMatrixLookAtLH(&g_View, &Eye, &LookAt, &Up);	g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_View);*/	D3DXMATRIX Projection;	FLOAT FOV = D3DX_PI / 2;	FLOAT Aspect = 320.0f /240.0f;	D3DXMatrixPerspectiveFovLH(&Projection, FOV, Aspect, 1.0f, 1000.0f);	g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &Projection);}VOID SetupLights(){	}VOID Cleanup(){	if( g_pTexture != NULL )        g_pTexture->Release();	if( g_pVB != NULL )        g_pVB->Release();	if( g_pVB1 != NULL )        g_pVB1->Release();	if( g_pVB2 != NULL )        g_pVB2->Release();    if( g_pd3dDevice != NULL )        g_pd3dDevice->Release();    if( g_pD3D != NULL )        g_pD3D->Release();}VOID Reddraw(UINT Param){	if(Param ==1)	{		fAngle += 0.05f;		if(fAngle > 2.0f * D3DX_PI) 			fAngle -= (2.0f * D3DX_PI);		D3DXMATRIX g_View;		D3DXVECTOR3 Eye (150.0f*sinf(fAngle), 150.0f, (-250.0f*cosf(fAngle)));		D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);		D3DXMatrixLookAtLH(&g_View, &Eye, &LookAt, &Up);		g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_View);	}	else if(Param == 2)	{		fAngle += 0.05f;		if(fAngle > 2.0f * D3DX_PI) 			fAngle -= (2.0f * D3DX_PI);		D3DXMATRIX g_View;		D3DXVECTOR3 Eye (-150.0f*sinf(fAngle), 150.0f, (-250.0f*cosf(fAngle)));		D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);		D3DXMatrixLookAtLH(&g_View, &Eye, &LookAt, &Up);		g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_View);	}	else if(Param == 3)	{		fAngle += 0.05f;		if(fAngle > 2.0f * D3DX_PI) 			fAngle -= (2.0f * D3DX_PI);		D3DXMATRIX g_View;		D3DXVECTOR3 Eye (-150.0f, 150.0f*cosf(fAngle), (250.0f*sinf(fAngle)));		D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);		D3DXMatrixLookAtLH(&g_View, &Eye, &LookAt, &Up);		g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_View);	}	else if(Param == 4)	{		fAngle += 0.05f;		if(fAngle > 2.0f * D3DX_PI) 			fAngle -= (2.0f * D3DX_PI);		D3DXMATRIX g_View;		D3DXVECTOR3 Eye (-150.0f, 150.0f*cosf(fAngle), (-250.0f*sinf(fAngle)));		D3DXVECTOR3 LookAt(0.0f, 0.0f, 0.0f);		D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f);		D3DXMatrixLookAtLH(&g_View, &Eye, &LookAt, &Up);		g_pd3dDevice->SetTransform(D3DTS_VIEW, &g_View);	}}VOID Render(){	D3DMATERIAL9 g_Material;	D3DXVECTOR3 vecDir, vecPos;	D3DLIGHT9 light;	SetupMatrices();	    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );	g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);//	g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_RGBA(255,0,0,22));    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )    {//---------------------------------------------------------------------	   g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX1));	   g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX1);	   /*g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,200);	   g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,600,200);	   g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,1200,200);	   g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,1800,200);	   g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,2400,200);	   g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,3000,200);	   *///---------------------------------------------------------------------	   	    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );		ZeroMemory(&g_Material, sizeof(D3DMATERIAL9));		g_Material.Diffuse.r = 1.0f;g_Material.Ambient.r = 0.0f;g_Material.Specular.r = 1.0f;		g_Material.Diffuse.g = 1.0f;g_Material.Ambient.g = 0.0f;g_Material.Specular.g = 1.0f;		g_Material.Diffuse.b = 1.0f;g_Material.Ambient.b = 0.0f;g_Material.Specular.b = 1.0f;		g_Material.Diffuse.a = 1.0f;g_Material.Ambient.a = 0.0f;g_Material.Specular.a = 1.0f;		g_pd3dDevice->SetMaterial(&g_Material);				g_pd3dDevice->SetStreamSource(0, g_pVB2, 0, sizeof(CUSTOMVERTEX));    	g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);		g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, CNumSP);		g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, ((CPar + 1) * 2), CNumEP);		g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, ((CPar + 1) * 3) + 1, CNumEP);		ZeroMemory(&g_Material, sizeof(D3DMATERIAL9));		g_Material.Diffuse.r = 1.0f;	g_Material.Ambient.r = 0.0f;		g_Material.Diffuse.g = 0.0f;	g_Material.Ambient.g = 0.0f;		g_Material.Diffuse.b = 1.0f;	g_Material.Ambient.b = 0.0f;		g_Material.Diffuse.a = 1.0f;	g_Material.Ambient.a = 0.0f;		g_pd3dDevice->SetMaterial(&g_Material);				g_pd3dDevice->SetStreamSource(0, g_pVB1, 0, sizeof(CUSTOMVERTEX));		g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);        g_pd3dDevice->SetIndices(g_pIB);   	    g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, SNumV,0, SNumP);//-----------------------LIGHTS-------------------------------------		g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );		ZeroMemory( &light, sizeof(D3DLIGHT9) );		light.Type       = D3DLIGHT_SPOT;		light.Diffuse.r  = 1.0f;	light.Ambient.r  = 1.0f;		light.Diffuse.g  = 1.0f;	light.Ambient.g  = 1.0f;		light.Diffuse.b  = 1.0f;	light.Ambient.b  = 1.0f;		light.Position = D3DXVECTOR3(0.0f, 150.0f, 0.0f);		light.Theta = D3DX_PI/4.0f; light.Phi = D3DX_PI/2.0f;		light.Attenuation0 = 0.0f;		light.Attenuation1 = 0.0f;		light.Attenuation2 = 1.0f;		vecDir = D3DXVECTOR3(0.0f,1.0f,0.0f);		D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );		light.Range       = 1000.0f;		g_pd3dDevice->SetLight( 0, &light );		g_pd3dDevice->LightEnable( 0, TRUE );				ZeroMemory( &light, sizeof(D3DLIGHT9) );		light.Type       = D3DLIGHT_DIRECTIONAL;		light.Diffuse.r  = 1.0f;//	light.Ambient.r  = 1.0f;		light.Diffuse.g  = 0.0f;//	light.Ambient.g  = 0.0f;		light.Diffuse.b  = 1.0f;//	light.Ambient.b  = 0.0f;		light.Theta = 30;			light.Phi = 90;		light.Position = D3DXVECTOR3(0.0f,0.0f,0.0f);		vecDir = D3DXVECTOR3(-150.0f,50.0f,0.0f);		D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );		light.Range       = 1000.0f;		g_pd3dDevice->SetLight( 0, &light );		g_pd3dDevice->LightEnable( 0, TRUE );		//		ZeroMemory( &light, sizeof(D3DLIGHT9) );		light.Type       = D3DLIGHT_DIRECTIONAL;		light.Diffuse.r  = 1.0f;	light.Ambient.r  = 0.0f;		light.Diffuse.g  = 1.0f;	light.Ambient.g  = 0.0f;		light.Diffuse.b  = 0.0f;	light.Ambient.b  = 0.0f;		vecDir = D3DXVECTOR3(150.0f,150.0f,0.0f);		D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );		light.Range       = 1000.0f;		g_pd3dDevice->SetLight( 0, &light );		g_pd3dDevice->LightEnable( 0, TRUE );		//				   	g_pd3dDevice->EndScene();	}	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );}LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){    switch( msg )    {	case WM_PAINT:		Reddraw(1);		break;    case WM_DESTROY:        Cleanup();        PostQuitMessage( 0 );		return 0;		break;    case WM_KEYUP:             switch (wParam)            {                 case VK_ESCAPE:                    DestroyWindow(hWnd);                    return 0;            }         break;	case WM_KEYDOWN:             switch (wParam)            {                 case VK_RIGHT:					Reddraw(1);                break;				case VK_LEFT:					Reddraw(2);                break;				case VK_UP:					Reddraw(3);                break;				case VK_DOWN:					Reddraw(4);                break;            }         break;        return 0;    }    return DefWindowProc( hWnd, msg, wParam, lParam );}INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT ){    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,        GetModuleHandle(NULL), NULL, NULL, NULL, NULL,        "app", NULL };    RegisterClassEx( &wc );	RECT rc = {0, 0, 320, 240};	AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);	HWND hWnd = CreateWindow( "app", "Application",        WS_OVERLAPPEDWINDOW, 100, 100, rc.right - rc.left, rc.bottom - rc.top,       GetDesktopWindow(), NULL, wc.hInstance, NULL );        if( SUCCEEDED( InitD3D( hWnd ) ) )    {        if( SUCCEEDED( InitGeometry() ) )        {            ShowWindow( hWnd, SW_SHOWDEFAULT );            UpdateWindow( hWnd );            MSG msg;            ZeroMemory( &msg, sizeof(msg) );            while( msg.message!=WM_QUIT )            {                if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )                {                    TranslateMessage( &msg );                    DispatchMessage( &msg );                }                else                    Render();            }        }    }    UnregisterClass( "app", wc.hInstance );    return 0;}

nedemon
nedemon
By the way, if i try to turn on spot or point lights after directional, everything is just black.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.