SA-MP Forums Archive
Moving objects in bulk - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Moving objects in bulk (/showthread.php?tid=661534)



Moving objects in bulk - Paulthaz - 07.12.2018

Hi, I'm trying to do a include to move objects in bulk by grouping them into a group and moving that group. Only I have a problem with the object's Z rotation. It gets very crooked when it should move at the same speed and rotation as other objects.

Код:
yagr_MoveGroup(groupid, Float:X, Float:Y, Float:Z, Float:rZ, Float:Speed)
{
	if(!Iter_Contains(ValidGroups, groupid))
		return 0;

	new Float:CoordCenter[3], Float:ObjectPos[6], nmax, Float:g_sin[3], Float:g_cos[3];
	yagr_GetCenterCoords(groupid, CoordCenter[0], CoordCenter[1], CoordCenter[2]);
	for(new i; i < MAX_GROUP_OBJECTS; i ++)
	{
		if(GroupInfo[groupid][yagr_objectid][i] != -1)
		{
			yagr_GetObjectPos(groupid, GroupInfo[groupid][yagr_objectid][i], ObjectPos[0], ObjectPos[1], ObjectPos[2], ObjectPos[3], ObjectPos[4], ObjectPos[5]);
			GroupInfo[groupid][yagr_obdestinyX][i] = X + (ObjectPos[0]-CoordCenter[0]);
			GroupInfo[groupid][yagr_obdestinyY][i] = Y + (ObjectPos[1]-CoordCenter[1]);
			GroupInfo[groupid][yagr_obdestinyZ][i] = Z + (ObjectPos[2]-CoordCenter[2]);

			yagr_ConverterValores(ObjectPos[3], ObjectPos[4], ObjectPos[5]-rZ, g_sin, g_cos);
			GroupInfo[groupid][yagr_obdestinyRZ][i] = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]);
			nmax = i;
		}
	}
	for(new i; i < nmax; i ++)
	{
		if(GroupInfo[groupid][yagr_objectid][i] != -1)
		{
			if(GroupInfo[groupid][yagr_objectdynamic][i])
				MoveDynamicObject(GroupInfo[groupid][yagr_objectid][i], GroupInfo[groupid][yagr_obdestinyX][i], GroupInfo[groupid][yagr_obdestinyY][i], GroupInfo[groupid][yagr_obdestinyZ][i], Speed, GroupInfo[groupid][yagr_originRX][i], GroupInfo[groupid][yagr_originRY][i], GroupInfo[groupid][yagr_obdestinyRZ][i]);
			else
				MoveObject(GroupInfo[groupid][yagr_objectid][i], GroupInfo[groupid][yagr_obdestinyX][i], GroupInfo[groupid][yagr_obdestinyY][i], GroupInfo[groupid][yagr_obdestinyZ][i], Speed, GroupInfo[groupid][yagr_originRX][i], GroupInfo[groupid][yagr_originRY][i], GroupInfo[groupid][yagr_obdestinyRZ][i]);
		}
	}
	return 1;
}

yagr_GetCenterCoords(groupid, &Float:X, &Float:Y, &Float:Z)
{
	new Float:highX = -9999999.0;
	new Float:highY = -9999999.0;
	new Float:highZ = -9999999.0;

	new Float:lowX  = 9999999.0;
	new Float:lowY  = 9999999.0;
	new Float:lowZ  = 9999999.0;

	new count, Float:oX, Float:oY, Float:oZ, Float:null;

	for(new i; i < MAX_GROUP_OBJECTS; i ++)
	{
		if(GroupInfo[groupid][yagr_objectid][i] != -1)
		{
			yagr_GetObjectPos(groupid, GroupInfo[groupid][yagr_objectid][i], oX, oY, oZ, null, null, null);
			if(oX > highX) highX = oX;
			if(oY > highY) highY = oY;
			if(oZ > highZ) highZ = oZ;
			if(oX < lowX) lowX = oX;
			if(oY < lowY) lowY = oY;
			if(oZ < lowZ) lowZ = oZ;
			count++;
		}
	}

	if(count < 1) return 0;

	X = (highX + lowX) / 2;
	Y = (highY + lowY) / 2;
	Z = (highZ + lowZ) / 2;
	return 1;
}
yagr_ConverterValores(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3])
{
    sin[0] = floatsin(rot_x, degrees);
    sin[1] = floatsin(rot_y, degrees);
    sin[2] = floatsin(rot_z, degrees);
    cos[0] = floatcos(rot_x, degrees);
    cos[1] = floatcos(rot_y, degrees);
    cos[2] = floatcos(rot_z, degrees);
    return 1;
}



Re: Moving objects in bulk - NaS - 07.12.2018

It's not possible to include rotation when you only try to make it with one movement, as the objects need to rotate around a pivot to stay "in sync" with each other.

You can use YSF to attach all objects to a pivot object, move + rotate the pivot object and after that deattach them again (you can calculate the final positions including rotations).

Except you don't want them to stay together while moving, then you'd only need to calculate the final positions using a pivot and move all objects there in a straight line.


Re: Moving objects in bulk - Paulthaz - 07.12.2018

Quote:
Originally Posted by NaS
Посмотреть сообщение
It's not possible to include rotation when you only try to make it with one movement, as the objects need to rotate around a pivot to stay "in sync" with each other.

You can use YSF to attach all objects to a pivot object, move + rotate the pivot object and after that deattach them again (you can calculate the final positions including rotations).

Except you don't want them to stay together while moving, then you'd only need to calculate the final positions using a pivot and move all objects there in a straight line.
Код:
yagr_GetCenterCoords(groupid, CoordCenter[0], CoordCenter[1], CoordCenter[2]);
But in this function it takes the pivot that the objects revolve around him.


Re: Moving objects in bulk - Nero_3D - 08.12.2018

There is no need for such an include, just attach all your objects to your "main" object and move that one

Anyway regarding your problem, your rotation is missing the translation part, see this image



So if your object isn't the "pivot point" you need to adjust the position correctly