mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 03:55:18 -04:00
Add some ASCII drawings explaining yaw/pitch, move some direction calculation into a common utils class.
This commit is contained in:
parent
b238bb1432
commit
dddf8fd5b9
@ -27,22 +27,15 @@ namespace MCGalaxy.BlockBehaviour {
|
||||
|
||||
int dx = 0, dy = 0, dz = 0;
|
||||
p.RevertBlock(x, y, z);
|
||||
if ( p.rot[0] < 48 || p.rot[0] > ( 256 - 48 ) )
|
||||
dz = -1;
|
||||
else if ( p.rot[0] > ( 128 - 48 ) && p.rot[0] < ( 128 + 48 ) )
|
||||
dz = 1;
|
||||
|
||||
if ( p.rot[0] > ( 64 - 48 ) && p.rot[0] < ( 64 + 48 ) )
|
||||
dx = 1;
|
||||
else if ( p.rot[0] > ( 192 - 48 ) && p.rot[0] < ( 192 + 48 ) )
|
||||
dx = -1;
|
||||
DirUtils.EightYaw(p.rot[0], out dx, out dz);
|
||||
|
||||
if ( p.rot[1] >= 192 && p.rot[1] <= ( 192 + 32 ) )
|
||||
dy = 1;
|
||||
else if ( p.rot[1] <= 64 && p.rot[1] >= 32 )
|
||||
dy = -1;
|
||||
|
||||
if ( 192 <= p.rot[1] && p.rot[1] <= 196 || 60 <= p.rot[1] && p.rot[1] <= 64 ) { dx = 0; dz = 0; }
|
||||
// Looking straight up or down
|
||||
if (p.rot[1] >= 192 && p.rot[1] <= 196 || p.rot[1] >= 60 && p.rot[1] <= 64) { dx = 0; dz = 0; }
|
||||
|
||||
byte b1 = p.level.GetTile((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 ));
|
||||
byte b2 = p.level.GetTile((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz ));
|
||||
|
@ -40,10 +40,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
int dist = (int)state;
|
||||
|
||||
int dx = 0, dz = 0;
|
||||
if (p.rot[0] <= 32 || p.rot[0] >= 224) { dz = -1; }
|
||||
else if (p.rot[0] <= 96) { dx = 1; }
|
||||
else if (p.rot[0] <= 160) { dz = 1; }
|
||||
else dx = -1;
|
||||
DirUtils.FourYaw(p.rot[0], out dx, out dz);
|
||||
|
||||
List<int> buffer = new List<int>();
|
||||
int depth = 0;
|
||||
|
@ -607,10 +607,11 @@
|
||||
<Compile Include="util\FastList.cs" />
|
||||
<Compile Include="util\App.cs" />
|
||||
<Compile Include="util\Formatter.cs" />
|
||||
<Compile Include="util\Math\DirUtils.cs" />
|
||||
<Compile Include="util\Math\Vectors.cs" />
|
||||
<Compile Include="util\SparseBitSet.cs" />
|
||||
<Compile Include="util\TimeUtils.cs" />
|
||||
<Compile Include="util\Utils.cs" />
|
||||
<Compile Include="util\Vectors.cs" />
|
||||
<Compile Include="util\VolatileArray.cs" />
|
||||
<Compile Include="sharkbite.thresher\ChannelModeInfo.cs" />
|
||||
<Compile Include="sharkbite.thresher\CommandBuilder.cs" />
|
||||
@ -720,6 +721,7 @@
|
||||
<Folder Include="Bots" />
|
||||
<Folder Include="Events" />
|
||||
<Folder Include="Chat" />
|
||||
<Folder Include="util\Math" />
|
||||
<Folder Include="Player\Group" />
|
||||
<Folder Include="Player\List" />
|
||||
<Folder Include="Player\Undo" />
|
||||
|
67
util/Math/DirUtils.cs
Normal file
67
util/Math/DirUtils.cs
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
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;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public static class DirUtils {
|
||||
|
||||
/* How yaw works: * How pitch works:
|
||||
* 64 | +X * 192 | +Y
|
||||
* ___|___ * |
|
||||
* / | \ * flipped |
|
||||
* / | \ * heads |
|
||||
* 128 | | | 0 * 128 | 0
|
||||
*------------+----------- * ------------+------------
|
||||
* +Z | | | -Z * Y=0 | Y=0
|
||||
* \ | / * flipped |
|
||||
* \___|___/ * heads |
|
||||
* | * |
|
||||
* 192 | -X * 64 | -Y
|
||||
* */
|
||||
|
||||
public static void EightYaw(byte yaw, out int dirX, out int dirZ) {
|
||||
dirX = 0; dirZ = 0;
|
||||
const byte extent = 48;
|
||||
|
||||
if (yaw < (0 + extent) || yaw > (256 - extent))
|
||||
dirZ = -1;
|
||||
else if (yaw > (128 - extent) && yaw < (128 + extent))
|
||||
dirZ = 1;
|
||||
|
||||
if (yaw > (64 - extent) && yaw < (64 + extent))
|
||||
dirX = 1;
|
||||
else if (yaw > (192 - extent) && yaw < (192 + extent))
|
||||
dirX = -1;
|
||||
}
|
||||
|
||||
public static void FourYaw(byte yaw, out int dirX, out int dirZ) {
|
||||
dirX = 0; dirZ = 0;
|
||||
const byte quadrant = 32;
|
||||
|
||||
if (yaw <= (0 + quadrant) || yaw >= (256 - quadrant))
|
||||
dirZ = -1;
|
||||
else if (yaw <= (128 - quadrant))
|
||||
dirX = 1;
|
||||
else if (yaw <= (128 + quadrant))
|
||||
dirZ = 1;
|
||||
else
|
||||
dirX = -1;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy {
|
||||
public struct Vec3U16 : IEquatable<Vec3U16> {
|
||||
public struct Vec3U16 : IEquatable<Vec3U16> {
|
||||
public ushort X, Y, Z;
|
||||
public static Vec3U16 Zero = new Vec3U16(0);
|
||||
public static Vec3U16 MinVal = new Vec3U16(ushort.MinValue);
|
Loading…
x
Reference in New Issue
Block a user