Commit 6f1db5fc authored by cutealien's avatar cutealien

- Add vector2d and dimension2d attributes (both already had incomplete parts...

- Add vector2d and dimension2d attributes (both already had incomplete parts of implementations for some reason)
- Add tests for vector2d and dimension2d attributes
- Test currently failing on Win32-VS: collisionResponseAnimator, sceneCollisionManager, screenshot

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3996 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ca0a9cca
...@@ -40,7 +40,7 @@ enum E_ATTRIBUTE_TYPE ...@@ -40,7 +40,7 @@ enum E_ATTRIBUTE_TYPE
// 2d position attribute // 2d position attribute
EAT_POSITION2D, EAT_POSITION2D,
// vector 2d // vector 2d attribute
EAT_VECTOR2D, EAT_VECTOR2D,
// rectangle attribute // rectangle attribute
...@@ -85,6 +85,9 @@ enum E_ATTRIBUTE_TYPE ...@@ -85,6 +85,9 @@ enum E_ATTRIBUTE_TYPE
// user pointer void* // user pointer void*
EAT_USER_POINTER, EAT_USER_POINTER,
// dimension attribute
EAT_DIMENSION2D,
// known attribute type count // known attribute type count
EAT_COUNT, EAT_COUNT,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "triangle3d.h" #include "triangle3d.h"
#include "position2d.h" #include "position2d.h"
#include "rect.h" #include "rect.h"
#include "dimension2d.h"
#include "matrix4.h" #include "matrix4.h"
#include "quaternion.h" #include "quaternion.h"
#include "plane3d.h" #include "plane3d.h"
...@@ -412,6 +413,30 @@ public: ...@@ -412,6 +413,30 @@ public:
//! Sets an attribute as vector //! Sets an attribute as vector
virtual void setAttribute(s32 index, core::vector3df v) = 0; virtual void setAttribute(s32 index, core::vector3df v) = 0;
/*
Vector2d Attribute
*/
//! Adds an attribute as 2d vector
virtual void addVector2d(const c8* attributeName, core::vector2df value) = 0;
//! Sets a attribute as 2d vector
virtual void setAttribute(const c8* attributeName, core::vector2df v) = 0;
//! Gets an attribute as vector
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::vector2df getAttributeAsVector2d(const c8* attributeName) = 0;
//! Gets an attribute as position
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::vector2df getAttributeAsVector2d(s32 index) = 0;
//! Sets an attribute as 2d vector
virtual void setAttribute(s32 index, core::vector2df v) = 0;
/* /*
Position2d Attribute Position2d Attribute
...@@ -461,6 +486,31 @@ public: ...@@ -461,6 +486,31 @@ public:
virtual void setAttribute(s32 index, core::rect<s32> v) = 0; virtual void setAttribute(s32 index, core::rect<s32> v) = 0;
/*
Dimension2d Attribute
*/
//! Adds an attribute as dimension2d
virtual void addDimension2d(const c8* attributeName, core::dimension2d<u32> value) = 0;
//! Sets an attribute as dimension2d
virtual void setAttribute(const c8* attributeName, core::dimension2d<u32> v) = 0;
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName) = 0;
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index) = 0;
//! Sets an attribute as dimension2d
virtual void setAttribute(s32 index, core::dimension2d<u32> v) = 0;
/* /*
matrix attribute matrix attribute
*/ */
......
...@@ -544,6 +544,23 @@ public: ...@@ -544,6 +544,23 @@ public:
return r; return r;
} }
virtual core::dimension2du getDimension2d()
{
core::dimension2d<u32> dim;
if (IsFloat)
{
dim.Width = (u32)(Count > 0 ? ValueF[0] : 0);
dim.Height = (u32)(Count > 1 ? ValueF[1] : 0);
}
else
{
dim.Width = (u32)(Count > 0 ? ValueI[0] : 0);
dim.Height = (u32)(Count > 1 ? ValueI[1] : 0);
}
return dim;
}
virtual core::matrix4 getMatrix() virtual core::matrix4 getMatrix()
{ {
core::matrix4 ret; core::matrix4 ret;
...@@ -1076,8 +1093,8 @@ public: ...@@ -1076,8 +1093,8 @@ public:
} }
else else
{ {
if (Count > 0) ValueI[0] = v.Width; if (Count > 0) ValueI[0] = (s32)v.Width;
if (Count > 1) ValueI[1] = v.Height; if (Count > 1) ValueI[1] = (s32)v.Height;
} }
} }
...@@ -1294,6 +1311,24 @@ public: ...@@ -1294,6 +1311,24 @@ public:
} }
}; };
// Attribute implemented for 2d vectors
class CVector2DAttribute : public CNumbersAttribute
{
public:
CVector2DAttribute(const char* name, core::vector2df value) : CNumbersAttribute(name, value) {}
virtual E_ATTRIBUTE_TYPE getType() const
{
return EAT_VECTOR2D;
}
virtual const wchar_t* getTypeString() const
{
return L"vector2d";
}
};
// Attribute implemented for 2d vectors // Attribute implemented for 2d vectors
class CPosition2DAttribute : public CNumbersAttribute class CPosition2DAttribute : public CNumbersAttribute
{ {
...@@ -1332,6 +1367,25 @@ public: ...@@ -1332,6 +1367,25 @@ public:
} }
}; };
// Attribute implemented for dimension
class CDimension2dAttribute : public CNumbersAttribute
{
public:
CDimension2dAttribute (const char* name, core::dimension2d<u32> value) : CNumbersAttribute(name, value) { }
virtual E_ATTRIBUTE_TYPE getType() const
{
return EAT_DIMENSION2D;
}
virtual const wchar_t* getTypeString() const
{
return L"dimension2d";
}
};
// Attribute implemented for matrices // Attribute implemented for matrices
class CMatrixAttribute : public CNumbersAttribute class CMatrixAttribute : public CNumbersAttribute
{ {
...@@ -1979,6 +2033,7 @@ public: ...@@ -1979,6 +2033,7 @@ public:
}; };
// todo: CGUIFontAttribute // todo: CGUIFontAttribute
} // end namespace io } // end namespace io
......
...@@ -416,6 +416,28 @@ core::rect<s32> CAttributes::getAttributeAsRect(const c8* attributeName) ...@@ -416,6 +416,28 @@ core::rect<s32> CAttributes::getAttributeAsRect(const c8* attributeName)
return core::rect<s32>(); return core::rect<s32>();
} }
//! Sets a attribute as dimension2d
void CAttributes::setAttribute(const c8* attributeName, core::dimension2d<u32> value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setDimension2d(value);
else
Attributes.push_back(new CDimension2dAttribute(attributeName, value));
}
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getDimension2d();
else
return core::dimension2d<u32>();
}
//! Sets a attribute as vector //! Sets a attribute as vector
void CAttributes::setAttribute(const c8* attributeName, core::vector3df value) void CAttributes::setAttribute(const c8* attributeName, core::vector3df value)
{ {
...@@ -426,6 +448,16 @@ void CAttributes::setAttribute(const c8* attributeName, core::vector3df value) ...@@ -426,6 +448,16 @@ void CAttributes::setAttribute(const c8* attributeName, core::vector3df value)
Attributes.push_back(new CVector3DAttribute(attributeName, value)); Attributes.push_back(new CVector3DAttribute(attributeName, value));
} }
//! Sets a attribute as vector
void CAttributes::setAttribute(const c8* attributeName, core::vector2df value)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
att->setVector2d(value);
else
Attributes.push_back(new CVector2DAttribute(attributeName, value));
}
//! Gets an attribute as vector //! Gets an attribute as vector
//! \param attributeName: Name of the attribute to get. //! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute() //! \return Returns value of the attribute previously set by setAttribute()
...@@ -438,6 +470,16 @@ core::vector3df CAttributes::getAttributeAsVector3d(const c8* attributeName) ...@@ -438,6 +470,16 @@ core::vector3df CAttributes::getAttributeAsVector3d(const c8* attributeName)
return core::vector3df(); return core::vector3df();
} }
//! Gets an attribute as vector
core::vector2df CAttributes::getAttributeAsVector2d(const c8* attributeName)
{
IAttribute* att = getAttributeP(attributeName);
if (att)
return att->getVector2d();
else
return core::vector2df();
}
//! Sets an attribute as binary data //! Sets an attribute as binary data
void CAttributes::setAttribute(const c8* attributeName, void* data, s32 dataSizeInBytes ) void CAttributes::setAttribute(const c8* attributeName, void* data, s32 dataSizeInBytes )
{ {
...@@ -664,7 +706,16 @@ core::vector3df CAttributes::getAttributeAsVector3d(s32 index) ...@@ -664,7 +706,16 @@ core::vector3df CAttributes::getAttributeAsVector3d(s32 index)
return core::vector3df(); return core::vector3df();
} }
//! Gets an attribute as rectangle //! Gets an attribute as 2d vector
core::vector2df CAttributes::getAttributeAsVector2d(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getVector2d();
else
return core::vector2df();
}
//! Gets an attribute as position2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1. //! \param index: Index value, must be between 0 and getAttributeCount()-1.
core::position2di CAttributes::getAttributeAsPosition2d(s32 index) core::position2di CAttributes::getAttributeAsPosition2d(s32 index)
{ {
...@@ -684,6 +735,16 @@ core::rect<s32> CAttributes::getAttributeAsRect(s32 index) ...@@ -684,6 +735,16 @@ core::rect<s32> CAttributes::getAttributeAsRect(s32 index)
return core::rect<s32>(); return core::rect<s32>();
} }
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
core::dimension2d<u32> CAttributes::getAttributeAsDimension2d(s32 index)
{
if ((u32)index < Attributes.size())
return Attributes[index]->getDimension2d();
else
return core::dimension2d<u32>();
}
//! Gets an attribute as binary data //! Gets an attribute as binary data
///! \param index: Index value, must be between 0 and getAttributeCount()-1. ///! \param index: Index value, must be between 0 and getAttributeCount()-1.
...@@ -799,6 +860,13 @@ void CAttributes::addVector3d(const c8* attributeName, core::vector3df value) ...@@ -799,6 +860,13 @@ void CAttributes::addVector3d(const c8* attributeName, core::vector3df value)
Attributes.push_back(new CVector3DAttribute(attributeName, value)); Attributes.push_back(new CVector3DAttribute(attributeName, value));
} }
//! Adds an attribute as 2d vector
void CAttributes::addVector2d(const c8* attributeName, core::vector2df value)
{
Attributes.push_back(new CVector2DAttribute(attributeName, value));
}
//! Adds an attribute as 2d position //! Adds an attribute as 2d position
void CAttributes::addPosition2d(const c8* attributeName, core::position2di value) void CAttributes::addPosition2d(const c8* attributeName, core::position2di value)
{ {
...@@ -811,6 +879,12 @@ void CAttributes::addRect(const c8* attributeName, core::rect<s32> value) ...@@ -811,6 +879,12 @@ void CAttributes::addRect(const c8* attributeName, core::rect<s32> value)
Attributes.push_back(new CRectAttribute(attributeName, value)); Attributes.push_back(new CRectAttribute(attributeName, value));
} }
//! Adds an attribute as dimension2d
void CAttributes::addDimension2d(const c8* attributeName, core::dimension2d<u32> value)
{
Attributes.push_back(new CDimension2dAttribute(attributeName, value));
}
//! Adds an attribute as binary data //! Adds an attribute as binary data
void CAttributes::addBinary(const c8* attributeName, void* data, s32 dataSizeInBytes) void CAttributes::addBinary(const c8* attributeName, void* data, s32 dataSizeInBytes)
{ {
...@@ -887,6 +961,13 @@ void CAttributes::setAttribute(s32 index, core::vector3df v) ...@@ -887,6 +961,13 @@ void CAttributes::setAttribute(s32 index, core::vector3df v)
Attributes[index]->setVector(v); Attributes[index]->setVector(v);
} }
//! Sets a attribute as vector
void CAttributes::setAttribute(s32 index, core::vector2df v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setVector2d(v);
}
//! Sets a attribute as position //! Sets a attribute as position
void CAttributes::setAttribute(s32 index, core::position2di v) void CAttributes::setAttribute(s32 index, core::position2di v)
{ {
...@@ -901,6 +982,13 @@ void CAttributes::setAttribute(s32 index, core::rect<s32> v) ...@@ -901,6 +982,13 @@ void CAttributes::setAttribute(s32 index, core::rect<s32> v)
Attributes[index]->setRect(v); Attributes[index]->setRect(v);
} }
//! Sets a attribute as dimension2d
void CAttributes::setAttribute(s32 index, core::dimension2d<u32> v)
{
if ((u32)index < Attributes.size())
Attributes[index]->setDimension2d(v);
}
//! Sets an attribute as binary data //! Sets an attribute as binary data
void CAttributes::setAttribute(s32 index, void* data, s32 dataSizeInBytes ) void CAttributes::setAttribute(s32 index, void* data, s32 dataSizeInBytes )
{ {
...@@ -1420,6 +1508,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader) ...@@ -1420,6 +1508,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader)
Attributes.getLast()->setString(reader->getAttributeValue(L"value")); Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
} }
else else
if (element == L"vector2d")
{
addVector2d(name.c_str(), core::vector2df());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
else
if (element == L"position") if (element == L"position")
{ {
addPosition2d(name.c_str(), core::position2di()); addPosition2d(name.c_str(), core::position2di());
...@@ -1493,6 +1587,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader) ...@@ -1493,6 +1587,12 @@ void CAttributes::readAttributeFromXML(io::IXMLReader* reader)
// It's debatable if a pointer should be set or not, but it's more likely that adding it now would wreck user-applications. // It's debatable if a pointer should be set or not, but it's more likely that adding it now would wreck user-applications.
// Also it probably doesn't makes sense setting this to a value when it comes from file. // Also it probably doesn't makes sense setting this to a value when it comes from file.
} }
else
if (element == L"dimension2d")
{
addDimension2d(name.c_str(), core::dimension2d<u32>());
Attributes.getLast()->setString(reader->getAttributeValue(L"value"));
}
} }
//! Write these attributes into a xml file //! Write these attributes into a xml file
......
...@@ -375,6 +375,32 @@ public: ...@@ -375,6 +375,32 @@ public:
//! Sets an attribute as vector //! Sets an attribute as vector
virtual void setAttribute(s32 index, core::vector3df v); virtual void setAttribute(s32 index, core::vector3df v);
/*
Vector2d Attribute
*/
//! Adds an attribute as 2d vector
virtual void addVector2d(const c8* attributeName, core::vector2df value);
//! Sets a attribute as 2d vector
virtual void setAttribute(const c8* attributeName, core::vector2df v);
//! Gets an attribute as 2d vector
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::vector2df getAttributeAsVector2d(const c8* attributeName);
//! Gets an attribute as 3d vector
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::vector2df getAttributeAsVector2d(s32 index);
//! Sets an attribute as vector
virtual void setAttribute(s32 index, core::vector2df v);
/* /*
Position2d Attribute Position2d Attribute
...@@ -424,6 +450,31 @@ public: ...@@ -424,6 +450,31 @@ public:
virtual void setAttribute(s32 index, core::rect<s32> v); virtual void setAttribute(s32 index, core::rect<s32> v);
/*
Dimension2d Attribute
*/
//! Adds an attribute as dimension2d
virtual void addDimension2d(const c8* attributeName, core::dimension2d<u32> value);
//! Sets an attribute as dimension2d
virtual void setAttribute(const c8* attributeName, core::dimension2d<u32> v);
//! Gets an attribute as dimension2d
//! \param attributeName: Name of the attribute to get.
//! \return Returns value of the attribute previously set by setAttribute()
virtual core::dimension2d<u32> getAttributeAsDimension2d(const c8* attributeName);
//! Gets an attribute as dimension2d
//! \param index: Index value, must be between 0 and getAttributeCount()-1.
virtual core::dimension2d<u32> getAttributeAsDimension2d(s32 index);
//! Sets an attribute as dimension2d
virtual void setAttribute(s32 index, core::dimension2d<u32> v);
/* /*
matrix attribute matrix attribute
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "triangle3d.h" #include "triangle3d.h"
#include "position2d.h" #include "position2d.h"
#include "rect.h" #include "rect.h"
#include "dimension2d.h"
#include "matrix4.h" #include "matrix4.h"
#include "quaternion.h" #include "quaternion.h"
#include "plane3d.h" #include "plane3d.h"
......
...@@ -50,6 +50,7 @@ int main(int argumentCount, char * arguments[]) ...@@ -50,6 +50,7 @@ int main(int argumentCount, char * arguments[])
// (temporarily) to the beginning of the list, since each test runs in its own // (temporarily) to the beginning of the list, since each test runs in its own
// process. // process.
TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory. TEST(disambiguateTextures); // Normally you should run this first, since it validates the working directory.
// Now the simple tests without device // Now the simple tests without device
TEST(testIrrArray); TEST(testIrrArray);
......
...@@ -42,6 +42,8 @@ public: ...@@ -42,6 +42,8 @@ public:
out->addColor("ValColor", ValColor); out->addColor("ValColor", ValColor);
out->addColorf("ValColorf", ValColorf); out->addColorf("ValColorf", ValColorf);
out->addVector3d("ValVector3df", ValVector3df); out->addVector3d("ValVector3df", ValVector3df);
out->addVector2d("ValVector2df", ValVector2df);
out->addDimension2d("ValDimension2du", ValDimension2du);
out->addPosition2d("ValPosition2di", ValPosition2di); out->addPosition2d("ValPosition2di", ValPosition2di);
out->addRect("ValRect", ValRect); out->addRect("ValRect", ValRect);
out->addMatrix("ValMatrix", ValMatrix); out->addMatrix("ValMatrix", ValMatrix);
...@@ -68,6 +70,8 @@ public: ...@@ -68,6 +70,8 @@ public:
ValColor = in->getAttributeAsColor("ValColor"); ValColor = in->getAttributeAsColor("ValColor");
ValColorf = in->getAttributeAsColorf("ValColorf"); ValColorf = in->getAttributeAsColorf("ValColorf");
ValVector3df = in->getAttributeAsVector3d("ValVector3df"); ValVector3df = in->getAttributeAsVector3d("ValVector3df");
ValVector2df = in->getAttributeAsVector2d("ValVector2df");
ValDimension2du = in->getAttributeAsDimension2d("ValDimension2du");
ValPosition2di = in->getAttributeAsPosition2d("ValPosition2di"); ValPosition2di = in->getAttributeAsPosition2d("ValPosition2di");
ValRect = in->getAttributeAsRect("ValRect"); ValRect = in->getAttributeAsRect("ValRect");
ValMatrix = in->getAttributeAsMatrix("ValMatrix"); ValMatrix = in->getAttributeAsMatrix("ValMatrix");
...@@ -102,6 +106,8 @@ public: ...@@ -102,6 +106,8 @@ public:
return false; return false;
} }
COMPARE(ValVector3df, other.ValVector3df); COMPARE(ValVector3df, other.ValVector3df);
COMPARE(ValVector2df, other.ValVector2df);
COMPARE(ValDimension2du, other.ValDimension2du);
COMPARE(ValPosition2di, other.ValPosition2di); COMPARE(ValPosition2di, other.ValPosition2di);
COMPARE(ValRect, other.ValRect); COMPARE(ValRect, other.ValRect);
COMPARE(ValMatrix, other.ValMatrix); COMPARE(ValMatrix, other.ValMatrix);
...@@ -130,6 +136,8 @@ public: ...@@ -130,6 +136,8 @@ public:
ValColor.set(0,0,0,0); ValColor.set(0,0,0,0);
ValColorf.set(0.f, 0.f, 0.f, 0.f); ValColorf.set(0.f, 0.f, 0.f, 0.f);
ValVector3df.set(0.f, 0.f, 0.f); ValVector3df.set(0.f, 0.f, 0.f);
ValVector2df.set(0.f, 0.f);
ValDimension2du.set(0, 0);
ValPosition2di.set(0,0); ValPosition2di.set(0,0);
ValRect = core::rect<s32>(0,0,0,0); ValRect = core::rect<s32>(0,0,0,0);
ValMatrix.makeIdentity(); ValMatrix.makeIdentity();
...@@ -158,6 +166,8 @@ public: ...@@ -158,6 +166,8 @@ public:
ValColor.set(1,2,3,4); ValColor.set(1,2,3,4);
ValColorf.set(1.f, 2.f, 3.f, 4.f); ValColorf.set(1.f, 2.f, 3.f, 4.f);
ValVector3df.set(1.f, 2.f, 3.f); ValVector3df.set(1.f, 2.f, 3.f);
ValVector2df.set(1.f, 2.f);
ValDimension2du.set(1, 2);
ValPosition2di.set(1,2); ValPosition2di.set(1,2);
ValRect = core::rect<s32>(1,2,3,4); ValRect = core::rect<s32>(1,2,3,4);
ValMatrix = 99.9f; ValMatrix = 99.9f;
...@@ -182,6 +192,8 @@ public: ...@@ -182,6 +192,8 @@ public:
video::SColor ValColor; video::SColor ValColor;
video::SColorf ValColorf; video::SColorf ValColorf;
core::vector3df ValVector3df; core::vector3df ValVector3df;
core::vector2df ValVector2df;
core::dimension2du ValDimension2du;
core::position2di ValPosition2di; core::position2di ValPosition2di;
core::rect<s32> ValRect; core::rect<s32> ValRect;
core::matrix4 ValMatrix; core::matrix4 ValMatrix;
......
Tests finished. 61 tests of 61 passed. Tests finished. 1 test of 1 passed.
Compiled as DEBUG Compiled as DEBUG
Test suite pass at GMT Mon Jan 17 10:25:55 2011 Test suite pass at GMT Tue Nov 29 22:04:07 2011
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment