protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(ISceneChildEntity part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist)
{
ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock();
if (holeshape != (int)ScriptBaseClass.PRIM_HOLE_DEFAULT &&
holeshape != (int)ScriptBaseClass.PRIM_HOLE_CIRCLE &&
holeshape != (int)ScriptBaseClass.PRIM_HOLE_SQUARE &&
holeshape != (int)ScriptBaseClass.PRIM_HOLE_TRIANGLE)
{
holeshape = ScriptBaseClass.PRIM_HOLE_DEFAULT;
}
shapeBlock.ProfileCurve = (byte)holeshape;
if (cut.x < 0f)
{
cut.x = 0f;
}
if (cut.x > 1f)
{
cut.x = 1f;
}
if (cut.y < 0f)
{
cut.y = 0f;
}
if (cut.y > 1f)
{
cut.y = 1f;
}
if (cut.y - cut.x < 0.05f)
{
cut.x = cut.y - 0.05f;
if (cut.x < 0.0f)
{
cut.x = 0.0f;
cut.y = 0.05f;
}
}
shapeBlock.ProfileBegin = (ushort)(50000 * cut.x);
shapeBlock.ProfileEnd = (ushort)(50000 * (1 - cut.y));
if (hollow < 0f)
{
hollow = 0f;
}
if (hollow > 0.95)
{
hollow = 0.95f;
}
shapeBlock.ProfileHollow = (ushort)(50000 * hollow);
if (twist.x < -1.0f)
{
twist.x = -1.0f;
}
if (twist.x > 1.0f)
{
twist.x = 1.0f;
}
if (twist.y < -1.0f)
{
twist.y = -1.0f;
}
if (twist.y > 1.0f)
{
twist.y = 1.0f;
}
// A fairly large precision error occurs for some calculations,
// if a float or double is directly cast to a byte or sbyte
// variable, in both .Net and Mono. In .Net, coding
// "(sbyte)(float)(some expression)" corrects the precision
// errors. But this does not work for Mono. This longer coding
// form of creating a tempoary float variable from the
// expression first, then casting that variable to a byte or
// sbyte, works for both .Net and Mono. These types of
// assignments occur in SetPrimtiveBlockShapeParams and
// SetPrimitiveShapeParams in support of llSetPrimitiveParams.
float tempFloat = (float)(100.0d * twist.x);
shapeBlock.PathTwistBegin = (sbyte)tempFloat;
tempFloat = (float)(100.0d * twist.y);
shapeBlock.PathTwist = (sbyte)tempFloat;
shapeBlock.ObjectLocalID = part.LocalId;
// retain pathcurve
shapeBlock.PathCurve = part.Shape.PathCurve;
part.Shape.SculptEntry = false;
return shapeBlock;
}