Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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[i].nRMul/(1+_i);
      planetMeshMaterials[0].Ambient.g:=(0.7-i/90)*planettyp[i].ngMul/(1+_i);
      planetMeshMaterials[0].Ambient.b:=(0.7-i/90)*planettyp[i].nbMul/(1+_i);
      planetMeshMaterials[0].Diffuse.r:=(0.5)*planettyp[i].nRMul/(1+_i);
      planetMeshMaterials[0].Diffuse.g:=(0.5)*planettyp[i].nGMul/(1+_i);
      planetMeshMaterials[0].Diffuse.b:=(0.5)*planettyp[i].nBMul/(1+_i);
      planetMeshMaterials[0].Specular.r:=(0.5)*planettyp[i].nRMul/(1+_i);
      planetMeshMaterials[0].Specular.g:=(0.5)*planettyp[i].nGMul/(1+_i);
      planetMeshMaterials[0].Specular.b:=(0.5)*planettyp[i].nBMul/(1+_i);
      planetMeshMaterials[0].Emissive.r:=(1-i/90)*planettyp[i].nRMul/(1+_i);
      planetMeshMaterials[0].Emissive.g:=(1-i/90)*planettyp[i].nGMul/(1+_i);
      planetMeshMaterials[0].Emissive.b:=(1-i/90)*planettyp[i].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[i].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[i].texture);
        if i=1 then SetTexture(0,planet3d[i].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[i].matrot,planet3d[i].nweite/600*(_i+1));
        x:=cos(planet3d[i].nweite/planet3d[nchosenplanet].nRotSpeed)*planet3d[i].nRotX;
        z:=sin(planet3d[i].nweite/planet3d[nchosenplanet].nRotSpeed)*planet3d[i].nRotX;
        y:=32-i*2;
      end else
      if i=1 then begin
        D3DXMatrixRotationY(planet3d[i].matrot,nresttimer*_i/1000);
        x:=0;
        y:=0;
        z:=0;
      end;
      planet3d[i].x:=x;
      planet3d[i].y:=y;
      planet3d[i].z:=z;
      D3DXMatrixTranslation(planet3d[i].matxyz,x,y,z);
      D3DXMatrixMultiply(matTmp, planet3d[i].matrot, planet3d[i].matxyz);
      //Skalieren
      mattmp._11 := mattmp._11 * planettyp[i].nradius/(5000-_i*160);
      mattmp._12 := mattmp._12 * planettyp[i].nradius/(5000-_i*160);
      mattmp._13 := mattmp._13 * planettyp[i].nradius/(5000-_i*160);
      mattmp._21 := mattmp._21 * planettyp[i].nradius/(5000-_i*160);
      mattmp._22 := mattmp._22 * planettyp[i].nradius/(5000-_i*160);
      mattmp._23 := mattmp._23 * planettyp[i].nradius/(5000-_i*160);
      mattmp._31 := mattmp._31 * planettyp[i].nradius/(5000-_i*160);
      mattmp._32 := mattmp._32 * planettyp[i].nradius/(5000-_i*160);
      mattmp._33 := mattmp._33 * planettyp[i].nradius/(5000-_i*160);
      //if i=1 then D3DXMatrixScaling(planet3d[i].matxyz,planettyp[i].nradius/5000,planettyp[i].nradius/5000,planettyp[i].nradius/5000); //größer skalieren
      xenscreen.Device.SetTransform(D3DTS_WORLD,mattmp);
      planetMesh.DrawSubset(0);
      if i>1 then inc(planet3d[i].nweite);
    end;
    for i:=1 to 5 do begin
      SetMaterial(ring3d[i].g_pMeshMaterials[0]);
      SetTexture(0,ring3d[i].g_pMeshTextures[0]);
      SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
      SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
      SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_Modulate);
      D3DXMatrixRotationY(ring3d[i].matrot,planet3d[i*6].nweite/1200);
      D3DXMatrixMultiply(ring3d[i].mat,ring3d[i].matrot, planet3d[i*6].matxyz);
      xenscreen.Device.SetTransform(D3DTS_WORLD,ring3d[i].mat);
      ring3d[i].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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this