1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#pragma once
#include "Stdafx.h"
namespace Box2D
{
namespace Net
{
public ref class Vector
{
internal:
b2Vec2 getVec2()
{
return b2Vec2(X, Y);
}
public:
//TODO: this needs to be read only outside the class,
//because if you have a vector as a get property, and
//try to set the X,Y components, it won't take to the
//original vector:
//
//ie: Shape.Extents.X += 10;
//won't behave like you think it should (or will it?)
float32 X, Y;
Vector() : X(0), Y(0) { }
Vector(float32 x, float32 y) : X(x), Y(y) { }
Vector(Vector^ other) : X(other->X), Y(other->Y) { }
Vector(const b2Vec2 &other) : X(other.x), Y(other.y) { }
/*
Vector^ Set(float32 x, float32 y)
{
X = x;
Y = y;
return this;
}
*/
///Defines basic vector addition
static Vector^ operator +(Vector^ a, Vector^ b)
{
return gcnew Vector(a->X + b->X, a->Y + b->Y);
}
///<summary>Negates a vector (that is, returns (-X, -Y)</summary>
static Vector^ operator - (Vector^ a)
{
return gcnew Vector(-a->X, -a->Y);
}
///<summary>Defines basic vector subtraction</summary>
static Vector^ operator - (Vector^ a, Vector^ b)
{
return gcnew Vector(a->X - b->X, a->Y - b->Y);
}
///<summary>Scalar multiplication for a vector</summary>
static Vector^ operator * (Vector^ a, float32 b)
{
return gcnew Vector(a->X * b, a->Y * b);
}
/*
static Vector^ operator = (Vector^ a, Vector^ b)
{
a.X = b.X;
a.Y = b.Y;
}
*/
///<summary>Returns a string representation of this vector</summary>
virtual System::String^ ToString() override
{
return gcnew System::String("<" + X + ", " + Y + ">");
}
};
}
}
|