mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Implement bezier curve, partially addresses #474.
This commit is contained in:
parent
7ec367d45f
commit
441aa52470
38
MCGalaxy/Commands/building/CmdBezier.cs
Normal file
38
MCGalaxy/Commands/building/CmdBezier.cs
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright 2015 MCGalaxy
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.Drawing.Ops;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdBezier : DrawCmd {
|
||||
public override string name { get { return "bezier"; } }
|
||||
protected override string PlaceMessage { get { return "Place or break two blocks to determine the endpoints, then another for the control point"; } }
|
||||
public override int MarksCount { get { return 3; } }
|
||||
|
||||
protected override DrawOp GetDrawOp(DrawArgs dArgs) {
|
||||
return new BezierDrawOp();
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/bezier <brush args>");
|
||||
Player.Message(p, "%HDraws a quadratic bezier curve.");
|
||||
Player.Message(p, "%HFirst two points specify the endpoints, then another point specifies the control point.");
|
||||
Player.Message(p, " %HFor help about brushes, type %T/help brush%H.");
|
||||
}
|
||||
}
|
||||
}
|
54
MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs
Normal file
54
MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2011 MCForge
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Drawing.Brushes;
|
||||
using MCGalaxy.Maths;
|
||||
|
||||
namespace MCGalaxy.Drawing.Ops {
|
||||
public class BezierDrawOp : DrawOp {
|
||||
public override string Name { get { return "Bezier"; } }
|
||||
public bool WallsMode;
|
||||
public int MaxLength = int.MaxValue;
|
||||
|
||||
public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
|
||||
Vec3S32 p0 = marks[0], p2 = marks[1], p1 = marks[2];
|
||||
return (long)((p1 - p0).Length + (p1 - p2).Length);
|
||||
}
|
||||
|
||||
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
|
||||
int steps = 20;
|
||||
Vec3F32 p0 = marks[0], p2 = marks[1], p1 = marks[2];
|
||||
steps *= (int)((p1 - p0).Length + (p1 - p2).Length);
|
||||
|
||||
float t = 0, invT = 1, delta = 1.0f / steps;
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
Vec3F32 B = invT * invT * p0 + 2 * invT * t * p1 + t * t * p2;
|
||||
output(Place(Round(B.X), Round(B.Y), Round(B.Z), brush));
|
||||
t += delta; invT -= delta;
|
||||
}
|
||||
}
|
||||
|
||||
static ushort Round(float value) {
|
||||
int valueI = (int)value;
|
||||
int floored = value < valueI ? valueI - 1 : valueI;
|
||||
float frac = (value % 1.0f);
|
||||
return (ushort)(floored + (frac > 0.5f ? 1 : 0));
|
||||
}
|
||||
}
|
||||
}
|
@ -125,6 +125,7 @@
|
||||
<Compile Include="Commands\Bots\CmdBotSet.cs" />
|
||||
<Compile Include="Commands\Bots\CmdBotSummon.cs" />
|
||||
<Compile Include="Commands\building\CmdAbort.cs" />
|
||||
<Compile Include="Commands\building\CmdBezier.cs" />
|
||||
<Compile Include="Commands\building\CmdBind.cs" />
|
||||
<Compile Include="Commands\building\CmdBrush.cs" />
|
||||
<Compile Include="Commands\building\CmdCenter.cs" />
|
||||
@ -434,6 +435,7 @@
|
||||
<Compile Include="Drawing\DrawOps\AdvConeDrawOps.cs" />
|
||||
<Compile Include="Drawing\DrawOps\AdvDrawOps.cs" />
|
||||
<Compile Include="Drawing\DrawOps\AdvPyramidDrawOps.cs" />
|
||||
<Compile Include="Drawing\DrawOps\BezierDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\CuboidDrawOp.cs" />
|
||||
<Compile Include="Drawing\DrawOps\CuboidDrawOps.cs" />
|
||||
<Compile Include="Drawing\DrawOps\DrawOpPerformer.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user