Add operator[] to vector2d and vector3d
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5841 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
2178368d71
commit
fd155bead0
|
@ -1,5 +1,6 @@
|
|||
--------------------------
|
||||
Changes in 1.9 (not yet released)
|
||||
- Add operator[] to vector2d and vector3d
|
||||
- Bugfix: IrrlichtDevice::isWindowMinimized no longer returns true when it's maximized on Windows.
|
||||
- Ignore degenerated faces in obj file loader when they would generate triangles where 2 vertices use identical indices.
|
||||
- Add CMatrix4::transformVec4 to transform vectors with 4 elements (thx @ devsh)
|
||||
|
|
|
@ -64,6 +64,20 @@ public:
|
|||
vector2d<T> operator/(const T v) const { return vector2d<T>(X / v, Y / v); }
|
||||
vector2d<T>& operator/=(const T v) { X/=v; Y/=v; return *this; }
|
||||
|
||||
T& operator [](u32 index)
|
||||
{
|
||||
_IRR_DEBUG_BREAK_IF(index>1) // access violation
|
||||
|
||||
return *(&X+index);
|
||||
}
|
||||
|
||||
const T& operator [](u32 index) const
|
||||
{
|
||||
_IRR_DEBUG_BREAK_IF(index>1) // access violation
|
||||
|
||||
return *(&X+index);
|
||||
}
|
||||
|
||||
//! sort in order X, Y. Equality with rounding tolerance.
|
||||
bool operator<=(const vector2d<T>&other) const
|
||||
{
|
||||
|
|
|
@ -57,6 +57,20 @@ namespace core
|
|||
vector3d<T> operator/(const T v) const { T i=(T)1.0/v; return vector3d<T>(X * i, Y * i, Z * i); }
|
||||
vector3d<T>& operator/=(const T v) { T i=(T)1.0/v; X*=i; Y*=i; Z*=i; return *this; }
|
||||
|
||||
T& operator [](u32 index)
|
||||
{
|
||||
_IRR_DEBUG_BREAK_IF(index>2) // access violation
|
||||
|
||||
return *(&X+index);
|
||||
}
|
||||
|
||||
const T& operator [](u32 index) const
|
||||
{
|
||||
_IRR_DEBUG_BREAK_IF(index>2) // access violation
|
||||
|
||||
return *(&X+index);
|
||||
}
|
||||
|
||||
//! sort in order X, Y, Z. Equality with rounding tolerance.
|
||||
bool operator<=(const vector3d<T>&other) const
|
||||
{
|
||||
|
|
|
@ -36,6 +36,15 @@ static bool doTests()
|
|||
return false;
|
||||
}
|
||||
|
||||
otherVec = vector2d<T>(1,2);
|
||||
otherVec[0] = vec[0];
|
||||
otherVec[1] = vec[1];
|
||||
if(!vec.equals(otherVec))
|
||||
{
|
||||
logTestString("vector2d::operator[] failed\n");
|
||||
assert_log(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
vec.rotateBy(45); // Test implicit (0, 0) center
|
||||
COMPARE_VECTORS(vec, vector2d<T>(0, (T)7.0710678118654755));
|
||||
|
|
|
@ -208,6 +208,7 @@ static bool doTests()
|
|||
{
|
||||
vector3d<T> vec(-5, 5, 0);
|
||||
vector3d<T> otherVec((T)-5.1, 5, 0);
|
||||
|
||||
if(!vec.equals(otherVec, (T)0.1))
|
||||
{
|
||||
logTestString("vector3d::equals failed\n");
|
||||
|
@ -215,6 +216,17 @@ static bool doTests()
|
|||
return false;
|
||||
}
|
||||
|
||||
otherVec = vector3d<T>(1,2,3);
|
||||
otherVec[0] = vec[0];
|
||||
otherVec[1] = vec[1];
|
||||
otherVec[2] = vec[2];
|
||||
if(!vec.equals(otherVec))
|
||||
{
|
||||
logTestString("vector3d::operator[] failed\n");
|
||||
assert_log(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
vec.set(5, 5, 0);
|
||||
otherVec.set(10, 20, 0);
|
||||
if(!equals(vec.getDistanceFrom(otherVec), (T)15.8113883))
|
||||
|
|
Loading…
Reference in New Issue