How do I find the center of the map?

Started by 1337, March 06, 2010, 07:09:17 AM

Previous topic - Next topic

1337

Or generate any static Point value?


I can't do:
point p;
p = new point(0,0);


any idea?

Kernel64

in SC1, 0,0 is the bottom left corner of the playable area. Not sure though.

asdf14

As far as I'm concerned there is no 'new' keyword in galaxy. It's not Java/C#.
To declare a new point use point Point(fixed, fixed);e.g.

point p;
p = (0,0)



Not sure about the center of the map, but if you knew map size you could do:


x = mapWidth;
y = mapHeight;
point center(x/2, y/2);



Other stuff you might find useful:
point PointWithOffset(point, fixed, fixed);
point PointWithOffsetPolar(point, fixed, fixed);
bool PointsInRange(point, point, fixed);
fixed AngleBetweenPoints(point, point);
fixed DistanceBetweenPoints(point, point);
region RegionCircle(point, fixed);
point RegionRandomPoint(region);
point UnitGetPosition(unit);

1337

OK so now say I have a point, how do I get the x and y coordinates of that point?


is it point.x or point.X or point.x() or point.X() or point.GetX()

Aeg1s

Quote from: 1337 on March 07, 2010, 12:32:46 AM
OK so now say I have a point, how do I get the x and y coordinates of that point?


is it point.x or point.X or point.x() or point.X() or point.GetX()


I would very much like to know this too; so far I've tried:


point.x
point.X
point.fx
point.fX
point.mx
point.mX
point.m_x
point.m_X


and none of them work :(

asdf14

Again, this is OOP model you are thinking about. Galaxy is not object-oriented and point is not a class, so it doesn't have methods (point.getX()) or properties (point.x). Honestly I don't see the way of getting its coordinates the easy way, but I also don't see any reason for it. Most things you would like to do with the point you can achieve using functions I have listed above. Can I ask what do you need its coordinates for?


Now, if you really wanted to, here's an example which may work and uses a struct to hold both the point and its coordinates:


struct myPoint
{
int x;
int y;
point coordinates;
}
void createMyPoint (int x, int y)
{
myPoint.x = x;
myPoint.y = y;
myPoint.coordinates = (x, y);
}

1337

Quote from: asdf14 on March 07, 2010, 10:42:42 AM
Again, this is OOP model you are thinking about. Galaxy is not object-oriented and point is not a class, so it doesn't have methods (point.getX()) or properties (point.x).
Now, if you really wanted to, here's an example which may work and uses a struct to hold both the point and its coordinates:
struct myPoint
{
int x;
int y;
point coordinates;
}
void createMyPoint (int x, int y)
{
myPoint.x = x;
myPoint.y = y;
myPoint.coordinates = (x, y);
}



You are burning me for using OOP model but then you use myPoint.x in your call. Did you even test this code to see if it works? Looks too easy to be true.


Although if it does work maybe I could use (x,y) = myPoint.coordinates to get the values out...

SPmac

have you tried .first and .second

Looking at the point type, it could just be a kind of typedef of pair<int, int>... I've yet to mess around w/ points or anything yet, so I've not tested any of this, try it out though, perhaps it works.