SFML community forums
General => Feature requests => Topic started by: Groogy on January 18, 2011, 11:21:50 am
-
Yo!
We're going trough 3D math(don't know how to translate it from Swedish so let's just call it that) at school right now and I realized that you are missing a Shape class that are not for being drawn but for checking intersections.
Kinda like the Rect class but by using a normal vector(Again, I think that's the correct translation) on each line we can check if a point is inside the shape and so on.
This is more or less a simple utility that for most of the time will be used for collision detection for more complex shapes. If you feel that you don't got time for that I could just make it myself and add it to the Wiki and then you can add it to SFML2 if you feel it fits ^^
-
I was thinking about a polygon classe maybe, not sure.
Anyway you'd better write what you need and share it on the wiki, it will definitely be better than waiting for whatever I may write one day :)
-
Just now quickly I made a LineVolume class that's for an assignment at school but with some modifications(like making the line calculation internal) it would be possible to use it like I intended and place it at the wiki.
#ifndef VOLUME_HEADER_
#define VOLUME_HEADER_
#include <vector>
// LineVolume inherits from this class. I made it like this as in the
// assignment we also had to create a PlaneVolume with the same
// functionallity but using planes as the primitive instead.
template<class Primitive, class VectorType>
class Volume
{
public:
Volume()
{
}
Volume(const std::vector<Primitive> &aList)
{
myList = aList;
}
~Volume()
{
}
void Add(const Primitive &aPrimitive)
{
myList.push_back(aPrimitive);
}
void Remove(const Primitive &aPrimitive)
{
for(std::vector<Primitive>::iterator it = myList.begin(), end = myList.end(); it != end; it++)
{
if(*it == aPrimitive)
{
myList.erase(it);
break;
}
}
}
bool Inside(const VectorType &aPoint) const
{
for(std::vector<Primitive>::const_iterator it = myList.begin(), end = myList.end(); it != end; it++)
{
if(it->Inside(aPoint) == false)
{
return false;
}
}
return true;
}
private:
std::vector<Primitive> myList;
};
#endif VOLUME_HEADER_
#ifndef LINE_HEADER_
#define LINE_HEADER_
#include "Vector2.h"
template<class Type>
class Line
{
public:
Line() {}
Line(const Vector2<Type> &aPoint, const Vector2<Type> &aSecondPoint)
{
InitWith2Points(aPoint, aSecondPoint);
}
void InitWith2Points(const Vector2<Type> &aPoint, const Vector2<Type> &aSecondPoint)
{
myPoint = aPoint;
myDirection = aSecondPoint - aPoint;
myDirection /= myDirection.Length();
}
void InitWithPointAndDirection(const Vector2<Type> &aPoint, const Vector2<Type> &aDirection)
{
myPoint = aPoint;
myDirection = aDirection;
}
bool Inside(const Vector2<Type> &aPoint) const
{
Vector2<Type> normal;
normal.x = -myDirection.y;
normal.y = myDirection.x;
Vector2<Type> testPosition = aPoint - myPoint;
testPosition /= testPosition.Length();
return normal.Dot(testPosition) > 0;
}
bool operator==(const Line<Type> aLine)
{
return myPoint == aLine.myPoint && myDirection == aLine.myDirection;
}
private:
Vector2<Type> myPoint;
Vector2<Type> myDirection;
};
#endif LINE_HEADER_