Results 1 to 3 of 3

Thread: D3DMaterials matching

  1. #1

    D3DMaterials matching

    Hi all!
    Sorry for that... but... i have a fantastic stupid question :?

    So: DirectX 8.1 Clootie header (Hi Clootie! )

    var D3DMatA, D3DMatB: D3DMaterial8;
    ...
    if D3DMatA=D3DMatB then ...
    ...

    Compile -> Hmm, no, "Incompatible types...". Ok:

    ...
    if D3DMatA.Ambient=D3DMatB.Ambient then ...
    ...

    Compile -> Hmm, no, "Incompatible types...". Ok:

    ...
    if (D3DMatA.Ambient.r=D3DMatB.Ambient.r) and (D3DMatA.Ambient.g=D3DMatB.Ambient.g) and ...
    ...

    It works! But, <GH!> I'm sure that's not the right method :shock:

    How to do it? Tanks in advance

  2. #2

    D3DMaterials matching

    Hi!
    So, we have:
    [pascal][background=#FFFFFF][normal=#000000][number=#0000FF][string=#0000FF][comment=#248F24][reserved=#000000] TD3DColorValue = packed record
    r: Single;
    g: Single;
    b: Single;
    a: Single;
    end {_D3DCOLORVALUE};

    TD3DMaterial8 = packed record
    Diffuse: TD3DColorValue; { Diffuse color RGBA }
    Ambient: TD3DColorValue; { Ambient color RGB }
    Specular: TD3DColorValue; { Specular 'shininess' }
    Emissive: TD3DColorValue; { Emissive color RGB }
    Power: Single; { Sharpness if specular highlight }
    end {_D3DMATERIAL8};[/pascal]
    So you can't compare record directly in Delphi. And compiler is right. One of possible quick solution is to use:
    [pascal][background=#FFFFFF][normal=#000000][number=#0000FF][string=#0000FF][comment=#248F24][reserved=#000000]if CompareMem(@mat1, @mat2, SizeOf(mat1)) = 0 then // they are equal memory wise[/pascal]
    But this can be correct in your case but incorrect in general as colors represented by floats and nobody should compare float by "=" operator.
    Ideal solutions should be:
    [pascal][background=#FFFFFF][normal=#000000][number=#0000FF][string=#0000FF][comment=#248F24][reserved=#000000]function CompareMaterials(m1, m2: TD3ddMaterial): Boolean;
    const
    Eps = 0.00001;
    function CompareColors(c1, c2: TD3DColorValue): Boolean;
    begin
    Result:= (Abs(c1.r - c2.r) < Eps) and (Abs(c1.g - c2.g) < Eps) and (Abs(c1.b - c2.b) < Eps) and (Abs(c1.a - c2.a) < Eps);
    end
    begin
    Result:= CompareColors(m1.Diffuse, m2.Diffuse) and ....
    and (Abs(m1.Power - m2.Power) < Eps);
    end;
    [/pascal]
    There are only 10 types of people in this world; those who understand binary and those who don't.

  3. #3

    D3DMaterials matching

    I'm glad that i was not so wrong...

    Thank you! I like your solution

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •