large worlds engine compat refactor, change vector -> float

This commit is contained in:
2022-06-13 22:06:37 +03:00
parent 3b6b5686d0
commit a0d2b127de
18 changed files with 389 additions and 389 deletions

View File

@@ -26,29 +26,29 @@ namespace Game
private static readonly Dictionary<Actor, ActorAudioChannels> actorAudioChannels =
new Dictionary<Actor, ActorAudioChannels>();
public static void PlaySound(string soundName, Actor actor, Vector3 position, float volume = 1f)
public static void PlaySound(string soundName, Actor actor, Float3 position, float volume = 1f)
{
PlaySound(soundName, actor, 0, AudioFlags.None, position, volume, Vector2.One);
PlaySound(soundName, actor, 0, AudioFlags.None, position, volume, Float2.One);
}
public static void PlaySound(string soundName, Actor actor, Vector3 position, float volume, Vector2 pitchRange)
public static void PlaySound(string soundName, Actor actor, Float3 position, float volume, Float2 pitchRange)
{
PlaySound(soundName, actor, 0, AudioFlags.None, position, volume, pitchRange);
}
public static void PlaySound(string soundName, Actor actor, int channel, Vector3 position, float volume = 1f)
public static void PlaySound(string soundName, Actor actor, int channel, Float3 position, float volume = 1f)
{
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, Vector2.One);
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, Float2.One);
}
public static void PlaySound(string soundName, Actor actor, int channel, AudioFlags flags, Vector3 position,
public static void PlaySound(string soundName, Actor actor, int channel, AudioFlags flags, Float3 position,
float volume = 1f)
{
PlaySound(soundName, actor, channel, flags, position, volume, Vector2.One);
PlaySound(soundName, actor, channel, flags, position, volume, Float2.One);
}
public static void PlaySound(string soundName, Actor actor, int channel, AudioFlags flags, Vector3 position,
float volume, Vector2 pitchRange)
public static void PlaySound(string soundName, Actor actor, int channel, AudioFlags flags, Float3 position,
float volume, Float2 pitchRange)
{
AudioInfo audio = GetSound(soundName);
if (audio.AudioClips.Length == 0)
@@ -125,8 +125,8 @@ namespace Game
actorChannels.channelSources[channel] = audioSource;
}
public static async void PlaySoundDelayed(Vector2 delayRange, string soundName, Actor actor, int channel,
Vector3 position, float volume = 1f)
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
Float3 position, float volume = 1f)
{
float randomDelay;
if (delayRange[0] < delayRange[1])
@@ -134,16 +134,16 @@ namespace Game
else
randomDelay = delayRange[0];
//PlaySoundDelayed(delay, soundName, actor, channel, AudioFlags.None, position, volume, Vector2.One);
//PlaySoundDelayed(delay, soundName, actor, channel, AudioFlags.None, position, volume, Float2.One);
await Task.Delay((int)(randomDelay * 1000f));
//FlaxEngine.Scripting.RunOnUpdate(() =>
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
if (actor) // Engine might have cleaned up the actor
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, Vector2.One);
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, Float2.One);
}
public static async void PlaySoundDelayed(Vector2 delayRange, string soundName, Actor actor, int channel,
Vector3 position, float volume, Vector2 pitchRange)
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
Float3 position, float volume, Float2 pitchRange)
{
float randomDelay;
if (delayRange[0] < delayRange[1])
@@ -151,7 +151,7 @@ namespace Game
else
randomDelay = delayRange[0];
//PlaySoundDelayed(delay, soundName, actor, channel, AudioFlags.None, position, volume, Vector2.One);
//PlaySoundDelayed(delay, soundName, actor, channel, AudioFlags.None, position, volume, Float2.One);
await Task.Delay((int)(randomDelay * 1000f));
//FlaxEngine.Scripting.RunOnUpdate(() =>
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
@@ -159,8 +159,8 @@ namespace Game
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, pitchRange);
}
public static async void PlaySoundDelayed(Vector2 delayRange, string soundName, Actor actor, int channel,
AudioFlags flags, Vector3 position, float volume, Vector2 pitchRange)
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
AudioFlags flags, Float3 position, float volume, Float2 pitchRange)
{
float randomDelay;
if (delayRange[0] < delayRange[1])

View File

@@ -34,7 +34,7 @@ namespace Game
public override void OnStart()
{
Vector3 initialEulerAngles = Actor.Orientation.EulerAngles;
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
viewPitch = initialEulerAngles.X;
viewYaw = initialEulerAngles.Y;
viewRoll = initialEulerAngles.Z;
@@ -62,7 +62,7 @@ namespace Game
float inputH = InputManager.GetAxis("Horizontal");
float inputV = InputManager.GetAxis("Vertical");
Vector3 move = new Vector3(inputH, 0.0f, inputV);
Float3 move = new Float3(inputH, 0.0f, inputV);
if (!move.IsZero)
{
@@ -70,7 +70,7 @@ namespace Game
move = camera.Transform.TransformDirection(move) * MoveSpeed;
{
Vector3 delta = move * Time.UnscaledDeltaTime;
Float3 delta = move * Time.UnscaledDeltaTime;
float movementLeft = delta.Length;
// TODO: check multiple times in case we get stuck in walls
@@ -83,7 +83,7 @@ namespace Game
//bool nohit = true;
float hitDistance = moveDist;
Vector3 hitNormal = move.Normalized;
Float3 hitNormal = move.Normalized;
foreach (RayCastHit hitInfo in hitInfos)
{
if (hitInfo.Collider.Parent == Parent)
@@ -99,7 +99,7 @@ namespace Game
}
if (hitDistance != moveDist)
//camTrans.Translation = Vector3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
//camTrans.Translation = Float3.Lerp(Actor.Transform.Translation, camTrans.Translation, hitDistance);
//projected = normal * dot(direction, normal);
//direction = direction - projected
@@ -107,7 +107,7 @@ namespace Game
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
//camTrans.Translation = Actor.Transform.Translation;
delta += -Vector3.Dot(delta, hitNormal) * hitNormal; // correct?
delta += -Float3.Dot(delta, hitNormal) * hitNormal; // correct?
camTrans.Translation += delta;
}

View File

@@ -141,9 +141,9 @@ namespace Game
{
lastRescale = rescaleModel;
if (rescaleModel)
viewModelHolder.Scale = new Vector3(0.75f);
viewModelHolder.Scale = new Float3(0.75f);
else
viewModelHolder.Scale = new Vector3(1.0f);
viewModelHolder.Scale = new Float3(1.0f);
}
if (!camera.IsActive)

View File

@@ -5,14 +5,14 @@ namespace Game
public class CameraSpring : Script
{
private bool lastGround;
private Vector3 lastPosition;
private Float3 lastPosition;
public float percY;
private Actor playerActor;
private PlayerMovement playerMovement;
public float speed = 240f;
private Vector3 targetOffset;
private Float3 targetOffset;
private Actor viewModelHolder;
public override void OnStart()
@@ -25,7 +25,7 @@ namespace Game
targetOffset = Actor.LocalPosition;
}
private void UpdatePosition(Vector3 position)
private void UpdatePosition(Float3 position)
{
Actor.Position = position;
viewModelHolder.Position = position;
@@ -33,8 +33,8 @@ namespace Game
public override void OnUpdate()
{
Vector3 position = Actor.Parent.Position + targetOffset;
Vector3 targetPosition = position;
Float3 position = Actor.Parent.Position + targetOffset;
Float3 targetPosition = position;
if (playerMovement.onGround)
{

View File

@@ -30,8 +30,8 @@ namespace Game
{
Quaternion rotation = GetRotation();
Vector3 targetAngles = rotation.EulerAngles;
Vector3 angles = Actor.LocalOrientation.EulerAngles;
Float3 targetAngles = rotation.EulerAngles;
Float3 angles = Actor.LocalOrientation.EulerAngles;
// Ensure the swaying is smooth when framerate fluctuates slightly
float remaining = Time.DeltaTime + timeRemainder;

View File

@@ -186,7 +186,7 @@ namespace Game
public override void Draw()
{
// Cache data
Rectangle rect = new Rectangle(Vector2.Zero, Size);
Rectangle rect = new Rectangle(Float2.Zero, Size);
Font font = Font.GetFont();
if (!font)
return;
@@ -267,7 +267,7 @@ namespace Game
if (lineIndex > selectionLeftLine && lineIndex < selectionRightLine)
{
// whole line is selected
Vector2 lineSize = font.MeasureText(line);
Float2 lineSize = font.MeasureText(line);
selectionRect.Width = lineSize.X;
selectionRect.Height = lineSize.Y;
}
@@ -276,8 +276,8 @@ namespace Game
if (lineIndex < selectionRightLine)
{
// right side of the line is selected
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
Vector2 rightSize = font.MeasureText(fullLine.Substring(leftChar));
Float2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
Float2 rightSize = font.MeasureText(fullLine.Substring(leftChar));
selectionRect.X += leftSize.X;
selectionRect.Width = rightSize.X;
selectionRect.Height = rightSize.Y;
@@ -288,9 +288,9 @@ namespace Game
else if (lineIndex == selectionRightLine && leftChar != rightChar)
{
// selecting middle of the one line
Vector2 lineSize = font.MeasureText(fullLine);
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
Vector2 midSize =
Float2 lineSize = font.MeasureText(fullLine);
Float2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
Float2 midSize =
font.MeasureText(fullLine.Substring(leftChar, rightChar - leftChar));
selectionRect.X += leftSize.X;
@@ -304,7 +304,7 @@ namespace Game
else if (lineIndex == selectionRightLine)
{
// left side of the line is selected
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, rightChar));
Float2 leftSize = font.MeasureText(fullLine.Substring(0, rightChar));
selectionRect.Width = leftSize.X;
selectionRect.Height = leftSize.Y;
@@ -340,7 +340,7 @@ namespace Game
/*if (CaretPosition > -1)
{
var prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Vector2();
var prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Float2();
var caretBounds = CaretBounds;
caretBounds.X += prefixSize.X;
@@ -374,7 +374,7 @@ namespace Game
EndMouseCapture();
}
public bool HitTestText(Vector2 location, out int hitLine, out int hitChar)
public bool HitTestText(Float2 location, out int hitLine, out int hitChar)
{
hitLine = 0;
hitChar = 0;
@@ -422,7 +422,7 @@ namespace Game
return true;
}
/*public int CharIndexAtPoint(ref Vector2 location)
/*public int CharIndexAtPoint(ref Float2 location)
{
return HitTestText(location + _viewOffset);
}*/
@@ -460,7 +460,7 @@ namespace Game
return base.OnKeyDown(key);
}
public override bool OnMouseWheel(Vector2 location, float delta)
public override bool OnMouseWheel(Float2 location, float delta)
{
if (delta < 0)
{
@@ -479,7 +479,7 @@ namespace Game
return false;
}
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
bool ret = false;
if (button == MouseButton.Left && !IsFocused)
@@ -525,7 +525,7 @@ namespace Game
return ret;
}
public override void OnMouseMove(Vector2 location)
public override void OnMouseMove(Float2 location)
{
if (selectionActive)
if (HitTestText(location, out int hitLine, out int hitChar))
@@ -537,7 +537,7 @@ namespace Game
}
/// <inheritdoc />
public override bool OnMouseUp(Vector2 location, MouseButton button)
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{

View File

@@ -146,13 +146,13 @@ namespace Game
_isEditing = oldEditing;
}
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
base.OnMouseDown(location, button);
return true;
}
public override bool OnMouseWheel(Vector2 location, float delta)
public override bool OnMouseWheel(Float2 location, float delta)
{
return contentBox.OnMouseWheel(location, delta);
}

View File

@@ -70,7 +70,7 @@ namespace Game
consoleBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, true);
//consoleBox.AnchorMax = new Vector2(1.0f, ConsoleHeight);
//consoleBox.AnchorMax = new Float2(1.0f, ConsoleHeight);
//consoleBox.Height = consoleSize.Y - fontHeight;
//consoleBox.HorizontalAlignment = TextAlignment.Near;
@@ -84,7 +84,7 @@ namespace Game
consoleBox.CaretFlashSpeed = 0;
}
Vector2 locationFix = consoleBox.Location;
Float2 locationFix = consoleBox.Location;
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
parentControl.Name = "ConsoleContent";
parentControl.Control = consoleBox;
@@ -97,7 +97,7 @@ namespace Game
consoleNotifyBox.HeightMultiplier = 0;
consoleNotifyBox.Height = ConsoleNotifyLines * fontHeight;
consoleNotifyBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, true);
//consoleBox.AnchorMax = new Vector2(1.0f, ConsoleHeight);
//consoleBox.AnchorMax = new Float2(1.0f, ConsoleHeight);
//consoleBox.HorizontalAlignment = TextAlignment.Near;
//consoleBox.VerticalAlignment = TextAlignment.Near;
@@ -110,7 +110,7 @@ namespace Game
consoleNotifyBox.CaretFlashSpeed = 0;
}
Vector2 locationFix2 = consoleNotifyBox.Location;
Float2 locationFix2 = consoleNotifyBox.Location;
UIControl parentControl2 = Actor.AddChild<UIControl>();
parentControl2.Name = "ConsoleNotifyContent";
parentControl2.Control = consoleNotifyBox;
@@ -122,7 +122,7 @@ namespace Game
//consoleInputBox = new ConsoleInputTextBox(consoleBox, 0, consoleSize.Y - fontHeight, consoleSize.X, fontHeight);
consoleInputBox = new ConsoleInputTextBox(consoleBox, 0, 0, 0, 0);
consoleInputBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, false);
//consoleInputBox.Location = new Vector2(0, consoleSize.Y - fontHeight);
//consoleInputBox.Location = new Float2(0, consoleSize.Y - fontHeight);
consoleInputBox.Height = fontHeight;
consoleInputBox.Font = fontReference;
@@ -137,7 +137,7 @@ namespace Game
}
Vector2 locationFix = consoleInputBox.Location;
Float2 locationFix = consoleInputBox.Location;
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
parentControl.Name = "ConsoleInput";
parentControl.Control = consoleInputBox;
@@ -227,7 +227,7 @@ namespace Game
// hide console by default, and close it instantly
Console.Close();
Vector2 rootlocation = rootControl.Control.Location;
Float2 rootlocation = rootControl.Control.Location;
rootlocation.Y = -rootControl.Control.Height;
rootControl.Control.Location = rootlocation;
@@ -339,7 +339,7 @@ namespace Game
else
targetY = 0.0f;
Vector2 location = rootControl.Control.Location;
Float2 location = rootControl.Control.Location;
if (location.Y != targetY)
{
if (location.Y > targetY)

View File

@@ -11,7 +11,7 @@ namespace Game
protected TextLayoutOptions _layout;
private bool doubleClicked;
private Vector2 lastDoubleClickLocation = new Vector2(0, 0);
private Float2 lastDoubleClickLocation = new Float2(0, 0);
/// <summary>
/// Gets or sets the color of the selection (Transparent if not used).
@@ -121,7 +121,7 @@ namespace Game
public override void ResetViewOffset()
{
TargetViewOffset = new Vector2(0, 0);
TargetViewOffset = new Float2(0, 0);
}
/*public void ScrollToEnd()
@@ -130,7 +130,7 @@ namespace Game
float spacing = GetRealLineSpacing();
maxY += spacing;
TargetViewOffset = new Vector2(0, Math.Max(0, maxY));
TargetViewOffset = new Float2(0, Math.Max(0, maxY));
}*/
public override void ScrollToCaret()
@@ -142,13 +142,13 @@ namespace Game
float maxY = TextSize.Y - Height;
Vector2 newLocation = CaretBounds.Location;
TargetViewOffset = Vector2.Clamp(newLocation, new Vector2(0, 0), new Vector2(_targetViewOffset.X, maxY));
Float2 newLocation = CaretBounds.Location;
TargetViewOffset = Float2.Clamp(newLocation, new Float2(0, 0), new Float2(_targetViewOffset.X, maxY));
}
/*const bool smoothScrolling = false;
public override bool OnMouseWheel(Vector2 location, float delta)
public override bool OnMouseWheel(Float2 location, float delta)
{
if (!IsMultiline || Text.Length == 0)
return false;
@@ -161,33 +161,33 @@ namespace Game
float maxY = TextSize.Y - Height;
float offset = GetRealLineSpacing();
maxY += offset;
TargetViewOffset = Vector2.Clamp(_targetViewOffset - new Vector2(0, delta), new Vector2(0, offset), new Vector2(_targetViewOffset.X, maxY));
TargetViewOffset = Float2.Clamp(_targetViewOffset - new Float2(0, delta), new Float2(0, offset), new Float2(_targetViewOffset.X, maxY));
return true;
}*/
public override Vector2 GetTextSize()
public override Float2 GetTextSize()
{
Font font = Font.GetFont();
if (font == null)
return Vector2.Zero;
return Float2.Zero;
return font.MeasureText(Text, ref _layout);
}
public override Vector2 GetCharPosition(int index, out float height)
public override Float2 GetCharPosition(int index, out float height)
{
Font font = Font.GetFont();
if (font == null)
{
height = Height;
return Vector2.Zero;
return Float2.Zero;
}
height = GetFontHeight();
return font.GetCharPosition(Text, index, ref _layout);
}
public override int HitTestText(Vector2 location)
public override int HitTestText(Float2 location)
{
Font font = Font.GetFont();
if (font == null)
@@ -195,7 +195,7 @@ namespace Game
if (TextPrefix != "")
{
Vector2 prefixSize = font.MeasureText(TextPrefix);
Float2 prefixSize = font.MeasureText(TextPrefix);
location.X -= prefixSize.X;
}
@@ -237,7 +237,7 @@ namespace Game
return base.OnKeyDown(key);
}
public override bool OnMouseDown(Vector2 location, MouseButton button)
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (doubleClicked && lastDoubleClick.Elapsed.TotalSeconds < 0.5 &&
location == lastDoubleClickLocation) // Windows defaults to 500ms window
@@ -251,7 +251,7 @@ namespace Game
}
public override bool OnMouseDoubleClick(Vector2 location, MouseButton button)
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
{
doubleClicked = true;
lastDoubleClick.Restart();
@@ -260,7 +260,7 @@ namespace Game
return base.OnMouseDoubleClick(location, button);
}
public bool OnMouseTripleClick(Vector2 location, MouseButton button)
public bool OnMouseTripleClick(Float2 location, MouseButton button)
{
if (!IsMultiline)
SelectAll();
@@ -281,7 +281,7 @@ namespace Game
public override void Draw()
{
// Cache data
Rectangle rect = new Rectangle(Vector2.Zero, Size);
Rectangle rect = new Rectangle(Float2.Zero, Size);
Font font = Font.GetFont();
if (!font)
return;
@@ -312,8 +312,8 @@ namespace Game
// Check if any text is selected to draw selection
if (HasSelection)
{
Vector2 leftEdge = font.GetCharPosition(text, SelectionLeft + TextPrefix.Length, ref _layout);
Vector2 rightEdge = font.GetCharPosition(text, SelectionRight + TextPrefix.Length, ref _layout);
Float2 leftEdge = font.GetCharPosition(text, SelectionLeft + TextPrefix.Length, ref _layout);
Float2 rightEdge = font.GetCharPosition(text, SelectionRight + TextPrefix.Length, ref _layout);
float fontHeight = GetFontHeight();
// Draw selection background
@@ -349,7 +349,7 @@ namespace Game
if (CaretPosition > -1)
{
Vector2 prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Vector2();
Float2 prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Float2();
Rectangle caretBounds = CaretBounds;
caretBounds.X += prefixSize.X;

View File

@@ -37,7 +37,7 @@ namespace Game
private class PlayerFrame
{
public ulong frame;
public Vector3 position;
public Float3 position;
}
private static Dictionary<uint, PlayerActor> players;
@@ -211,12 +211,12 @@ namespace Game
for (int i=0; i<numActors; i++)
{
uint playerId = networkEvent.Message.ReadUInt32();
Vector3 playerPosition;
Float3 playerPosition;
playerPosition.X = networkEvent.Message.ReadSingle();
playerPosition.Y = networkEvent.Message.ReadSingle();
playerPosition.Z = networkEvent.Message.ReadSingle();
SpawnPlayer(playerId, playerPosition, new Vector3(0));
SpawnPlayer(playerId, playerPosition, new Float3(0));
}
Console.Print("received welcome: frame " + worldState.frame);
@@ -234,8 +234,8 @@ namespace Game
uint playerId = networkEvent.Message.ReadUInt32();
ulong playerFrameIndex = networkEvent.Message.ReadUInt64();
SpawnPlayer(playerId,
new Vector3(networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle()),
new Vector3(networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle()));
new Float3(networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle()),
new Float3(networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle()));
break;
}
case GameModeMessageType.PlayerInput:
@@ -256,7 +256,7 @@ namespace Game
case GameModeMessageType.PlayerPosition:
{
uint playerId = networkEvent.Sender.ConnectionId;
Vector3 reportedPosition;
Float3 reportedPosition;
ulong reportedFrame = networkEvent.Message.ReadUInt64();
uint reportedPlayerId = networkEvent.Message.ReadUInt32();
@@ -276,7 +276,7 @@ namespace Game
Console.Print("frame is in the past, unable to verify frame");
else
{
Vector3 playerFramePosition = playerFrame.position;
Float3 playerFramePosition = playerFrame.position;
if ((playerFramePosition - reportedPosition).Length > 0.0001)
{
Console.Print("player drifted, len: " + (playerFramePosition - reportedPosition).Length);
@@ -348,8 +348,8 @@ namespace Game
var randomSpawn = spawns.First();
uint playerId = connection.ConnectionId;
Vector3 position = randomSpawn.Position + new Vector3(0f, 4.1f, 0f);
Vector3 eulerAngles = randomSpawn.Orientation.EulerAngles;
Float3 position = randomSpawn.Position + new Float3(0f, 4.1f, 0f);
Float3 eulerAngles = randomSpawn.Orientation.EulerAngles;
players.Add(playerId, null);
playerConnections.Add(playerId, connection);
@@ -377,7 +377,7 @@ namespace Game
return true;
}
private static void SpawnPlayer(uint playerId, Vector3 position, Vector3 eulerAngles)
private static void SpawnPlayer(uint playerId, Float3 position, Vector3 eulerAngles)
{
if (NetworkManager.IsLocalClient)
return; // Handled by listenserver

View File

@@ -11,12 +11,12 @@ namespace Game
{
public struct MapFacePlane
{
public Vector3 v1, v2, v3;
public Float3 v1, v2, v3;
public Plane plane;
public string texture;
public Vector2 offset;
public Float2 offset;
public float rotation;
public Vector2 scale;
public Float2 scale;
public int contentFlags, surfaceFlags, surfaceValue;
}
@@ -32,8 +32,8 @@ namespace Game
public struct PatchVertex
{
public Vector3 v;
public Vector2 uv;
public Float3 v;
public Float2 uv;
}
public class MapEntity
@@ -245,24 +245,24 @@ namespace Game
throw new Exception("failed to ParseInt: " + fs);
}
private static Vector3 ParseVector3(byte[] data, ref int index)
private static Float3 ParseFloat3(byte[] data, ref int index)
{
return new Vector3(
return new Float3(
ParseFloat(data, ref index),
ParseFloat(data, ref index),
ParseFloat(data, ref index)
);
}
private static Vector2 ParseVector2(byte[] data, ref int index)
private static Float2 ParseFloat2(byte[] data, ref int index)
{
return new Vector2(
return new Float2(
ParseFloat(data, ref index),
ParseFloat(data, ref index)
);
}
private static Vector3 ParsePlaneVector3(byte[] data, ref int index)
private static Float3 ParsePlaneFloat3(byte[] data, ref int index)
{
index++;
while (index < data.Length)
@@ -272,7 +272,7 @@ namespace Game
index++;
}
Vector3 vector = ParseVector3(data, ref index);
Float3 vector = ParseFloat3(data, ref index);
// rounding
/*float temp = vector.Z;
vector.Z = vector.Y;
@@ -328,16 +328,16 @@ namespace Game
case '(':
{
MapFacePlane plane = new MapFacePlane();
plane.v1 = ParsePlaneVector3(data, ref index);
plane.v2 = ParsePlaneVector3(data, ref index);
plane.v3 = ParsePlaneVector3(data, ref index);
plane.v1 = ParsePlaneFloat3(data, ref index);
plane.v2 = ParsePlaneFloat3(data, ref index);
plane.v3 = ParsePlaneFloat3(data, ref index);
plane.texture = ParseString(data, ref index);
if (true) // quake or quake3 format
{
plane.offset = ParseVector2(data, ref index);
plane.offset = ParseFloat2(data, ref index);
plane.rotation = ParseFloat(data, ref index);
plane.scale = ParseVector2(data, ref index);
plane.scale = ParseFloat2(data, ref index);
char peekChar = (char)data[index];
if (peekChar != '\n') // quake3 format
@@ -349,9 +349,9 @@ namespace Game
}
// Flip Y and Z
plane.v1 = new Vector3(plane.v1.X, plane.v1.Z, plane.v1.Y);
plane.v2 = new Vector3(plane.v2.X, plane.v2.Z, plane.v2.Y);
plane.v3 = new Vector3(plane.v3.X, plane.v3.Z, plane.v3.Y);
plane.v1 = new Float3(plane.v1.X, plane.v1.Z, plane.v1.Y);
plane.v2 = new Float3(plane.v2.X, plane.v2.Z, plane.v2.Y);
plane.v3 = new Float3(plane.v3.X, plane.v3.Z, plane.v3.Y);
plane.plane = new Plane(plane.v1, plane.v2, plane.v3);
@@ -494,9 +494,9 @@ namespace Game
index++;
}
vertices[vertexIndex].v = ParseVector3(data, ref index);
vertices[vertexIndex].v = ParseFloat3(data, ref index);
vertices[vertexIndex].uv =
new Vector2(ParseFloat(data, ref index), ParseFloat(data, ref index));
new Float2(ParseFloat(data, ref index), ParseFloat(data, ref index));
vertexIndex++;
while (index < data.Length)

View File

@@ -17,9 +17,9 @@ namespace Game
{
public List<uint> indices = new List<uint>();
public MaterialBase material;
public List<Vector3> normals = new List<Vector3>();
public List<Vector2> uvs = new List<Vector2>();
public List<Vector3> vertices = new List<Vector3>();
public List<Float3> normals = new List<Float3>();
public List<Float2> uvs = new List<Float2>();
public List<Float3> vertices = new List<Float3>();
}
public class BrushGeometry
@@ -28,8 +28,8 @@ namespace Game
public Dictionary<string, MaterialBase> brushMaterials;
public BrushGeometryMesh[] meshes;
public Model model;
public Vector3 offset;
public Vector3[] vertices; // all vertices
public Float3 offset;
public Float3[] vertices; // all vertices
}
[ExecuteInEditMode]
@@ -88,16 +88,16 @@ namespace Game
}
private static void QuickHull(Vector3[] points, out Vector3[] outVertices)
private static void QuickHull(Float3[] points, out Float3[] outVertices)
{
var verts = new List<Vector3>();
var verts = new List<Float3>();
var tris = new List<int>();
var normals = new List<Vector3>();
var normals = new List<Float3>();
ConvexHullCalculator calc = new ConvexHullCalculator();
calc.GenerateHull(points.ToList(), true, ref verts, ref tris, ref normals);
var finalPoints = new List<Vector3>();
var finalPoints = new List<Float3>();
foreach (int tri in tris)
finalPoints.Add(verts[tri]);
@@ -122,9 +122,9 @@ namespace Game
/// Triangulates the brush by calculating intersection points between triplets of planes.
/// Does not work well with off-axis aligned planes.
/// </summary>
public static void TriangulateBrush(MapBrush brush, out Vector3[] vertices)
public static void TriangulateBrush(MapBrush brush, out Float3[] vertices)
{
var planePoints = new HashSet<Vector3>();
var planePoints = new HashSet<Float3>();
var planes = new List<Plane>();
float maxDist = 0f;
@@ -149,14 +149,14 @@ namespace Game
//var maxDist = Math.Abs(p1.D * p2.D * p3.D);//Math.Max(p1.D, Math.Max(p2.D, p3.D));
// intersection of three planes
double denom = Vector3.Dot(p1.Normal, Vector3.Cross(p2.Normal, p3.Normal));
double denom = Float3.Dot(p1.Normal, Float3.Cross(p2.Normal, p3.Normal));
//if (denom < 0.0000000001)
// continue;
Vector3 intersection = (Vector3.Cross(p2.Normal, p3.Normal) * -p1.D +
Vector3.Cross(p3.Normal, p1.Normal) * -p2.D +
Vector3.Cross(p1.Normal, p2.Normal) * -p3.D) / (float)denom;
Float3 intersection = (Float3.Cross(p2.Normal, p3.Normal) * -p1.D +
Float3.Cross(p3.Normal, p1.Normal) * -p2.D +
Float3.Cross(p1.Normal, p2.Normal) * -p3.D) / (float)denom;
if (Mathf.Abs(intersection.X) > maxDist * 1f || Mathf.Abs(intersection.Y) > maxDist * 1f ||
Mathf.Abs(intersection.Z) > maxDist * 1f)
@@ -180,12 +180,12 @@ namespace Game
// remove duplicate points
var planePoints3 = planePoints;
planePoints = new HashSet<Vector3>();
planePoints = new HashSet<Float3>();
foreach (Vector3 p1 in planePoints3)
foreach (Float3 p1 in planePoints3)
{
bool found = false;
foreach (Vector3 p2 in planePoints)
foreach (Float3 p2 in planePoints)
if (Mathf.Abs((p1 - p2).Length) < 0.00001f)
{
found = true;
@@ -201,9 +201,9 @@ namespace Game
// pass 2: cull points behind clipping planes
var planePoints2 = planePoints;
planePoints = new HashSet<Vector3>();
planePoints = new HashSet<Float3>();
foreach (Vector3 p in planePoints2)
foreach (Float3 p in planePoints2)
{
bool front = true;
foreach (MapFacePlane brushPlane in brush.planes)
@@ -227,7 +227,7 @@ namespace Game
return;
}
vertices = new Vector3[0];
vertices = new Float3[0];
}
#if FLAX_EDITOR
@@ -422,7 +422,7 @@ namespace Game
Assert.IsTrue(geom.vertices.Length > 0);
foreach (Vector3 vert in geom.vertices)
foreach (Float3 vert in geom.vertices)
geom.offset += vert;
geom.offset /= geom.vertices.Length;
@@ -485,16 +485,16 @@ namespace Game
var brushVertices = geom.vertices;
for (int i = 0; i < brushVertices.Length; i += 3)
{
Vector3 v1 = brushVertices[i + 0];
Vector3 v2 = brushVertices[i + 1];
Vector3 v3 = brushVertices[i + 2];
Float3 v1 = brushVertices[i + 0];
Float3 v2 = brushVertices[i + 1];
Float3 v3 = brushVertices[i + 2];
Vector3 normal = -Vector3.Cross(v3 - v1, v2 - v1).Normalized;
Float3 normal = -Float3.Cross(v3 - v1, v2 - v1).Normalized;
// fetch the texture parameters from the plane with matching normal
Vector2 uvScale = new Vector2(0f);
Float2 uvScale = new Float2(0f);
float uvRotation = 0f;
Vector2 uvOffset = new Vector2(0f);
Float2 uvOffset = new Float2(0f);
bool found = false;
int meshIndex = 0;
foreach (MapFacePlane brushPlane in geom.brush.planes)
@@ -512,7 +512,7 @@ namespace Game
if (!found)
Console.Print("no matching plane found for brush " + brushIndex + ", bad geometry?");
Vector2 uv1, uv2, uv3;
Float2 uv1, uv2, uv3;
// if quake format
{
// The texture is projected to the surface from three angles, the axis with least
@@ -521,43 +521,43 @@ namespace Game
// Attempt to workaround most rounding errors at 45-degree angles which causes bias towards one axis.
// This behaviour is seemingly random in different engines and editors, so let's not bother.
Vector3 textureNormal = new Vector3((float)Math.Round(normal.X, 4),
Float3 textureNormal = new Float3((float)Math.Round(normal.X, 4),
(float)Math.Round(normal.Y, 4), (float)Math.Round(normal.Z, 4));
float dotX = Math.Abs(Vector3.Dot(textureNormal, Vector3.Right));
float dotY = Math.Abs(Vector3.Dot(textureNormal, Vector3.Up));
float dotZ = Math.Abs(Vector3.Dot(textureNormal, Vector3.Forward));
float dotX = Math.Abs(Float3.Dot(textureNormal, Float3.Right));
float dotY = Math.Abs(Float3.Dot(textureNormal, Float3.Up));
float dotZ = Math.Abs(Float3.Dot(textureNormal, Float3.Forward));
Vector3 axis;
Float3 axis;
if (dotY >= dotX && dotY >= dotZ)
axis = -Vector3.Up;
axis = -Float3.Up;
else if (dotX >= dotY && dotX >= dotZ)
axis = Vector3.Right;
axis = Float3.Right;
else if (dotZ >= dotX && dotZ >= dotY)
axis = -Vector3.Forward;
axis = -Float3.Forward;
else
axis = Vector3.Right;
axis = Float3.Right;
Vector3 axisForward = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
? -Vector3.Forward
: Vector3.Up;
Vector3 axisForward2 = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
? Vector3.Up
: -Vector3.Forward;
Float3 axisForward = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
? -Float3.Forward
: Float3.Up;
Float3 axisForward2 = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
? Float3.Up
: -Float3.Forward;
Quaternion rot = Quaternion.Identity;
rot = rot * Quaternion.LookRotation(axis, axisForward);
rot = rot * Quaternion.RotationAxis(-Vector3.Forward,
rot = rot * Quaternion.RotationAxis(-Float3.Forward,
180f * Mathf.DegreesToRadians);
rot = rot * Quaternion.RotationAxis(
Mathf.Abs(Vector3.Dot(axis, Vector3.Right)) > 0.01f
? Vector3.Right
Mathf.Abs(Float3.Dot(axis, Float3.Right)) > 0.01f
? Float3.Right
: axisForward2,
uvRotation * Mathf.DegreesToRadians);
uv1 = ((Vector2)((v1 + geom.offset) * rot) + uvOffset) * uvScale;
uv2 = ((Vector2)((v2 + geom.offset) * rot) + uvOffset) * uvScale;
uv3 = ((Vector2)((v3 + geom.offset) * rot) + uvOffset) * uvScale;
uv1 = ((Float2)((v1 + geom.offset) * rot) + uvOffset) * uvScale;
uv2 = ((Float2)((v2 + geom.offset) * rot) + uvOffset) * uvScale;
uv3 = ((Float2)((v3 + geom.offset) * rot) + uvOffset) * uvScale;
}
BrushGeometryMesh mesh = geom.meshes[meshIndex];
@@ -679,9 +679,9 @@ namespace Game
}
else
{
var vertices = new List<Vector3>();
var uvs = new List<Vector2>();
var normals = new List<Vector3>();
var vertices = new List<Float3>();
var uvs = new List<Float2>();
var normals = new List<Float3>();
sw.Restart();
int brushIndex = 0;
@@ -690,21 +690,21 @@ namespace Game
try
{
TriangulateBrush(brush, out var brushVertices);
var brushUvs = new Vector2[brushVertices.Length];
var brushNormals = new Vector3[brushVertices.Length];
var brushUvs = new Float2[brushVertices.Length];
var brushNormals = new Float3[brushVertices.Length];
for (int i = 0; i < brushVertices.Length; i += 3)
{
Vector3 v1 = brushVertices[i + 0];
Vector3 v2 = brushVertices[i + 1];
Vector3 v3 = brushVertices[i + 2];
Float3 v1 = brushVertices[i + 0];
Float3 v2 = brushVertices[i + 1];
Float3 v3 = brushVertices[i + 2];
Vector3 normal = -Vector3.Cross(v3 - v1, v2 - v1).Normalized;
Float3 normal = -Float3.Cross(v3 - v1, v2 - v1).Normalized;
// fetch the texture parameters from the plane with matching normal
Vector2 uvScale = new Vector2(0f);
Float2 uvScale = new Float2(0f);
float uvRotation = 0f;
Vector2 uvOffset = new Vector2(0f);
Float2 uvOffset = new Float2(0f);
bool found = false;
foreach (MapFacePlane brushPlane in brush.planes)
if ((brushPlane.plane.Normal - normal).Length < 0.01f)
@@ -720,7 +720,7 @@ namespace Game
if (!found)
Console.Print("no matching plane found, bad geometry?");
Vector2 uv1, uv2, uv3;
Float2 uv1, uv2, uv3;
// if quake format
{
// The texture is projected to the surface from three angles, the axis with least
@@ -728,43 +728,43 @@ namespace Game
// Attempt to workaround most rounding errors at 45-degree angles which causes bias towards one axis.
// This behaviour is seemingly random in different engines and editors, so let's not bother.
Vector3 textureNormal = new Vector3((float)Math.Round(normal.X, 4),
Float3 textureNormal = new Float3((float)Math.Round(normal.X, 4),
(float)Math.Round(normal.Y, 4), (float)Math.Round(normal.Z, 4));
float dotX = Math.Abs(Vector3.Dot(textureNormal, Vector3.Right));
float dotY = Math.Abs(Vector3.Dot(textureNormal, Vector3.Up));
float dotZ = Math.Abs(Vector3.Dot(textureNormal, Vector3.Forward));
float dotX = Math.Abs(Float3.Dot(textureNormal, Float3.Right));
float dotY = Math.Abs(Float3.Dot(textureNormal, Float3.Up));
float dotZ = Math.Abs(Float3.Dot(textureNormal, Float3.Forward));
Vector3 axis;
Float3 axis;
if (dotY >= dotX && dotY >= dotZ)
axis = -Vector3.Up;
axis = -Float3.Up;
else if (dotX >= dotY && dotX >= dotZ)
axis = Vector3.Right;
axis = Float3.Right;
else if (dotZ >= dotX && dotZ >= dotY)
axis = -Vector3.Forward;
axis = -Float3.Forward;
else
axis = Vector3.Right;
axis = Float3.Right;
Vector3 axisForward = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
? -Vector3.Forward
: Vector3.Up;
Vector3 axisForward2 = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
? Vector3.Up
: -Vector3.Forward;
Float3 axisForward = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
? -Float3.Forward
: Float3.Up;
Float3 axisForward2 = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
? Float3.Up
: -Float3.Forward;
Quaternion rot = Quaternion.Identity;
rot = rot * Quaternion.LookRotation(axis, axisForward);
rot = rot * Quaternion.RotationAxis(-Vector3.Forward,
rot = rot * Quaternion.RotationAxis(-Float3.Forward,
180f * Mathf.DegreesToRadians);
rot = rot * Quaternion.RotationAxis(
Mathf.Abs(Vector3.Dot(axis, Vector3.Right)) > 0.01f
? Vector3.Right
Mathf.Abs(Float3.Dot(axis, Float3.Right)) > 0.01f
? Float3.Right
: axisForward2,
uvRotation * Mathf.DegreesToRadians);
uv1 = ((Vector2)(v1 * rot) + uvOffset) * uvScale;
uv2 = ((Vector2)(v2 * rot) + uvOffset) * uvScale;
uv3 = ((Vector2)(v3 * rot) + uvOffset) * uvScale;
uv1 = ((Float2)(v1 * rot) + uvOffset) * uvScale;
uv2 = ((Float2)(v2 * rot) + uvOffset) * uvScale;
uv3 = ((Float2)(v3 * rot) + uvOffset) * uvScale;
}
brushUvs[i + 0] = uv1;
@@ -965,10 +965,10 @@ namespace Game
playerSpawnIndex++;
}
private static Vector3 ParseOrigin(string origin)
private static Float3 ParseOrigin(string origin)
{
string[] points = origin.Split(' ');
return new Vector3(float.Parse(points[0]), float.Parse(points[2]), float.Parse(points[1]));
return new Float3(float.Parse(points[0]), float.Parse(points[2]), float.Parse(points[1]));
}
private static Color ParseColor(string origin)
@@ -980,14 +980,14 @@ namespace Game
private static Quaternion ParseAngle(string origin)
{
string[] angles = origin.Split(' ');
//Console.Print("parseangle: " + new Vector3(0f, float.Parse(angles[0]) + 45f, 0f).ToString());
return Quaternion.Euler(new Vector3(0f, float.Parse(angles[0]) + 90f, 0f));
//Console.Print("parseangle: " + new Float3(0f, float.Parse(angles[0]) + 45f, 0f).ToString());
return Quaternion.Euler(new Float3(0f, float.Parse(angles[0]) + 90f, 0f));
}
private static Vector3 ParseAngleEuler(string origin)
private static Float3 ParseAngleEuler(string origin)
{
string[] angles = origin.Split(' ');
return new Vector3(0f, float.Parse(angles[0]) + 45f, 0f);
return new Float3(0f, float.Parse(angles[0]) + 45f, 0f);
}
public override void OnDestroy()

View File

@@ -28,7 +28,7 @@ namespace Game
face.halfEdges.Add(this);
}
public Vector3 tail
public Float3 tail
{
get
{
@@ -44,15 +44,15 @@ namespace Game
public struct Edge
{
public Vector3 v1, v2;
public Float3 v1, v2;
public Edge(Vector3 v1, Vector3 v2)
public Edge(Float3 v1, Float3 v2)
{
this.v1 = v1;
this.v2 = v2;
}
public static Edge[] GetEdges(Vector3 v1, Vector3 v2, Vector3 v3)
public static Edge[] GetEdges(Float3 v1, Float3 v2, Float3 v3)
{
return new[]
{
@@ -97,11 +97,11 @@ namespace Game
public class Face
{
public Vector3 v1, v2, v3;
public Float3 v1, v2, v3;
public List<HalfEdge> halfEdges;
public bool visited;
public Face(Vector3 v1, Vector3 v2, Vector3 v3)
public Face(Float3 v1, Float3 v2, Float3 v3)
{
this.v1 = v1;
this.v2 = v2;
@@ -119,7 +119,7 @@ namespace Game
};
}
public float DistanceToPoint(Vector3 point)
public float DistanceToPoint(Float3 point)
{
Plane plane = new Plane(v1, v2, v3);
@@ -143,13 +143,13 @@ namespace Game
{
HalfEdge areaEdgeStart = halfEdges[0];
HalfEdge areaEdge = areaEdgeStart.previous;
Vector3 areaNorm = Vector3.Zero;
Float3 areaNorm = Float3.Zero;
int iters = 0;
do
{
if (iters++ > 1000)
throw new Exception("merge infinite loop");
areaNorm += Vector3.Cross(areaEdge.edge.v1 - areaEdgeStart.edge.v1,
areaNorm += Float3.Cross(areaEdge.edge.v1 - areaEdgeStart.edge.v1,
areaEdge.next.edge.v1 - areaEdgeStart.edge.v1);
areaEdge = areaEdge.previous;
@@ -161,9 +161,9 @@ namespace Game
public struct Tetrahedron
{
public Vector3 v1, v2, v3, v4;
public Float3 v1, v2, v3, v4;
public Tetrahedron(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4)
public Tetrahedron(Float3 v1, Vector3 v2, Vector3 v3, Vector3 v4)
{
this.v1 = v1;
this.v2 = v2;
@@ -187,9 +187,9 @@ namespace Game
{
const float epsilon = 0.01f;
private void SortPoints(List<Vector3> points, Vector3 planeNormal)
private void SortPoints(List<Float3> points, Vector3 planeNormal)
{
Vector3 center = Vector3.Zero;
Vector3 center = Float3.Zero;
foreach (var vert in points)
{
center += vert;
@@ -200,7 +200,7 @@ namespace Game
points.Sort((v1, v2) =>
{
var dot = Vector3.Dot(planeNormal, Vector3.Cross(v1 - center, v2 - center));
var dot = Float3.Dot(planeNormal, Float3.Cross(v1 - center, v2 - center));
if (dot > 0)
return 1;
else
@@ -208,7 +208,7 @@ namespace Game
});
}
float PointDistanceFromPlane(Vector3 point, Plane plane)
float PointDistanceFromPlane(Float3 point, Plane plane)
{
float distance = (point.X * plane.Normal.X) + (point.Y * plane.Normal.Y) +
(point.Z * plane.Normal.Z) + plane.D;
@@ -217,15 +217,15 @@ namespace Game
(plane.Normal.Z * plane.Normal.Z));
}
private Face[] CreateInitialSimplex(Vector3[] points)
private Face[] CreateInitialSimplex(Float3[] points)
{
if (false)
{
// TODO: more optimal to find first set of points which are not coplanar?
// find the longest edge
Vector3 v1 = Vector3.Zero;
Vector3 v2 = Vector3.Zero;
Vector3 v1 = Float3.Zero;
Vector3 v2 = Float3.Zero;
foreach (var p1 in points)
{
foreach (var p2 in points)
@@ -244,7 +244,7 @@ namespace Game
Assert.IsTrue(v1 != v2, "a1 != a2");
// find the furthest point from the edge to form a face
Vector3 v3 = Vector3.Zero;
Vector3 v3 = Float3.Zero;
float furthestDist = 0f;
foreach (var point in points)
{
@@ -252,7 +252,7 @@ namespace Game
// continue;
var edgeDir = (v2 - v1).Normalized;
var closest = v1 + edgeDir * Vector3.Dot(point - v1, edgeDir);
var closest = v1 + edgeDir * Float3.Dot(point - v1, edgeDir);
var dist = (point - closest).Length;
if (dist > furthestDist)
@@ -267,7 +267,7 @@ namespace Game
// find the furthest point from he face
Plane plane = new Plane(v1, v2, v3);
Vector3 v4 = Vector3.Zero;
Vector3 v4 = Float3.Zero;
float fourthDist = 0f;
foreach (var point in points)
{
@@ -306,7 +306,7 @@ namespace Game
}
else
{
Vector3 v1 = Vector3.Zero, v2 = Vector3.Zero, v3 = Vector3.Zero, v4 = Vector3.Zero;
Vector3 v1 = Float3.Zero, v2 = Float3.Zero, v3 = Float3.Zero, v4 = Float3.Zero;
bool found = false;
foreach (var p1 in points)
@@ -403,7 +403,7 @@ namespace Game
}
}
public List<Vector3> QuickHull2(Vector3[] points)
public List<Float3> QuickHull2(Float3[] points)
{
Assert.IsTrue(points.Length >= 4, "points.Length >= 4");
@@ -430,7 +430,7 @@ namespace Game
// verify
{
var tetrapoints = new List<Vector3>();
var tetrapoints = new List<Float3>();
foreach (var face in tetrahedron)
{
foreach (var he in face.halfEdges)
@@ -569,7 +569,7 @@ namespace Game
}
var hullFacesNew = new List<Face>();
var unclaimedPoints = new List<Vector3>();
var unclaimedPoints = new List<Float3>();
AddPointToHull(pointToAdd.Item2, pointFace, unclaimedPoints, outsideSet, horizonEdges, hullFacesNew);
@@ -629,7 +629,7 @@ namespace Game
foreach (var f in discardedFaces)
hullFaces.Remove(f);
List<Vector3> hullPoints = new List<Vector3>(hullFaces.Count * 3);
List<Float3> hullPoints = new List<Float3>(hullFaces.Count * 3);
foreach (var face in hullFaces)
{
hullPoints.Add(face.v1);
@@ -640,7 +640,7 @@ namespace Game
return hullPoints;
}
private void AddUnique(List<Vector3> list, Vector3 point)
private void AddUnique(List<Float3> list, Vector3 point)
{
foreach (var p in list)
{
@@ -650,27 +650,27 @@ namespace Game
list.Add(point);
}
bool AreCoincident(Vector3 a, Vector3 b)
bool AreCoincident(Float3 a, Vector3 b)
{
return (a - b).Length <= epsilon;
}
bool AreCollinear(Vector3 a, Vector3 b, Vector3 c)
bool AreCollinear(Float3 a, Vector3 b, Vector3 c)
{
return Vector3.Cross(c - a, c - b).Length <= epsilon;
return Float3.Cross(c - a, c - b).Length <= epsilon;
}
bool AreCoplanar(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
bool AreCoplanar(Float3 a, Vector3 b, Vector3 c, Vector3 d)
{
var n1 = Vector3.Cross(c - a, c - b);
var n2 = Vector3.Cross(d - a, d - b);
var n1 = Float3.Cross(c - a, c - b);
var n2 = Float3.Cross(d - a, d - b);
var m1 = n1.Length;
var m2 = n2.Length;
return m1 > epsilon
&& m2 > epsilon
&& AreCollinear(Vector3.Zero,
&& AreCollinear(Float3.Zero,
(1.0f / m1) * n1,
(1.0f / m2) * n2);
}
@@ -687,7 +687,7 @@ namespace Game
bool merge = false;
Vector3 ni = new Plane(face.v1, face.v2, face.v3).Normal;
Vector3 nj = new Plane(oppFace.v1, oppFace.v2, oppFace.v3).Normal;
float dotP = Vector3.Dot(ni, nj);
float dotP = Float3.Dot(ni, nj);
if (dotP > maxdot_minang)
{
@@ -724,7 +724,7 @@ namespace Game
// construct the merged face
List<HalfEdge> edges = new List<HalfEdge>();
Face mergedFace = new Face(new Vector3(float.NaN), new Vector3(float.NaN), new Vector3(float.NaN));
Face mergedFace = new Face(new Float3(float.NaN), new Float3(float.NaN), new Float3(float.NaN));
// copy the first face edges
HalfEdge heTwin = null;
@@ -828,7 +828,7 @@ namespace Game
float mTolarenace = epsilon;//-1;
float mPlaneTolerance = epsilon;//-1f;
float maxDist = mPlaneTolerance;
List<Vector3> uniqPoints = new List<Vector3>();
List<Float3> uniqPoints = new List<Float3>();
foreach (var hullFace in hullFaces)
{
AddUnique(uniqPoints, hullFace.v1);
@@ -855,13 +855,13 @@ namespace Game
Vector3 edgeVector = (nextVertex - vertex).Normalized;
Vector3 outVector =
Vector3.Cross(-(new Plane(mergedFace.v1, mergedFace.v2, mergedFace.v3).Normal), edgeVector);
Float3.Cross(-(new Plane(mergedFace.v1, mergedFace.v2, mergedFace.v3).Normal), edgeVector);
HalfEdge testHe = qhe.next;
do
{
Vector3 testVertex = testHe.tail;
float dist = Vector3.Dot(testVertex - vertex, outVector);
float dist = Float3.Dot(testVertex - vertex, outVector);
if (dist > mTolarenace)
return false;
@@ -910,7 +910,7 @@ namespace Game
return true;
}
private void AddPointToHull(Vector3 point, Face face, List<Vector3> unclaimedPoints,
private void AddPointToHull(Float3 point, Face face, List<Float3> unclaimedPoints,
List<Tuple<Face, Vector3>> outsideSet,
List<HalfEdge> horizonEdges, List<Face> hullFaces)
{
@@ -929,7 +929,7 @@ namespace Game
var newFace = new Face(point, edge.edge.v1, edge.edge.v2);
var newPlane = new Plane(newFace.v1, newFace.v2, newFace.v3);
var uniqPoints = new List<Vector3>();
var uniqPoints = new List<Float3>();
AddUnique(uniqPoints, newFace.v1);
AddUnique(uniqPoints, newFace.v2);
AddUnique(uniqPoints, newFace.v3);
@@ -1070,7 +1070,7 @@ namespace Game
}
}
private bool AdjacentMerge(Vector3 point, Face face, List<Vector3> unclaimedPoints, List<Tuple<Face, Vector3>> outsideSet, bool mergeWrtLargerFace)
private bool AdjacentMerge(Float3 point, Face face, List<Float3> unclaimedPoints, List<Tuple<Face, Vector3>> outsideSet, bool mergeWrtLargerFace)
{
const float tolerance = -1f;
@@ -1270,7 +1270,7 @@ namespace Game
}
// calculates the outermost edges of the geometry seen from the eyePoint
private void CalculateHorizon(Face face, Vector3 eyePoint, List<Vector3> unclaimedPoints,
private void CalculateHorizon(Face face, Vector3 eyePoint, List<Float3> unclaimedPoints,
List<Tuple<Face, Vector3>> outsideSet,
List<HalfEdge> horizonEdges, HalfEdge currentEdge)
{

View File

@@ -157,11 +157,11 @@ namespace Game
/// used for more than one triangle.
/// </summary>
public void GenerateHull(
List<Vector3> points,
List<Float3> points,
bool splitVerts,
ref List<Vector3> verts,
ref List<Float3> verts,
ref List<int> tris,
ref List<Vector3> normals)
ref List<Float3> normals)
{
if (points.Count < 4)
throw new ArgumentException("Need at least 4 points to generate a convex hull");
@@ -181,7 +181,7 @@ namespace Game
/// Make sure all the buffers and variables needed for the algorithm
/// are initialized.
/// </summary>
private void Initialize(List<Vector3> points, bool splitVerts)
private void Initialize(List<Float3> points, bool splitVerts)
{
faceCount = 0;
openSetTail = -1;
@@ -226,7 +226,7 @@ namespace Game
/// <summary>
/// Create initial seed hull.
/// </summary>
private void GenerateInitialHull(List<Vector3> points)
private void GenerateInitialHull(List<Float3> points)
{
// Find points suitable for use as the seed hull. Some varieties of
// this algorithm pick extreme points here, but I'm not convinced
@@ -235,10 +235,10 @@ namespace Game
int b0, b1, b2, b3;
FindInitialHullIndices(points, out b0, out b1, out b2, out b3);
Vector3 v0 = points[b0];
Vector3 v1 = points[b1];
Vector3 v2 = points[b2];
Vector3 v3 = points[b3];
Float3 v0 = points[b0];
Float3 v1 = points[b1];
Float3 v2 = points[b2];
Float3 v3 = points[b3];
bool above = Dot(v3 - v1, Cross(v1 - v0, v2 - v0)) > 0.0f;
@@ -358,29 +358,29 @@ namespace Game
/// Find four points in the point cloud that are not coplanar for the
/// seed hull
/// </summary>
private void FindInitialHullIndices(List<Vector3> points, out int b0, out int b1, out int b2, out int b3)
private void FindInitialHullIndices(List<Float3> points, out int b0, out int b1, out int b2, out int b3)
{
int count = points.Count;
for (int i0 = 0; i0 < count - 3; i0++)
for (int i1 = i0 + 1; i1 < count - 2; i1++)
{
Vector3 p0 = points[i0];
Vector3 p1 = points[i1];
Float3 p0 = points[i0];
Float3 p1 = points[i1];
if (AreCoincident(p0, p1))
continue;
for (int i2 = i1 + 1; i2 < count - 1; i2++)
{
Vector3 p2 = points[i2];
Float3 p2 = points[i2];
if (AreCollinear(p0, p1, p2))
continue;
for (int i3 = i2 + 1; i3 < count - 0; i3++)
{
Vector3 p3 = points[i3];
Float3 p3 = points[i3];
if (AreCoplanar(p0, p1, p2, p3))
continue;
@@ -402,7 +402,7 @@ namespace Game
/// to encompass the point in openSet with the point furthest away
/// from its face.
/// </summary>
private void GrowHull(List<Vector3> points)
private void GrowHull(List<Float3> points)
{
Assert.IsTrue(openSetTail >= 0);
Assert.IsTrue(openSet[0].Face != INSIDE);
@@ -451,7 +451,7 @@ namespace Game
/// only has to visit two (because one of them has already been
/// visited, the one you came from).
/// </summary>
private void FindHorizon(List<Vector3> points, Vector3 point, int fi, Face face)
private void FindHorizon(List<Float3> points, Float3 point, int fi, Face face)
{
// TODO should I use epsilon in the PointFaceDistance comparisons?
@@ -530,7 +530,7 @@ namespace Game
/// <summary>
/// Recursively search to find the horizon or lit set.
/// </summary>
private void SearchHorizon(List<Vector3> points, Vector3 point, int prevFaceIndex, int faceCount, Face face)
private void SearchHorizon(List<Float3> points, Float3 point, int prevFaceIndex, int faceCount, Face face)
{
Assert.IsTrue(prevFaceIndex >= 0);
Assert.IsTrue(litFaces.Contains(prevFaceIndex));
@@ -631,7 +631,7 @@ namespace Game
/// on the other side of the horizon to reflect it's new neighbor from
/// the cone.
/// </summary>
private void ConstructCone(List<Vector3> points, int farthestPoint)
private void ConstructCone(List<Float3> points, int farthestPoint)
{
foreach (int fi in litFaces)
{
@@ -642,7 +642,7 @@ namespace Game
int firstNewFace = faceCount;
// Check for coplanar faces
/*var firstNormal = new Vector3(0, 0, 0);
/*var firstNormal = new Float3(0, 0, 0);
int sameNormals = 1;
for (int i = 0; i < horizon.Count; i++)
{
@@ -725,7 +725,7 @@ namespace Game
/// doing that to make this loop shorter, a straight for-loop through
/// a list is pretty darn fast. Still, it might be worth trying
/// </summary>
private void ReassignPoints(List<Vector3> points)
private void ReassignPoints(List<Float3> points)
{
for (int i = 0; i <= openSetTail; i++)
{
@@ -734,7 +734,7 @@ namespace Game
if (litFaces.Contains(fp.Face))
{
bool assigned = false;
Vector3 point = points[fp.Point];
Float3 point = points[fp.Point];
foreach (var kvp in faces)
{
@@ -785,14 +785,14 @@ namespace Game
/// leaves the normal array empty.
/// </summary>
private void ExportMesh(
List<Vector3> points,
List<Float3> points,
bool splitVerts,
ref List<Vector3> verts,
ref List<Float3> verts,
ref List<int> tris,
ref List<Vector3> normals)
ref List<Float3> normals)
{
if (verts == null)
verts = new List<Vector3>();
verts = new List<Float3>();
else
verts.Clear();
@@ -802,7 +802,7 @@ namespace Game
tris.Clear();
if (normals == null)
normals = new List<Vector3>();
normals = new List<Float3>();
else
normals.Clear();
@@ -858,7 +858,7 @@ namespace Game
/// the point is above the face)
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private float PointFaceDistance(Vector3 point, Vector3 pointOnFace, Face face)
private float PointFaceDistance(Float3 point, Float3 pointOnFace, Face face)
{
return Dot(face.Normal, point - pointOnFace);
}
@@ -867,7 +867,7 @@ namespace Game
/// Calculate normal for triangle
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Vector3 Normal(Vector3 v0, Vector3 v1, Vector3 v2)
private Float3 Normal(Float3 v0, Float3 v1, Float3 v2)
{
return Cross(v1 - v0, v2 - v0).Normalized;
}
@@ -876,20 +876,20 @@ namespace Game
/// Dot product, for convenience.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static float Dot(Vector3 a, Vector3 b)
private static float Dot(Float3 a, Float3 b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}
/// <summary>
/// Vector3.Cross i left-handed, the algorithm is right-handed. Also,
/// Float3.Cross i left-handed, the algorithm is right-handed. Also,
/// i wanna test to see if using aggressive inlining makes any
/// difference here.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector3 Cross(Vector3 a, Vector3 b)
private static Float3 Cross(Float3 a, Float3 b)
{
return new Vector3(
return new Float3(
a.Y * b.Z - a.Z * b.Y,
a.Z * b.X - a.X * b.Z,
a.X * b.Y - a.Y * b.X);
@@ -899,7 +899,7 @@ namespace Game
/// Check if two points are coincident
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool AreCoincident(Vector3 a, Vector3 b)
private bool AreCoincident(Float3 a, Float3 b)
{
return (a - b).Length <= EPSILON;
}
@@ -908,7 +908,7 @@ namespace Game
/// Check if three points are collinear
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool AreCollinear(Vector3 a, Vector3 b, Vector3 c)
private bool AreCollinear(Float3 a, Float3 b, Float3 c)
{
return Cross(c - a, c - b).Length <= EPSILON;
}
@@ -917,17 +917,17 @@ namespace Game
/// Check if four points are coplanar
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool AreCoplanar(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
private bool AreCoplanar(Float3 a, Float3 b, Float3 c, Float3 d)
{
Vector3 n1 = Cross(c - a, c - b);
Vector3 n2 = Cross(d - a, d - b);
Float3 n1 = Cross(c - a, c - b);
Float3 n2 = Cross(d - a, d - b);
float m1 = n1.Length;
float m2 = n2.Length;
return m1 <= EPSILON
|| m2 <= EPSILON
|| AreCollinear(Vector3.Zero,
|| AreCollinear(Float3.Zero,
1.0f / m1 * n1,
1.0f / m2 * n2);
}
@@ -937,7 +937,7 @@ namespace Game
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
/// defined.
/// </summary>
private void VerifyOpenSet(List<Vector3> points)
private void VerifyOpenSet(List<Float3> points)
{
for (int i = 0; i < openSet.Count; i++)
if (i > openSetTail)
@@ -977,7 +977,7 @@ namespace Game
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
/// defined.
/// </summary>
private void VerifyFaces(List<Vector3> points)
private void VerifyFaces(List<Float3> points)
{
foreach (var kvp in faces)
{
@@ -1012,18 +1012,18 @@ namespace Game
/// actually a convex hull of all the points. Conditionally compiled
/// if DEBUG_QUICKHULL if defined.
/// </summary>
private void VerifyMesh(List<Vector3> points, ref List<Vector3> verts, ref List<int> tris)
private void VerifyMesh(List<Float3> points, ref List<Float3> verts, ref List<int> tris)
{
Assert.IsTrue(tris.Count % 3 == 0);
for (int i = 0; i < points.Count; i++)
for (int j = 0; j < tris.Count; j += 3)
{
Vector3 t0 = verts[tris[j]];
Vector3 t1 = verts[tris[j + 1]];
Vector3 t2 = verts[tris[j + 2]];
Float3 t0 = verts[tris[j]];
Float3 t1 = verts[tris[j + 1]];
Float3 t2 = verts[tris[j + 2]];
float dot = Dot(points[i] - t0, Vector3.Cross(t1 - t0, t2 - t0));
float dot = Dot(points[i] - t0, Float3.Cross(t1 - t0, t2 - t0));
//Assert.IsTrue(dot <= EPSILON, $"not convex hull: {dot} > {EPSILON}");
if (!(dot <= EPSILON))
Console.PrintError($"not convex hull: {dot} > {EPSILON}");
@@ -1061,9 +1061,9 @@ namespace Game
public int Opposite1;
public int Opposite2;
public readonly Vector3 Normal;
public readonly Float3 Normal;
public Face(int v0, int v1, int v2, int o0, int o1, int o2, Vector3 normal)
public Face(int v0, int v1, int v2, int o0, int o1, int o2, Float3 normal)
{
Vertex0 = v0;
Vertex1 = v1;

View File

@@ -73,17 +73,17 @@ namespace Game
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
}
public void SetPosition(Vector3 newPosition)
public void SetPosition(Float3 newPosition)
{
Position = newPosition;
}
public void SetRotation(Vector3 eulerAngles)
public void SetRotation(Float3 eulerAngles)
{
playerMovement.ResetRotation(eulerAngles);
}
public void Teleport(Vector3 newPosition, Vector3 eulerAngles)
public void Teleport(Float3 newPosition, Float3 eulerAngles)
{
SetPosition(newPosition);
SetRotation(eulerAngles);

View File

@@ -13,19 +13,19 @@ namespace Game
public bool attacking;
public bool jumping;
public Vector3 verificationPosition;
public Vector3 verificationVelocity;
public Vector3 verificationViewAngles;
public Float3 verificationPosition;
public Float3 verificationVelocity;
public Float3 verificationViewAngles;
public Quaternion verificationOrientation;
}
[StructLayout(LayoutKind.Sequential)]
public struct PlayerActorState
{
public Vector3 position;
public Vector3 velocity;
public Float3 position;
public Float3 velocity;
public Quaternion orientation;
public Vector3 viewAngles; // yaw, pitch, roll
public Float3 viewAngles; // yaw, pitch, roll
}
[StructLayout(LayoutKind.Sequential)]

View File

@@ -12,14 +12,14 @@ namespace Game
// closest hit
public float fraction;
public Vector3 endPosition;
public Vector3 hitNormal;
public Vector3 hitPosition;
public Float3 endPosition;
public Float3 hitNormal;
public Float3 hitPosition;
// furthest hit
//public float maxFraction;
//public Vector3 maxHitNormal;
//public Vector3 maxEndPosition;
//public Float3 maxHitNormal;
//public Float3 maxEndPosition;
}
[Networked]
@@ -83,7 +83,7 @@ namespace Game
public int currentInputFrame;
private int currentInputFrame2;
private Vector3 currentVelocity;
private Float3 currentVelocity;
public PlayerInput input;
//private bool physicsInteractions = false;
@@ -114,9 +114,9 @@ namespace Game
[Tooltip("Base Movement speed")]
public float MoveSpeed { get; set; } = 320;
private static Vector3 Gravity { get; } = new Vector3(0, -800.0f, 0f);
private static Float3 Gravity { get; } = new Float3(0, -800.0f, 0f);
//private Vector3 safePosition;
//private Float3 safePosition;
public uint PlayerId = 0;
@@ -132,7 +132,7 @@ namespace Game
{
get
{
Vector3 horizontalSpeed = currentVelocity;
Float3 horizontalSpeed = currentVelocity;
horizontalSpeed.Y = 0f;
return horizontalSpeed.Length;
}
@@ -229,7 +229,7 @@ namespace Game
ResetRotation(Actor.Orientation.EulerAngles);
}
public void ResetRotation(Vector3 eulerAngles)
public void ResetRotation(Float3 eulerAngles)
{
viewPitch = eulerAngles.X;
viewYaw = eulerAngles.Y;
@@ -238,7 +238,7 @@ namespace Game
viewYawLastFrame = viewYaw;
viewRollLastFrame = viewRoll;
SetCameraEulerAngles(new Vector3(viewYaw, viewPitch, viewRoll));
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewRoll));
}
public override void OnUpdate()
@@ -298,7 +298,7 @@ namespace Game
// Verify view angles first
if (demoDeltasVerify)
{
Vector3 viewAngles = new Vector3(viewYaw, viewPitch, viewRoll);
Float3 viewAngles = new Float3(viewYaw, viewPitch, viewRoll);
float viewAnglesDelta = (viewAngles - inputState.verificationViewAngles).Length;
if (viewAnglesDelta > 0.00001)
{
@@ -346,7 +346,7 @@ namespace Game
position = Actor.Position,
velocity = currentVelocity,
orientation = rootActor.Orientation,
viewAngles = new Vector3(viewYaw, viewPitch, viewRoll)
viewAngles = new Float3(viewYaw, viewPitch, viewRoll)
});
input.OnEndFrame();
@@ -370,17 +370,17 @@ namespace Game
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
viewYaw += xAxis;
SetCameraEulerAngles(new Vector3(viewYaw, viewPitch, viewRoll));
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewRoll));
}
private void SetCameraEulerAngles(Vector3 viewAngles)
private void SetCameraEulerAngles(Float3 viewAngles)
{
// Root orientation must be set first
rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0);
cameraHolder.Orientation = Quaternion.Euler(viewAngles.Y, viewAngles.X, viewAngles.Z);
}
private static bool SweepPlayerCollider(Actor actor, Vector3 start, Vector3 end, out RayCastHit[] hits)
private static bool SweepPlayerCollider(Actor actor, Float3 start, Vector3 end, out RayCastHit[] hits)
{
Vector3 delta = end - start;
float distance = delta.Length;
@@ -422,7 +422,7 @@ namespace Game
return collided;
}
private bool SweepPlayerCollider(Vector3 position, out PhysicsColliderActor[] colliders)
private bool SweepPlayerCollider(Float3 position, out PhysicsColliderActor[] colliders)
{
bool collided = false;
CapsuleCollider capsuleCollider = Actor.GetChild<CapsuleCollider>();
@@ -526,7 +526,7 @@ namespace Game
traceInfo.hitInfos = hitInfosFiltered.ToArray();
traceInfo.fraction = 0f;
traceInfo.hitNormal = Vector3.Zero;
traceInfo.hitNormal = Float3.Zero;
traceInfo.hitPosition = start;
traceInfo.endPosition = start;
traceInfo.startSolid = true;
@@ -659,11 +659,11 @@ namespace Game
// step down
Vector3 stepDown = position - stepDelta;
TraceInfo traceDown = TracePlayer(actor, position, stepDown);
if (traceDown.fraction < 1f && -Vector3.Dot(gravityDirection, traceDown.hitNormal) < slopeNormal)
if (traceDown.fraction < 1f && -Float3.Dot(gravityDirection, traceDown.hitNormal) < slopeNormal)
{
// can't step down, slide move like normally
Console.Print("no stepping 1, frac: " + traceDown.fraction + ", dot: " +
-Vector3.Dot(gravityDirection, traceDown.hitNormal) +
-Float3.Dot(gravityDirection, traceDown.hitNormal) +
", norm: " + traceDown.hitNormal);
position = slidePosition;
velocity = slideVelocity;
@@ -678,8 +678,8 @@ namespace Game
position.Y += collisionMargin;
// ??
float d1 = -Vector3.Dot(gravityDirection, position);
float d2 = -Vector3.Dot(gravityDirection, originalPosition);
float d1 = -Float3.Dot(gravityDirection, position);
float d2 = -Float3.Dot(gravityDirection, originalPosition);
if (d1 < d2)
{
//Console.Print("no stepping 2, " + d1 + " < " + d2);
@@ -720,7 +720,7 @@ namespace Game
float timeleft = Time.DeltaTime;
var hitNormals = new List<Vector3>();
var hitNormals = new List<Float3>();
for (int bump = 0; bump < 4; bump++)
{
@@ -735,7 +735,7 @@ namespace Game
if (trace.startSolid)
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
@@ -759,8 +759,8 @@ namespace Game
// this doesn't seem to do anything, we never have any hitNormals stored here
bool hitPreviousNormal = false;
foreach (Vector3 normal in hitNormals)
if (Vector3.Dot(hitNormal, normal) > 0.99)
foreach (Float3 normal in hitNormals)
if (Float3.Dot(hitNormal, normal) > 0.99)
{
// nudge away from the same wall we hit earlier and try again
velocity += hitNormal;
@@ -776,14 +776,14 @@ namespace Game
Console.Print("hitNormals: " + hitNormals.Count);
int plane;
Vector3 normalMargin = Vector3.Zero;
Vector3 normalMargin = Float3.Zero;
for (plane = 0; plane < hitNormals.Count; plane++)
{
Vector3 normal = hitNormals[plane];
// clip velocity
velocity -= normal * Vector3.Dot(velocity, normal);
//velocity = Vector3.ProjectOnPlane(velocity, normal);
velocity -= normal * Float3.Dot(velocity, normal);
//velocity = Float3.ProjectOnPlane(velocity, normal);
//traceOffset = normal * 1f;
normalMargin += normal;
@@ -795,7 +795,7 @@ namespace Game
if (plane == plane2)
continue;
if (Vector3.Dot(velocity, hitNormals[plane2]) < 0f)
if (Float3.Dot(velocity, hitNormals[plane2]) < 0f)
break;
}
@@ -811,22 +811,22 @@ namespace Game
{
if (hitNormals.Count == 2)
{
Vector3 dir = Vector3.Cross(hitNormals[0], hitNormals[1]);
Vector3 dir = Float3.Cross(hitNormals[0], hitNormals[1]);
//dir.Normalize();
float dist = Vector3.Dot(dir, velocity);
float dist = Float3.Dot(dir, velocity);
velocity = dist * dir;
}
else
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
}
// prevents bouncing against the wall
if ( /*velocity.Length > 0f && */Vector3.Dot(velocity, originalVelocity) <= 0f)
if ( /*velocity.Length > 0f && */Float3.Dot(velocity, originalVelocity) <= 0f)
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
}
@@ -839,13 +839,13 @@ namespace Game
Transform rootTrans = rootActor.Transform;
Vector3 inputDirection =
new Vector3(inputState.moveRight, 0.0f, inputState.moveForward);
new Float3(inputState.moveRight, 0.0f, inputState.moveForward);
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
Vector3 position = rigidBody.Position;
Vector3 velocity = currentVelocity; //rigidBody.LinearVelocity;
Vector3 wishVelocity = Vector3.Zero;
Vector3 wishVelocity = Float3.Zero;
if (!inputDirection.IsZero)
wishVelocity = moveDirection.Normalized * MoveSpeed;
@@ -910,7 +910,7 @@ namespace Game
}
}
private TraceInfo CategorizePosition(Vector3 position, ref Vector3 velocity)
private TraceInfo CategorizePosition(Float3 position, ref Vector3 velocity)
{
Vector3 groundDelta = Gravity.Normalized; //Gravity.Normalized * (collisionMargin * 2);
//if (velocity.Y < 0f)
@@ -919,13 +919,13 @@ namespace Game
//Console.PrintDebug(1, true, "startSolid: " + traceGround.startSolid);
if (!traceGround.startSolid && traceGround.fraction < 1f &&
-Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)
-Float3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)
{
// clip velocity
Vector3 bounce = groundDelta;
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
float backoff = Float3.Dot(bounce, traceGround.hitNormal) * 2f;
bounce -= traceGround.hitNormal * backoff;
//velocity = velocityProjected;
@@ -939,7 +939,7 @@ namespace Game
}
if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
-Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal))
-Float3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal))
// falling or sliding down a slope
onGround = false;
//Console.PrintDebug(1, true, "fall or slide");
@@ -963,26 +963,26 @@ namespace Game
jumpVel += jumpBoostVelocity;
// Reset velocity from gravity
if (-Vector3.Dot(Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
if (-Float3.Dot(Gravity.Normalized, velocity) < 0 &&
Float3.Dot(velocity, traceGround.hitNormal) < -0.1)
{
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
velocity = Float3.ProjectOnPlane(velocity, traceGround.hitNormal);
}
if (jumpAdditive)
{
velocity += Vector3.Up * jumpVel;
velocity += Float3.Up * jumpVel;
if (velocity.Y < jumpVel)
velocity.Y = jumpVel;
}
else
velocity = Vector3.Up * jumpVel;
velocity = Float3.Up * jumpVel;
onGround = false;
// Allow stairs to eat the first jump to allow easy stair jumps
if (jumpStairBehavior && jumpBoostMaxJumps >= 2 && numJumps == 0 &&
-Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) > 0.85)
-Float3.Dot(Gravity.Normalized, traceGround.hitNormal) > 0.85)
{
// Try stepping into stairs without vertical velocity
Vector3 stairCheckPosition = position;
@@ -1007,7 +1007,7 @@ namespace Game
return true;
}
private void OnLanded(Vector3 landingVelocity, bool hardLanding)
private void OnLanded(Float3 landingVelocity, bool hardLanding)
{
if (!predicting)
PlayJumpLandSound(true, hardLanding);
@@ -1020,8 +1020,8 @@ namespace Game
float volume1 = 0.8f;
float volume2 = volume1;
Vector2 pitchRange = new Vector2(0.9f, 1.05f);
Vector2 secondStepDelayRange = new Vector2(0.031f, 0.059f);
Float2 pitchRange = new Float2(0.9f, 1.05f);
Float2 secondStepDelayRange = new Float2(0.031f, 0.059f);
if (landing)
volume2 *= 0.6f;
@@ -1064,7 +1064,7 @@ namespace Game
{
// Q2+ air acceleration
float accel = airAcceleration;
if (Vector3.Dot(velocity, wishDir) < 0)
if (Float3.Dot(velocity, wishDir) < 0)
accel = airStopAcceleration;
if (airStrafeAcceleration != 0 && Mathf.Abs(wishVelocity.X) > 0 && wishVelocity.Y == 0)
@@ -1101,7 +1101,7 @@ namespace Game
if (wishspeed > maxWishspeed)
wishspeed = maxWishspeed;
float currentSpeed = Vector3.Dot(velocity, wishDir);
float currentSpeed = Float3.Dot(velocity, wishDir);
float addSpeed = wishspeed - currentSpeed;
if (addSpeed <= 0f)
return;

View File

@@ -15,14 +15,14 @@ namespace Game
// closest hit
public float fraction;
public Vector3 endPosition;
public Vector3 hitNormal;
public Vector3 hitPosition;
public Float3 endPosition;
public Float3 hitNormal;
public Float3 hitPosition;
// furthest hit
//public float maxFraction;
//public Vector3 maxHitNormal;
//public Vector3 maxEndPosition;
//public Float3 maxHitNormal;
//public Float3 maxEndPosition;
}
public class PlayerMovement_NK : Script
@@ -96,7 +96,7 @@ namespace Game
/// </summary>
/// <param name="position">Position</param>
/// <returns></returns>
private Collider[] TracePlayer(Vector3 position, float tolerance = 0.0f)
private Collider[] TracePlayer(Float3 position, float tolerance = 0.0f)
{
Collider[] colliders = null;
@@ -159,13 +159,13 @@ namespace Game
/// <param name="start">Start position</param>
/// <param name="end">End position</param>
/// <returns></returns>
private TraceInfo TracePlayer(Vector3 start, Vector3 end, float tolerance = 0.0f)
private TraceInfo TracePlayer(Float3 start, Float3 end, float tolerance = 0.0f)
{
TraceInfo traceInfo = new TraceInfo();
Vector3 delta = end - start;
Float3 delta = end - start;
float maxDistance = delta.Length;
Vector3 direction = delta.Normalized;
Float3 direction = delta.Normalized;
bool collided = false;
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
@@ -289,7 +289,7 @@ namespace Game
float timeleft = Time.DeltaTime;
List<Vector3> hitNormals = new List<Vector3>();
List<Float3> hitNormals = new List<Float3>();
for (int bump = 0; bump < 4; bump++)
{
@@ -304,7 +304,7 @@ namespace Game
if (trace.startSolid)
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
@@ -335,9 +335,9 @@ namespace Game
// this doesn't seem to do anything, we never have any hitNormals stored here
bool hitPreviousNormal = false;
foreach (Vector3 normal in hitNormals)
foreach (Float3 normal in hitNormals)
{
if (Vector3.Dot(hitNormal, normal) > 0.99)
if (Float3.Dot(hitNormal, normal) > 0.99)
{
// nudge away from the same wall we hit earlier and try again
velocity += hitNormal;
@@ -353,14 +353,14 @@ namespace Game
Console.Print("hitNormals: " + hitNormals.Count);
int plane;
Vector3 normalMargin = Vector3.Zero;
Vector3 normalMargin = Float3.Zero;
for (plane = 0; plane < hitNormals.Count; plane++)
{
Vector3 normal = hitNormals[plane];
// clip velocity
velocity -= normal * Vector3.Dot(velocity, normal);
//velocity = Vector3.ProjectOnPlane(velocity, normal);
velocity -= normal * Float3.Dot(velocity, normal);
//velocity = Float3.ProjectOnPlane(velocity, normal);
//traceOffset = normal * 1f;
normalMargin += normal;
@@ -372,7 +372,7 @@ namespace Game
if (plane == plane2)
continue;
if (Vector3.Dot(velocity, hitNormals[plane2]) < 0f)
if (Float3.Dot(velocity, hitNormals[plane2]) < 0f)
break;
}
@@ -387,14 +387,14 @@ namespace Game
{
if (hitNormals.Count == 2)
{
Vector3 dir = Vector3.Cross(hitNormals[0], hitNormals[1]);
Vector3 dir = Float3.Cross(hitNormals[0], hitNormals[1]);
//dir.Normalize();
float dist = Vector3.Dot(dir, velocity);
float dist = Float3.Dot(dir, velocity);
velocity = dist * dir;
}
else
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
}
@@ -406,17 +406,17 @@ namespace Game
}
// prevents bouncing against the wall
if (/*velocity.Length > 0f && */Vector3.Dot(velocity, originalVelocity) <= 0f)
if (/*velocity.Length > 0f && */Float3.Dot(velocity, originalVelocity) <= 0f)
{
velocity = Vector3.Zero;
velocity = Float3.Zero;
break;
}
}
}
//Vector3 wishVelocity = Vector3.Zero;
//Vector3 gravityVelocity = Vector3.Zero;
//Vector3 currentVelocity = Vector3.Zero;
//Vector3 wishVelocity = Float3.Zero;
//Vector3 gravityVelocity = Float3.Zero;
//Vector3 currentVelocity = Float3.Zero;
private bool onGround = false;
private const float friction = 4f;
@@ -446,13 +446,13 @@ namespace Game
Transform rootTrans = rootActor.Transform;
Vector3 inputDirection =
new Vector3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
new Float3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
//Vector3 position = rigidBody.Position;
Vector3 velocity = rigidBody.LinearVelocity;//currentVelocity;
Vector3 wishVelocity = Vector3.Zero;
Vector3 wishVelocity = Float3.Zero;
if (!inputDirection.IsZero)
wishVelocity = moveDirection.Normalized * MoveSpeed;
@@ -473,8 +473,8 @@ namespace Game
// clip velocity
Vector3 bounce = -groundDelta;
Vector3 bounceDir = -groundDelta.Normalized;//traceGround.hitNormal;
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
float backoff = Vector3.Dot(bounce, bounceDir) * 2f;
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
float backoff = Float3.Dot(bounce, bounceDir) * 2f;
bounce -= bounceDir * backoff;
//velocity = velocityProjected;
@@ -489,13 +489,13 @@ namespace Game
}
/*if (!traceGround.startSolid && traceGround.fraction < 1f &&
-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f)
-Float3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f)
{
// slope
// clip velocity
Vector3 bounce = groundDelta;
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
float backoff = Float3.Dot(bounce, traceGround.hitNormal) * 2f;
bounce -= traceGround.hitNormal * backoff;
//velocity = velocityProjected;
@@ -507,9 +507,9 @@ namespace Game
}*/
//if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
// -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f))
// -Float3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f))
float rampDot = -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal);
float rampDot = -Float3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal);
if (traceGround.fraction >= 1f)
rampDot = 1f;
else if (traceGround.hitNormal.IsZero)
@@ -517,7 +517,7 @@ namespace Game
if (traceGround.fraction >= 1f || rampDot < 0.7f)
{
//Console.Print("air: " + (-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
//Console.Print("air: " + (-Float3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
// falling or sliding down a slope
onGround = false;
}
@@ -532,7 +532,7 @@ namespace Game
if (traceGround.fraction == 0f && closestDist != 0f)
Console.Print("minteresting");
//Console.Print("grund: "+ (-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
//Console.Print("grund: "+ (-Float3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
onGround = true;//!traceGround.startSolid;
//velocity.Y = 0f;
@@ -619,7 +619,7 @@ namespace Game
{
foreach (var hitInfo in traceGround.hitInfos)
{
var dot = Vector3.Dot(Physics.Gravity.Normalized, hitInfo.Normal);
var dot = Float3.Dot(Physics.Gravity.Normalized, hitInfo.Normal);
if (-dot >= 0.7) //~45deg slope
{
//Console.Print("d: " + hitInfo.Distance);
@@ -650,7 +650,7 @@ namespace Game
{
jumped = true;
velocity += Vector3.Up * jumpVelocity;
velocity += Float3.Up * jumpVelocity;
onGround = false;
}
}
@@ -730,7 +730,7 @@ namespace Game
if (wishspeed > maxWishspeed)
wishspeed = maxWishspeed;
float currentSpeed = Vector3.Dot(velocity, wishDir);
float currentSpeed = Float3.Dot(velocity, wishDir);
float addSpeed = wishspeed - currentSpeed;
if (addSpeed <= 0f)
return;