53
« on: September 21, 2011, 11:27:42 PM »
This seems to work -- but its a bit laggy when the circles get big
function Player::dobrickstuff(%player, %pos, %datablock)
{
%playerPos = %player.tempBrick.getPosition();
%position = vectorAdd(%playerPos, %pos);
%brick = new fxDTSBrick()
{
client = %player.client;
datablock = %datablock;
position = %position;
rotation = "0 0 0 0";
colorID = %player.client.currentColor;
scale = "1 1 1";
angleID = "0";
colorfxID = "0";
shapefxID = "0";
isPlanted = 1;
stackBL_ID = %player.client;
};
%brick.setTrusted(1);
%brick.plant();
%player.client.brickGroup.add(%brick);
}
function makeEllipse(%player, %r1, %r2, %scale, %addedZ)
{
%steps = (3.14159265 * %r1 * %r1) / 0.5;
%inc = 360 / %steps;
echo("%r1: " @ %r1 @ " steps: " @ %steps @ " inc: " @ %inc);
if(%r2 > 0)
{
for(%i = 0; %i < 360; %i+= %inc)
{
%x = %r1 * mFloatLength(mCos(mRadToDeg(%i)), 6);
%y = %r2 * mFloatLength(mSin(mRadToDeg(%i)), 6);
%player.doBrickStuff(%x SPC %y SPC 0 + %addedZ, Brick1x1Data);
}
}
else
{
for(%i = 0; %i < 360; %i+= %inc)
{
%x = %r1 * mFloatLength(mCos(mRadToDeg(%i)), 6);
%y = %r1 * mFloatLength(mSin(mRadToDeg(%i)), 6);
%player.doBrickStuff(%x SPC %y SPC 0 + %addedZ, Brick1x1Data);
}
}
}
function serverCmdMakeCircle(%client, %r1, %r2)
{
if ( !isObject(%client.player.tempBrick) )
{
messageClient(%client, '', "place a ghost brick first");
return;
}
makeEllipse(%client.player , %r1, %r2, 0);
}
function serverCmdCircleTest(%client)
{
for ( %a=5; %a < 50; %a+=4)
{
serverCmdMakeCircle(%client, %a, %a);
}
}
and it really only works properly when %r1 = %r2
to fix -- consult your math book and lookup the formula for the circumference of an ellipse, then adjust the forumla accordiingly.
the magic number here is 0.5 - the width of a 1x1 brick.
place a brick and type /circletest to see it in action