Skip navigation

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
  }
}
Advertisements

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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: