I do not like the lack of flexibility in how you call a base class constructor in C#:


Example of how its limiting: I’ve inherited the BoundingFrustum:

public class MyFrustum : BoundingFrustum
{
  public MyFrustum( Matrix value ) : base( value )
  {

  }
}

Because passing a matrix describing your frustum to the BoundingFrustum class constructor is REQUIRED, I have to call the base class constructor IMMEDIATELY with some matrix describing the frustum.

Now I personally, created this class so that the Frustum can remember its Eye, Look, Up vectors conveniently, and its View matrix and its Projection matrix.

SO, I write:

public class MyFrustum : BoundingFrustum
{
  Vector3 eye, look, up ;  Matrix view, projection ;
  public MyFrustum( Vector3 Eye, Vector3 Look, Vector3 Up, Matrix Projection ) : base( Matrix.CreateLookAt( Eye, Look, Up ) * Projection )
  {
    eye=Eye; look=Look; up=Up;
    projection=Projection;

    // NOW I HAVE TO RECOMPUTE THE VIEW MATRIX __AGAIN__!!
    // because i LOSt the value passed to the base class ctor
    // and I can't get it back
    view = Matrix.CreateLookAt( Eye, Look, Up ) ;

  }
}

You might say, “well just pass the View matrix and get the Eye from it!”

Well, you can’t do that without an inversion which is too expensive.

Wouldn’t it be better, C#, to let me just do something like:

public class MyFrustum : BoundingFrustum
{
  Vector3 eye, look, up ;  Matrix view, projection ;
  public MyFrustum( Vector3 Eye, Vector3 Look, Vector3 Up, Matrix Projection )
  {
    eye=Eye; look=Look; up=Up;
    projection=Projection;

    // NOW I HAVE TO RECOMPUTE THE VIEW MATRIX __AGAIN__!!
    // because i LOSt the value passed to the base class ctor
    // and I can't get it back
    view = Matrix.CreateLookAt( Eye, Look, Up ) ;

    base( view * projection ) ;  // This WOULD work much better
  }
}

One Comment

    • RaiulBaztepo
    • Posted March 30, 2009 at 11:25 am
    • Permalink

    Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo


Post a Comment