01.08.2014, 13:17
I'm currently working on a game that involves materials to be combined on a working table in order to produce drugs/chemicals. Then the player would have to place a chem-kit on it with some /placesomething command.
I've placed a table object (937) with 0.0 Z-rotation, then I've placed some objects on it for simulating some containers for the products. Then I've taken all offsets from those objects by subtracting the coordinates of the table.
Example result:
Obivously, those offsets are valid only if the table has a Z-rotation of 0.0 and they would fail if the table has a different rotation.
So, I've been working on this snippet of code based on GetXYInDirection function for hours, but I still haven't figured out how to rotate those offsets accordingly on the table rotation.
My not working code (bad result: http://*******/HZBLDD)
Thanks in advance for any help since this is really driving me mad!
I've placed a table object (937) with 0.0 Z-rotation, then I've placed some objects on it for simulating some containers for the products. Then I've taken all offsets from those objects by subtracting the coordinates of the table.
Example result:
Obivously, those offsets are valid only if the table has a Z-rotation of 0.0 and they would fail if the table has a different rotation.
So, I've been working on this snippet of code based on GetXYInDirection function for hours, but I still haven't figured out how to rotate those offsets accordingly on the table rotation.
My not working code (bad result: http://*******/HZBLDD)
pawn Код:
const Float:tablerot = ... ,
Float:tablex = ... ,
Float:tabley = ... ,
Float:tablez = ... ;
stock const tableItems[] =
{
...
};
stock const Float:tableItemsOffsets[sizeof(tableItems)][6] =
{
...
};
new Float:sin = floatsin(tablerot+180.0, degrees),
Float:cos = floatcos(tablerot+180.0, degrees);
CreateDynamicObject(937, tablex, tabley, tablez, 0.000000, 0.000000, tablerot);
new Float:X, Float:Y;
for(new i; i < sizeof(tableItems); i++)
{
//X = tablex - tableItemsOffsets[i][0];
//Y = tabley - tableItemsOffsets[i][1];
X = tablex + (tableItemsOffsets[i][0] * sin);
Y = tabley + (tableItemsOffsets[i][1] * cos);
CreateDynamicObject(tableItems[i],
X,
Y,
tablez + tableItemsOffsets[i][2],
tableItemsOffsets[i][3],
tableItemsOffsets[i][4],
tablerot-tableItemsOffsets[i][5]);
}