Problem with coordinates whit larger distance to 0/0/0

This topic is 4970 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, I made my own 3D universe map with 31 planets, planet 1 is the sun with coordinates, the other 30 planets rotate around the sun with different distances to the sun. First I made a 'dublesphere', a sphere with 2 materials, one smaller for surface texture, one larger for cloud texture. But the more the planets are away from the sun, the more the both materials/textures don't fit, the first planet near the sun looks perfect, the last one it seems the materials have different coordinates. So I changed the 'doublesphere' to a 'sphere' with only one material, and I draw it twice, the second time I make it a bit larger for my cloud texture. But the problem is exactly the same, looking very strange. Near planet Distant planet (1024 x 768 pixels) Here the code to draw the planets:
procedure TCommandoForm.draw_planets(booltext:boolean);
var _i : longint;
i:   integer;
x,y,z: single;
dwCaps: DWORD;
v: TD3DXVector3;
fogstart,fogend,fogdensity: single;
var matTmp: TD3DXMatrix;
begin
with xenscreen.Device do begin
for i:=1 to 31 do
for _i:=0 to ndetail do begin
// Set the material for the subset.
planetMeshMaterials[0].Ambient.r:=(0.7-i/90)*planettyp.nRMul/(1+_i);
planetMeshMaterials[0].Ambient.g:=(0.7-i/90)*planettyp.ngMul/(1+_i);
planetMeshMaterials[0].Ambient.b:=(0.7-i/90)*planettyp.nbMul/(1+_i);
planetMeshMaterials[0].Diffuse.r:=(0.5)*planettyp.nRMul/(1+_i);
planetMeshMaterials[0].Diffuse.g:=(0.5)*planettyp.nGMul/(1+_i);
planetMeshMaterials[0].Diffuse.b:=(0.5)*planettyp.nBMul/(1+_i);
planetMeshMaterials[0].Specular.r:=(0.5)*planettyp.nRMul/(1+_i);
planetMeshMaterials[0].Specular.g:=(0.5)*planettyp.nGMul/(1+_i);
planetMeshMaterials[0].Specular.b:=(0.5)*planettyp.nBMul/(1+_i);
planetMeshMaterials[0].Emissive.r:=(1-i/90)*planettyp.nRMul/(1+_i);
planetMeshMaterials[0].Emissive.g:=(1-i/90)*planettyp.nGMul/(1+_i);
planetMeshMaterials[0].Emissive.b:=(1-i/90)*planettyp.nBMul/(1+_i);
SetMaterial(planetMeshMaterials[0]);
// Set the texture for the subset.
if _i=0 then begin
//Oberflächen-Textur
setrenderstate(d3drs_alphablendenable,dword(false));
SetTexture(0,planet3d.texture);
SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_Modulate);
end;
if _i>0 then begin
//Cloud-Textur
setrenderstate(d3drs_alphablendenable,dword(true));
//        SetTexture(0,planet3d.texture);
if i=1 then SetTexture(0,planet3d.texture) else
SetTexture(0,planetMeshTexture);
setrenderstate(d3drs_alphablendenable,dword(true));
setrenderstate(d3drs_srcblend,d3dblend_srcalpha);
//setrenderstate(d3drs_destblend,d3dblend_invsrcalpha);
setrenderstate(d3drs_destblend,d3dblend_one);
SetTextureStageState(0,D3DTSS_colorarg1,d3dta_texture);
SetTextureStageState(0,D3DTSS_colorarg2,d3dta_diffuse);
SetTextureStageState(0,D3DTSS_colorOP,D3DTOP_modulate);
end;
if i>1 then begin
D3DXMatrixRotationY(planet3d.matrot,planet3d.nweite/600*(_i+1));
x:=cos(planet3d.nweite/planet3d[nchosenplanet].nRotSpeed)*planet3d.nRotX;
z:=sin(planet3d.nweite/planet3d[nchosenplanet].nRotSpeed)*planet3d.nRotX;
y:=32-i*2;
end else
if i=1 then begin
D3DXMatrixRotationY(planet3d.matrot,nresttimer*_i/1000);
x:=0;
y:=0;
z:=0;
end;
planet3d.x:=x;
planet3d.y:=y;
planet3d.z:=z;
D3DXMatrixTranslation(planet3d.matxyz,x,y,z);
D3DXMatrixMultiply(matTmp, planet3d.matrot, planet3d.matxyz);
//Skalieren
xenscreen.Device.SetTransform(D3DTS_WORLD,mattmp);
planetMesh.DrawSubset(0);
if i>1 then inc(planet3d.nweite);
end;
for i:=1 to 5 do begin
SetMaterial(ring3d.g_pMeshMaterials[0]);
SetTexture(0,ring3d.g_pMeshTextures[0]);
SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_Modulate);
D3DXMatrixRotationY(ring3d.matrot,planet3d[i*6].nweite/1200);
D3DXMatrixMultiply(ring3d.mat,ring3d.matrot, planet3d[i*6].matxyz);
xenscreen.Device.SetTransform(D3DTS_WORLD,ring3d.mat);
ring3d.g_pMesh.DrawSubset(0);
end;
setrenderstate(d3drs_alphablendenable,dword(false));
end;
end;


Any ideas please? I am trying to solve this *%\$%§!!! problem for a week now. Thanks a lot, Firle [Edited by - LessBread on February 11, 2005 2:50:48 AM]

Share on other sites
Hi,
Iam not the "god-like dx9" programmer, but Iam interested in your problem. When I face some problem like your (ie. I think that nothing is wrong in my code and error must be in DX or CPU, not in my code), I try to reduce my code to the torso, when almost everything is disabled (/* code*/) BUT the program works properly. Then I (very slowly, one by one) add little parts of disabled code, test it, until I catch the single commmand, that causes "!?@*!! problem. Now I know know who is "guilty" and can easily fix it.
I know that this is not an advice you have expected, but Iam only trying to share my experience. This way I repaired all my "unfixable" bugs. So try to build your universe without any material settings and if it worx fine, slowly add some material (or other) specifications, until you find the damn line(s).

good luck

Share on other sites
There's no problem with the coordinates, the problem is with the mipmaps, when the planet is far away D3D is using a small mipmap that probably is completely white so you get that effect.
To fix it you could create your own mipmaps using the DXTex program.

Share on other sites
Wait, nevermind I read it all wrong ahah
The problam is probably that the floating point accuracy is maxed out. You could create some clever mechamism to make the camera always at 0,0,0 and the planets move instead of the camera, that way you always get the same precision.

Share on other sites
Hello Anonymous,

is there any other way to fix it instead of changing every single coordinate?
That would be a hell of work...

The effect is stronger when the planet is far away, so there should be an other solution, I hope. what about that mipmaps, is it worth a try?
How do I do that?

Could it also be a problem that the surface texture is smaller than the clouds texture?

Thanks,
Firle

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
14
5. 5

• 12
• 9
• 17
• 19
• 9
• Forum Statistics

• Total Topics
632599
• Total Posts
3007335

×