vector2d and position2d

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
CaptainPants
Posts: 19
Joined: Wed Dec 06, 2006 10:15 am

Post by CaptainPants »

Sorry to bump, but I've come across a more personally compelling reasons to combine vector2d and position2d, or at least to have some of the trigonometry functionality added to position2d...

I'm current working on a project that in one place requires working out whether the mouse is within circular regions of different sizes. Because I am working with the gui I have to use position2d or perform redundant copying and using vector2di's built in trig functions.

Code: Select all

bool isPointInside(const position2di & mouse, const position2di & center, s32 radius)
{
    position2di dist = mouse - center;
    return hypot(dist.X, dist.Y) < radius;
}

// instead of

bool isPointInside(const vector2di & mouse, const vector2di & center, s32 radius)
{
    return (mouse - center).getLength() < radius;
}
(please excuse if this code isn't quite right, I don't have the original code in front of me)

I realize this isn't much, but it means (as far as I can see) that the methods within vector2di are useless because they're in *the wrong class*.

In another part of the same project I am converting between an isometric display on the screen to a grid coordinate. This uses (2 or 3) dot products, but once again because the gui elements all use position2di instead of vector2di, these products have to be done *by hand* rather than using vector2d's built in dotProduct method.

I guess this could seem like a lot of whining, but I think its frustrating that this functionality is here (in the vector2d template) but is *in the wrong place*, because the whole gui system and drawing methods all use position2d.

Anyways, in almost every other respect, I love Irrlicht.

I also notice that this thread generated a lot of positive responses to the idea earlier. I thought I'd give at one last shot at getting the idea noticed. If people hate it then it will be forgotten.

Thanks guys,
~~Captain Pants
Kimundi
Posts: 11
Joined: Sun Apr 01, 2007 11:04 am

Post by Kimundi »

I still think that Position2d and Dimension2d should be replaced by Vector2d.
The only different between Postion2d/Dimension2d and Vector2d is that Postion2d/Dimension2d can only hold 2 values and has operator overloads, whereas Vector2d has many additional functions like for example Interpolating.
The different-y-direction problem (down in screen coordinates, but should be up) is not really a problem, it's just the way you interprete them. If we would replace all Position2ds in the source code with vector2ds then the whole GUI System would still work without any different.


I'd also like to hear the comment of a mod abut this :)
Image
[Sorry for possible bad English]
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Go for it, but you'll have to implement serialisation for vector2d, as it's currently missing.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
CaptainPants
Posts: 19
Joined: Wed Dec 06, 2006 10:15 am

Post by CaptainPants »

rogerborg wrote:Go for it, but you'll have to implement serialisation for vector2d, as it's currently missing.
If someone where to replace all occurrences of position2d with vector2d, wouldn't the serialization code also just have to be changed from position2d to vector2d?

My vote is just for replacing position2d with vector2d, and possibly adding some extra functions/overloads to vector2d to make it have ALL the functions of position2d.

dimension2d does have its uses, although the main one seems to be in the overloads for the rect constructor..
i.e:

rect (const position2d< T > &pos, const dimension2d< T > &size)
vs
rect (const position2d< T > &upperLeft, const position2d< T > &lowerRight)

although I believe this could be replaced by having static 'constructor' functions, i.e:
rect rect::fromSize(const vector2d< T > &pos, const vector2d< T > &size)
rect rect::fromPoints(const vector2d< T > &upperLeft, const vector2d< T > &lowerRight)

Anyways, if no-one else feels like it, I'll look into making a position2d to vector2d patch when I get some time
~~Captain Pants
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I'd suggest that actually removing either type would cause millions of voices to cry out in terror. Instead, how about combining their methods to produce a superset and then aliasing one type to the other, either with a #define or typedeffing position2df and vector2df as either vector2d<f32> or position2d<f32>.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Kimundi
Posts: 11
Joined: Sun Apr 01, 2007 11:04 am

Post by Kimundi »

Yeah, I had that Idea, too.
We could remove Position2D nd then #define Vector2D as Position2d. (But I'm not a c++ coder, so I'm not sure if that would work)
Image
[Sorry for possible bad English]
Post Reply