Am I pursuing a Bad Idea With Char's?

closed account (zb0S216C)
I'm creating a small library that contains 3D/2D vectors and such for any future gaming projects. I though to myself, "Should I use the X, Y and Z characters to represent the 3D/2D axes?". Here's and example of what I mean:
1
2
3
4
5
6
7
8
9
10
11
12
13
int ExampleArray[ 3 ] = { 0.0f, 0.0f, 0.0f };

void Set( char Axis, float NewValue )
{
    switch( Axis )
    {
        case 'X' : case 'x': ExampleArray[ 0 ] = NewValue; break;
        case 'Y' : case 'y': ExampleArray[ 1 ] = NewValue; break;
        case 'Z' : case 'z': ExampleArray[ 2 ] = NewValue; break;
        default: break;
    }
    return;
}

Is this a good idea to pursue? To me it's simpler than entering the array index manually and I know which axis I'm altering. I would appreciate any input. Thanks.
Last edited on
Don't do that. Use a struct:

1
2
3
4
5
6
struct Vector3D {
    int x, y, z;

    Vector3D(xx, yy, zz)
    :x(xx), y(yy), z(zz) { }
};
closed account (zb0S216C)
I suppose I could do that. This is an example code, not the actual code. Also, the actual code is enclosed in an class.
Last edited on
Topic archived. No new replies allowed.