stereo's picture


I propose to add to the math library:

to a Vector2 struc:
/// Defines a one-length Vector2
public static readonly Vector2 One = new Vector2(1, 1);

to a Vector3 struc:
/// Defines a one-length Vector3
public static readonly Vector3 One = new Vector3(1, 1, 1);

to a Vector4 struc:
/// Defines a one-length Vector4
public static readonly Vector4 One = new Vector4(1, 1, 1, 1);

This is helpfuly in many cases.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kamujin's picture

Since we are on the topic, it might be worth while to add negative unit vectors.

public static readonly Vector3 UnitXNeg = new Vector3(-1, 0, 0);
public static readonly Vector3 UnitYNeg = new Vector3(0, -1, 0);
public static readonly Vector3 UnitZNeg = new Vector3(0, 0, -1);
the Fiddler's picture

And finally rename these to:

Vector3.Left / Right
Vector3.Up / Down
Vector3.Forward / Backward

which are slightly more readable.

Kamujin's picture

I wouldn't mind those names, but they do imply an understanding of OpenGL's right handed bias.

Just playing devils advocate, do you think it would be too confusing to someone trying to use OpenGL with left handed coordinates?

the Fiddler's picture

I don't think that would be a problem when using a left-hand coordinate system:

  • You have made a conscious choice to use a non-default coordinate system, and you should be aware of the caveats.
  • UnitX / UnitXNeg hold the same potential for confusion (they need to be swapped).

We should probably make it clear that the default (right-hand) system is assumed.

objarni's picture

BTW OpenTK does make a judgement call on using OpenGL, right..? So assuming OpenGL coordinate system is not a problem.

Entropy's picture

Personally, I prefer UnitX/Y/Z(Neg), as they are somewhat more general, in a mathematical sense.

I agree that the Math and OpenGL namespaces should interface well with each other, but I think there's a lot to be said for keeping the Math library "pure", in a sense.

Perhaps the XML documentation should clarify the coordinate system?

/// Unit vector in the X (Left) direction
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);

Or something like that.

objarni's picture

@Entropy: I think you mean Right == (1,0,0), at least that is how I visualize OpenGLs coordinate system.

Entropy's picture


Yes, I do. Never could get the hang of left & right...

Maybe that's the real reason I prefer UnitX! ;-)