add InsertVertex script function to insert a vertex at arbitrary position

liquid_container
Maikel de Vries 2016-03-28 17:35:47 +02:00
parent 12ae155015
commit 6bdbc5b5c7
5 changed files with 51 additions and 0 deletions

View File

@ -32,6 +32,7 @@
</example>
</examples>
<related>
<funclink>InsertVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>InsertVertex</title>
<category>Objects</category>
<subcat>Vertices</subcat>
<version>8.0 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>index</name>
<desc>Index of the vertex to be removed, ranges from 0 to <funclink>GetVertexNum</funclink>.</desc>
</param>
<param>
<type>int</type>
<name>x</name>
<desc>X coordinate, relative to the object center.</desc>
</param>
<param>
<type>int</type>
<name>y</name>
<desc>Y coordinate, relative to the object center.</desc>
</param>
</params>
</syntax>
<desc>Inserts a new vertex to an object.</desc>
<remark>Notice: with any vertex updated caused by stretching or rotation of the object (e.g. building or growth) the vertices will be reset to their original defined position unless a special vertex mode is selected.</remark>
<related>
<funclink>AddVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>
<funclink>RemoveVertex</funclink>
</related>
</func>
<author>Maikel</author><date>2016-03</date>
</funcs>

View File

@ -28,6 +28,7 @@
</examples>
<related>
<funclink>AddVertex</funclink>
<funclink>InsertVertex</funclink>
<funclink>GetVertex</funclink>
<funclink>SetVertex</funclink>
<funclink>GetVertexNum</funclink>

View File

@ -694,6 +694,11 @@ static bool FnAddVertex(C4Object *Obj, long iX, long iY)
return !!Obj->Shape.AddVertex(iX,iY);
}
static bool FnInsertVertex(C4Object *Obj, long iIndex, long iX, long iY)
{
return !!Obj->Shape.InsertVertex(iIndex,iX,iY);
}
static bool FnRemoveVertex(C4Object *Obj, long iIndex)
{
return !!Obj->Shape.RemoveVertex(iIndex);
@ -2608,6 +2613,7 @@ void InitObjectFunctionMap(C4AulScriptEngine *pEngine)
F(GetVertex);
F(SetVertex);
F(AddVertex);
F(InsertVertex);
F(RemoveVertex);
::AddFunc(p, "SetContactDensity", FnSetContactDensity, false);
F(GetController);

View File

@ -316,6 +316,7 @@ out:
bool C4Shape::InsertVertex(int32_t iPos, int32_t tx, int32_t ty)
{
if (VtxNum+1>C4D_MaxVertex) return false;
if (iPos < 0 || iPos > VtxNum) return false;
// Insert vertex before iPos
for (int32_t cnt=VtxNum; cnt>iPos; cnt--)
{ VtxX[cnt]=VtxX[cnt-1]; VtxY[cnt]=VtxY[cnt-1]; }