large worlds engine compat refactor, change vector -> float
This commit is contained in:
@@ -26,29 +26,29 @@ namespace Game
|
|||||||
private static readonly Dictionary<Actor, ActorAudioChannels> actorAudioChannels =
|
private static readonly Dictionary<Actor, ActorAudioChannels> actorAudioChannels =
|
||||||
new Dictionary<Actor, 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);
|
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)
|
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,
|
public static void PlaySound(string soundName, Actor actor, int channel, AudioFlags flags, Float3 position,
|
||||||
float volume, Vector2 pitchRange)
|
float volume, Float2 pitchRange)
|
||||||
{
|
{
|
||||||
AudioInfo audio = GetSound(soundName);
|
AudioInfo audio = GetSound(soundName);
|
||||||
if (audio.AudioClips.Length == 0)
|
if (audio.AudioClips.Length == 0)
|
||||||
@@ -125,8 +125,8 @@ namespace Game
|
|||||||
actorChannels.channelSources[channel] = audioSource;
|
actorChannels.channelSources[channel] = audioSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void PlaySoundDelayed(Vector2 delayRange, string soundName, Actor actor, int channel,
|
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
|
||||||
Vector3 position, float volume = 1f)
|
Float3 position, float volume = 1f)
|
||||||
{
|
{
|
||||||
float randomDelay;
|
float randomDelay;
|
||||||
if (delayRange[0] < delayRange[1])
|
if (delayRange[0] < delayRange[1])
|
||||||
@@ -134,16 +134,16 @@ namespace Game
|
|||||||
else
|
else
|
||||||
randomDelay = delayRange[0];
|
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));
|
await Task.Delay((int)(randomDelay * 1000f));
|
||||||
//FlaxEngine.Scripting.RunOnUpdate(() =>
|
//FlaxEngine.Scripting.RunOnUpdate(() =>
|
||||||
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
|
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
|
||||||
if (actor) // Engine might have cleaned up the actor
|
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,
|
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
|
||||||
Vector3 position, float volume, Vector2 pitchRange)
|
Float3 position, float volume, Float2 pitchRange)
|
||||||
{
|
{
|
||||||
float randomDelay;
|
float randomDelay;
|
||||||
if (delayRange[0] < delayRange[1])
|
if (delayRange[0] < delayRange[1])
|
||||||
@@ -151,7 +151,7 @@ namespace Game
|
|||||||
else
|
else
|
||||||
randomDelay = delayRange[0];
|
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));
|
await Task.Delay((int)(randomDelay * 1000f));
|
||||||
//FlaxEngine.Scripting.RunOnUpdate(() =>
|
//FlaxEngine.Scripting.RunOnUpdate(() =>
|
||||||
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
|
// PlaySound(soundName, actor, channel, flags, position, volume, pitchRange));
|
||||||
@@ -159,8 +159,8 @@ namespace Game
|
|||||||
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, pitchRange);
|
PlaySound(soundName, actor, channel, AudioFlags.None, position, volume, pitchRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void PlaySoundDelayed(Vector2 delayRange, string soundName, Actor actor, int channel,
|
public static async void PlaySoundDelayed(Float2 delayRange, string soundName, Actor actor, int channel,
|
||||||
AudioFlags flags, Vector3 position, float volume, Vector2 pitchRange)
|
AudioFlags flags, Float3 position, float volume, Float2 pitchRange)
|
||||||
{
|
{
|
||||||
float randomDelay;
|
float randomDelay;
|
||||||
if (delayRange[0] < delayRange[1])
|
if (delayRange[0] < delayRange[1])
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Game
|
|||||||
|
|
||||||
public override void OnStart()
|
public override void OnStart()
|
||||||
{
|
{
|
||||||
Vector3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
Float3 initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||||
viewPitch = initialEulerAngles.X;
|
viewPitch = initialEulerAngles.X;
|
||||||
viewYaw = initialEulerAngles.Y;
|
viewYaw = initialEulerAngles.Y;
|
||||||
viewRoll = initialEulerAngles.Z;
|
viewRoll = initialEulerAngles.Z;
|
||||||
@@ -62,7 +62,7 @@ namespace Game
|
|||||||
|
|
||||||
float inputH = InputManager.GetAxis("Horizontal");
|
float inputH = InputManager.GetAxis("Horizontal");
|
||||||
float inputV = InputManager.GetAxis("Vertical");
|
float inputV = InputManager.GetAxis("Vertical");
|
||||||
Vector3 move = new Vector3(inputH, 0.0f, inputV);
|
Float3 move = new Float3(inputH, 0.0f, inputV);
|
||||||
|
|
||||||
if (!move.IsZero)
|
if (!move.IsZero)
|
||||||
{
|
{
|
||||||
@@ -70,7 +70,7 @@ namespace Game
|
|||||||
move = camera.Transform.TransformDirection(move) * MoveSpeed;
|
move = camera.Transform.TransformDirection(move) * MoveSpeed;
|
||||||
|
|
||||||
{
|
{
|
||||||
Vector3 delta = move * Time.UnscaledDeltaTime;
|
Float3 delta = move * Time.UnscaledDeltaTime;
|
||||||
float movementLeft = delta.Length;
|
float movementLeft = delta.Length;
|
||||||
|
|
||||||
// TODO: check multiple times in case we get stuck in walls
|
// TODO: check multiple times in case we get stuck in walls
|
||||||
@@ -83,7 +83,7 @@ namespace Game
|
|||||||
|
|
||||||
//bool nohit = true;
|
//bool nohit = true;
|
||||||
float hitDistance = moveDist;
|
float hitDistance = moveDist;
|
||||||
Vector3 hitNormal = move.Normalized;
|
Float3 hitNormal = move.Normalized;
|
||||||
foreach (RayCastHit hitInfo in hitInfos)
|
foreach (RayCastHit hitInfo in hitInfos)
|
||||||
{
|
{
|
||||||
if (hitInfo.Collider.Parent == Parent)
|
if (hitInfo.Collider.Parent == Parent)
|
||||||
@@ -99,7 +99,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hitDistance != moveDist)
|
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);
|
//projected = normal * dot(direction, normal);
|
||||||
//direction = direction - projected
|
//direction = direction - projected
|
||||||
@@ -107,7 +107,7 @@ namespace Game
|
|||||||
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
|
//camTrans.Translation += hitNormal * (moveDist - hitDistance); // correct?
|
||||||
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
|
//camTrans.Translation = hitNormal * (move * hitNormal); // correct?
|
||||||
//camTrans.Translation = Actor.Transform.Translation;
|
//camTrans.Translation = Actor.Transform.Translation;
|
||||||
delta += -Vector3.Dot(delta, hitNormal) * hitNormal; // correct?
|
delta += -Float3.Dot(delta, hitNormal) * hitNormal; // correct?
|
||||||
|
|
||||||
camTrans.Translation += delta;
|
camTrans.Translation += delta;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,9 +141,9 @@ namespace Game
|
|||||||
{
|
{
|
||||||
lastRescale = rescaleModel;
|
lastRescale = rescaleModel;
|
||||||
if (rescaleModel)
|
if (rescaleModel)
|
||||||
viewModelHolder.Scale = new Vector3(0.75f);
|
viewModelHolder.Scale = new Float3(0.75f);
|
||||||
else
|
else
|
||||||
viewModelHolder.Scale = new Vector3(1.0f);
|
viewModelHolder.Scale = new Float3(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!camera.IsActive)
|
if (!camera.IsActive)
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ namespace Game
|
|||||||
public class CameraSpring : Script
|
public class CameraSpring : Script
|
||||||
{
|
{
|
||||||
private bool lastGround;
|
private bool lastGround;
|
||||||
private Vector3 lastPosition;
|
private Float3 lastPosition;
|
||||||
public float percY;
|
public float percY;
|
||||||
|
|
||||||
private Actor playerActor;
|
private Actor playerActor;
|
||||||
private PlayerMovement playerMovement;
|
private PlayerMovement playerMovement;
|
||||||
|
|
||||||
public float speed = 240f;
|
public float speed = 240f;
|
||||||
private Vector3 targetOffset;
|
private Float3 targetOffset;
|
||||||
private Actor viewModelHolder;
|
private Actor viewModelHolder;
|
||||||
|
|
||||||
public override void OnStart()
|
public override void OnStart()
|
||||||
@@ -25,7 +25,7 @@ namespace Game
|
|||||||
targetOffset = Actor.LocalPosition;
|
targetOffset = Actor.LocalPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePosition(Vector3 position)
|
private void UpdatePosition(Float3 position)
|
||||||
{
|
{
|
||||||
Actor.Position = position;
|
Actor.Position = position;
|
||||||
viewModelHolder.Position = position;
|
viewModelHolder.Position = position;
|
||||||
@@ -33,8 +33,8 @@ namespace Game
|
|||||||
|
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
{
|
{
|
||||||
Vector3 position = Actor.Parent.Position + targetOffset;
|
Float3 position = Actor.Parent.Position + targetOffset;
|
||||||
Vector3 targetPosition = position;
|
Float3 targetPosition = position;
|
||||||
|
|
||||||
if (playerMovement.onGround)
|
if (playerMovement.onGround)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace Game
|
|||||||
{
|
{
|
||||||
Quaternion rotation = GetRotation();
|
Quaternion rotation = GetRotation();
|
||||||
|
|
||||||
Vector3 targetAngles = rotation.EulerAngles;
|
Float3 targetAngles = rotation.EulerAngles;
|
||||||
Vector3 angles = Actor.LocalOrientation.EulerAngles;
|
Float3 angles = Actor.LocalOrientation.EulerAngles;
|
||||||
|
|
||||||
// Ensure the swaying is smooth when framerate fluctuates slightly
|
// Ensure the swaying is smooth when framerate fluctuates slightly
|
||||||
float remaining = Time.DeltaTime + timeRemainder;
|
float remaining = Time.DeltaTime + timeRemainder;
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace Game
|
|||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
// Cache data
|
// Cache data
|
||||||
Rectangle rect = new Rectangle(Vector2.Zero, Size);
|
Rectangle rect = new Rectangle(Float2.Zero, Size);
|
||||||
Font font = Font.GetFont();
|
Font font = Font.GetFont();
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
@@ -267,7 +267,7 @@ namespace Game
|
|||||||
if (lineIndex > selectionLeftLine && lineIndex < selectionRightLine)
|
if (lineIndex > selectionLeftLine && lineIndex < selectionRightLine)
|
||||||
{
|
{
|
||||||
// whole line is selected
|
// whole line is selected
|
||||||
Vector2 lineSize = font.MeasureText(line);
|
Float2 lineSize = font.MeasureText(line);
|
||||||
selectionRect.Width = lineSize.X;
|
selectionRect.Width = lineSize.X;
|
||||||
selectionRect.Height = lineSize.Y;
|
selectionRect.Height = lineSize.Y;
|
||||||
}
|
}
|
||||||
@@ -276,8 +276,8 @@ namespace Game
|
|||||||
if (lineIndex < selectionRightLine)
|
if (lineIndex < selectionRightLine)
|
||||||
{
|
{
|
||||||
// right side of the line is selected
|
// right side of the line is selected
|
||||||
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
Float2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
||||||
Vector2 rightSize = font.MeasureText(fullLine.Substring(leftChar));
|
Float2 rightSize = font.MeasureText(fullLine.Substring(leftChar));
|
||||||
selectionRect.X += leftSize.X;
|
selectionRect.X += leftSize.X;
|
||||||
selectionRect.Width = rightSize.X;
|
selectionRect.Width = rightSize.X;
|
||||||
selectionRect.Height = rightSize.Y;
|
selectionRect.Height = rightSize.Y;
|
||||||
@@ -288,9 +288,9 @@ namespace Game
|
|||||||
else if (lineIndex == selectionRightLine && leftChar != rightChar)
|
else if (lineIndex == selectionRightLine && leftChar != rightChar)
|
||||||
{
|
{
|
||||||
// selecting middle of the one line
|
// selecting middle of the one line
|
||||||
Vector2 lineSize = font.MeasureText(fullLine);
|
Float2 lineSize = font.MeasureText(fullLine);
|
||||||
Vector2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
Float2 leftSize = font.MeasureText(fullLine.Substring(0, leftChar));
|
||||||
Vector2 midSize =
|
Float2 midSize =
|
||||||
font.MeasureText(fullLine.Substring(leftChar, rightChar - leftChar));
|
font.MeasureText(fullLine.Substring(leftChar, rightChar - leftChar));
|
||||||
|
|
||||||
selectionRect.X += leftSize.X;
|
selectionRect.X += leftSize.X;
|
||||||
@@ -304,7 +304,7 @@ namespace Game
|
|||||||
else if (lineIndex == selectionRightLine)
|
else if (lineIndex == selectionRightLine)
|
||||||
{
|
{
|
||||||
// left side of the line is selected
|
// 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.Width = leftSize.X;
|
||||||
selectionRect.Height = leftSize.Y;
|
selectionRect.Height = leftSize.Y;
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ namespace Game
|
|||||||
|
|
||||||
/*if (CaretPosition > -1)
|
/*if (CaretPosition > -1)
|
||||||
{
|
{
|
||||||
var prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Vector2();
|
var prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Float2();
|
||||||
var caretBounds = CaretBounds;
|
var caretBounds = CaretBounds;
|
||||||
caretBounds.X += prefixSize.X;
|
caretBounds.X += prefixSize.X;
|
||||||
|
|
||||||
@@ -374,7 +374,7 @@ namespace Game
|
|||||||
EndMouseCapture();
|
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;
|
hitLine = 0;
|
||||||
hitChar = 0;
|
hitChar = 0;
|
||||||
@@ -422,7 +422,7 @@ namespace Game
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public int CharIndexAtPoint(ref Vector2 location)
|
/*public int CharIndexAtPoint(ref Float2 location)
|
||||||
{
|
{
|
||||||
return HitTestText(location + _viewOffset);
|
return HitTestText(location + _viewOffset);
|
||||||
}*/
|
}*/
|
||||||
@@ -460,7 +460,7 @@ namespace Game
|
|||||||
return base.OnKeyDown(key);
|
return base.OnKeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnMouseWheel(Vector2 location, float delta)
|
public override bool OnMouseWheel(Float2 location, float delta)
|
||||||
{
|
{
|
||||||
if (delta < 0)
|
if (delta < 0)
|
||||||
{
|
{
|
||||||
@@ -479,7 +479,7 @@ namespace Game
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
public override bool OnMouseDown(Float2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
if (button == MouseButton.Left && !IsFocused)
|
if (button == MouseButton.Left && !IsFocused)
|
||||||
@@ -525,7 +525,7 @@ namespace Game
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnMouseMove(Vector2 location)
|
public override void OnMouseMove(Float2 location)
|
||||||
{
|
{
|
||||||
if (selectionActive)
|
if (selectionActive)
|
||||||
if (HitTestText(location, out int hitLine, out int hitChar))
|
if (HitTestText(location, out int hitLine, out int hitChar))
|
||||||
@@ -537,7 +537,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool OnMouseUp(Vector2 location, MouseButton button)
|
public override bool OnMouseUp(Float2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
if (button == MouseButton.Left)
|
if (button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -146,13 +146,13 @@ namespace Game
|
|||||||
_isEditing = oldEditing;
|
_isEditing = oldEditing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnMouseDown(Vector2 location, MouseButton button)
|
public override bool OnMouseDown(Float2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(location, button);
|
base.OnMouseDown(location, button);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnMouseWheel(Vector2 location, float delta)
|
public override bool OnMouseWheel(Float2 location, float delta)
|
||||||
{
|
{
|
||||||
return contentBox.OnMouseWheel(location, delta);
|
return contentBox.OnMouseWheel(location, delta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace Game
|
|||||||
|
|
||||||
|
|
||||||
consoleBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, true);
|
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.Height = consoleSize.Y - fontHeight;
|
||||||
|
|
||||||
//consoleBox.HorizontalAlignment = TextAlignment.Near;
|
//consoleBox.HorizontalAlignment = TextAlignment.Near;
|
||||||
@@ -84,7 +84,7 @@ namespace Game
|
|||||||
consoleBox.CaretFlashSpeed = 0;
|
consoleBox.CaretFlashSpeed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 locationFix = consoleBox.Location;
|
Float2 locationFix = consoleBox.Location;
|
||||||
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
|
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
|
||||||
parentControl.Name = "ConsoleContent";
|
parentControl.Name = "ConsoleContent";
|
||||||
parentControl.Control = consoleBox;
|
parentControl.Control = consoleBox;
|
||||||
@@ -97,7 +97,7 @@ namespace Game
|
|||||||
consoleNotifyBox.HeightMultiplier = 0;
|
consoleNotifyBox.HeightMultiplier = 0;
|
||||||
consoleNotifyBox.Height = ConsoleNotifyLines * fontHeight;
|
consoleNotifyBox.Height = ConsoleNotifyLines * fontHeight;
|
||||||
consoleNotifyBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, true);
|
consoleNotifyBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, true);
|
||||||
//consoleBox.AnchorMax = new Vector2(1.0f, ConsoleHeight);
|
//consoleBox.AnchorMax = new Float2(1.0f, ConsoleHeight);
|
||||||
|
|
||||||
//consoleBox.HorizontalAlignment = TextAlignment.Near;
|
//consoleBox.HorizontalAlignment = TextAlignment.Near;
|
||||||
//consoleBox.VerticalAlignment = TextAlignment.Near;
|
//consoleBox.VerticalAlignment = TextAlignment.Near;
|
||||||
@@ -110,7 +110,7 @@ namespace Game
|
|||||||
consoleNotifyBox.CaretFlashSpeed = 0;
|
consoleNotifyBox.CaretFlashSpeed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 locationFix2 = consoleNotifyBox.Location;
|
Float2 locationFix2 = consoleNotifyBox.Location;
|
||||||
UIControl parentControl2 = Actor.AddChild<UIControl>();
|
UIControl parentControl2 = Actor.AddChild<UIControl>();
|
||||||
parentControl2.Name = "ConsoleNotifyContent";
|
parentControl2.Name = "ConsoleNotifyContent";
|
||||||
parentControl2.Control = consoleNotifyBox;
|
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, consoleSize.Y - fontHeight, consoleSize.X, fontHeight);
|
||||||
consoleInputBox = new ConsoleInputTextBox(consoleBox, 0, 0, 0, 0);
|
consoleInputBox = new ConsoleInputTextBox(consoleBox, 0, 0, 0, 0);
|
||||||
consoleInputBox.SetAnchorPreset(AnchorPresets.HorizontalStretchTop, false);
|
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.Height = fontHeight;
|
||||||
|
|
||||||
consoleInputBox.Font = fontReference;
|
consoleInputBox.Font = fontReference;
|
||||||
@@ -137,7 +137,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector2 locationFix = consoleInputBox.Location;
|
Float2 locationFix = consoleInputBox.Location;
|
||||||
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
|
UIControl parentControl = contentContainerControl.AddChild<UIControl>();
|
||||||
parentControl.Name = "ConsoleInput";
|
parentControl.Name = "ConsoleInput";
|
||||||
parentControl.Control = consoleInputBox;
|
parentControl.Control = consoleInputBox;
|
||||||
@@ -227,7 +227,7 @@ namespace Game
|
|||||||
|
|
||||||
// hide console by default, and close it instantly
|
// hide console by default, and close it instantly
|
||||||
Console.Close();
|
Console.Close();
|
||||||
Vector2 rootlocation = rootControl.Control.Location;
|
Float2 rootlocation = rootControl.Control.Location;
|
||||||
rootlocation.Y = -rootControl.Control.Height;
|
rootlocation.Y = -rootControl.Control.Height;
|
||||||
rootControl.Control.Location = rootlocation;
|
rootControl.Control.Location = rootlocation;
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ namespace Game
|
|||||||
else
|
else
|
||||||
targetY = 0.0f;
|
targetY = 0.0f;
|
||||||
|
|
||||||
Vector2 location = rootControl.Control.Location;
|
Float2 location = rootControl.Control.Location;
|
||||||
if (location.Y != targetY)
|
if (location.Y != targetY)
|
||||||
{
|
{
|
||||||
if (location.Y > targetY)
|
if (location.Y > targetY)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Game
|
|||||||
protected TextLayoutOptions _layout;
|
protected TextLayoutOptions _layout;
|
||||||
|
|
||||||
private bool doubleClicked;
|
private bool doubleClicked;
|
||||||
private Vector2 lastDoubleClickLocation = new Vector2(0, 0);
|
private Float2 lastDoubleClickLocation = new Float2(0, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the color of the selection (Transparent if not used).
|
/// Gets or sets the color of the selection (Transparent if not used).
|
||||||
@@ -121,7 +121,7 @@ namespace Game
|
|||||||
|
|
||||||
public override void ResetViewOffset()
|
public override void ResetViewOffset()
|
||||||
{
|
{
|
||||||
TargetViewOffset = new Vector2(0, 0);
|
TargetViewOffset = new Float2(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void ScrollToEnd()
|
/*public void ScrollToEnd()
|
||||||
@@ -130,7 +130,7 @@ namespace Game
|
|||||||
float spacing = GetRealLineSpacing();
|
float spacing = GetRealLineSpacing();
|
||||||
maxY += spacing;
|
maxY += spacing;
|
||||||
|
|
||||||
TargetViewOffset = new Vector2(0, Math.Max(0, maxY));
|
TargetViewOffset = new Float2(0, Math.Max(0, maxY));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public override void ScrollToCaret()
|
public override void ScrollToCaret()
|
||||||
@@ -142,13 +142,13 @@ namespace Game
|
|||||||
|
|
||||||
float maxY = TextSize.Y - Height;
|
float maxY = TextSize.Y - Height;
|
||||||
|
|
||||||
Vector2 newLocation = CaretBounds.Location;
|
Float2 newLocation = CaretBounds.Location;
|
||||||
TargetViewOffset = Vector2.Clamp(newLocation, new Vector2(0, 0), new Vector2(_targetViewOffset.X, maxY));
|
TargetViewOffset = Float2.Clamp(newLocation, new Float2(0, 0), new Float2(_targetViewOffset.X, maxY));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*const bool smoothScrolling = false;
|
/*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)
|
if (!IsMultiline || Text.Length == 0)
|
||||||
return false;
|
return false;
|
||||||
@@ -161,33 +161,33 @@ namespace Game
|
|||||||
float maxY = TextSize.Y - Height;
|
float maxY = TextSize.Y - Height;
|
||||||
float offset = GetRealLineSpacing();
|
float offset = GetRealLineSpacing();
|
||||||
maxY += offset;
|
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;
|
return true;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
public override Vector2 GetTextSize()
|
public override Float2 GetTextSize()
|
||||||
{
|
{
|
||||||
Font font = Font.GetFont();
|
Font font = Font.GetFont();
|
||||||
if (font == null)
|
if (font == null)
|
||||||
return Vector2.Zero;
|
return Float2.Zero;
|
||||||
|
|
||||||
return font.MeasureText(Text, ref _layout);
|
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();
|
Font font = Font.GetFont();
|
||||||
if (font == null)
|
if (font == null)
|
||||||
{
|
{
|
||||||
height = Height;
|
height = Height;
|
||||||
return Vector2.Zero;
|
return Float2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
height = GetFontHeight();
|
height = GetFontHeight();
|
||||||
return font.GetCharPosition(Text, index, ref _layout);
|
return font.GetCharPosition(Text, index, ref _layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int HitTestText(Vector2 location)
|
public override int HitTestText(Float2 location)
|
||||||
{
|
{
|
||||||
Font font = Font.GetFont();
|
Font font = Font.GetFont();
|
||||||
if (font == null)
|
if (font == null)
|
||||||
@@ -195,7 +195,7 @@ namespace Game
|
|||||||
|
|
||||||
if (TextPrefix != "")
|
if (TextPrefix != "")
|
||||||
{
|
{
|
||||||
Vector2 prefixSize = font.MeasureText(TextPrefix);
|
Float2 prefixSize = font.MeasureText(TextPrefix);
|
||||||
location.X -= prefixSize.X;
|
location.X -= prefixSize.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ namespace Game
|
|||||||
return base.OnKeyDown(key);
|
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 &&
|
if (doubleClicked && lastDoubleClick.Elapsed.TotalSeconds < 0.5 &&
|
||||||
location == lastDoubleClickLocation) // Windows defaults to 500ms window
|
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;
|
doubleClicked = true;
|
||||||
lastDoubleClick.Restart();
|
lastDoubleClick.Restart();
|
||||||
@@ -260,7 +260,7 @@ namespace Game
|
|||||||
return base.OnMouseDoubleClick(location, button);
|
return base.OnMouseDoubleClick(location, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnMouseTripleClick(Vector2 location, MouseButton button)
|
public bool OnMouseTripleClick(Float2 location, MouseButton button)
|
||||||
{
|
{
|
||||||
if (!IsMultiline)
|
if (!IsMultiline)
|
||||||
SelectAll();
|
SelectAll();
|
||||||
@@ -281,7 +281,7 @@ namespace Game
|
|||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
// Cache data
|
// Cache data
|
||||||
Rectangle rect = new Rectangle(Vector2.Zero, Size);
|
Rectangle rect = new Rectangle(Float2.Zero, Size);
|
||||||
Font font = Font.GetFont();
|
Font font = Font.GetFont();
|
||||||
if (!font)
|
if (!font)
|
||||||
return;
|
return;
|
||||||
@@ -312,8 +312,8 @@ namespace Game
|
|||||||
// Check if any text is selected to draw selection
|
// Check if any text is selected to draw selection
|
||||||
if (HasSelection)
|
if (HasSelection)
|
||||||
{
|
{
|
||||||
Vector2 leftEdge = font.GetCharPosition(text, SelectionLeft + TextPrefix.Length, ref _layout);
|
Float2 leftEdge = font.GetCharPosition(text, SelectionLeft + TextPrefix.Length, ref _layout);
|
||||||
Vector2 rightEdge = font.GetCharPosition(text, SelectionRight + TextPrefix.Length, ref _layout);
|
Float2 rightEdge = font.GetCharPosition(text, SelectionRight + TextPrefix.Length, ref _layout);
|
||||||
float fontHeight = GetFontHeight();
|
float fontHeight = GetFontHeight();
|
||||||
|
|
||||||
// Draw selection background
|
// Draw selection background
|
||||||
@@ -349,7 +349,7 @@ namespace Game
|
|||||||
|
|
||||||
if (CaretPosition > -1)
|
if (CaretPosition > -1)
|
||||||
{
|
{
|
||||||
Vector2 prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Vector2();
|
Float2 prefixSize = TextPrefix != "" ? font.MeasureText(TextPrefix) : new Float2();
|
||||||
Rectangle caretBounds = CaretBounds;
|
Rectangle caretBounds = CaretBounds;
|
||||||
caretBounds.X += prefixSize.X;
|
caretBounds.X += prefixSize.X;
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Game
|
|||||||
private class PlayerFrame
|
private class PlayerFrame
|
||||||
{
|
{
|
||||||
public ulong frame;
|
public ulong frame;
|
||||||
public Vector3 position;
|
public Float3 position;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<uint, PlayerActor> players;
|
private static Dictionary<uint, PlayerActor> players;
|
||||||
@@ -211,12 +211,12 @@ namespace Game
|
|||||||
for (int i=0; i<numActors; i++)
|
for (int i=0; i<numActors; i++)
|
||||||
{
|
{
|
||||||
uint playerId = networkEvent.Message.ReadUInt32();
|
uint playerId = networkEvent.Message.ReadUInt32();
|
||||||
Vector3 playerPosition;
|
Float3 playerPosition;
|
||||||
playerPosition.X = networkEvent.Message.ReadSingle();
|
playerPosition.X = networkEvent.Message.ReadSingle();
|
||||||
playerPosition.Y = networkEvent.Message.ReadSingle();
|
playerPosition.Y = networkEvent.Message.ReadSingle();
|
||||||
playerPosition.Z = 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);
|
Console.Print("received welcome: frame " + worldState.frame);
|
||||||
@@ -234,8 +234,8 @@ namespace Game
|
|||||||
uint playerId = networkEvent.Message.ReadUInt32();
|
uint playerId = networkEvent.Message.ReadUInt32();
|
||||||
ulong playerFrameIndex = networkEvent.Message.ReadUInt64();
|
ulong playerFrameIndex = networkEvent.Message.ReadUInt64();
|
||||||
SpawnPlayer(playerId,
|
SpawnPlayer(playerId,
|
||||||
new Vector3(networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle(), networkEvent.Message.ReadSingle()),
|
new Float3(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()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GameModeMessageType.PlayerInput:
|
case GameModeMessageType.PlayerInput:
|
||||||
@@ -256,7 +256,7 @@ namespace Game
|
|||||||
case GameModeMessageType.PlayerPosition:
|
case GameModeMessageType.PlayerPosition:
|
||||||
{
|
{
|
||||||
uint playerId = networkEvent.Sender.ConnectionId;
|
uint playerId = networkEvent.Sender.ConnectionId;
|
||||||
Vector3 reportedPosition;
|
Float3 reportedPosition;
|
||||||
|
|
||||||
ulong reportedFrame = networkEvent.Message.ReadUInt64();
|
ulong reportedFrame = networkEvent.Message.ReadUInt64();
|
||||||
uint reportedPlayerId = networkEvent.Message.ReadUInt32();
|
uint reportedPlayerId = networkEvent.Message.ReadUInt32();
|
||||||
@@ -276,7 +276,7 @@ namespace Game
|
|||||||
Console.Print("frame is in the past, unable to verify frame");
|
Console.Print("frame is in the past, unable to verify frame");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Vector3 playerFramePosition = playerFrame.position;
|
Float3 playerFramePosition = playerFrame.position;
|
||||||
if ((playerFramePosition - reportedPosition).Length > 0.0001)
|
if ((playerFramePosition - reportedPosition).Length > 0.0001)
|
||||||
{
|
{
|
||||||
Console.Print("player drifted, len: " + (playerFramePosition - reportedPosition).Length);
|
Console.Print("player drifted, len: " + (playerFramePosition - reportedPosition).Length);
|
||||||
@@ -348,8 +348,8 @@ namespace Game
|
|||||||
var randomSpawn = spawns.First();
|
var randomSpawn = spawns.First();
|
||||||
|
|
||||||
uint playerId = connection.ConnectionId;
|
uint playerId = connection.ConnectionId;
|
||||||
Vector3 position = randomSpawn.Position + new Vector3(0f, 4.1f, 0f);
|
Float3 position = randomSpawn.Position + new Float3(0f, 4.1f, 0f);
|
||||||
Vector3 eulerAngles = randomSpawn.Orientation.EulerAngles;
|
Float3 eulerAngles = randomSpawn.Orientation.EulerAngles;
|
||||||
|
|
||||||
players.Add(playerId, null);
|
players.Add(playerId, null);
|
||||||
playerConnections.Add(playerId, connection);
|
playerConnections.Add(playerId, connection);
|
||||||
@@ -377,7 +377,7 @@ namespace Game
|
|||||||
return true;
|
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)
|
if (NetworkManager.IsLocalClient)
|
||||||
return; // Handled by listenserver
|
return; // Handled by listenserver
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ namespace Game
|
|||||||
{
|
{
|
||||||
public struct MapFacePlane
|
public struct MapFacePlane
|
||||||
{
|
{
|
||||||
public Vector3 v1, v2, v3;
|
public Float3 v1, v2, v3;
|
||||||
public Plane plane;
|
public Plane plane;
|
||||||
public string texture;
|
public string texture;
|
||||||
public Vector2 offset;
|
public Float2 offset;
|
||||||
public float rotation;
|
public float rotation;
|
||||||
public Vector2 scale;
|
public Float2 scale;
|
||||||
public int contentFlags, surfaceFlags, surfaceValue;
|
public int contentFlags, surfaceFlags, surfaceValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,8 +32,8 @@ namespace Game
|
|||||||
|
|
||||||
public struct PatchVertex
|
public struct PatchVertex
|
||||||
{
|
{
|
||||||
public Vector3 v;
|
public Float3 v;
|
||||||
public Vector2 uv;
|
public Float2 uv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MapEntity
|
public class MapEntity
|
||||||
@@ -245,24 +245,24 @@ namespace Game
|
|||||||
throw new Exception("failed to ParseInt: " + fs);
|
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),
|
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),
|
||||||
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++;
|
index++;
|
||||||
while (index < data.Length)
|
while (index < data.Length)
|
||||||
@@ -272,7 +272,7 @@ namespace Game
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 vector = ParseVector3(data, ref index);
|
Float3 vector = ParseFloat3(data, ref index);
|
||||||
// rounding
|
// rounding
|
||||||
/*float temp = vector.Z;
|
/*float temp = vector.Z;
|
||||||
vector.Z = vector.Y;
|
vector.Z = vector.Y;
|
||||||
@@ -328,16 +328,16 @@ namespace Game
|
|||||||
case '(':
|
case '(':
|
||||||
{
|
{
|
||||||
MapFacePlane plane = new MapFacePlane();
|
MapFacePlane plane = new MapFacePlane();
|
||||||
plane.v1 = ParsePlaneVector3(data, ref index);
|
plane.v1 = ParsePlaneFloat3(data, ref index);
|
||||||
plane.v2 = ParsePlaneVector3(data, ref index);
|
plane.v2 = ParsePlaneFloat3(data, ref index);
|
||||||
plane.v3 = ParsePlaneVector3(data, ref index);
|
plane.v3 = ParsePlaneFloat3(data, ref index);
|
||||||
plane.texture = ParseString(data, ref index);
|
plane.texture = ParseString(data, ref index);
|
||||||
|
|
||||||
if (true) // quake or quake3 format
|
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.rotation = ParseFloat(data, ref index);
|
||||||
plane.scale = ParseVector2(data, ref index);
|
plane.scale = ParseFloat2(data, ref index);
|
||||||
|
|
||||||
char peekChar = (char)data[index];
|
char peekChar = (char)data[index];
|
||||||
if (peekChar != '\n') // quake3 format
|
if (peekChar != '\n') // quake3 format
|
||||||
@@ -349,9 +349,9 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Flip Y and Z
|
// Flip Y and Z
|
||||||
plane.v1 = new Vector3(plane.v1.X, plane.v1.Z, plane.v1.Y);
|
plane.v1 = new Float3(plane.v1.X, plane.v1.Z, plane.v1.Y);
|
||||||
plane.v2 = new Vector3(plane.v2.X, plane.v2.Z, plane.v2.Y);
|
plane.v2 = new Float3(plane.v2.X, plane.v2.Z, plane.v2.Y);
|
||||||
plane.v3 = new Vector3(plane.v3.X, plane.v3.Z, plane.v3.Y);
|
plane.v3 = new Float3(plane.v3.X, plane.v3.Z, plane.v3.Y);
|
||||||
|
|
||||||
plane.plane = new Plane(plane.v1, plane.v2, plane.v3);
|
plane.plane = new Plane(plane.v1, plane.v2, plane.v3);
|
||||||
|
|
||||||
@@ -494,9 +494,9 @@ namespace Game
|
|||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices[vertexIndex].v = ParseVector3(data, ref index);
|
vertices[vertexIndex].v = ParseFloat3(data, ref index);
|
||||||
vertices[vertexIndex].uv =
|
vertices[vertexIndex].uv =
|
||||||
new Vector2(ParseFloat(data, ref index), ParseFloat(data, ref index));
|
new Float2(ParseFloat(data, ref index), ParseFloat(data, ref index));
|
||||||
vertexIndex++;
|
vertexIndex++;
|
||||||
|
|
||||||
while (index < data.Length)
|
while (index < data.Length)
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ namespace Game
|
|||||||
{
|
{
|
||||||
public List<uint> indices = new List<uint>();
|
public List<uint> indices = new List<uint>();
|
||||||
public MaterialBase material;
|
public MaterialBase material;
|
||||||
public List<Vector3> normals = new List<Vector3>();
|
public List<Float3> normals = new List<Float3>();
|
||||||
public List<Vector2> uvs = new List<Vector2>();
|
public List<Float2> uvs = new List<Float2>();
|
||||||
public List<Vector3> vertices = new List<Vector3>();
|
public List<Float3> vertices = new List<Float3>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BrushGeometry
|
public class BrushGeometry
|
||||||
@@ -28,8 +28,8 @@ namespace Game
|
|||||||
public Dictionary<string, MaterialBase> brushMaterials;
|
public Dictionary<string, MaterialBase> brushMaterials;
|
||||||
public BrushGeometryMesh[] meshes;
|
public BrushGeometryMesh[] meshes;
|
||||||
public Model model;
|
public Model model;
|
||||||
public Vector3 offset;
|
public Float3 offset;
|
||||||
public Vector3[] vertices; // all vertices
|
public Float3[] vertices; // all vertices
|
||||||
}
|
}
|
||||||
|
|
||||||
[ExecuteInEditMode]
|
[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 tris = new List<int>();
|
||||||
var normals = new List<Vector3>();
|
var normals = new List<Float3>();
|
||||||
|
|
||||||
ConvexHullCalculator calc = new ConvexHullCalculator();
|
ConvexHullCalculator calc = new ConvexHullCalculator();
|
||||||
calc.GenerateHull(points.ToList(), true, ref verts, ref tris, ref normals);
|
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)
|
foreach (int tri in tris)
|
||||||
finalPoints.Add(verts[tri]);
|
finalPoints.Add(verts[tri]);
|
||||||
@@ -122,9 +122,9 @@ namespace Game
|
|||||||
/// Triangulates the brush by calculating intersection points between triplets of planes.
|
/// Triangulates the brush by calculating intersection points between triplets of planes.
|
||||||
/// Does not work well with off-axis aligned planes.
|
/// Does not work well with off-axis aligned planes.
|
||||||
/// </summary>
|
/// </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>();
|
var planes = new List<Plane>();
|
||||||
float maxDist = 0f;
|
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));
|
//var maxDist = Math.Abs(p1.D * p2.D * p3.D);//Math.Max(p1.D, Math.Max(p2.D, p3.D));
|
||||||
|
|
||||||
// intersection of three planes
|
// 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)
|
//if (denom < 0.0000000001)
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
|
|
||||||
Vector3 intersection = (Vector3.Cross(p2.Normal, p3.Normal) * -p1.D +
|
Float3 intersection = (Float3.Cross(p2.Normal, p3.Normal) * -p1.D +
|
||||||
Vector3.Cross(p3.Normal, p1.Normal) * -p2.D +
|
Float3.Cross(p3.Normal, p1.Normal) * -p2.D +
|
||||||
Vector3.Cross(p1.Normal, p2.Normal) * -p3.D) / (float)denom;
|
Float3.Cross(p1.Normal, p2.Normal) * -p3.D) / (float)denom;
|
||||||
|
|
||||||
if (Mathf.Abs(intersection.X) > maxDist * 1f || Mathf.Abs(intersection.Y) > maxDist * 1f ||
|
if (Mathf.Abs(intersection.X) > maxDist * 1f || Mathf.Abs(intersection.Y) > maxDist * 1f ||
|
||||||
Mathf.Abs(intersection.Z) > maxDist * 1f)
|
Mathf.Abs(intersection.Z) > maxDist * 1f)
|
||||||
@@ -180,12 +180,12 @@ namespace Game
|
|||||||
|
|
||||||
// remove duplicate points
|
// remove duplicate points
|
||||||
var planePoints3 = planePoints;
|
var planePoints3 = planePoints;
|
||||||
planePoints = new HashSet<Vector3>();
|
planePoints = new HashSet<Float3>();
|
||||||
|
|
||||||
foreach (Vector3 p1 in planePoints3)
|
foreach (Float3 p1 in planePoints3)
|
||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (Vector3 p2 in planePoints)
|
foreach (Float3 p2 in planePoints)
|
||||||
if (Mathf.Abs((p1 - p2).Length) < 0.00001f)
|
if (Mathf.Abs((p1 - p2).Length) < 0.00001f)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
@@ -201,9 +201,9 @@ namespace Game
|
|||||||
|
|
||||||
// pass 2: cull points behind clipping planes
|
// pass 2: cull points behind clipping planes
|
||||||
var planePoints2 = planePoints;
|
var planePoints2 = planePoints;
|
||||||
planePoints = new HashSet<Vector3>();
|
planePoints = new HashSet<Float3>();
|
||||||
|
|
||||||
foreach (Vector3 p in planePoints2)
|
foreach (Float3 p in planePoints2)
|
||||||
{
|
{
|
||||||
bool front = true;
|
bool front = true;
|
||||||
foreach (MapFacePlane brushPlane in brush.planes)
|
foreach (MapFacePlane brushPlane in brush.planes)
|
||||||
@@ -227,7 +227,7 @@ namespace Game
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices = new Vector3[0];
|
vertices = new Float3[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FLAX_EDITOR
|
#if FLAX_EDITOR
|
||||||
@@ -422,7 +422,7 @@ namespace Game
|
|||||||
|
|
||||||
Assert.IsTrue(geom.vertices.Length > 0);
|
Assert.IsTrue(geom.vertices.Length > 0);
|
||||||
|
|
||||||
foreach (Vector3 vert in geom.vertices)
|
foreach (Float3 vert in geom.vertices)
|
||||||
geom.offset += vert;
|
geom.offset += vert;
|
||||||
geom.offset /= geom.vertices.Length;
|
geom.offset /= geom.vertices.Length;
|
||||||
|
|
||||||
@@ -485,16 +485,16 @@ namespace Game
|
|||||||
var brushVertices = geom.vertices;
|
var brushVertices = geom.vertices;
|
||||||
for (int i = 0; i < brushVertices.Length; i += 3)
|
for (int i = 0; i < brushVertices.Length; i += 3)
|
||||||
{
|
{
|
||||||
Vector3 v1 = brushVertices[i + 0];
|
Float3 v1 = brushVertices[i + 0];
|
||||||
Vector3 v2 = brushVertices[i + 1];
|
Float3 v2 = brushVertices[i + 1];
|
||||||
Vector3 v3 = brushVertices[i + 2];
|
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
|
// fetch the texture parameters from the plane with matching normal
|
||||||
Vector2 uvScale = new Vector2(0f);
|
Float2 uvScale = new Float2(0f);
|
||||||
float uvRotation = 0f;
|
float uvRotation = 0f;
|
||||||
Vector2 uvOffset = new Vector2(0f);
|
Float2 uvOffset = new Float2(0f);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int meshIndex = 0;
|
int meshIndex = 0;
|
||||||
foreach (MapFacePlane brushPlane in geom.brush.planes)
|
foreach (MapFacePlane brushPlane in geom.brush.planes)
|
||||||
@@ -512,7 +512,7 @@ namespace Game
|
|||||||
if (!found)
|
if (!found)
|
||||||
Console.Print("no matching plane found for brush " + brushIndex + ", bad geometry?");
|
Console.Print("no matching plane found for brush " + brushIndex + ", bad geometry?");
|
||||||
|
|
||||||
Vector2 uv1, uv2, uv3;
|
Float2 uv1, uv2, uv3;
|
||||||
// if quake format
|
// if quake format
|
||||||
{
|
{
|
||||||
// The texture is projected to the surface from three angles, the axis with least
|
// 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.
|
// 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.
|
// 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)Math.Round(normal.Y, 4), (float)Math.Round(normal.Z, 4));
|
||||||
|
|
||||||
float dotX = Math.Abs(Vector3.Dot(textureNormal, Vector3.Right));
|
float dotX = Math.Abs(Float3.Dot(textureNormal, Float3.Right));
|
||||||
float dotY = Math.Abs(Vector3.Dot(textureNormal, Vector3.Up));
|
float dotY = Math.Abs(Float3.Dot(textureNormal, Float3.Up));
|
||||||
float dotZ = Math.Abs(Vector3.Dot(textureNormal, Vector3.Forward));
|
float dotZ = Math.Abs(Float3.Dot(textureNormal, Float3.Forward));
|
||||||
|
|
||||||
Vector3 axis;
|
Float3 axis;
|
||||||
if (dotY >= dotX && dotY >= dotZ)
|
if (dotY >= dotX && dotY >= dotZ)
|
||||||
axis = -Vector3.Up;
|
axis = -Float3.Up;
|
||||||
else if (dotX >= dotY && dotX >= dotZ)
|
else if (dotX >= dotY && dotX >= dotZ)
|
||||||
axis = Vector3.Right;
|
axis = Float3.Right;
|
||||||
else if (dotZ >= dotX && dotZ >= dotY)
|
else if (dotZ >= dotX && dotZ >= dotY)
|
||||||
axis = -Vector3.Forward;
|
axis = -Float3.Forward;
|
||||||
else
|
else
|
||||||
axis = Vector3.Right;
|
axis = Float3.Right;
|
||||||
|
|
||||||
Vector3 axisForward = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
Float3 axisForward = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
|
||||||
? -Vector3.Forward
|
? -Float3.Forward
|
||||||
: Vector3.Up;
|
: Float3.Up;
|
||||||
Vector3 axisForward2 = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
Float3 axisForward2 = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
|
||||||
? Vector3.Up
|
? Float3.Up
|
||||||
: -Vector3.Forward;
|
: -Float3.Forward;
|
||||||
|
|
||||||
Quaternion rot = Quaternion.Identity;
|
Quaternion rot = Quaternion.Identity;
|
||||||
rot = rot * Quaternion.LookRotation(axis, axisForward);
|
rot = rot * Quaternion.LookRotation(axis, axisForward);
|
||||||
rot = rot * Quaternion.RotationAxis(-Vector3.Forward,
|
rot = rot * Quaternion.RotationAxis(-Float3.Forward,
|
||||||
180f * Mathf.DegreesToRadians);
|
180f * Mathf.DegreesToRadians);
|
||||||
rot = rot * Quaternion.RotationAxis(
|
rot = rot * Quaternion.RotationAxis(
|
||||||
Mathf.Abs(Vector3.Dot(axis, Vector3.Right)) > 0.01f
|
Mathf.Abs(Float3.Dot(axis, Float3.Right)) > 0.01f
|
||||||
? Vector3.Right
|
? Float3.Right
|
||||||
: axisForward2,
|
: axisForward2,
|
||||||
uvRotation * Mathf.DegreesToRadians);
|
uvRotation * Mathf.DegreesToRadians);
|
||||||
|
|
||||||
uv1 = ((Vector2)((v1 + geom.offset) * rot) + uvOffset) * uvScale;
|
uv1 = ((Float2)((v1 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||||
uv2 = ((Vector2)((v2 + geom.offset) * rot) + uvOffset) * uvScale;
|
uv2 = ((Float2)((v2 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||||
uv3 = ((Vector2)((v3 + geom.offset) * rot) + uvOffset) * uvScale;
|
uv3 = ((Float2)((v3 + geom.offset) * rot) + uvOffset) * uvScale;
|
||||||
}
|
}
|
||||||
BrushGeometryMesh mesh = geom.meshes[meshIndex];
|
BrushGeometryMesh mesh = geom.meshes[meshIndex];
|
||||||
|
|
||||||
@@ -679,9 +679,9 @@ namespace Game
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var vertices = new List<Vector3>();
|
var vertices = new List<Float3>();
|
||||||
var uvs = new List<Vector2>();
|
var uvs = new List<Float2>();
|
||||||
var normals = new List<Vector3>();
|
var normals = new List<Float3>();
|
||||||
|
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
int brushIndex = 0;
|
int brushIndex = 0;
|
||||||
@@ -690,21 +690,21 @@ namespace Game
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
TriangulateBrush(brush, out var brushVertices);
|
TriangulateBrush(brush, out var brushVertices);
|
||||||
var brushUvs = new Vector2[brushVertices.Length];
|
var brushUvs = new Float2[brushVertices.Length];
|
||||||
var brushNormals = new Vector3[brushVertices.Length];
|
var brushNormals = new Float3[brushVertices.Length];
|
||||||
|
|
||||||
for (int i = 0; i < brushVertices.Length; i += 3)
|
for (int i = 0; i < brushVertices.Length; i += 3)
|
||||||
{
|
{
|
||||||
Vector3 v1 = brushVertices[i + 0];
|
Float3 v1 = brushVertices[i + 0];
|
||||||
Vector3 v2 = brushVertices[i + 1];
|
Float3 v2 = brushVertices[i + 1];
|
||||||
Vector3 v3 = brushVertices[i + 2];
|
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
|
// fetch the texture parameters from the plane with matching normal
|
||||||
Vector2 uvScale = new Vector2(0f);
|
Float2 uvScale = new Float2(0f);
|
||||||
float uvRotation = 0f;
|
float uvRotation = 0f;
|
||||||
Vector2 uvOffset = new Vector2(0f);
|
Float2 uvOffset = new Float2(0f);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
foreach (MapFacePlane brushPlane in brush.planes)
|
foreach (MapFacePlane brushPlane in brush.planes)
|
||||||
if ((brushPlane.plane.Normal - normal).Length < 0.01f)
|
if ((brushPlane.plane.Normal - normal).Length < 0.01f)
|
||||||
@@ -720,7 +720,7 @@ namespace Game
|
|||||||
if (!found)
|
if (!found)
|
||||||
Console.Print("no matching plane found, bad geometry?");
|
Console.Print("no matching plane found, bad geometry?");
|
||||||
|
|
||||||
Vector2 uv1, uv2, uv3;
|
Float2 uv1, uv2, uv3;
|
||||||
// if quake format
|
// if quake format
|
||||||
{
|
{
|
||||||
// The texture is projected to the surface from three angles, the axis with least
|
// 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.
|
// 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.
|
// 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)Math.Round(normal.Y, 4), (float)Math.Round(normal.Z, 4));
|
||||||
|
|
||||||
float dotX = Math.Abs(Vector3.Dot(textureNormal, Vector3.Right));
|
float dotX = Math.Abs(Float3.Dot(textureNormal, Float3.Right));
|
||||||
float dotY = Math.Abs(Vector3.Dot(textureNormal, Vector3.Up));
|
float dotY = Math.Abs(Float3.Dot(textureNormal, Float3.Up));
|
||||||
float dotZ = Math.Abs(Vector3.Dot(textureNormal, Vector3.Forward));
|
float dotZ = Math.Abs(Float3.Dot(textureNormal, Float3.Forward));
|
||||||
|
|
||||||
Vector3 axis;
|
Float3 axis;
|
||||||
if (dotY >= dotX && dotY >= dotZ)
|
if (dotY >= dotX && dotY >= dotZ)
|
||||||
axis = -Vector3.Up;
|
axis = -Float3.Up;
|
||||||
else if (dotX >= dotY && dotX >= dotZ)
|
else if (dotX >= dotY && dotX >= dotZ)
|
||||||
axis = Vector3.Right;
|
axis = Float3.Right;
|
||||||
else if (dotZ >= dotX && dotZ >= dotY)
|
else if (dotZ >= dotX && dotZ >= dotY)
|
||||||
axis = -Vector3.Forward;
|
axis = -Float3.Forward;
|
||||||
else
|
else
|
||||||
axis = Vector3.Right;
|
axis = Float3.Right;
|
||||||
|
|
||||||
Vector3 axisForward = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
Float3 axisForward = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
|
||||||
? -Vector3.Forward
|
? -Float3.Forward
|
||||||
: Vector3.Up;
|
: Float3.Up;
|
||||||
Vector3 axisForward2 = Mathf.Abs(Vector3.Dot(axis, Vector3.Up)) > 0.01f
|
Float3 axisForward2 = Mathf.Abs(Float3.Dot(axis, Float3.Up)) > 0.01f
|
||||||
? Vector3.Up
|
? Float3.Up
|
||||||
: -Vector3.Forward;
|
: -Float3.Forward;
|
||||||
|
|
||||||
Quaternion rot = Quaternion.Identity;
|
Quaternion rot = Quaternion.Identity;
|
||||||
rot = rot * Quaternion.LookRotation(axis, axisForward);
|
rot = rot * Quaternion.LookRotation(axis, axisForward);
|
||||||
rot = rot * Quaternion.RotationAxis(-Vector3.Forward,
|
rot = rot * Quaternion.RotationAxis(-Float3.Forward,
|
||||||
180f * Mathf.DegreesToRadians);
|
180f * Mathf.DegreesToRadians);
|
||||||
rot = rot * Quaternion.RotationAxis(
|
rot = rot * Quaternion.RotationAxis(
|
||||||
Mathf.Abs(Vector3.Dot(axis, Vector3.Right)) > 0.01f
|
Mathf.Abs(Float3.Dot(axis, Float3.Right)) > 0.01f
|
||||||
? Vector3.Right
|
? Float3.Right
|
||||||
: axisForward2,
|
: axisForward2,
|
||||||
uvRotation * Mathf.DegreesToRadians);
|
uvRotation * Mathf.DegreesToRadians);
|
||||||
|
|
||||||
uv1 = ((Vector2)(v1 * rot) + uvOffset) * uvScale;
|
uv1 = ((Float2)(v1 * rot) + uvOffset) * uvScale;
|
||||||
uv2 = ((Vector2)(v2 * rot) + uvOffset) * uvScale;
|
uv2 = ((Float2)(v2 * rot) + uvOffset) * uvScale;
|
||||||
uv3 = ((Vector2)(v3 * rot) + uvOffset) * uvScale;
|
uv3 = ((Float2)(v3 * rot) + uvOffset) * uvScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
brushUvs[i + 0] = uv1;
|
brushUvs[i + 0] = uv1;
|
||||||
@@ -965,10 +965,10 @@ namespace Game
|
|||||||
playerSpawnIndex++;
|
playerSpawnIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector3 ParseOrigin(string origin)
|
private static Float3 ParseOrigin(string origin)
|
||||||
{
|
{
|
||||||
string[] points = origin.Split(' ');
|
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)
|
private static Color ParseColor(string origin)
|
||||||
@@ -980,14 +980,14 @@ namespace Game
|
|||||||
private static Quaternion ParseAngle(string origin)
|
private static Quaternion ParseAngle(string origin)
|
||||||
{
|
{
|
||||||
string[] angles = origin.Split(' ');
|
string[] angles = origin.Split(' ');
|
||||||
//Console.Print("parseangle: " + new Vector3(0f, float.Parse(angles[0]) + 45f, 0f).ToString());
|
//Console.Print("parseangle: " + new Float3(0f, float.Parse(angles[0]) + 45f, 0f).ToString());
|
||||||
return Quaternion.Euler(new Vector3(0f, float.Parse(angles[0]) + 90f, 0f));
|
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(' ');
|
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()
|
public override void OnDestroy()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Game
|
|||||||
face.halfEdges.Add(this);
|
face.halfEdges.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector3 tail
|
public Float3 tail
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -44,15 +44,15 @@ namespace Game
|
|||||||
|
|
||||||
public struct Edge
|
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.v1 = v1;
|
||||||
this.v2 = v2;
|
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[]
|
return new[]
|
||||||
{
|
{
|
||||||
@@ -97,11 +97,11 @@ namespace Game
|
|||||||
|
|
||||||
public class Face
|
public class Face
|
||||||
{
|
{
|
||||||
public Vector3 v1, v2, v3;
|
public Float3 v1, v2, v3;
|
||||||
public List<HalfEdge> halfEdges;
|
public List<HalfEdge> halfEdges;
|
||||||
public bool visited;
|
public bool visited;
|
||||||
|
|
||||||
public Face(Vector3 v1, Vector3 v2, Vector3 v3)
|
public Face(Float3 v1, Float3 v2, Float3 v3)
|
||||||
{
|
{
|
||||||
this.v1 = v1;
|
this.v1 = v1;
|
||||||
this.v2 = v2;
|
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);
|
Plane plane = new Plane(v1, v2, v3);
|
||||||
|
|
||||||
@@ -143,13 +143,13 @@ namespace Game
|
|||||||
{
|
{
|
||||||
HalfEdge areaEdgeStart = halfEdges[0];
|
HalfEdge areaEdgeStart = halfEdges[0];
|
||||||
HalfEdge areaEdge = areaEdgeStart.previous;
|
HalfEdge areaEdge = areaEdgeStart.previous;
|
||||||
Vector3 areaNorm = Vector3.Zero;
|
Float3 areaNorm = Float3.Zero;
|
||||||
int iters = 0;
|
int iters = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (iters++ > 1000)
|
if (iters++ > 1000)
|
||||||
throw new Exception("merge infinite loop");
|
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.next.edge.v1 - areaEdgeStart.edge.v1);
|
||||||
areaEdge = areaEdge.previous;
|
areaEdge = areaEdge.previous;
|
||||||
|
|
||||||
@@ -161,9 +161,9 @@ namespace Game
|
|||||||
|
|
||||||
public struct Tetrahedron
|
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.v1 = v1;
|
||||||
this.v2 = v2;
|
this.v2 = v2;
|
||||||
@@ -187,9 +187,9 @@ namespace Game
|
|||||||
{
|
{
|
||||||
const float epsilon = 0.01f;
|
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)
|
foreach (var vert in points)
|
||||||
{
|
{
|
||||||
center += vert;
|
center += vert;
|
||||||
@@ -200,7 +200,7 @@ namespace Game
|
|||||||
|
|
||||||
points.Sort((v1, v2) =>
|
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)
|
if (dot > 0)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
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) +
|
float distance = (point.X * plane.Normal.X) + (point.Y * plane.Normal.Y) +
|
||||||
(point.Z * plane.Normal.Z) + plane.D;
|
(point.Z * plane.Normal.Z) + plane.D;
|
||||||
@@ -217,15 +217,15 @@ namespace Game
|
|||||||
(plane.Normal.Z * plane.Normal.Z));
|
(plane.Normal.Z * plane.Normal.Z));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Face[] CreateInitialSimplex(Vector3[] points)
|
private Face[] CreateInitialSimplex(Float3[] points)
|
||||||
{
|
{
|
||||||
if (false)
|
if (false)
|
||||||
{
|
{
|
||||||
// TODO: more optimal to find first set of points which are not coplanar?
|
// TODO: more optimal to find first set of points which are not coplanar?
|
||||||
|
|
||||||
// find the longest edge
|
// find the longest edge
|
||||||
Vector3 v1 = Vector3.Zero;
|
Vector3 v1 = Float3.Zero;
|
||||||
Vector3 v2 = Vector3.Zero;
|
Vector3 v2 = Float3.Zero;
|
||||||
foreach (var p1 in points)
|
foreach (var p1 in points)
|
||||||
{
|
{
|
||||||
foreach (var p2 in points)
|
foreach (var p2 in points)
|
||||||
@@ -244,7 +244,7 @@ namespace Game
|
|||||||
Assert.IsTrue(v1 != v2, "a1 != a2");
|
Assert.IsTrue(v1 != v2, "a1 != a2");
|
||||||
|
|
||||||
// find the furthest point from the edge to form a face
|
// find the furthest point from the edge to form a face
|
||||||
Vector3 v3 = Vector3.Zero;
|
Vector3 v3 = Float3.Zero;
|
||||||
float furthestDist = 0f;
|
float furthestDist = 0f;
|
||||||
foreach (var point in points)
|
foreach (var point in points)
|
||||||
{
|
{
|
||||||
@@ -252,7 +252,7 @@ namespace Game
|
|||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
var edgeDir = (v2 - v1).Normalized;
|
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;
|
var dist = (point - closest).Length;
|
||||||
if (dist > furthestDist)
|
if (dist > furthestDist)
|
||||||
@@ -267,7 +267,7 @@ namespace Game
|
|||||||
|
|
||||||
// find the furthest point from he face
|
// find the furthest point from he face
|
||||||
Plane plane = new Plane(v1, v2, v3);
|
Plane plane = new Plane(v1, v2, v3);
|
||||||
Vector3 v4 = Vector3.Zero;
|
Vector3 v4 = Float3.Zero;
|
||||||
float fourthDist = 0f;
|
float fourthDist = 0f;
|
||||||
foreach (var point in points)
|
foreach (var point in points)
|
||||||
{
|
{
|
||||||
@@ -306,7 +306,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
else
|
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;
|
bool found = false;
|
||||||
|
|
||||||
foreach (var p1 in points)
|
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");
|
Assert.IsTrue(points.Length >= 4, "points.Length >= 4");
|
||||||
|
|
||||||
@@ -430,7 +430,7 @@ namespace Game
|
|||||||
|
|
||||||
// verify
|
// verify
|
||||||
{
|
{
|
||||||
var tetrapoints = new List<Vector3>();
|
var tetrapoints = new List<Float3>();
|
||||||
foreach (var face in tetrahedron)
|
foreach (var face in tetrahedron)
|
||||||
{
|
{
|
||||||
foreach (var he in face.halfEdges)
|
foreach (var he in face.halfEdges)
|
||||||
@@ -569,7 +569,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
var hullFacesNew = new List<Face>();
|
var hullFacesNew = new List<Face>();
|
||||||
var unclaimedPoints = new List<Vector3>();
|
var unclaimedPoints = new List<Float3>();
|
||||||
|
|
||||||
AddPointToHull(pointToAdd.Item2, pointFace, unclaimedPoints, outsideSet, horizonEdges, hullFacesNew);
|
AddPointToHull(pointToAdd.Item2, pointFace, unclaimedPoints, outsideSet, horizonEdges, hullFacesNew);
|
||||||
|
|
||||||
@@ -629,7 +629,7 @@ namespace Game
|
|||||||
foreach (var f in discardedFaces)
|
foreach (var f in discardedFaces)
|
||||||
hullFaces.Remove(f);
|
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)
|
foreach (var face in hullFaces)
|
||||||
{
|
{
|
||||||
hullPoints.Add(face.v1);
|
hullPoints.Add(face.v1);
|
||||||
@@ -640,7 +640,7 @@ namespace Game
|
|||||||
return hullPoints;
|
return hullPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddUnique(List<Vector3> list, Vector3 point)
|
private void AddUnique(List<Float3> list, Vector3 point)
|
||||||
{
|
{
|
||||||
foreach (var p in list)
|
foreach (var p in list)
|
||||||
{
|
{
|
||||||
@@ -650,27 +650,27 @@ namespace Game
|
|||||||
list.Add(point);
|
list.Add(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AreCoincident(Vector3 a, Vector3 b)
|
bool AreCoincident(Float3 a, Vector3 b)
|
||||||
{
|
{
|
||||||
return (a - b).Length <= epsilon;
|
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 n1 = Float3.Cross(c - a, c - b);
|
||||||
var n2 = Vector3.Cross(d - a, d - b);
|
var n2 = Float3.Cross(d - a, d - b);
|
||||||
|
|
||||||
var m1 = n1.Length;
|
var m1 = n1.Length;
|
||||||
var m2 = n2.Length;
|
var m2 = n2.Length;
|
||||||
|
|
||||||
return m1 > epsilon
|
return m1 > epsilon
|
||||||
&& m2 > epsilon
|
&& m2 > epsilon
|
||||||
&& AreCollinear(Vector3.Zero,
|
&& AreCollinear(Float3.Zero,
|
||||||
(1.0f / m1) * n1,
|
(1.0f / m1) * n1,
|
||||||
(1.0f / m2) * n2);
|
(1.0f / m2) * n2);
|
||||||
}
|
}
|
||||||
@@ -687,7 +687,7 @@ namespace Game
|
|||||||
bool merge = false;
|
bool merge = false;
|
||||||
Vector3 ni = new Plane(face.v1, face.v2, face.v3).Normal;
|
Vector3 ni = new Plane(face.v1, face.v2, face.v3).Normal;
|
||||||
Vector3 nj = new Plane(oppFace.v1, oppFace.v2, oppFace.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)
|
if (dotP > maxdot_minang)
|
||||||
{
|
{
|
||||||
@@ -724,7 +724,7 @@ namespace Game
|
|||||||
|
|
||||||
// construct the merged face
|
// construct the merged face
|
||||||
List<HalfEdge> edges = new List<HalfEdge>();
|
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
|
// copy the first face edges
|
||||||
HalfEdge heTwin = null;
|
HalfEdge heTwin = null;
|
||||||
@@ -828,7 +828,7 @@ namespace Game
|
|||||||
float mTolarenace = epsilon;//-1;
|
float mTolarenace = epsilon;//-1;
|
||||||
float mPlaneTolerance = epsilon;//-1f;
|
float mPlaneTolerance = epsilon;//-1f;
|
||||||
float maxDist = mPlaneTolerance;
|
float maxDist = mPlaneTolerance;
|
||||||
List<Vector3> uniqPoints = new List<Vector3>();
|
List<Float3> uniqPoints = new List<Float3>();
|
||||||
foreach (var hullFace in hullFaces)
|
foreach (var hullFace in hullFaces)
|
||||||
{
|
{
|
||||||
AddUnique(uniqPoints, hullFace.v1);
|
AddUnique(uniqPoints, hullFace.v1);
|
||||||
@@ -855,13 +855,13 @@ namespace Game
|
|||||||
|
|
||||||
Vector3 edgeVector = (nextVertex - vertex).Normalized;
|
Vector3 edgeVector = (nextVertex - vertex).Normalized;
|
||||||
Vector3 outVector =
|
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;
|
HalfEdge testHe = qhe.next;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Vector3 testVertex = testHe.tail;
|
Vector3 testVertex = testHe.tail;
|
||||||
float dist = Vector3.Dot(testVertex - vertex, outVector);
|
float dist = Float3.Dot(testVertex - vertex, outVector);
|
||||||
|
|
||||||
if (dist > mTolarenace)
|
if (dist > mTolarenace)
|
||||||
return false;
|
return false;
|
||||||
@@ -910,7 +910,7 @@ namespace Game
|
|||||||
return true;
|
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<Tuple<Face, Vector3>> outsideSet,
|
||||||
List<HalfEdge> horizonEdges, List<Face> hullFaces)
|
List<HalfEdge> horizonEdges, List<Face> hullFaces)
|
||||||
{
|
{
|
||||||
@@ -929,7 +929,7 @@ namespace Game
|
|||||||
var newFace = new Face(point, edge.edge.v1, edge.edge.v2);
|
var newFace = new Face(point, edge.edge.v1, edge.edge.v2);
|
||||||
var newPlane = new Plane(newFace.v1, newFace.v2, newFace.v3);
|
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.v1);
|
||||||
AddUnique(uniqPoints, newFace.v2);
|
AddUnique(uniqPoints, newFace.v2);
|
||||||
AddUnique(uniqPoints, newFace.v3);
|
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;
|
const float tolerance = -1f;
|
||||||
|
|
||||||
@@ -1270,7 +1270,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
// calculates the outermost edges of the geometry seen from the eyePoint
|
// 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<Tuple<Face, Vector3>> outsideSet,
|
||||||
List<HalfEdge> horizonEdges, HalfEdge currentEdge)
|
List<HalfEdge> horizonEdges, HalfEdge currentEdge)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -157,11 +157,11 @@ namespace Game
|
|||||||
/// used for more than one triangle.
|
/// used for more than one triangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void GenerateHull(
|
public void GenerateHull(
|
||||||
List<Vector3> points,
|
List<Float3> points,
|
||||||
bool splitVerts,
|
bool splitVerts,
|
||||||
ref List<Vector3> verts,
|
ref List<Float3> verts,
|
||||||
ref List<int> tris,
|
ref List<int> tris,
|
||||||
ref List<Vector3> normals)
|
ref List<Float3> normals)
|
||||||
{
|
{
|
||||||
if (points.Count < 4)
|
if (points.Count < 4)
|
||||||
throw new ArgumentException("Need at least 4 points to generate a convex hull");
|
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
|
/// Make sure all the buffers and variables needed for the algorithm
|
||||||
/// are initialized.
|
/// are initialized.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Initialize(List<Vector3> points, bool splitVerts)
|
private void Initialize(List<Float3> points, bool splitVerts)
|
||||||
{
|
{
|
||||||
faceCount = 0;
|
faceCount = 0;
|
||||||
openSetTail = -1;
|
openSetTail = -1;
|
||||||
@@ -226,7 +226,7 @@ namespace Game
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create initial seed hull.
|
/// Create initial seed hull.
|
||||||
/// </summary>
|
/// </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
|
// Find points suitable for use as the seed hull. Some varieties of
|
||||||
// this algorithm pick extreme points here, but I'm not convinced
|
// this algorithm pick extreme points here, but I'm not convinced
|
||||||
@@ -235,10 +235,10 @@ namespace Game
|
|||||||
int b0, b1, b2, b3;
|
int b0, b1, b2, b3;
|
||||||
FindInitialHullIndices(points, out b0, out b1, out b2, out b3);
|
FindInitialHullIndices(points, out b0, out b1, out b2, out b3);
|
||||||
|
|
||||||
Vector3 v0 = points[b0];
|
Float3 v0 = points[b0];
|
||||||
Vector3 v1 = points[b1];
|
Float3 v1 = points[b1];
|
||||||
Vector3 v2 = points[b2];
|
Float3 v2 = points[b2];
|
||||||
Vector3 v3 = points[b3];
|
Float3 v3 = points[b3];
|
||||||
|
|
||||||
bool above = Dot(v3 - v1, Cross(v1 - v0, v2 - v0)) > 0.0f;
|
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
|
/// Find four points in the point cloud that are not coplanar for the
|
||||||
/// seed hull
|
/// seed hull
|
||||||
/// </summary>
|
/// </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;
|
int count = points.Count;
|
||||||
|
|
||||||
for (int i0 = 0; i0 < count - 3; i0++)
|
for (int i0 = 0; i0 < count - 3; i0++)
|
||||||
for (int i1 = i0 + 1; i1 < count - 2; i1++)
|
for (int i1 = i0 + 1; i1 < count - 2; i1++)
|
||||||
{
|
{
|
||||||
Vector3 p0 = points[i0];
|
Float3 p0 = points[i0];
|
||||||
Vector3 p1 = points[i1];
|
Float3 p1 = points[i1];
|
||||||
|
|
||||||
if (AreCoincident(p0, p1))
|
if (AreCoincident(p0, p1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int i2 = i1 + 1; i2 < count - 1; i2++)
|
for (int i2 = i1 + 1; i2 < count - 1; i2++)
|
||||||
{
|
{
|
||||||
Vector3 p2 = points[i2];
|
Float3 p2 = points[i2];
|
||||||
|
|
||||||
if (AreCollinear(p0, p1, p2))
|
if (AreCollinear(p0, p1, p2))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int i3 = i2 + 1; i3 < count - 0; i3++)
|
for (int i3 = i2 + 1; i3 < count - 0; i3++)
|
||||||
{
|
{
|
||||||
Vector3 p3 = points[i3];
|
Float3 p3 = points[i3];
|
||||||
|
|
||||||
if (AreCoplanar(p0, p1, p2, p3))
|
if (AreCoplanar(p0, p1, p2, p3))
|
||||||
continue;
|
continue;
|
||||||
@@ -402,7 +402,7 @@ namespace Game
|
|||||||
/// to encompass the point in openSet with the point furthest away
|
/// to encompass the point in openSet with the point furthest away
|
||||||
/// from its face.
|
/// from its face.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void GrowHull(List<Vector3> points)
|
private void GrowHull(List<Float3> points)
|
||||||
{
|
{
|
||||||
Assert.IsTrue(openSetTail >= 0);
|
Assert.IsTrue(openSetTail >= 0);
|
||||||
Assert.IsTrue(openSet[0].Face != INSIDE);
|
Assert.IsTrue(openSet[0].Face != INSIDE);
|
||||||
@@ -451,7 +451,7 @@ namespace Game
|
|||||||
/// only has to visit two (because one of them has already been
|
/// only has to visit two (because one of them has already been
|
||||||
/// visited, the one you came from).
|
/// visited, the one you came from).
|
||||||
/// </summary>
|
/// </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?
|
// TODO should I use epsilon in the PointFaceDistance comparisons?
|
||||||
|
|
||||||
@@ -530,7 +530,7 @@ namespace Game
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Recursively search to find the horizon or lit set.
|
/// Recursively search to find the horizon or lit set.
|
||||||
/// </summary>
|
/// </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(prevFaceIndex >= 0);
|
||||||
Assert.IsTrue(litFaces.Contains(prevFaceIndex));
|
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
|
/// on the other side of the horizon to reflect it's new neighbor from
|
||||||
/// the cone.
|
/// the cone.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ConstructCone(List<Vector3> points, int farthestPoint)
|
private void ConstructCone(List<Float3> points, int farthestPoint)
|
||||||
{
|
{
|
||||||
foreach (int fi in litFaces)
|
foreach (int fi in litFaces)
|
||||||
{
|
{
|
||||||
@@ -642,7 +642,7 @@ namespace Game
|
|||||||
int firstNewFace = faceCount;
|
int firstNewFace = faceCount;
|
||||||
|
|
||||||
// Check for coplanar faces
|
// Check for coplanar faces
|
||||||
/*var firstNormal = new Vector3(0, 0, 0);
|
/*var firstNormal = new Float3(0, 0, 0);
|
||||||
int sameNormals = 1;
|
int sameNormals = 1;
|
||||||
for (int i = 0; i < horizon.Count; i++)
|
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
|
/// doing that to make this loop shorter, a straight for-loop through
|
||||||
/// a list is pretty darn fast. Still, it might be worth trying
|
/// a list is pretty darn fast. Still, it might be worth trying
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ReassignPoints(List<Vector3> points)
|
private void ReassignPoints(List<Float3> points)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= openSetTail; i++)
|
for (int i = 0; i <= openSetTail; i++)
|
||||||
{
|
{
|
||||||
@@ -734,7 +734,7 @@ namespace Game
|
|||||||
if (litFaces.Contains(fp.Face))
|
if (litFaces.Contains(fp.Face))
|
||||||
{
|
{
|
||||||
bool assigned = false;
|
bool assigned = false;
|
||||||
Vector3 point = points[fp.Point];
|
Float3 point = points[fp.Point];
|
||||||
|
|
||||||
foreach (var kvp in faces)
|
foreach (var kvp in faces)
|
||||||
{
|
{
|
||||||
@@ -785,14 +785,14 @@ namespace Game
|
|||||||
/// leaves the normal array empty.
|
/// leaves the normal array empty.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ExportMesh(
|
private void ExportMesh(
|
||||||
List<Vector3> points,
|
List<Float3> points,
|
||||||
bool splitVerts,
|
bool splitVerts,
|
||||||
ref List<Vector3> verts,
|
ref List<Float3> verts,
|
||||||
ref List<int> tris,
|
ref List<int> tris,
|
||||||
ref List<Vector3> normals)
|
ref List<Float3> normals)
|
||||||
{
|
{
|
||||||
if (verts == null)
|
if (verts == null)
|
||||||
verts = new List<Vector3>();
|
verts = new List<Float3>();
|
||||||
else
|
else
|
||||||
verts.Clear();
|
verts.Clear();
|
||||||
|
|
||||||
@@ -802,7 +802,7 @@ namespace Game
|
|||||||
tris.Clear();
|
tris.Clear();
|
||||||
|
|
||||||
if (normals == null)
|
if (normals == null)
|
||||||
normals = new List<Vector3>();
|
normals = new List<Float3>();
|
||||||
else
|
else
|
||||||
normals.Clear();
|
normals.Clear();
|
||||||
|
|
||||||
@@ -858,7 +858,7 @@ namespace Game
|
|||||||
/// the point is above the face)
|
/// the point is above the face)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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);
|
return Dot(face.Normal, point - pointOnFace);
|
||||||
}
|
}
|
||||||
@@ -867,7 +867,7 @@ namespace Game
|
|||||||
/// Calculate normal for triangle
|
/// Calculate normal for triangle
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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;
|
return Cross(v1 - v0, v2 - v0).Normalized;
|
||||||
}
|
}
|
||||||
@@ -876,20 +876,20 @@ namespace Game
|
|||||||
/// Dot product, for convenience.
|
/// Dot product, for convenience.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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;
|
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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
|
/// i wanna test to see if using aggressive inlining makes any
|
||||||
/// difference here.
|
/// difference here.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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.Y * b.Z - a.Z * b.Y,
|
||||||
a.Z * b.X - a.X * b.Z,
|
a.Z * b.X - a.X * b.Z,
|
||||||
a.X * b.Y - a.Y * b.X);
|
a.X * b.Y - a.Y * b.X);
|
||||||
@@ -899,7 +899,7 @@ namespace Game
|
|||||||
/// Check if two points are coincident
|
/// Check if two points are coincident
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private bool AreCoincident(Vector3 a, Vector3 b)
|
private bool AreCoincident(Float3 a, Float3 b)
|
||||||
{
|
{
|
||||||
return (a - b).Length <= EPSILON;
|
return (a - b).Length <= EPSILON;
|
||||||
}
|
}
|
||||||
@@ -908,7 +908,7 @@ namespace Game
|
|||||||
/// Check if three points are collinear
|
/// Check if three points are collinear
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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;
|
return Cross(c - a, c - b).Length <= EPSILON;
|
||||||
}
|
}
|
||||||
@@ -917,17 +917,17 @@ namespace Game
|
|||||||
/// Check if four points are coplanar
|
/// Check if four points are coplanar
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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);
|
Float3 n1 = Cross(c - a, c - b);
|
||||||
Vector3 n2 = Cross(d - a, d - b);
|
Float3 n2 = Cross(d - a, d - b);
|
||||||
|
|
||||||
float m1 = n1.Length;
|
float m1 = n1.Length;
|
||||||
float m2 = n2.Length;
|
float m2 = n2.Length;
|
||||||
|
|
||||||
return m1 <= EPSILON
|
return m1 <= EPSILON
|
||||||
|| m2 <= EPSILON
|
|| m2 <= EPSILON
|
||||||
|| AreCollinear(Vector3.Zero,
|
|| AreCollinear(Float3.Zero,
|
||||||
1.0f / m1 * n1,
|
1.0f / m1 * n1,
|
||||||
1.0f / m2 * n2);
|
1.0f / m2 * n2);
|
||||||
}
|
}
|
||||||
@@ -937,7 +937,7 @@ namespace Game
|
|||||||
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
||||||
/// defined.
|
/// defined.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void VerifyOpenSet(List<Vector3> points)
|
private void VerifyOpenSet(List<Float3> points)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < openSet.Count; i++)
|
for (int i = 0; i < openSet.Count; i++)
|
||||||
if (i > openSetTail)
|
if (i > openSetTail)
|
||||||
@@ -977,7 +977,7 @@ namespace Game
|
|||||||
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
/// sensible state. Conditionally compiled if DEBUG_QUICKHULL if
|
||||||
/// defined.
|
/// defined.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void VerifyFaces(List<Vector3> points)
|
private void VerifyFaces(List<Float3> points)
|
||||||
{
|
{
|
||||||
foreach (var kvp in faces)
|
foreach (var kvp in faces)
|
||||||
{
|
{
|
||||||
@@ -1012,18 +1012,18 @@ namespace Game
|
|||||||
/// actually a convex hull of all the points. Conditionally compiled
|
/// actually a convex hull of all the points. Conditionally compiled
|
||||||
/// if DEBUG_QUICKHULL if defined.
|
/// if DEBUG_QUICKHULL if defined.
|
||||||
/// </summary>
|
/// </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);
|
Assert.IsTrue(tris.Count % 3 == 0);
|
||||||
|
|
||||||
for (int i = 0; i < points.Count; i++)
|
for (int i = 0; i < points.Count; i++)
|
||||||
for (int j = 0; j < tris.Count; j += 3)
|
for (int j = 0; j < tris.Count; j += 3)
|
||||||
{
|
{
|
||||||
Vector3 t0 = verts[tris[j]];
|
Float3 t0 = verts[tris[j]];
|
||||||
Vector3 t1 = verts[tris[j + 1]];
|
Float3 t1 = verts[tris[j + 1]];
|
||||||
Vector3 t2 = verts[tris[j + 2]];
|
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}");
|
//Assert.IsTrue(dot <= EPSILON, $"not convex hull: {dot} > {EPSILON}");
|
||||||
if (!(dot <= EPSILON))
|
if (!(dot <= EPSILON))
|
||||||
Console.PrintError($"not convex hull: {dot} > {EPSILON}");
|
Console.PrintError($"not convex hull: {dot} > {EPSILON}");
|
||||||
@@ -1061,9 +1061,9 @@ namespace Game
|
|||||||
public int Opposite1;
|
public int Opposite1;
|
||||||
public int Opposite2;
|
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;
|
Vertex0 = v0;
|
||||||
Vertex1 = v1;
|
Vertex1 = v1;
|
||||||
|
|||||||
@@ -73,17 +73,17 @@ namespace Game
|
|||||||
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
|
(playerMovement.input as PlayerInputNetwork).currentState.input = inputState;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(Vector3 newPosition)
|
public void SetPosition(Float3 newPosition)
|
||||||
{
|
{
|
||||||
Position = newPosition;
|
Position = newPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRotation(Vector3 eulerAngles)
|
public void SetRotation(Float3 eulerAngles)
|
||||||
{
|
{
|
||||||
playerMovement.ResetRotation(eulerAngles);
|
playerMovement.ResetRotation(eulerAngles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Teleport(Vector3 newPosition, Vector3 eulerAngles)
|
public void Teleport(Float3 newPosition, Float3 eulerAngles)
|
||||||
{
|
{
|
||||||
SetPosition(newPosition);
|
SetPosition(newPosition);
|
||||||
SetRotation(eulerAngles);
|
SetRotation(eulerAngles);
|
||||||
|
|||||||
@@ -13,19 +13,19 @@ namespace Game
|
|||||||
public bool attacking;
|
public bool attacking;
|
||||||
public bool jumping;
|
public bool jumping;
|
||||||
|
|
||||||
public Vector3 verificationPosition;
|
public Float3 verificationPosition;
|
||||||
public Vector3 verificationVelocity;
|
public Float3 verificationVelocity;
|
||||||
public Vector3 verificationViewAngles;
|
public Float3 verificationViewAngles;
|
||||||
public Quaternion verificationOrientation;
|
public Quaternion verificationOrientation;
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct PlayerActorState
|
public struct PlayerActorState
|
||||||
{
|
{
|
||||||
public Vector3 position;
|
public Float3 position;
|
||||||
public Vector3 velocity;
|
public Float3 velocity;
|
||||||
public Quaternion orientation;
|
public Quaternion orientation;
|
||||||
public Vector3 viewAngles; // yaw, pitch, roll
|
public Float3 viewAngles; // yaw, pitch, roll
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ namespace Game
|
|||||||
|
|
||||||
// closest hit
|
// closest hit
|
||||||
public float fraction;
|
public float fraction;
|
||||||
public Vector3 endPosition;
|
public Float3 endPosition;
|
||||||
public Vector3 hitNormal;
|
public Float3 hitNormal;
|
||||||
public Vector3 hitPosition;
|
public Float3 hitPosition;
|
||||||
|
|
||||||
// furthest hit
|
// furthest hit
|
||||||
//public float maxFraction;
|
//public float maxFraction;
|
||||||
//public Vector3 maxHitNormal;
|
//public Float3 maxHitNormal;
|
||||||
//public Vector3 maxEndPosition;
|
//public Float3 maxEndPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Networked]
|
[Networked]
|
||||||
@@ -83,7 +83,7 @@ namespace Game
|
|||||||
public int currentInputFrame;
|
public int currentInputFrame;
|
||||||
private int currentInputFrame2;
|
private int currentInputFrame2;
|
||||||
|
|
||||||
private Vector3 currentVelocity;
|
private Float3 currentVelocity;
|
||||||
public PlayerInput input;
|
public PlayerInput input;
|
||||||
|
|
||||||
//private bool physicsInteractions = false;
|
//private bool physicsInteractions = false;
|
||||||
@@ -114,9 +114,9 @@ namespace Game
|
|||||||
[Tooltip("Base Movement speed")]
|
[Tooltip("Base Movement speed")]
|
||||||
public float MoveSpeed { get; set; } = 320;
|
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;
|
public uint PlayerId = 0;
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
Vector3 horizontalSpeed = currentVelocity;
|
Float3 horizontalSpeed = currentVelocity;
|
||||||
horizontalSpeed.Y = 0f;
|
horizontalSpeed.Y = 0f;
|
||||||
return horizontalSpeed.Length;
|
return horizontalSpeed.Length;
|
||||||
}
|
}
|
||||||
@@ -229,7 +229,7 @@ namespace Game
|
|||||||
ResetRotation(Actor.Orientation.EulerAngles);
|
ResetRotation(Actor.Orientation.EulerAngles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetRotation(Vector3 eulerAngles)
|
public void ResetRotation(Float3 eulerAngles)
|
||||||
{
|
{
|
||||||
viewPitch = eulerAngles.X;
|
viewPitch = eulerAngles.X;
|
||||||
viewYaw = eulerAngles.Y;
|
viewYaw = eulerAngles.Y;
|
||||||
@@ -238,7 +238,7 @@ namespace Game
|
|||||||
viewYawLastFrame = viewYaw;
|
viewYawLastFrame = viewYaw;
|
||||||
viewRollLastFrame = viewRoll;
|
viewRollLastFrame = viewRoll;
|
||||||
|
|
||||||
SetCameraEulerAngles(new Vector3(viewYaw, viewPitch, viewRoll));
|
SetCameraEulerAngles(new Float3(viewYaw, viewPitch, viewRoll));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnUpdate()
|
public override void OnUpdate()
|
||||||
@@ -298,7 +298,7 @@ namespace Game
|
|||||||
// Verify view angles first
|
// Verify view angles first
|
||||||
if (demoDeltasVerify)
|
if (demoDeltasVerify)
|
||||||
{
|
{
|
||||||
Vector3 viewAngles = new Vector3(viewYaw, viewPitch, viewRoll);
|
Float3 viewAngles = new Float3(viewYaw, viewPitch, viewRoll);
|
||||||
float viewAnglesDelta = (viewAngles - inputState.verificationViewAngles).Length;
|
float viewAnglesDelta = (viewAngles - inputState.verificationViewAngles).Length;
|
||||||
if (viewAnglesDelta > 0.00001)
|
if (viewAnglesDelta > 0.00001)
|
||||||
{
|
{
|
||||||
@@ -346,7 +346,7 @@ namespace Game
|
|||||||
position = Actor.Position,
|
position = Actor.Position,
|
||||||
velocity = currentVelocity,
|
velocity = currentVelocity,
|
||||||
orientation = rootActor.Orientation,
|
orientation = rootActor.Orientation,
|
||||||
viewAngles = new Vector3(viewYaw, viewPitch, viewRoll)
|
viewAngles = new Float3(viewYaw, viewPitch, viewRoll)
|
||||||
});
|
});
|
||||||
input.OnEndFrame();
|
input.OnEndFrame();
|
||||||
|
|
||||||
@@ -370,17 +370,17 @@ namespace Game
|
|||||||
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
viewPitch = Mathf.Clamp(viewPitch + yAxis, -90.0f, 90.0f);
|
||||||
viewYaw += xAxis;
|
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
|
// Root orientation must be set first
|
||||||
rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0);
|
rootActor.Orientation = Quaternion.Euler(0, viewAngles.X, 0);
|
||||||
cameraHolder.Orientation = Quaternion.Euler(viewAngles.Y, viewAngles.X, viewAngles.Z);
|
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;
|
Vector3 delta = end - start;
|
||||||
float distance = delta.Length;
|
float distance = delta.Length;
|
||||||
@@ -422,7 +422,7 @@ namespace Game
|
|||||||
return collided;
|
return collided;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SweepPlayerCollider(Vector3 position, out PhysicsColliderActor[] colliders)
|
private bool SweepPlayerCollider(Float3 position, out PhysicsColliderActor[] colliders)
|
||||||
{
|
{
|
||||||
bool collided = false;
|
bool collided = false;
|
||||||
CapsuleCollider capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
CapsuleCollider capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||||
@@ -526,7 +526,7 @@ namespace Game
|
|||||||
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
||||||
|
|
||||||
traceInfo.fraction = 0f;
|
traceInfo.fraction = 0f;
|
||||||
traceInfo.hitNormal = Vector3.Zero;
|
traceInfo.hitNormal = Float3.Zero;
|
||||||
traceInfo.hitPosition = start;
|
traceInfo.hitPosition = start;
|
||||||
traceInfo.endPosition = start;
|
traceInfo.endPosition = start;
|
||||||
traceInfo.startSolid = true;
|
traceInfo.startSolid = true;
|
||||||
@@ -659,11 +659,11 @@ namespace Game
|
|||||||
// step down
|
// step down
|
||||||
Vector3 stepDown = position - stepDelta;
|
Vector3 stepDown = position - stepDelta;
|
||||||
TraceInfo traceDown = TracePlayer(actor, position, stepDown);
|
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
|
// can't step down, slide move like normally
|
||||||
Console.Print("no stepping 1, frac: " + traceDown.fraction + ", dot: " +
|
Console.Print("no stepping 1, frac: " + traceDown.fraction + ", dot: " +
|
||||||
-Vector3.Dot(gravityDirection, traceDown.hitNormal) +
|
-Float3.Dot(gravityDirection, traceDown.hitNormal) +
|
||||||
", norm: " + traceDown.hitNormal);
|
", norm: " + traceDown.hitNormal);
|
||||||
position = slidePosition;
|
position = slidePosition;
|
||||||
velocity = slideVelocity;
|
velocity = slideVelocity;
|
||||||
@@ -678,8 +678,8 @@ namespace Game
|
|||||||
position.Y += collisionMargin;
|
position.Y += collisionMargin;
|
||||||
|
|
||||||
// ??
|
// ??
|
||||||
float d1 = -Vector3.Dot(gravityDirection, position);
|
float d1 = -Float3.Dot(gravityDirection, position);
|
||||||
float d2 = -Vector3.Dot(gravityDirection, originalPosition);
|
float d2 = -Float3.Dot(gravityDirection, originalPosition);
|
||||||
if (d1 < d2)
|
if (d1 < d2)
|
||||||
{
|
{
|
||||||
//Console.Print("no stepping 2, " + d1 + " < " + d2);
|
//Console.Print("no stepping 2, " + d1 + " < " + d2);
|
||||||
@@ -720,7 +720,7 @@ namespace Game
|
|||||||
|
|
||||||
float timeleft = Time.DeltaTime;
|
float timeleft = Time.DeltaTime;
|
||||||
|
|
||||||
var hitNormals = new List<Vector3>();
|
var hitNormals = new List<Float3>();
|
||||||
|
|
||||||
for (int bump = 0; bump < 4; bump++)
|
for (int bump = 0; bump < 4; bump++)
|
||||||
{
|
{
|
||||||
@@ -735,7 +735,7 @@ namespace Game
|
|||||||
|
|
||||||
if (trace.startSolid)
|
if (trace.startSolid)
|
||||||
{
|
{
|
||||||
velocity = Vector3.Zero;
|
velocity = Float3.Zero;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,8 +759,8 @@ namespace Game
|
|||||||
|
|
||||||
// this doesn't seem to do anything, we never have any hitNormals stored here
|
// this doesn't seem to do anything, we never have any hitNormals stored here
|
||||||
bool hitPreviousNormal = false;
|
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
|
// nudge away from the same wall we hit earlier and try again
|
||||||
velocity += hitNormal;
|
velocity += hitNormal;
|
||||||
@@ -776,14 +776,14 @@ namespace Game
|
|||||||
Console.Print("hitNormals: " + hitNormals.Count);
|
Console.Print("hitNormals: " + hitNormals.Count);
|
||||||
|
|
||||||
int plane;
|
int plane;
|
||||||
Vector3 normalMargin = Vector3.Zero;
|
Vector3 normalMargin = Float3.Zero;
|
||||||
for (plane = 0; plane < hitNormals.Count; plane++)
|
for (plane = 0; plane < hitNormals.Count; plane++)
|
||||||
{
|
{
|
||||||
Vector3 normal = hitNormals[plane];
|
Vector3 normal = hitNormals[plane];
|
||||||
|
|
||||||
// clip velocity
|
// clip velocity
|
||||||
velocity -= normal * Vector3.Dot(velocity, normal);
|
velocity -= normal * Float3.Dot(velocity, normal);
|
||||||
//velocity = Vector3.ProjectOnPlane(velocity, normal);
|
//velocity = Float3.ProjectOnPlane(velocity, normal);
|
||||||
|
|
||||||
//traceOffset = normal * 1f;
|
//traceOffset = normal * 1f;
|
||||||
normalMargin += normal;
|
normalMargin += normal;
|
||||||
@@ -795,7 +795,7 @@ namespace Game
|
|||||||
if (plane == plane2)
|
if (plane == plane2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Vector3.Dot(velocity, hitNormals[plane2]) < 0f)
|
if (Float3.Dot(velocity, hitNormals[plane2]) < 0f)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,22 +811,22 @@ namespace Game
|
|||||||
{
|
{
|
||||||
if (hitNormals.Count == 2)
|
if (hitNormals.Count == 2)
|
||||||
{
|
{
|
||||||
Vector3 dir = Vector3.Cross(hitNormals[0], hitNormals[1]);
|
Vector3 dir = Float3.Cross(hitNormals[0], hitNormals[1]);
|
||||||
//dir.Normalize();
|
//dir.Normalize();
|
||||||
float dist = Vector3.Dot(dir, velocity);
|
float dist = Float3.Dot(dir, velocity);
|
||||||
velocity = dist * dir;
|
velocity = dist * dir;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
velocity = Vector3.Zero;
|
velocity = Float3.Zero;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevents bouncing against the wall
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -839,13 +839,13 @@ namespace Game
|
|||||||
Transform rootTrans = rootActor.Transform;
|
Transform rootTrans = rootActor.Transform;
|
||||||
|
|
||||||
Vector3 inputDirection =
|
Vector3 inputDirection =
|
||||||
new Vector3(inputState.moveRight, 0.0f, inputState.moveForward);
|
new Float3(inputState.moveRight, 0.0f, inputState.moveForward);
|
||||||
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
|
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||||
|
|
||||||
Vector3 position = rigidBody.Position;
|
Vector3 position = rigidBody.Position;
|
||||||
Vector3 velocity = currentVelocity; //rigidBody.LinearVelocity;
|
Vector3 velocity = currentVelocity; //rigidBody.LinearVelocity;
|
||||||
|
|
||||||
Vector3 wishVelocity = Vector3.Zero;
|
Vector3 wishVelocity = Float3.Zero;
|
||||||
if (!inputDirection.IsZero)
|
if (!inputDirection.IsZero)
|
||||||
wishVelocity = moveDirection.Normalized * MoveSpeed;
|
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);
|
Vector3 groundDelta = Gravity.Normalized; //Gravity.Normalized * (collisionMargin * 2);
|
||||||
//if (velocity.Y < 0f)
|
//if (velocity.Y < 0f)
|
||||||
@@ -919,13 +919,13 @@ namespace Game
|
|||||||
//Console.PrintDebug(1, true, "startSolid: " + traceGround.startSolid);
|
//Console.PrintDebug(1, true, "startSolid: " + traceGround.startSolid);
|
||||||
|
|
||||||
if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
||||||
-Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)
|
-Float3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)
|
||||||
{
|
{
|
||||||
// clip velocity
|
// clip velocity
|
||||||
|
|
||||||
Vector3 bounce = groundDelta;
|
Vector3 bounce = groundDelta;
|
||||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
|
||||||
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
|
float backoff = Float3.Dot(bounce, traceGround.hitNormal) * 2f;
|
||||||
bounce -= traceGround.hitNormal * backoff;
|
bounce -= traceGround.hitNormal * backoff;
|
||||||
//velocity = velocityProjected;
|
//velocity = velocityProjected;
|
||||||
|
|
||||||
@@ -939,7 +939,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
|
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
|
// falling or sliding down a slope
|
||||||
onGround = false;
|
onGround = false;
|
||||||
//Console.PrintDebug(1, true, "fall or slide");
|
//Console.PrintDebug(1, true, "fall or slide");
|
||||||
@@ -963,26 +963,26 @@ namespace Game
|
|||||||
jumpVel += jumpBoostVelocity;
|
jumpVel += jumpBoostVelocity;
|
||||||
|
|
||||||
// Reset velocity from gravity
|
// Reset velocity from gravity
|
||||||
if (-Vector3.Dot(Gravity.Normalized, velocity) < 0 &&
|
if (-Float3.Dot(Gravity.Normalized, velocity) < 0 &&
|
||||||
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
|
Float3.Dot(velocity, traceGround.hitNormal) < -0.1)
|
||||||
{
|
{
|
||||||
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
|
velocity = Float3.ProjectOnPlane(velocity, traceGround.hitNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jumpAdditive)
|
if (jumpAdditive)
|
||||||
{
|
{
|
||||||
velocity += Vector3.Up * jumpVel;
|
velocity += Float3.Up * jumpVel;
|
||||||
if (velocity.Y < jumpVel)
|
if (velocity.Y < jumpVel)
|
||||||
velocity.Y = jumpVel;
|
velocity.Y = jumpVel;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
velocity = Vector3.Up * jumpVel;
|
velocity = Float3.Up * jumpVel;
|
||||||
|
|
||||||
onGround = false;
|
onGround = false;
|
||||||
|
|
||||||
// Allow stairs to eat the first jump to allow easy stair jumps
|
// Allow stairs to eat the first jump to allow easy stair jumps
|
||||||
if (jumpStairBehavior && jumpBoostMaxJumps >= 2 && numJumps == 0 &&
|
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
|
// Try stepping into stairs without vertical velocity
|
||||||
Vector3 stairCheckPosition = position;
|
Vector3 stairCheckPosition = position;
|
||||||
@@ -1007,7 +1007,7 @@ namespace Game
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnLanded(Vector3 landingVelocity, bool hardLanding)
|
private void OnLanded(Float3 landingVelocity, bool hardLanding)
|
||||||
{
|
{
|
||||||
if (!predicting)
|
if (!predicting)
|
||||||
PlayJumpLandSound(true, hardLanding);
|
PlayJumpLandSound(true, hardLanding);
|
||||||
@@ -1020,8 +1020,8 @@ namespace Game
|
|||||||
|
|
||||||
float volume1 = 0.8f;
|
float volume1 = 0.8f;
|
||||||
float volume2 = volume1;
|
float volume2 = volume1;
|
||||||
Vector2 pitchRange = new Vector2(0.9f, 1.05f);
|
Float2 pitchRange = new Float2(0.9f, 1.05f);
|
||||||
Vector2 secondStepDelayRange = new Vector2(0.031f, 0.059f);
|
Float2 secondStepDelayRange = new Float2(0.031f, 0.059f);
|
||||||
|
|
||||||
if (landing)
|
if (landing)
|
||||||
volume2 *= 0.6f;
|
volume2 *= 0.6f;
|
||||||
@@ -1064,7 +1064,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
// Q2+ air acceleration
|
// Q2+ air acceleration
|
||||||
float accel = airAcceleration;
|
float accel = airAcceleration;
|
||||||
if (Vector3.Dot(velocity, wishDir) < 0)
|
if (Float3.Dot(velocity, wishDir) < 0)
|
||||||
accel = airStopAcceleration;
|
accel = airStopAcceleration;
|
||||||
|
|
||||||
if (airStrafeAcceleration != 0 && Mathf.Abs(wishVelocity.X) > 0 && wishVelocity.Y == 0)
|
if (airStrafeAcceleration != 0 && Mathf.Abs(wishVelocity.X) > 0 && wishVelocity.Y == 0)
|
||||||
@@ -1101,7 +1101,7 @@ namespace Game
|
|||||||
if (wishspeed > maxWishspeed)
|
if (wishspeed > maxWishspeed)
|
||||||
wishspeed = maxWishspeed;
|
wishspeed = maxWishspeed;
|
||||||
|
|
||||||
float currentSpeed = Vector3.Dot(velocity, wishDir);
|
float currentSpeed = Float3.Dot(velocity, wishDir);
|
||||||
float addSpeed = wishspeed - currentSpeed;
|
float addSpeed = wishspeed - currentSpeed;
|
||||||
if (addSpeed <= 0f)
|
if (addSpeed <= 0f)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ namespace Game
|
|||||||
|
|
||||||
// closest hit
|
// closest hit
|
||||||
public float fraction;
|
public float fraction;
|
||||||
public Vector3 endPosition;
|
public Float3 endPosition;
|
||||||
public Vector3 hitNormal;
|
public Float3 hitNormal;
|
||||||
public Vector3 hitPosition;
|
public Float3 hitPosition;
|
||||||
|
|
||||||
// furthest hit
|
// furthest hit
|
||||||
//public float maxFraction;
|
//public float maxFraction;
|
||||||
//public Vector3 maxHitNormal;
|
//public Float3 maxHitNormal;
|
||||||
//public Vector3 maxEndPosition;
|
//public Float3 maxEndPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlayerMovement_NK : Script
|
public class PlayerMovement_NK : Script
|
||||||
@@ -96,7 +96,7 @@ namespace Game
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position">Position</param>
|
/// <param name="position">Position</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private Collider[] TracePlayer(Vector3 position, float tolerance = 0.0f)
|
private Collider[] TracePlayer(Float3 position, float tolerance = 0.0f)
|
||||||
{
|
{
|
||||||
Collider[] colliders = null;
|
Collider[] colliders = null;
|
||||||
|
|
||||||
@@ -159,13 +159,13 @@ namespace Game
|
|||||||
/// <param name="start">Start position</param>
|
/// <param name="start">Start position</param>
|
||||||
/// <param name="end">End position</param>
|
/// <param name="end">End position</param>
|
||||||
/// <returns></returns>
|
/// <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();
|
TraceInfo traceInfo = new TraceInfo();
|
||||||
|
|
||||||
Vector3 delta = end - start;
|
Float3 delta = end - start;
|
||||||
float maxDistance = delta.Length;
|
float maxDistance = delta.Length;
|
||||||
Vector3 direction = delta.Normalized;
|
Float3 direction = delta.Normalized;
|
||||||
|
|
||||||
bool collided = false;
|
bool collided = false;
|
||||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||||
@@ -289,7 +289,7 @@ namespace Game
|
|||||||
|
|
||||||
float timeleft = Time.DeltaTime;
|
float timeleft = Time.DeltaTime;
|
||||||
|
|
||||||
List<Vector3> hitNormals = new List<Vector3>();
|
List<Float3> hitNormals = new List<Float3>();
|
||||||
|
|
||||||
for (int bump = 0; bump < 4; bump++)
|
for (int bump = 0; bump < 4; bump++)
|
||||||
{
|
{
|
||||||
@@ -304,7 +304,7 @@ namespace Game
|
|||||||
|
|
||||||
if (trace.startSolid)
|
if (trace.startSolid)
|
||||||
{
|
{
|
||||||
velocity = Vector3.Zero;
|
velocity = Float3.Zero;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,9 +335,9 @@ namespace Game
|
|||||||
|
|
||||||
// this doesn't seem to do anything, we never have any hitNormals stored here
|
// this doesn't seem to do anything, we never have any hitNormals stored here
|
||||||
bool hitPreviousNormal = false;
|
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
|
// nudge away from the same wall we hit earlier and try again
|
||||||
velocity += hitNormal;
|
velocity += hitNormal;
|
||||||
@@ -353,14 +353,14 @@ namespace Game
|
|||||||
Console.Print("hitNormals: " + hitNormals.Count);
|
Console.Print("hitNormals: " + hitNormals.Count);
|
||||||
|
|
||||||
int plane;
|
int plane;
|
||||||
Vector3 normalMargin = Vector3.Zero;
|
Vector3 normalMargin = Float3.Zero;
|
||||||
for (plane = 0; plane < hitNormals.Count; plane++)
|
for (plane = 0; plane < hitNormals.Count; plane++)
|
||||||
{
|
{
|
||||||
Vector3 normal = hitNormals[plane];
|
Vector3 normal = hitNormals[plane];
|
||||||
|
|
||||||
// clip velocity
|
// clip velocity
|
||||||
velocity -= normal * Vector3.Dot(velocity, normal);
|
velocity -= normal * Float3.Dot(velocity, normal);
|
||||||
//velocity = Vector3.ProjectOnPlane(velocity, normal);
|
//velocity = Float3.ProjectOnPlane(velocity, normal);
|
||||||
|
|
||||||
//traceOffset = normal * 1f;
|
//traceOffset = normal * 1f;
|
||||||
normalMargin += normal;
|
normalMargin += normal;
|
||||||
@@ -372,7 +372,7 @@ namespace Game
|
|||||||
if (plane == plane2)
|
if (plane == plane2)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Vector3.Dot(velocity, hitNormals[plane2]) < 0f)
|
if (Float3.Dot(velocity, hitNormals[plane2]) < 0f)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,14 +387,14 @@ namespace Game
|
|||||||
{
|
{
|
||||||
if (hitNormals.Count == 2)
|
if (hitNormals.Count == 2)
|
||||||
{
|
{
|
||||||
Vector3 dir = Vector3.Cross(hitNormals[0], hitNormals[1]);
|
Vector3 dir = Float3.Cross(hitNormals[0], hitNormals[1]);
|
||||||
//dir.Normalize();
|
//dir.Normalize();
|
||||||
float dist = Vector3.Dot(dir, velocity);
|
float dist = Float3.Dot(dir, velocity);
|
||||||
velocity = dist * dir;
|
velocity = dist * dir;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
velocity = Vector3.Zero;
|
velocity = Float3.Zero;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,17 +406,17 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prevents bouncing against the wall
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Vector3 wishVelocity = Vector3.Zero;
|
//Vector3 wishVelocity = Float3.Zero;
|
||||||
//Vector3 gravityVelocity = Vector3.Zero;
|
//Vector3 gravityVelocity = Float3.Zero;
|
||||||
//Vector3 currentVelocity = Vector3.Zero;
|
//Vector3 currentVelocity = Float3.Zero;
|
||||||
private bool onGround = false;
|
private bool onGround = false;
|
||||||
|
|
||||||
private const float friction = 4f;
|
private const float friction = 4f;
|
||||||
@@ -446,13 +446,13 @@ namespace Game
|
|||||||
Transform rootTrans = rootActor.Transform;
|
Transform rootTrans = rootActor.Transform;
|
||||||
|
|
||||||
Vector3 inputDirection =
|
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 moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||||
|
|
||||||
//Vector3 position = rigidBody.Position;
|
//Vector3 position = rigidBody.Position;
|
||||||
Vector3 velocity = rigidBody.LinearVelocity;//currentVelocity;
|
Vector3 velocity = rigidBody.LinearVelocity;//currentVelocity;
|
||||||
|
|
||||||
Vector3 wishVelocity = Vector3.Zero;
|
Vector3 wishVelocity = Float3.Zero;
|
||||||
if (!inputDirection.IsZero)
|
if (!inputDirection.IsZero)
|
||||||
wishVelocity = moveDirection.Normalized * MoveSpeed;
|
wishVelocity = moveDirection.Normalized * MoveSpeed;
|
||||||
|
|
||||||
@@ -473,8 +473,8 @@ namespace Game
|
|||||||
// clip velocity
|
// clip velocity
|
||||||
Vector3 bounce = -groundDelta;
|
Vector3 bounce = -groundDelta;
|
||||||
Vector3 bounceDir = -groundDelta.Normalized;//traceGround.hitNormal;
|
Vector3 bounceDir = -groundDelta.Normalized;//traceGround.hitNormal;
|
||||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
|
||||||
float backoff = Vector3.Dot(bounce, bounceDir) * 2f;
|
float backoff = Float3.Dot(bounce, bounceDir) * 2f;
|
||||||
bounce -= bounceDir * backoff;
|
bounce -= bounceDir * backoff;
|
||||||
//velocity = velocityProjected;
|
//velocity = velocityProjected;
|
||||||
|
|
||||||
@@ -489,13 +489,13 @@ namespace Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
/*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
|
// slope
|
||||||
// clip velocity
|
// clip velocity
|
||||||
Vector3 bounce = groundDelta;
|
Vector3 bounce = groundDelta;
|
||||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
//Vector3 velocityProjected = Float3.ProjectOnPlane(velocity, normal);
|
||||||
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
|
float backoff = Float3.Dot(bounce, traceGround.hitNormal) * 2f;
|
||||||
bounce -= traceGround.hitNormal * backoff;
|
bounce -= traceGround.hitNormal * backoff;
|
||||||
//velocity = velocityProjected;
|
//velocity = velocityProjected;
|
||||||
|
|
||||||
@@ -507,9 +507,9 @@ namespace Game
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
//if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
|
//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)
|
if (traceGround.fraction >= 1f)
|
||||||
rampDot = 1f;
|
rampDot = 1f;
|
||||||
else if (traceGround.hitNormal.IsZero)
|
else if (traceGround.hitNormal.IsZero)
|
||||||
@@ -517,7 +517,7 @@ namespace Game
|
|||||||
|
|
||||||
if (traceGround.fraction >= 1f || rampDot < 0.7f)
|
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
|
// falling or sliding down a slope
|
||||||
onGround = false;
|
onGround = false;
|
||||||
}
|
}
|
||||||
@@ -532,7 +532,7 @@ namespace Game
|
|||||||
|
|
||||||
if (traceGround.fraction == 0f && closestDist != 0f)
|
if (traceGround.fraction == 0f && closestDist != 0f)
|
||||||
Console.Print("minteresting");
|
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;
|
onGround = true;//!traceGround.startSolid;
|
||||||
//velocity.Y = 0f;
|
//velocity.Y = 0f;
|
||||||
|
|
||||||
@@ -619,7 +619,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
foreach (var hitInfo in traceGround.hitInfos)
|
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
|
if (-dot >= 0.7) //~45deg slope
|
||||||
{
|
{
|
||||||
//Console.Print("d: " + hitInfo.Distance);
|
//Console.Print("d: " + hitInfo.Distance);
|
||||||
@@ -650,7 +650,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
jumped = true;
|
jumped = true;
|
||||||
|
|
||||||
velocity += Vector3.Up * jumpVelocity;
|
velocity += Float3.Up * jumpVelocity;
|
||||||
onGround = false;
|
onGround = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -730,7 +730,7 @@ namespace Game
|
|||||||
if (wishspeed > maxWishspeed)
|
if (wishspeed > maxWishspeed)
|
||||||
wishspeed = maxWishspeed;
|
wishspeed = maxWishspeed;
|
||||||
|
|
||||||
float currentSpeed = Vector3.Dot(velocity, wishDir);
|
float currentSpeed = Float3.Dot(velocity, wishDir);
|
||||||
float addSpeed = wishspeed - currentSpeed;
|
float addSpeed = wishspeed - currentSpeed;
|
||||||
if (addSpeed <= 0f)
|
if (addSpeed <= 0f)
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user