Disign questions and more

Started by
2 comments, last by sjelkjd 19 years, 5 months ago
Hello all! I have some design questions. First let me say im using C#. 1.) I have a general quad class representing a quad aligned on the axis: Looks something like this:

sealed class AAQuad
{
   private Vector2 position;
   private  Vector2 size;
   //...   

   public static bool Collides( AAQuad qA, AAQuad qB ){ // .. }
}


So I store the quad as a position and a size. Well, this isn't so good! Here a new attempt:

sealed class AAQuad
{
   private Vector2 min;
   private Vector2 max;
   //...   

   public static bool Collides( AAQuad qA, Vector2 posA,
                               AAQuad qB, Vector2 posB )
   {
      // ..
   }
}


The quad is represented as a min and a max vector. The Collides() function uses the quad to get the collision mask and an extra vectors for an offset, that is normally inside the position Vector2 in attempt one. Which one is better? I think the 2nd, bcs. a quad is normally used by other higher systems that contain a position. 2.) When should I use static functions? Stroustrup.(spelled wrong) said that you should make as few as possible member functions. ( global in C++, static in C# ) Eg, wat about the Collide() function in my first question. 3.) More will come! ^^ Thank you! :D [/source]
Advertisement
Quote:Original post by rakoon2Which one is better? I think the 2nd, bcs. a quad is normally used by other higher systems that contain a position.

Hmm. What if it is used by other higher systems that also have a rotation? Or a scale?

I would handle this by doing what you did in the first function, where you just do quad/quad intersection. If the quads are in different coordinate systems you can either add a version of Collides that takes a matrix, which specifies the transform from one system to another, or you can transform the quads yourself.
BTW, the term 'Axis Aligned Bounding Box' is generally used for what you are describing.

Quote:
2.) When should I use static functions? Stroustrup.(spelled wrong) said that you should make as few as possible member functions. ( global in C++, static in C# )

It's less important to adhere to this rule in c# than it was in c++. In c++, every member function would increase the dependence on other classes - you had to have a class defined to use the member function(which meant including the header), but if it was a global function that took the class variable by ref, you only had to pre-declare the class(class blah;).

In c#, the physical organization of your class files isn't as important, due to the 2-pass nature of the compiler. In your specific case, use your instinct - it's more a matter of style.
Hi! :)


"Axis Aligned Bounding Box", well I already have that class. ( 3d )

Im going to use the first class concept. Im going to provide functions that take an extra offset( e.g. position ).



@Matrix, well I didnt have that at school yet. Gonna take some time till we will do that. Any >good< tutorials?


@Statics, ok. Normal and static functions have the same speed. ( If they are build the same, and use member data. )
A function that doesnt use member data and is static if better than a nonstatic. ( The this pointer isnt used. )


Thanks all. :)



Quote:Original post by rakoon2
@Matrix, well I didnt have that at school yet. Gonna take some time till we will do that. Any >good< tutorials?

Not any good web links. The best way to learn this is in an intro to graphics class.

This topic is closed to new replies.

Advertisement