Pottus/ColAndreas

CA_IsEntireModelInPolygon

Opened this issue · 4 comments

I don't know if this is possible, but AFAIK this plugin stores/can store the exact collision shape, so a function like

native CA_IsEntireModelInPolygon( modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, Float:points[ ], maxpoints = sizeof points );

/*
Description:
	- The <<points>> parameter would be like Streamer Plugin's CreateDynamicPolygon one,
	pairs of X, Y:
	{ X1, Y1, X2, Y2, X3, Y3 };

	- An internal check should be made, the <<maxpoints>> value shouldn't be odd and should 
	probably be bigger than 2*2, there's no need in specifying a line, as it would always
	return false.

Return:
	If there's any single bit of that object outside of the polygon, it should return false,
	otherwise true.
*/

would be amazing.

Q: "Wouldn't CA_IsModelInPolygon be better and easier to type ?"
A: Some scripters may think that it just checks the specified coordinates, not the entire collision shape.

Q: "Why aren't you using CA_GetModelBoundingSphere, CA_GetModelBoundingBox ?
A: This would be more way more exact than those functions, also allowing rotation.

Q: "Wouldn't objectid be better, without specifying all those position/rotation arguments ?"
A: Having this one function with all those position/rotation parameters would remove the need for lots of functions like

native CA_IsEntireObjectInPolygon( objectid, Float:points[ ], maxpoints = sizeof points );
native CA_IsEntirePlObjectInPolygon( objectid, Float:points[ ], maxpoints = sizeof points );
native CA_IsEntireDynObjectInPolygon( objectid, Float:points[ ], maxpoints = sizeof points );

and would also help us to detect it even if the object isn't actually created.

One possible usage, from which I got this function idea: the ability for players to add objects in their house's garden, while not being able to add any single object bit in any house's garden from the neighborhood.

I really hope that you can be make it, I think that this would have lots of advantages. It probably requires some more advanced math, unless Bullet Physics already has a similar function for checking a collision shape in a polygon. Anyway, AFAIK Crayder is pretty good at math and he could probably think of a way to do this reliably. Also, I already checked the include (as I'm not currently using this plugin, but I plan to convert to it from Map Andreas, which is way too limited) and there's no similar function.

Another idea this could help with: if players enter in an empty house, they need some empty space to be able to teleport in there, but if the house owner adds items in the spawn area, they will be bugged and eventually get out of the room because of the collisions. This function could prohibit adding items in the small area of house spawn.

Again, this can't be made with CA_GetModelBoundingSphere/CA_GetModelBoundingBox because those objects can have different rotations that could keep them out of that small area, but checking only the bounding sphere/box could detect false that they placed that object where they shouldn't.

@codectile, @Pottus, @Crayder, any of you could make this function ? I never worked with BulletPhysics. I don't know with what I should start.

By the way, wouldn't it be better if ColAndreas and cimulator got together in one single plugin ? cimulator isn't too popular and it is better to have one plugin using the same external library instead of two separate ones doing mostly the same thing. ColAndreas could implement all functions from cimulator and keep this ColAndreas plugin name.

This might help you: https://en.wikipedia.org/wiki/Point_in_polygon

Why cimulator isn't popular? because it needs more cpu power to run physics simulation and no one interested in physics, I guess.

cimulator has lots of features which ColAndreas doesn't have, for example, vehicle collisions, low RAM usage, no cpu power required if physics is turned off, and lots more.

I actually thought of merging projects but ColAndreas developers didn't respond.

It would actually need some kind of IsPolygonInPolygon, because it would need to check every point of the object (which is made out of polygons, it needs to check its mesh [if this is how it is called, you get the idea, not just a sphere]). If ANY actual point/collision of object's model would be outside of the specified polygon, it would return false. The thing you linked to can help only for one point of the specified object, while this function needs some more advanced calculations I guess.

Well, probably that and also because it wasn't advertised on sa-mp forums as much as ColAndreas. There was a period of time in which I saw ColAndreas everywhere (mainly advertised by Crayder).

I know, that's why it would be great. They both use BulletPhysics and do similar things. I bet developers prefer (I do) to use only one bigger plugin than two smaller different plugins doing similar things.

The link I provided can still help you. Firstly, create thin collision cylinders (its height must be equal to the distance between the points and width zero?) along all the polygon points. Then refer this pseudo code.

bool IsPolygonInPolygon(..../*parameters*/)
{
    if(IsEvenOddRaycasts(...)) //if even, returns true else false
        return false;
    //now check if the polygon is colliding with any of the collision cylinders
    if(IsCollidingWithCylinders(....))
        return false;
    //or combine them in one statement
    //if(IsEvenOddRaycasts(...) && IsCollidingWithCylinders(....))
    //    return false;

    return true;
}

Edit: or just raycast between the polygon points instead of creating collision cylinders; much better way to do this.