Would anyone happen to have a function or set of functions handy that can
Calculate the center position between 2,3,4,5 objects?
Eg
location l = GetCenterBetween(object1,object2);
location l = GetCenterBetween(object1,object2,object3);
location l = GetCenterBetween(object1,object2,object3,object4);
location l = GetCenterBetween(object1,object2,object3,object4,object5);
I'd like to be able to let my players drop items on the ground, in a circle shape, and the system be able to calculate the center position between the objects - and try to spawn a portal,
or summon a creature between them.
I can see that it should be doable, but im just not familiar with vector functionality that much.
I imagine it being like this
Player drops items in an arrangement like this
o
o
x o
o o
Even though its not a perfect shape, it still logically has a center. A place that is bisected by all points?
x being the point I want to get, based on the locations of the objects (o) around it.
get location between objects/points?
Débuté par
Baaleos
, janv. 30 2013 05:14
#1
Posté 30 janvier 2013 - 05:14
#2
Posté 30 janvier 2013 - 05:42
We have a vector library floating around (>< @ pun). I don't think you need it though. Just GetPositionFromLocation of their location, and average all the x values, then all the y values. Simple example: 10, 10 10,-10, -10, -10, -10, 10 defines a square centered on 0,0 with sides 20 long. This approach gives you 0,0 as the center. Should work, though it doesn't guarantee that the shapes form a shape without crossed lines...
Funky
Funky
Modifié par FunkySwerve, 30 janvier 2013 - 05:43 .
#3
Posté 30 janvier 2013 - 06:33
I agree with funcky, You should be able to do it without spliting up the vectors. Just add then together then devide.
vector GetCenterBetween(object o1,object o2,object o3,object o4,object o5)
{
return (GetPosition(o1) + GetPosition(o2)+ GetPosition(o3)+ GetPosition(o4)+ GetPosition(o5))/5.0;
}
vector GetCenterBetween(object o1,object o2,object o3,object o4,object o5)
{
return (GetPosition(o1) + GetPosition(o2)+ GetPosition(o3)+ GetPosition(o4)+ GetPosition(o5))/5.0;
}
#4
Posté 30 janvier 2013 - 10:34
Ah- cool.
I didn't realise it would be as simple as that.
I know that different shapes could potentially yield slightly off centre results.
But if it looks like its in the middle or at least between several of the points- it will have achieved the desired result.
I didn't realise it would be as simple as that.
I know that different shapes could potentially yield slightly off centre results.
But if it looks like its in the middle or at least between several of the points- it will have achieved the desired result.





Retour en haut






