You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 14:46:29 +09:00
Removed XNA extensions as a project since it doesn't build. Kept actual code file so it can be used manually.
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren XNA Extensions", "Lidgren XNA Extensions\Lidgren XNA Extensions.csproj", "{2B661ABD-63A8-4916-A94B-034729231271}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2B661ABD-63A8-4916-A94B-034729231271}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B661ABD-63A8-4916-A94B-034729231271}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B661ABD-63A8-4916-A94B-034729231271}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B661ABD-63A8-4916-A94B-034729231271}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -1,97 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{2B661ABD-63A8-4916-A94B-034729231271}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Lidgren.Network.Xna</RootNamespace>
|
||||
<AssemblyName>Lidgren.Network.Xna</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="XNAExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Lidgren XNA Extensions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("Lidgren XNA Extensions")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f9189a05-8455-4b82-b114-a806db01c367")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,296 +1,296 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics.PackedVector;
|
||||
|
||||
namespace Lidgren.Network.Xna
|
||||
{
|
||||
public static class XNAExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Write a Point
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Point value)
|
||||
{
|
||||
message.Write(value.X);
|
||||
message.Write(value.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a Point
|
||||
/// </summary>
|
||||
public static Point ReadPoint(this NetBuffer message)
|
||||
{
|
||||
return new Point(message.ReadInt32(), message.ReadInt32());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a Single with half precision (16 bits)
|
||||
/// </summary>
|
||||
public static void WriteHalfPrecision(this NetBuffer message, float value)
|
||||
{
|
||||
message.Write(new HalfSingle(value).PackedValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a half precision Single written using WriteHalfPrecision(float)
|
||||
/// </summary>
|
||||
public static float ReadHalfPrecisionSingle(this NetBuffer message)
|
||||
{
|
||||
HalfSingle h = new HalfSingle();
|
||||
h.PackedValue = message.ReadUInt16();
|
||||
return h.ToSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector2
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector2 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector2
|
||||
/// </summary>
|
||||
public static Vector2 ReadVector2(this NetBuffer message)
|
||||
{
|
||||
Vector2 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector3 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
message.Write(vector.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3 at half precision
|
||||
/// </summary>
|
||||
public static void WriteHalfPrecision(this NetBuffer message, Vector3 vector)
|
||||
{
|
||||
message.Write(new HalfSingle(vector.X).PackedValue);
|
||||
message.Write(new HalfSingle(vector.Y).PackedValue);
|
||||
message.Write(new HalfSingle(vector.Z).PackedValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector3
|
||||
/// </summary>
|
||||
public static Vector3 ReadVector3(this NetBuffer message)
|
||||
{
|
||||
Vector3 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
retval.Z = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3 at half precision
|
||||
/// </summary>
|
||||
public static Vector3 ReadHalfPrecisionVector3(this NetBuffer message)
|
||||
{
|
||||
HalfSingle hx = new HalfSingle();
|
||||
hx.PackedValue = message.ReadUInt16();
|
||||
|
||||
HalfSingle hy = new HalfSingle();
|
||||
hy.PackedValue = message.ReadUInt16();
|
||||
|
||||
HalfSingle hz = new HalfSingle();
|
||||
hz.PackedValue = message.ReadUInt16();
|
||||
|
||||
Vector3 retval;
|
||||
retval.X = hx.ToSingle();
|
||||
retval.Y = hy.ToSingle();
|
||||
retval.Z = hz.ToSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector4
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector4 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
message.Write(vector.Z);
|
||||
message.Write(vector.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector4
|
||||
/// </summary>
|
||||
public static Vector4 ReadVector4(this NetBuffer message)
|
||||
{
|
||||
Vector4 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
retval.Z = message.ReadSingle();
|
||||
retval.W = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes a unit vector (ie. a vector of length 1.0, for example a surface normal)
|
||||
/// using specified number of bits
|
||||
/// </summary>
|
||||
public static void WriteUnitVector3(this NetBuffer message, Vector3 unitVector, int numberOfBits)
|
||||
{
|
||||
float x = unitVector.X;
|
||||
float y = unitVector.Y;
|
||||
float z = unitVector.Z;
|
||||
double invPi = 1.0 / Math.PI;
|
||||
float phi = (float)(Math.Atan2(x, y) * invPi);
|
||||
float theta = (float)(Math.Atan2(z, Math.Sqrt(x * x + y * y)) * (invPi * 2));
|
||||
|
||||
int halfBits = numberOfBits / 2;
|
||||
message.WriteSignedSingle(phi, halfBits);
|
||||
message.WriteSignedSingle(theta, numberOfBits - halfBits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a unit vector written using WriteUnitVector3(numberOfBits)
|
||||
/// </summary>
|
||||
public static Vector3 ReadUnitVector3(this NetBuffer message, int numberOfBits)
|
||||
{
|
||||
int halfBits = numberOfBits / 2;
|
||||
float phi = message.ReadSignedSingle(halfBits) * (float)Math.PI;
|
||||
float theta = message.ReadSignedSingle(numberOfBits - halfBits) * (float)(Math.PI * 0.5);
|
||||
|
||||
Vector3 retval;
|
||||
retval.X = (float)(Math.Sin(phi) * Math.Cos(theta));
|
||||
retval.Y = (float)(Math.Cos(phi) * Math.Cos(theta));
|
||||
retval.Z = (float)Math.Sin(theta);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a unit quaternion using the specified number of bits per element
|
||||
/// for a total of 4 x bitsPerElements bits. Suggested value is 8 to 24 bits.
|
||||
/// </summary>
|
||||
public static void WriteRotation(this NetBuffer message, Quaternion quaternion, int bitsPerElement)
|
||||
{
|
||||
if (quaternion.X > 1.0f)
|
||||
quaternion.X = 1.0f;
|
||||
if (quaternion.Y > 1.0f)
|
||||
quaternion.Y = 1.0f;
|
||||
if (quaternion.Z > 1.0f)
|
||||
quaternion.Z = 1.0f;
|
||||
if (quaternion.W > 1.0f)
|
||||
quaternion.W = 1.0f;
|
||||
if (quaternion.X < -1.0f)
|
||||
quaternion.X = -1.0f;
|
||||
if (quaternion.Y < -1.0f)
|
||||
quaternion.Y = -1.0f;
|
||||
if (quaternion.Z < -1.0f)
|
||||
quaternion.Z = -1.0f;
|
||||
if (quaternion.W < -1.0f)
|
||||
quaternion.W = -1.0f;
|
||||
|
||||
message.WriteSignedSingle(quaternion.X, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.Y, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.Z, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.W, bitsPerElement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a unit quaternion written using WriteRotation(... ,bitsPerElement)
|
||||
/// </summary>
|
||||
public static Quaternion ReadRotation(this NetBuffer message, int bitsPerElement)
|
||||
{
|
||||
Quaternion retval;
|
||||
retval.X = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.Y = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.Z = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.W = message.ReadSignedSingle(bitsPerElement);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an orthonormal matrix (rotation, translation but not scaling or projection)
|
||||
/// </summary>
|
||||
public static void WriteMatrix(this NetBuffer message, ref Matrix matrix)
|
||||
{
|
||||
Quaternion rot = Quaternion.CreateFromRotationMatrix(matrix);
|
||||
WriteRotation(message, rot, 24);
|
||||
message.Write(matrix.M41);
|
||||
message.Write(matrix.M42);
|
||||
message.Write(matrix.M43);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an orthonormal matrix (rotation, translation but no scaling or projection)
|
||||
/// </summary>
|
||||
public static void WriteMatrix(this NetBuffer message, Matrix matrix)
|
||||
{
|
||||
Quaternion rot = Quaternion.CreateFromRotationMatrix(matrix);
|
||||
WriteRotation(message, rot, 24);
|
||||
message.Write(matrix.M41);
|
||||
message.Write(matrix.M42);
|
||||
message.Write(matrix.M43);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a matrix written using WriteMatrix()
|
||||
/// </summary>
|
||||
public static Matrix ReadMatrix(this NetBuffer message)
|
||||
{
|
||||
Quaternion rot = ReadRotation(message, 24);
|
||||
Matrix retval = Matrix.CreateFromQuaternion(rot);
|
||||
retval.M41 = message.ReadSingle();
|
||||
retval.M42 = message.ReadSingle();
|
||||
retval.M43 = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a matrix written using WriteMatrix()
|
||||
/// </summary>
|
||||
public static void ReadMatrix(this NetBuffer message, ref Matrix destination)
|
||||
{
|
||||
Quaternion rot = ReadRotation(message, 24);
|
||||
destination = Matrix.CreateFromQuaternion(rot);
|
||||
destination.M41 = message.ReadSingle();
|
||||
destination.M42 = message.ReadSingle();
|
||||
destination.M43 = message.ReadSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a bounding sphere
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, BoundingSphere bounds)
|
||||
{
|
||||
message.Write(bounds.Center.X);
|
||||
message.Write(bounds.Center.Y);
|
||||
message.Write(bounds.Center.Z);
|
||||
message.Write(bounds.Radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a bounding sphere written using Write(message, BoundingSphere)
|
||||
/// </summary>
|
||||
public static BoundingSphere ReadBoundingSphere(this NetBuffer message)
|
||||
{
|
||||
BoundingSphere retval;
|
||||
retval.Center.X = message.ReadSingle();
|
||||
retval.Center.Y = message.ReadSingle();
|
||||
retval.Center.Z = message.ReadSingle();
|
||||
retval.Radius = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics.PackedVector;
|
||||
|
||||
namespace Lidgren.Network.Xna
|
||||
{
|
||||
public static class XNAExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Write a Point
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Point value)
|
||||
{
|
||||
message.Write(value.X);
|
||||
message.Write(value.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a Point
|
||||
/// </summary>
|
||||
public static Point ReadPoint(this NetBuffer message)
|
||||
{
|
||||
return new Point(message.ReadInt32(), message.ReadInt32());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a Single with half precision (16 bits)
|
||||
/// </summary>
|
||||
public static void WriteHalfPrecision(this NetBuffer message, float value)
|
||||
{
|
||||
message.Write(new HalfSingle(value).PackedValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a half precision Single written using WriteHalfPrecision(float)
|
||||
/// </summary>
|
||||
public static float ReadHalfPrecisionSingle(this NetBuffer message)
|
||||
{
|
||||
HalfSingle h = new HalfSingle();
|
||||
h.PackedValue = message.ReadUInt16();
|
||||
return h.ToSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector2
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector2 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector2
|
||||
/// </summary>
|
||||
public static Vector2 ReadVector2(this NetBuffer message)
|
||||
{
|
||||
Vector2 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector3 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
message.Write(vector.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3 at half precision
|
||||
/// </summary>
|
||||
public static void WriteHalfPrecision(this NetBuffer message, Vector3 vector)
|
||||
{
|
||||
message.Write(new HalfSingle(vector.X).PackedValue);
|
||||
message.Write(new HalfSingle(vector.Y).PackedValue);
|
||||
message.Write(new HalfSingle(vector.Z).PackedValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector3
|
||||
/// </summary>
|
||||
public static Vector3 ReadVector3(this NetBuffer message)
|
||||
{
|
||||
Vector3 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
retval.Z = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector3 at half precision
|
||||
/// </summary>
|
||||
public static Vector3 ReadHalfPrecisionVector3(this NetBuffer message)
|
||||
{
|
||||
HalfSingle hx = new HalfSingle();
|
||||
hx.PackedValue = message.ReadUInt16();
|
||||
|
||||
HalfSingle hy = new HalfSingle();
|
||||
hy.PackedValue = message.ReadUInt16();
|
||||
|
||||
HalfSingle hz = new HalfSingle();
|
||||
hz.PackedValue = message.ReadUInt16();
|
||||
|
||||
Vector3 retval;
|
||||
retval.X = hx.ToSingle();
|
||||
retval.Y = hy.ToSingle();
|
||||
retval.Z = hz.ToSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a Vector4
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, Vector4 vector)
|
||||
{
|
||||
message.Write(vector.X);
|
||||
message.Write(vector.Y);
|
||||
message.Write(vector.Z);
|
||||
message.Write(vector.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Vector4
|
||||
/// </summary>
|
||||
public static Vector4 ReadVector4(this NetBuffer message)
|
||||
{
|
||||
Vector4 retval;
|
||||
retval.X = message.ReadSingle();
|
||||
retval.Y = message.ReadSingle();
|
||||
retval.Z = message.ReadSingle();
|
||||
retval.W = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes a unit vector (ie. a vector of length 1.0, for example a surface normal)
|
||||
/// using specified number of bits
|
||||
/// </summary>
|
||||
public static void WriteUnitVector3(this NetBuffer message, Vector3 unitVector, int numberOfBits)
|
||||
{
|
||||
float x = unitVector.X;
|
||||
float y = unitVector.Y;
|
||||
float z = unitVector.Z;
|
||||
double invPi = 1.0 / Math.PI;
|
||||
float phi = (float)(Math.Atan2(x, y) * invPi);
|
||||
float theta = (float)(Math.Atan2(z, Math.Sqrt(x * x + y * y)) * (invPi * 2));
|
||||
|
||||
int halfBits = numberOfBits / 2;
|
||||
message.WriteSignedSingle(phi, halfBits);
|
||||
message.WriteSignedSingle(theta, numberOfBits - halfBits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a unit vector written using WriteUnitVector3(numberOfBits)
|
||||
/// </summary>
|
||||
public static Vector3 ReadUnitVector3(this NetBuffer message, int numberOfBits)
|
||||
{
|
||||
int halfBits = numberOfBits / 2;
|
||||
float phi = message.ReadSignedSingle(halfBits) * (float)Math.PI;
|
||||
float theta = message.ReadSignedSingle(numberOfBits - halfBits) * (float)(Math.PI * 0.5);
|
||||
|
||||
Vector3 retval;
|
||||
retval.X = (float)(Math.Sin(phi) * Math.Cos(theta));
|
||||
retval.Y = (float)(Math.Cos(phi) * Math.Cos(theta));
|
||||
retval.Z = (float)Math.Sin(theta);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a unit quaternion using the specified number of bits per element
|
||||
/// for a total of 4 x bitsPerElements bits. Suggested value is 8 to 24 bits.
|
||||
/// </summary>
|
||||
public static void WriteRotation(this NetBuffer message, Quaternion quaternion, int bitsPerElement)
|
||||
{
|
||||
if (quaternion.X > 1.0f)
|
||||
quaternion.X = 1.0f;
|
||||
if (quaternion.Y > 1.0f)
|
||||
quaternion.Y = 1.0f;
|
||||
if (quaternion.Z > 1.0f)
|
||||
quaternion.Z = 1.0f;
|
||||
if (quaternion.W > 1.0f)
|
||||
quaternion.W = 1.0f;
|
||||
if (quaternion.X < -1.0f)
|
||||
quaternion.X = -1.0f;
|
||||
if (quaternion.Y < -1.0f)
|
||||
quaternion.Y = -1.0f;
|
||||
if (quaternion.Z < -1.0f)
|
||||
quaternion.Z = -1.0f;
|
||||
if (quaternion.W < -1.0f)
|
||||
quaternion.W = -1.0f;
|
||||
|
||||
message.WriteSignedSingle(quaternion.X, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.Y, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.Z, bitsPerElement);
|
||||
message.WriteSignedSingle(quaternion.W, bitsPerElement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a unit quaternion written using WriteRotation(... ,bitsPerElement)
|
||||
/// </summary>
|
||||
public static Quaternion ReadRotation(this NetBuffer message, int bitsPerElement)
|
||||
{
|
||||
Quaternion retval;
|
||||
retval.X = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.Y = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.Z = message.ReadSignedSingle(bitsPerElement);
|
||||
retval.W = message.ReadSignedSingle(bitsPerElement);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an orthonormal matrix (rotation, translation but not scaling or projection)
|
||||
/// </summary>
|
||||
public static void WriteMatrix(this NetBuffer message, ref Matrix matrix)
|
||||
{
|
||||
Quaternion rot = Quaternion.CreateFromRotationMatrix(matrix);
|
||||
WriteRotation(message, rot, 24);
|
||||
message.Write(matrix.M41);
|
||||
message.Write(matrix.M42);
|
||||
message.Write(matrix.M43);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an orthonormal matrix (rotation, translation but no scaling or projection)
|
||||
/// </summary>
|
||||
public static void WriteMatrix(this NetBuffer message, Matrix matrix)
|
||||
{
|
||||
Quaternion rot = Quaternion.CreateFromRotationMatrix(matrix);
|
||||
WriteRotation(message, rot, 24);
|
||||
message.Write(matrix.M41);
|
||||
message.Write(matrix.M42);
|
||||
message.Write(matrix.M43);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a matrix written using WriteMatrix()
|
||||
/// </summary>
|
||||
public static Matrix ReadMatrix(this NetBuffer message)
|
||||
{
|
||||
Quaternion rot = ReadRotation(message, 24);
|
||||
Matrix retval = Matrix.CreateFromQuaternion(rot);
|
||||
retval.M41 = message.ReadSingle();
|
||||
retval.M42 = message.ReadSingle();
|
||||
retval.M43 = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a matrix written using WriteMatrix()
|
||||
/// </summary>
|
||||
public static void ReadMatrix(this NetBuffer message, ref Matrix destination)
|
||||
{
|
||||
Quaternion rot = ReadRotation(message, 24);
|
||||
destination = Matrix.CreateFromQuaternion(rot);
|
||||
destination.M41 = message.ReadSingle();
|
||||
destination.M42 = message.ReadSingle();
|
||||
destination.M43 = message.ReadSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a bounding sphere
|
||||
/// </summary>
|
||||
public static void Write(this NetBuffer message, BoundingSphere bounds)
|
||||
{
|
||||
message.Write(bounds.Center.X);
|
||||
message.Write(bounds.Center.Y);
|
||||
message.Write(bounds.Center.Z);
|
||||
message.Write(bounds.Radius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a bounding sphere written using Write(message, BoundingSphere)
|
||||
/// </summary>
|
||||
public static BoundingSphere ReadBoundingSphere(this NetBuffer message)
|
||||
{
|
||||
BoundingSphere retval;
|
||||
retval.Center.X = message.ReadSingle();
|
||||
retval.Center.Y = message.ReadSingle();
|
||||
retval.Center.Z = message.ReadSingle();
|
||||
retval.Radius = message.ReadSingle();
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user