update module to new version

master
Christopher 2020-01-09 15:54:24 +01:00
parent 514f78e6a1
commit df000afb0d
5 changed files with 1080 additions and 1015 deletions

View File

@ -1,216 +1,217 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>14.0.23107.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D5EA1308-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ApplicationIcon></ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>OpenSim.Modules.Warp3DCachedImageModule</AssemblyName>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<OutputType>Library</OutputType>
<AppDesignerFolder></AppDesignerFolder>
<RootNamespace>OpenSim.Modules.Warp3DCachedImageModule</RootNamespace>
<StartupObject></StartupObject>
<StartArguments></StartArguments>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG;</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn></NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn></NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Axiom.MathLib.dll" >
<Name>Axiom.MathLib.dll</Name>
<HintPath>..\..\bin\Axiom.MathLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="CSJ2K.dll" >
<Name>CSJ2K.dll</Name>
<HintPath>..\..\..\bin\CSJ2K.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HttpServer_OpenSim.dll" >
<Name>HttpServer_OpenSim.dll</Name>
<HintPath>..\..\..\bin\HttpServer_OpenSim.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net.dll" >
<Name>log4net.dll</Name>
<HintPath>..\..\..\bin\log4net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Addins.dll" >
<Name>Mono.Addins.dll</Name>
<HintPath>..\..\..\bin\Mono.Addins.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Nini.dll" >
<Name>Nini.dll</Name>
<HintPath>..\..\..\bin\Nini.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverse.dll" >
<Name>OpenMetaverse.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverse.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverse.StructuredData.dll" >
<Name>OpenMetaverse.StructuredData.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverse.StructuredData.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverseTypes.dll" >
<Name>OpenMetaverseTypes.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverseTypes.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Region.PhysicsModules.SharedBase.dll" >
<Name>OpenSim.Region.PhysicsModules.SharedBase.dll</Name>
<HintPath>..\..\..\bin\OpenSim.Region.PhysicsModules.SharedBase.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" >
<Name>System</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Drawing" >
<Name>System.Drawing</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Runtime.Remoting" >
<Name>System.Runtime.Remoting</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml" >
<Name>System.Xml</Name>
<Private>False</Private>
</Reference>
<Reference Include="Warp3D.dll" >
<Name>Warp3D.dll</Name>
<HintPath>..\..\..\bin\Warp3D.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="XMLRPC.dll" >
<Name>XMLRPC.dll</Name>
<HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\OpenSim\Data\OpenSim.Data.csproj">
<Name>OpenSim.Data</Name>
<Project>{7E218E2D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\OpenSim.Framework.csproj">
<Name>OpenSim.Framework</Name>
<Project>{BCCDBB55-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name>
<Project>{0ED8EBE8-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\OpenSim.Framework.Servers.csproj">
<Name>OpenSim.Framework.Servers</Name>
<Project>{726D540D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\HttpServer\OpenSim.Framework.Servers.HttpServer.csproj">
<Name>OpenSim.Framework.Servers.HttpServer</Name>
<Project>{159EC5C2-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Region\Framework\OpenSim.Region.Framework.csproj">
<Name>OpenSim.Region.Framework</Name>
<Project>{C98F6D97-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Server\Base\OpenSim.Server.Base.csproj">
<Name>OpenSim.Server.Base</Name>
<Project>{2E0569BB-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Services\Interfaces\OpenSim.Services.Interfaces.csproj">
<Name>OpenSim.Services.Interfaces</Name>
<Project>{08ECE473-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Perlin.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TerrainSplat.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Viewport.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Warp3DImageModule.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>14.0.23107.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D5EA1308-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ApplicationIcon>
</ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>OpenSim.Modules.Warp3DCachedImageModule</AssemblyName>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<OutputType>Library</OutputType>
<AppDesignerFolder>
</AppDesignerFolder>
<RootNamespace>OpenSim.Modules.Warp3DCachedImageModule</RootNamespace>
<StartupObject>
</StartupObject>
<StartArguments>
</StartArguments>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG;</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>
</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoStdLib>False</NoStdLib>
<NoWarn>
</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>False</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Axiom.MathLib.dll">
<Name>Axiom.MathLib.dll</Name>
<HintPath>..\..\bin\Axiom.MathLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="CSJ2K.dll">
<Name>CSJ2K.dll</Name>
<HintPath>..\..\..\bin\CSJ2K.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="HttpServer_OpenSim.dll">
<Name>HttpServer_OpenSim.dll</Name>
<HintPath>..\..\..\bin\HttpServer_OpenSim.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="log4net.dll">
<Name>log4net.dll</Name>
<HintPath>..\..\..\bin\log4net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Mono.Addins.dll">
<Name>Mono.Addins.dll</Name>
<HintPath>..\..\..\bin\Mono.Addins.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Nini.dll">
<Name>Nini.dll</Name>
<HintPath>..\..\..\bin\Nini.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverse.dll">
<Name>OpenMetaverse.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverse.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverse.StructuredData.dll">
<Name>OpenMetaverse.StructuredData.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverse.StructuredData.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenMetaverseTypes.dll">
<Name>OpenMetaverseTypes.dll</Name>
<HintPath>..\..\..\bin\OpenMetaverseTypes.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Region.PhysicsModules.SharedBase.dll">
<Name>OpenSim.Region.PhysicsModules.SharedBase.dll</Name>
<HintPath>..\..\..\bin\OpenSim.Region.PhysicsModules.SharedBase.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System">
<Name>System</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Drawing">
<Name>System.Drawing</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Runtime.Remoting">
<Name>System.Runtime.Remoting</Name>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml">
<Name>System.Xml</Name>
<Private>False</Private>
</Reference>
<Reference Include="Warp3D.dll">
<Name>Warp3D.dll</Name>
<HintPath>..\..\..\bin\Warp3D.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="XMLRPC.dll">
<Name>XMLRPC.dll</Name>
<HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\OpenSim\Data\OpenSim.Data.csproj">
<Name>OpenSim.Data</Name>
<Project>{7E218E2D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\OpenSim.Framework.csproj">
<Name>OpenSim.Framework</Name>
<Project>{BCCDBB55-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Console\OpenSim.Framework.Console.csproj">
<Name>OpenSim.Framework.Console</Name>
<Project>{0ED8EBE8-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\OpenSim.Framework.Servers.csproj">
<Name>OpenSim.Framework.Servers</Name>
<Project>{726D540D-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Framework\Servers\HttpServer\OpenSim.Framework.Servers.HttpServer.csproj">
<Name>OpenSim.Framework.Servers.HttpServer</Name>
<Project>{159EC5C2-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Region\Framework\OpenSim.Region.Framework.csproj">
<Name>OpenSim.Region.Framework</Name>
<Project>{C98F6D97-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Server\Base\OpenSim.Server.Base.csproj">
<Name>OpenSim.Server.Base</Name>
<Project>{2E0569BB-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenSim\Services\Interfaces\OpenSim.Services.Interfaces.csproj">
<Name>OpenSim.Services.Interfaces</Name>
<Project>{08ECE473-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Perlin.cs" />
<Compile Include="TerrainSplat.cs" />
<Compile Include="Warp3DImageModule.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@ -103,41 +103,39 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float noise2(float x, float y)
{
int bx0, bx1, by0, by1, b00, b10, b01, b11;
int bx, by, b00, b10, b01, b11;
float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
int i, j;
t = x + N;
bx0 = ((int)t) & BM;
bx1 = (bx0 + 1) & BM;
rx0 = t - (int)t;
rx1 = rx0 - 1f;
bx = ((int)t) & BM;
i = p[bx];
bx = (bx + 1) & BM;
j = p[bx];
t = y + N;
by0 = ((int)t) & BM;
by1 = (by0 + 1) & BM;
ry0 = t - (int)t;
ry1 = ry0 - 1f;
by = ((int)t) & BM;
b00 = p[i + by];
b10 = p[j + by];
i = p[bx0];
j = p[bx1];
b00 = p[i + by0];
b10 = p[j + by0];
b01 = p[i + by1];
b11 = p[j + by1];
by = (by + 1) & BM;
b01 = p[i + by];
b11 = p[j + by];
sx = s_curve(rx0);
sy = s_curve(ry0);
u = rx0 * g2[b00, 0] + ry0 * g2[b00, 1];
rx1 = rx0 - 1f;
v = rx1 * g2[b10, 0] + ry0 * g2[b10, 1];
a = Utils.Lerp(u, v, sx);
ry1 = ry0 - 1f;
u = rx0 * g2[b01, 0] + ry1 * g2[b01, 1];
v = rx1 * g2[b11, 0] + ry1 * g2[b11, 1];
b = Utils.Lerp(u, v, sx);
sy = s_curve(ry0);
return Utils.Lerp(a, b, sy);
}
@ -202,12 +200,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float turbulence1(float x, float freq)
{
float t;
float v;
for (t = 0f; freq >= 1f; freq *= 0.5f)
{
v = freq * x;
t += noise1(v) / freq;
t += noise1(freq * x) / freq;
}
return t;
}
@ -215,28 +211,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
public static float turbulence2(float x, float y, float freq)
{
float t;
Vector2 vec;
for (t = 0f; freq >= 1f; freq *= 0.5f)
{
vec.X = freq * x;
vec.Y = freq * y;
t += noise2(vec.X, vec.Y) / freq;
}
t += noise2(freq * x, freq * y) / freq;
return t;
}
public static float turbulence3(float x, float y, float z, float freq)
{
float t;
Vector3 vec;
for (t = 0f; freq >= 1f; freq *= 0.5f)
{
vec.X = freq * x;
vec.Y = freq * y;
vec.Z = freq * z;
t += noise3(vec.X, vec.Y, vec.Z) / freq;
t += noise3(freq * x, freq * y, freq * z) / freq;
}
return t;
}
@ -244,23 +232,28 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
private static void normalize2(float[,] v, int i)
{
float s;
float a = v[i, 0];
float b = v[i, 1];
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1]);
s = (float)Math.Sqrt(a * a + b * b);
s = 1.0f / s;
v[i, 0] = v[i, 0] * s;
v[i, 1] = v[i, 1] * s;
v[i, 0] = a * s;
v[i, 1] = b * s;
}
private static void normalize3(float[,] v, int i)
{
float s;
float a = v[i, 0];
float b = v[i, 1];
float c = v[i, 2];
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1] + v[i, 2] * v[i, 2]);
s = (float)Math.Sqrt(a * a + b * b + c * c);
s = 1.0f / s;
v[i, 0] = v[i, 0] * s;
v[i, 1] = v[i, 1] * s;
v[i, 2] = v[i, 2] * s;
v[i, 0] = a * s;
v[i, 1] = b * s;
v[i, 2] = c * s;
}
private static float s_curve(float t)

View File

@ -80,9 +80,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
/// Note we create a 256x256 dimension texture even if the actual terrain is larger.
/// </remarks>
public static Bitmap Splat(ITerrainChannel terrain,
UUID[] textureIDs, float[] startHeights, float[] heightRanges,
Vector3d regionPosition, IAssetService assetService, bool textureTerrain)
public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs,
float[] startHeights, float[] heightRanges,
uint regionPositionX, uint regionPositionY,
IAssetService assetService, IJ2KDecoder decoder,
bool textureTerrain, bool averagetextureTerrain,
int twidth, int theight)
{
Debug.Assert(textureIDs.Length == 4);
Debug.Assert(startHeights.Length == 4);
@ -90,70 +93,80 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
Bitmap[] detailTexture = new Bitmap[4];
byte[] mapColorsRed = new byte[4];
byte[] mapColorsGreen = new byte[4];
byte[] mapColorsBlue = new byte[4];
bool usecolors = false;
if (textureTerrain)
{
// Swap empty terrain textureIDs with default IDs
for (int i = 0; i < textureIDs.Length; i++)
for(int i = 0; i < textureIDs.Length; i++)
{
if (textureIDs[i] == UUID.Zero)
if(textureIDs[i] == UUID.Zero)
textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
}
#region Texture Fetching
if (assetService != null)
if(assetService != null)
{
for (int i = 0; i < 4; i++)
for(int i = 0; i < 4; i++)
{
AssetBase asset;
UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
AssetBase asset = null;
// asset cache indexes are strings
string cacheName ="MAP-Patch" + textureIDs[i].ToString();
// Try to fetch a cached copy of the decoded/resized version of this texture
asset = assetService.GetCached(cacheID.ToString());
if (asset != null)
asset = assetService.GetCached(cacheName);
if(asset != null)
{
try
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
using(System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
detailTexture[i] = (Bitmap)Image.FromStream(stream);
if(detailTexture[i].PixelFormat != PixelFormat.Format24bppRgb ||
detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
{
detailTexture[i].Dispose();
detailTexture[i] = null;
}
}
catch (Exception ex)
catch(Exception ex)
{
m_log.Warn("Failed to decode cached terrain texture " + cacheID +
" (textureID: " + textureIDs[i] + "): " + ex.Message);
m_log.Warn("Failed to decode cached terrain patch texture" + textureIDs[i] + "): " + ex.Message);
}
}
if (detailTexture[i] == null)
if(detailTexture[i] == null)
{
// Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
asset = assetService.Get(textureIDs[i].ToString());
if (asset != null)
if(asset != null)
{
// m_log.DebugFormat(
// "[TERRAIN SPLAT]: Got cached original JPEG2000 terrain texture {0} {1}", i, asset.ID);
try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
catch (Exception ex)
try
{
detailTexture[i] = (Bitmap)decoder.DecodeToImage(asset.Data);
}
catch(Exception ex)
{
m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
}
}
if (detailTexture[i] != null)
if(detailTexture[i] != null)
{
// Make sure this texture is the correct size, otherwise resize
if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
{
using (Bitmap origBitmap = detailTexture[i])
{
detailTexture[i] = ImageUtils.ResizeImage(origBitmap, 256, 256);
}
}
if(detailTexture[i].PixelFormat != PixelFormat.Format24bppRgb ||
detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
using(Bitmap origBitmap = detailTexture[i])
detailTexture[i] = Util.ResizeImageSolid(origBitmap, 16, 16);
// Save the decoded and resized texture to the cache
byte[] data;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
using(System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
detailTexture[i].Save(stream, ImageFormat.Png);
data = stream.ToArray();
@ -165,8 +178,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
Data = data,
Description = "PNG",
Flags = AssetFlags.Collectable,
FullID = cacheID,
ID = cacheID.ToString(),
FullID = UUID.Zero,
ID = cacheName,
Local = true,
Name = String.Empty,
Temporary = true,
@ -180,209 +193,278 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
}
#endregion Texture Fetching
}
// Fill in any missing textures with a solid color
for (int i = 0; i < 4; i++)
{
if (detailTexture[i] == null)
if(averagetextureTerrain)
{
m_log.DebugFormat("{0} Missing terrain texture for layer {1}. Filling with solid default color",
LogHeader, i);
// Create a solid color texture for this layer
detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
for(int t = 0; t < 4; t++)
{
using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
gfx.FillRectangle(brush, 0, 0, 256, 256);
usecolors = true;
if(detailTexture[t] == null)
{
mapColorsRed[t] = DEFAULT_TERRAIN_COLOR[t].R;
mapColorsGreen[t] = DEFAULT_TERRAIN_COLOR[t].G;
mapColorsBlue[t] = DEFAULT_TERRAIN_COLOR[t].B;
continue;
}
int npixeis = 0;
int cR = 0;
int cG = 0;
int cB = 0;
BitmapData bmdata = detailTexture[t].LockBits(new Rectangle(0, 0, 16, 16),
ImageLockMode.ReadOnly, detailTexture[t].PixelFormat);
npixeis = bmdata.Height * bmdata.Width;
int ylen = bmdata.Height * bmdata.Stride;
unsafe
{
for(int y = 0; y < ylen; y += bmdata.Stride)
{
byte* ptrc = (byte*)bmdata.Scan0 + y;
for(int x = 0 ; x < bmdata.Width; ++x)
{
cR += *(ptrc++);
cG += *(ptrc++);
cB += *(ptrc++);
}
}
}
detailTexture[t].UnlockBits(bmdata);
detailTexture[t].Dispose();
mapColorsRed[t] = (byte)Util.Clamp(cR / npixeis, 0 , 255);
mapColorsGreen[t] = (byte)Util.Clamp(cG / npixeis, 0 , 255);
mapColorsBlue[t] = (byte)Util.Clamp(cB / npixeis, 0 , 255);
}
}
else
{
if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256)
// Fill in any missing textures with a solid color
for(int i = 0; i < 4; i++)
{
detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256);
if(detailTexture[i] == null)
{
m_log.DebugFormat("{0} Missing terrain texture for layer {1}. Filling with solid default color", LogHeader, i);
// Create a solid color texture for this layer
detailTexture[i] = new Bitmap(16, 16, PixelFormat.Format24bppRgb);
using(Graphics gfx = Graphics.FromImage(detailTexture[i]))
{
using(SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
gfx.FillRectangle(brush, 0, 0, 16, 16);
}
}
else
{
if(detailTexture[i].Width != 16 || detailTexture[i].Height != 16)
{
using(Bitmap origBitmap = detailTexture[i])
detailTexture[i] = Util.ResizeImageSolid(origBitmap, 16, 16);
}
}
}
}
}
else
{
usecolors = true;
for(int t = 0; t < 4; t++)
{
mapColorsRed[t] = DEFAULT_TERRAIN_COLOR[t].R;
mapColorsGreen[t] = DEFAULT_TERRAIN_COLOR[t].G;
mapColorsBlue[t] = DEFAULT_TERRAIN_COLOR[t].B;
}
}
#region Layer Map
float[,] layermap = new float[256, 256];
// Scale difference between actual region size and the 256 texture being created
int xFactor = terrain.Width / 256;
int yFactor = terrain.Height / 256;
// Create 'layermap' where each value is the fractional layer number to place
// at that point. For instance, a value of 1.345 gives the blending of
// layer 1 and layer 2 for that point.
for (int y = 0; y < 256; y++)
{
for (int x = 0; x < 256; x++)
{
float height = (float)terrain[x * xFactor, y * yFactor];
float pctX = (float)x / 255f;
float pctY = (float)y / 255f;
// Use bilinear interpolation between the four corners of start height and
// height range to select the current values at this position
float startHeight = ImageUtils.Bilinear(
startHeights[0],
startHeights[2],
startHeights[1],
startHeights[3],
pctX, pctY);
startHeight = Utils.Clamp(startHeight, 0f, 255f);
float heightRange = ImageUtils.Bilinear(
heightRanges[0],
heightRanges[2],
heightRanges[1],
heightRanges[3],
pctX, pctY);
heightRange = Utils.Clamp(heightRange, 0f, 255f);
// Generate two frequencies of perlin noise based on our global position
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
Vector3 vec = new Vector3
(
((float)regionPosition.X + (x * xFactor)) * 0.20319f,
((float)regionPosition.Y + (y * yFactor)) * 0.20319f,
height * 0.25f
);
float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
float noise = (lowFreq + highFreq) * 2f;
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
float layer = ((height + noise - startHeight) / heightRange) * 4f;
if (Single.IsNaN(layer))
layer = 0f;
layermap[x, y] = Utils.Clamp(layer, 0f, 3f);
}
}
float xFactor = terrain.Width / twidth;
float yFactor = terrain.Height / theight;
#endregion Layer Map
#region Texture Compositing
Bitmap output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
BitmapData outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
Bitmap output = new Bitmap(twidth, theight, PixelFormat.Format24bppRgb);
BitmapData outputData = output.LockBits(new Rectangle(0, 0, twidth, theight), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
// Unsafe work as we lock down the source textures for quicker access and access the
// pixel data directly
unsafe
float invtwitdthMinus1 = 1.0f / (twidth - 1);
float invtheightMinus1 = 1.0f / (theight - 1);
int ty;
int tx;
float pctx;
float pcty;
float height;
float layer;
float layerDiff;
int l0;
int l1;
uint yglobalpos;
if(usecolors)
{
// Get handles to all of the texture data arrays
BitmapData[] datas = new BitmapData[]
float a;
float b;
unsafe
{
detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
};
// Compute size of each pixel data (used to address into the pixel data array)
int[] comps = new int[]
{
(datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
(datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
};
for (int y = 0; y < 256; y++)
{
for (int x = 0; x < 256; x++)
byte* ptrO;
for(int y = 0; y < theight; ++y)
{
float layer = layermap[x, y];
pcty = y * invtheightMinus1;
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
ty = (int)(y * yFactor);
yglobalpos = (uint)ty + regionPositionY;
// Select two textures
int l0 = (int)Math.Floor(layer);
int l1 = Math.Min(l0 + 1, 3);
for(int x = 0; x < twidth; ++x)
{
tx = (int)(x * xFactor);
pctx = x * invtwitdthMinus1;
height = (float)terrain[tx, ty];
layer = getLayerTex(height, pctx, pcty,
(uint)tx + regionPositionX, yglobalpos,
startHeights, heightRanges);
byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
// Select two textures
l0 = (int)layer;
l1 = Math.Min(l0 + 1, 3);
float aB = *(ptrA + 0);
float aG = *(ptrA + 1);
float aR = *(ptrA + 2);
layerDiff = layer - l0;
float bB = *(ptrB + 0);
float bG = *(ptrB + 1);
float bR = *(ptrB + 2);
a = mapColorsRed[l0];
b = mapColorsRed[l1];
*(ptrO++) = (byte)(a + layerDiff * (b - a));
float layerDiff = layer - l0;
a = mapColorsGreen[l0];
b = mapColorsGreen[l1];
*(ptrO++) = (byte)(a + layerDiff * (b - a));
// Interpolate between the two selected textures
*(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
*(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
*(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
a = mapColorsBlue[l0];
b = mapColorsBlue[l1];
*(ptrO++) = (byte)(a + layerDiff * (b - a));
}
}
}
for (int i = 0; i < detailTexture.Length; i++)
detailTexture[i].UnlockBits(datas[i]);
}
else
{
float aB;
float aG;
float aR;
float bB;
float bG;
float bR;
for (int i = 0; i < detailTexture.Length; i++)
if (detailTexture[i] != null)
detailTexture[i].Dispose();
unsafe
{
// Get handles to all of the texture data arrays
BitmapData[] datas = new BitmapData[]
{
detailTexture[0].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
detailTexture[1].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
detailTexture[2].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
};
byte* ptr;
byte* ptrO;
for(int y = 0; y < theight; y++)
{
pcty = y * invtheightMinus1;
int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
ty = (int)(y * yFactor);
yglobalpos = (uint)ty + regionPositionY;
for(int x = 0; x < twidth; x++)
{
tx = (int)(x * xFactor);
pctx = x * invtwitdthMinus1;
height = (float)terrain[tx, ty];
layer = getLayerTex(height, pctx, pcty,
(uint)tx + regionPositionX, yglobalpos,
startHeights, heightRanges);
// Select two textures
l0 = (int)layer;
layerDiff = layer - l0;
int patchOffset = (tx & 0x0f) * 3 + ypatch;
ptr = (byte*)datas[l0].Scan0 + patchOffset;
aB = *(ptr++);
aG = *(ptr++);
aR = *(ptr);
l1 = Math.Min(l0 + 1, 3);
ptr = (byte*)datas[l1].Scan0 + patchOffset;
bB = *(ptr++);
bG = *(ptr++);
bR = *(ptr);
// Interpolate between the two selected textures
*(ptrO++) = (byte)(aB + layerDiff * (bB - aB));
*(ptrO++) = (byte)(aG + layerDiff * (bG - aG));
*(ptrO++) = (byte)(aR + layerDiff * (bR - aR));
}
}
for(int i = 0; i < detailTexture.Length; i++)
detailTexture[i].UnlockBits(datas[i]);
}
for(int i = 0; i < detailTexture.Length; i++)
if(detailTexture[i] != null)
detailTexture[i].Dispose();
}
output.UnlockBits(outputData);
// We generated the texture upside down, so flip it
output.RotateFlip(RotateFlipType.RotateNoneFlipY);
//output.Save("terr.png",ImageFormat.Png);
#endregion Texture Compositing
return output;
}
public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
private static float getLayerTex(float height, float pctX, float pctY, uint X, uint Y,
float[] startHeights, float[] heightRanges)
{
m_log.DebugFormat("{0} ResizeBitmap. From <{1},{2}> to <{3},{4}>",
LogHeader, b.Width, b.Height, nWidth, nHeight);
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage(result))
g.DrawImage(b, 0, 0, nWidth, nHeight);
b.Dispose();
return result;
}
public static Bitmap SplatSimple(float[] heightmap)
{
const float BASE_HSV_H = 93f / 360f;
const float BASE_HSV_S = 44f / 100f;
const float BASE_HSV_V = 34f / 100f;
// Use bilinear interpolation between the four corners of start height and
// height range to select the current values at this position
float startHeight = ImageUtils.Bilinear(
startHeights[0], startHeights[2],
startHeights[1], startHeights[3],
pctX, pctY);
if (float.IsNaN(startHeight))
return 0;
Bitmap img = new Bitmap(256, 256);
BitmapData bitmapData = img.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
startHeight = Utils.Clamp(startHeight, 0f, 255f);
unsafe
{
for (int y = 255; y >= 0; y--)
{
for (int x = 0; x < 256; x++)
{
float normHeight = heightmap[y * 256 + x] / 255f;
normHeight = Utils.Clamp(normHeight, BASE_HSV_V, 1.0f);
float heightRange = ImageUtils.Bilinear(
heightRanges[0], heightRanges[2],
heightRanges[1], heightRanges[3],
pctX, pctY);
heightRange = Utils.Clamp(heightRange, 0f, 255f);
if(heightRange == 0f || float.IsNaN(heightRange))
return 0;
Color4 color = Color4.FromHSV(BASE_HSV_H, BASE_HSV_S, normHeight);
// Generate two frequencies of perlin noise based on our global position
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
float sX = X * 0.20319f;
float sY = Y * 0.20319f;
byte* ptr = (byte*)bitmapData.Scan0 + y * bitmapData.Stride + x * 3;
*(ptr + 0) = (byte)(color.B * 255f);
*(ptr + 1) = (byte)(color.G * 255f);
*(ptr + 2) = (byte)(color.R * 255f);
}
}
}
float noise = Perlin.noise2(sX * 0.222222f, sY * 0.222222f) * 13.0f;
noise += Perlin.turbulence2(sX, sY, 2f) * 4.5f;
img.UnlockBits(bitmapData);
return img;
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
float layer = ((height + noise - startHeight) / heightRange) * 4f;
return Utils.Clamp(layer, 0f, 3f);
}
}
}

View File

@ -1,165 +0,0 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Drawing;
using OpenMetaverse;
namespace OpenSim.Region.CoreModules.World.Warp3DMap
{
public class Viewport
{
private const float DEG_TO_RAD = (float)Math.PI / 180f;
private static readonly Vector3 UP_DIRECTION = Vector3.UnitZ;
public Vector3 Position;
public Vector3 LookDirection;
public float FieldOfView;
public float NearPlaneDistance;
public float FarPlaneDistance;
public int Width;
public int Height;
public bool Orthographic;
public float OrthoWindowWidth;
public float OrthoWindowHeight;
public Viewport(Vector3 position, Vector3 lookDirection, float fieldOfView, float farPlaneDist, float nearPlaneDist, int width, int height)
{
// Perspective projection mode
Position = position;
LookDirection = lookDirection;
FieldOfView = fieldOfView;
FarPlaneDistance = farPlaneDist;
NearPlaneDistance = nearPlaneDist;
Width = width;
Height = height;
}
public Viewport(Vector3 position, Vector3 lookDirection, float farPlaneDist, float nearPlaneDist, int width, int height, float orthoWindowWidth, float orthoWindowHeight)
{
// Orthographic projection mode
Position = position;
LookDirection = lookDirection;
FarPlaneDistance = farPlaneDist;
NearPlaneDistance = nearPlaneDist;
Width = width;
Height = height;
OrthoWindowWidth = orthoWindowWidth;
OrthoWindowHeight = orthoWindowHeight;
Orthographic = true;
}
public Point VectorToScreen(Vector3 v)
{
Matrix4 m = GetWorldToViewportMatrix();
Vector3 screenPoint = v * m;
return new Point((int)screenPoint.X, (int)screenPoint.Y);
}
public Matrix4 GetWorldToViewportMatrix()
{
Matrix4 result = GetViewMatrix();
result *= GetPerspectiveProjectionMatrix();
result *= GetViewportMatrix();
return result;
}
public Matrix4 GetViewMatrix()
{
Vector3 zAxis = -LookDirection;
zAxis.Normalize();
Vector3 xAxis = Vector3.Cross(UP_DIRECTION, zAxis);
xAxis.Normalize();
Vector3 yAxis = Vector3.Cross(zAxis, xAxis);
Vector3 position = Position;
float offsetX = -Vector3.Dot(xAxis, position);
float offsetY = -Vector3.Dot(yAxis, position);
float offsetZ = -Vector3.Dot(zAxis, position);
return new Matrix4(
xAxis.X, yAxis.X, zAxis.X, 0f,
xAxis.Y, yAxis.Y, zAxis.Y, 0f,
xAxis.Z, yAxis.Z, zAxis.Z, 0f,
offsetX, offsetY, offsetZ, 1f);
}
public Matrix4 GetPerspectiveProjectionMatrix()
{
float aspectRatio = (float)Width / (float)Height;
float hFoV = FieldOfView * DEG_TO_RAD;
float zn = NearPlaneDistance;
float zf = FarPlaneDistance;
float xScale = 1f / (float)Math.Tan(hFoV / 2f);
float yScale = aspectRatio * xScale;
float m33 = (zf == double.PositiveInfinity) ? -1 : (zf / (zn - zf));
float m43 = zn * m33;
return new Matrix4(
xScale, 0f, 0f, 0f,
0f, yScale, 0f, 0f,
0f, 0f, m33, -1f,
0f, 0f, m43, 0f);
}
public Matrix4 GetOrthographicProjectionMatrix(float aspectRatio)
{
float w = Width;
float h = Height;
float zn = NearPlaneDistance;
float zf = FarPlaneDistance;
float m33 = 1 / (zn - zf);
float m43 = zn * m33;
return new Matrix4(
2f / w, 0f, 0f, 0f,
0f, 2f / h, 0f, 0f,
0f, 0f, m33, 0f,
0f, 0f, m43, 1f);
}
public Matrix4 GetViewportMatrix()
{
float scaleX = (float)Width * 0.5f;
float scaleY = (float)Height * 0.5f;
float offsetX = 0f + scaleX;
float offsetY = 0f + scaleY;
return new Matrix4(
scaleX, 0f, 0f, 0f,
0f, -scaleY, 0f, 0f,
0f, 0f, 1f, 0f,
offsetX, offsetY, 0f, 1f);
}
}
}

File diff suppressed because it is too large Load Diff