Error in Mat4x4::SetScale(Vec3)

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Error in Mat4x4::SetScale(Vec3)

      Hi,

      i really like the book and I currently test the Code.

      For the Mat4x4, if I'm not completely wrong, I believe that

      Source Code

      1. inline void Mat4x4::SetScale(Vec3 const &scale)
      2. {
      3. m[1][1] = scale.x;
      4. m[2][2] = scale.y;
      5. m[3][3] = scale.z;
      6. }


      should be:

      Source Code

      1. inline void Mat4x4::SetScale(Vec3 const &scale)
      2. {
      3. m[0][0] = scale.x;
      4. m[1][1] = scale.y;
      5. m[2][2] = scale.z;
      6. }


      Also for Mat4x4BuildScale it should be:

      Source Code

      1. inline void Mat4x4::BuildScale(const float x, const float y, const float z )
      2. {
      3. *this = Mat4x4::g_Identity;
      4. m[0][0] = x;
      5. m[1][1] = y;
      6. m[2][2] = z;
      7. }


      Cupiii

      The post was edited 1 time, last by cupiii ().

    • Also I think that:

      Source Code

      1. bool Plane::Inside(const Vec3 &point, const float radius) const
      2. {
      3. float fDistance; // calculate our distances to each of the planes
      4. // find the distance to this plane
      5. fDistance = D3DXPlaneDotCoord(this, &point);
      6. // if this distance is < -radius, we are outside
      7. return (fDistance >= -radius);
      8. }


      should be

      Source Code

      1. bool Plane::Inside(const Vec3 &point, const float radius) const
      2. {
      3. float fDistance; // calculate our distances to each of the planes
      4. // find the distance to this plane
      5. fDistance = D3DXPlaneDotCoord(this, &point);
      6. // if this distance is < radius, we are outside
      7. return (fDistance >= radius);
      8. }

      Changed return statement from -radius to radius.

      I'm just unit-Testing the Classes right now. I hope posting the errors i find is OK for all. As I said, I really like the book and recommended it already to several people.
    • I think "bool Plane::Inside()" method is correct. My math is little bit rusty so correct me if i am wrong. ( Assuming point parameter is the center of the bouding sphere, and radius is the radius of the bounding sphere ) D3DXPlaneDotCoord might give negative or positive result depending on whether center of the sphere is in the same side where the plane normal is pointing to. You could get negative fDistance if the center of the sphere is not in the same side where the plane normal is pointing to ;however this doesn't mean that whole sphere is out of the frustrum . Some little part of the sphere might be inside frustrum. If you check for only positive values, your model will popping in and out from the scene which would not result a good looking frustrum culling :)
    • Ah, now I see...

      The function checks, if ANYTHING of the sphere is inside the plane... Then it makes sense...

      I thought that this function checks, if EVERYTHING of the sphere is inside the plane.

      I'll rename the method to PartlyInside and add a Method called FullInside.

      Thanks for the suggestion! Great ;)