physicsExample
parent
67e07d9e29
commit
d69c951ed0
|
@ -68,7 +68,7 @@ namespace OpenSim
|
||||||
this.RegionLocY = 996;
|
this.RegionLocY = 996;
|
||||||
this.RegionHandle = Helpers.UIntsToLong((RegionLocX*256), (RegionLocY*256));
|
this.RegionHandle = Helpers.UIntsToLong((RegionLocX*256), (RegionLocY*256));
|
||||||
this.IPListenPort = 9000;
|
this.IPListenPort = 9000;
|
||||||
this.IPListenAddr = "4.78.190.75";
|
this.IPListenAddr = "127.0.0.1";
|
||||||
this.AssetURL = "http://www.osgrid.org/ogs/assetserver/";
|
this.AssetURL = "http://www.osgrid.org/ogs/assetserver/";
|
||||||
this.AssetSendKey = "1234";
|
this.AssetSendKey = "1234";
|
||||||
this.GridURL = "http://www.osgrid.org/ogs/gridserver/";
|
this.GridURL = "http://www.osgrid.org/ogs/gridserver/";
|
||||||
|
|
25
Main.cs
25
Main.cs
|
@ -33,11 +33,13 @@ using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Timers;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using libsecondlife;
|
using libsecondlife;
|
||||||
using libsecondlife.Packets;
|
using libsecondlife.Packets;
|
||||||
using OpenSim.world;
|
using OpenSim.world;
|
||||||
|
using PhysicsSystem;
|
||||||
|
|
||||||
namespace OpenSim
|
namespace OpenSim
|
||||||
{
|
{
|
||||||
|
@ -46,7 +48,7 @@ namespace OpenSim
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OpenSim_Main
|
public class OpenSim_Main
|
||||||
{
|
{
|
||||||
private static OpenSim_Main sim;
|
public static OpenSim_Main sim;
|
||||||
public static SimConfig cfg;
|
public static SimConfig cfg;
|
||||||
public static World local_world;
|
public static World local_world;
|
||||||
private static Thread MainListener;
|
private static Thread MainListener;
|
||||||
|
@ -60,10 +62,12 @@ namespace OpenSim
|
||||||
private static AsyncCallback ReceivedData;
|
private static AsyncCallback ReceivedData;
|
||||||
public Dictionary<EndPoint, OpenSimClient> ClientThreads = new Dictionary<EndPoint, OpenSimClient>();
|
public Dictionary<EndPoint, OpenSimClient> ClientThreads = new Dictionary<EndPoint, OpenSimClient>();
|
||||||
private PhysicsManager physManager;
|
private PhysicsManager physManager;
|
||||||
|
private System.Timers.Timer timer1 = new System.Timers.Timer();
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main( string[] args )
|
public static void Main( string[] args )
|
||||||
{
|
{
|
||||||
Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
|
//Console.WriteLine("OpenSim " + VersionInfo.Version + "\n");
|
||||||
Console.WriteLine("Starting...\n");
|
Console.WriteLine("Starting...\n");
|
||||||
sim = new OpenSim_Main();
|
sim = new OpenSim_Main();
|
||||||
sim.Startup();
|
sim.Startup();
|
||||||
|
@ -76,6 +80,10 @@ namespace OpenSim
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Startup() {
|
private void Startup() {
|
||||||
|
timer1.Enabled = true;
|
||||||
|
timer1.Interval = 100;
|
||||||
|
timer1.Elapsed +=new ElapsedEventHandler( this.Timer1Tick );
|
||||||
|
|
||||||
// We check our local database first, then the grid for config options
|
// We check our local database first, then the grid for config options
|
||||||
Console.WriteLine("Main.cs:Startup() - Loading configuration");
|
Console.WriteLine("Main.cs:Startup() - Loading configuration");
|
||||||
cfg = new SimConfig();
|
cfg = new SimConfig();
|
||||||
|
@ -87,12 +95,12 @@ namespace OpenSim
|
||||||
Console.WriteLine("Initialising world");
|
Console.WriteLine("Initialising world");
|
||||||
local_world = cfg.LoadWorld();
|
local_world = cfg.LoadWorld();
|
||||||
|
|
||||||
this.physManager = new PhysicsManager();
|
this.physManager = new PhysicsSystem.PhysicsManager();
|
||||||
this.physManager.LoadPlugins();
|
this.physManager.LoadPlugins();
|
||||||
local_world.PhysScene = this.physManager.GetScene("PhysX"); //should be reading from the config file what physics engine to use
|
|
||||||
|
|
||||||
Console.WriteLine("Main.cs:Startup() - Starting up messaging system");
|
Console.WriteLine("Main.cs:Startup() - Starting up messaging system");
|
||||||
MainListener = new Thread(new ThreadStart(MainServerListener));
|
local_world.PhysScene = this.physManager.GetPhysicsScene("PhysX"); //should be reading from the config file what physics engine to use
|
||||||
|
|
||||||
|
MainListener = new Thread(new ThreadStart(MainServerListener));
|
||||||
MainListener.Start();
|
MainListener.Start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -138,5 +146,10 @@ namespace OpenSim
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Timer1Tick( object sender, System.EventArgs e )
|
||||||
|
{
|
||||||
|
local_world.Update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ namespace OpenSim
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AssetLoader() {
|
public void AssetLoader() {
|
||||||
|
/*
|
||||||
Console.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread");
|
Console.WriteLine("OpenSimClient.cs:AssetLoader() - Starting new thread");
|
||||||
TransferRequestPacket reqPacket = AssetRequests.Dequeue();
|
TransferRequestPacket reqPacket = AssetRequests.Dequeue();
|
||||||
Console.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it");
|
Console.WriteLine("OpenSimClient.cs:AssetLoader() - Got a request, processing it");
|
||||||
|
@ -127,6 +128,7 @@ namespace OpenSim
|
||||||
OutPacket(TransferPacket);
|
OutPacket(TransferPacket);
|
||||||
}
|
}
|
||||||
AssetResponse.Close();
|
AssetResponse.Close();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessInPacket(Packet Pack) {
|
public void ProcessInPacket(Packet Pack) {
|
||||||
|
@ -150,6 +152,9 @@ namespace OpenSim
|
||||||
Thread AssetLoaderThread = new Thread(new ThreadStart(AssetLoader));
|
Thread AssetLoaderThread = new Thread(new ThreadStart(AssetLoader));
|
||||||
AssetLoaderThread.Start();
|
AssetLoaderThread.Start();
|
||||||
break;
|
break;
|
||||||
|
case PacketType.AgentUpdate:
|
||||||
|
ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +389,7 @@ namespace OpenSim
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AuthUser() {
|
private void AuthUser() {
|
||||||
Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid");
|
/*Console.WriteLine("OpenSimClient.cs:AuthUser() - Authenticating new user request with grid");
|
||||||
WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists");
|
WebRequest CheckSession = WebRequest.Create(OpenSim_Main.cfg.GridURL + "/usersessions/" + OpenSim_Main.cfg.GridSendKey + "/" + cirpack.CircuitCode.ID.ToString() + "/" + cirpack.CircuitCode.Code.ToString() + "/exists");
|
||||||
WebResponse GridResponse = CheckSession.GetResponse();
|
WebResponse GridResponse = CheckSession.GetResponse();
|
||||||
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
StreamReader sr = new StreamReader(GridResponse.GetResponseStream());
|
||||||
|
@ -401,7 +406,12 @@ namespace OpenSim
|
||||||
} else { // Invalid
|
} else { // Invalid
|
||||||
Console.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
|
Console.WriteLine("OpenSimClient.cs:AuthUser() - New user request denied to " + userEP.ToString());
|
||||||
ClientThread.Abort();
|
ClientThread.Abort();
|
||||||
}
|
}*/
|
||||||
|
this.AgentID=cirpack.CircuitCode.ID;
|
||||||
|
this.SessionID=cirpack.CircuitCode.SessionID;
|
||||||
|
this.CircuitCode=cirpack.CircuitCode.Code;
|
||||||
|
InitNewClient();
|
||||||
|
ClientLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,24 +25,27 @@
|
||||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Axiom.MathLib, Version=0.7.0.25497, Culture=neutral">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\bin\Axiom.MathLib.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="Db4objects.Db4o, Version=6.0.1.0, Culture=neutral, PublicKeyToken=6199cd4f203aa8eb, processorArchitecture=MSIL" />
|
|
||||||
<Reference Include="libsecondlife, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\bin\libsecondlife.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\bin\log4net.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="PhysicsManager">
|
<Reference Include="PhysicsManager">
|
||||||
<HintPath>..\..\..\..\physics\PhysicsManager\bin\Release\PhysicsManager.dll</HintPath>
|
<HintPath>..\physics\PhysicsManager\bin\Release\PhysicsManager.dll</HintPath>
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="log4net">
|
||||||
|
<HintPath>..\Version0_2_myserver\OpenSim\bin\Debug\log4net.dll</HintPath>
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Axiom.MathLib">
|
||||||
|
<HintPath>..\Version0_2_myserver\OpenSim\bin\Debug\Axiom.MathLib.dll</HintPath>
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Db4objects.Db4o">
|
||||||
|
<HintPath>..\Version0_2_myserver\OpenSim\bin\Debug\Db4objects.Db4o.dll</HintPath>
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="libsecondlife">
|
||||||
|
<HintPath>..\Version0_2_myserver\OpenSim\bin\Debug\libsecondlife.dll</HintPath>
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -54,7 +57,6 @@
|
||||||
<Compile Include="types\Mesh.cs" />
|
<Compile Include="types\Mesh.cs" />
|
||||||
<Compile Include="types\Triangle.cs" />
|
<Compile Include="types\Triangle.cs" />
|
||||||
<Compile Include="Util.cs" />
|
<Compile Include="Util.cs" />
|
||||||
<Compile Include="VersionInfo.cs" />
|
|
||||||
<Compile Include="world\Avatar.cs" />
|
<Compile Include="world\Avatar.cs" />
|
||||||
<Compile Include="world\Entity.cs" />
|
<Compile Include="world\Entity.cs" />
|
||||||
<Compile Include="world\Primitive.cs" />
|
<Compile Include="world\Primitive.cs" />
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
Copyright (c) OpenSim project, http://osgrid.org/
|
||||||
|
|
||||||
|
* Copyright (c) <year>, <copyright holder>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 <organization> 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 <copyright holder> ``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 <copyright holder> 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.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using libsecondlife;
|
||||||
|
using libsecondlife.Packets;
|
||||||
|
|
||||||
|
namespace OpenSim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
public class QueItem {
|
||||||
|
public QueItem()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet Packet;
|
||||||
|
public bool Incoming;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class BlockingQueue< T > {
|
||||||
|
private Queue< T > _queue = new Queue< T >();
|
||||||
|
private object _queueSync = new object();
|
||||||
|
|
||||||
|
public void Enqueue(T value)
|
||||||
|
{
|
||||||
|
lock(_queueSync)
|
||||||
|
{
|
||||||
|
_queue.Enqueue(value);
|
||||||
|
Monitor.Pulse(_queueSync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Dequeue()
|
||||||
|
{
|
||||||
|
lock(_queueSync)
|
||||||
|
{
|
||||||
|
if( _queue.Count < 1)
|
||||||
|
Monitor.Wait(_queueSync);
|
||||||
|
|
||||||
|
return _queue.Dequeue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ using System.Collections;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace PhysicsManager
|
namespace PhysicsSystem
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of MyClass.
|
/// Description of MyClass.
|
||||||
|
@ -48,10 +48,12 @@ namespace PhysicsManager
|
||||||
{
|
{
|
||||||
if(_plugins.ContainsKey(engineName))
|
if(_plugins.ContainsKey(engineName))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("returning "+engineName);
|
||||||
return _plugins[engineName].GetScene();
|
return _plugins[engineName].GetScene();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("couldn't find "+ engineName);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,7 +61,7 @@ namespace PhysicsManager
|
||||||
public void LoadPlugins()
|
public void LoadPlugins()
|
||||||
{
|
{
|
||||||
string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory ,"Physics");
|
string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory ,"Physics");
|
||||||
string[] pluginFiles = Directory.GetFiles(path, "*.Phy");
|
string[] pluginFiles = Directory.GetFiles(path, "*.Dll");
|
||||||
|
|
||||||
|
|
||||||
for(int i= 0; i<pluginFiles.Length; i++)
|
for(int i= 0; i<pluginFiles.Length; i++)
|
||||||
|
@ -123,6 +125,7 @@ namespace PhysicsManager
|
||||||
public abstract PhysicsVector Position
|
public abstract PhysicsVector Position
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract PhysicsVector Velocity
|
public abstract PhysicsVector Velocity
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following
|
||||||
|
// attributes.
|
||||||
|
//
|
||||||
|
// change them to the information which is associated with the assembly
|
||||||
|
// you compile.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("PhysXplugin")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("PhysXplugin")]
|
||||||
|
[assembly: AssemblyCopyright("")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// This sets the default COM visibility of types in the assembly to invisible.
|
||||||
|
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The assembly version has following format :
|
||||||
|
//
|
||||||
|
// Major.Minor.Build.Revision
|
||||||
|
//
|
||||||
|
// You can specify all values by your own or you can build default build and revision
|
||||||
|
// numbers with the '*' character (the default):
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
|
||||||
|
*
|
||||||
|
* 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 <organization> 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 <copyright holder> ``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 <copyright holder> 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.Collections.Generic;
|
||||||
|
using PhysicsSystem;
|
||||||
|
|
||||||
|
namespace PhysXplugin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Will be the PhysX plugin but for now will be a very basic physics engine
|
||||||
|
/// </summary>
|
||||||
|
public class PhysXPlugin : IPhysicsPlugin
|
||||||
|
{
|
||||||
|
private PhysXScene _mScene;
|
||||||
|
|
||||||
|
public PhysXPlugin()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Init()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PhysicsScene GetScene()
|
||||||
|
{
|
||||||
|
if(_mScene == null)
|
||||||
|
{
|
||||||
|
_mScene = new PhysXScene();
|
||||||
|
}
|
||||||
|
return(_mScene);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetName()
|
||||||
|
{
|
||||||
|
return("PhysX");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PhysXScene :PhysicsScene
|
||||||
|
{
|
||||||
|
private List<PhysXActor> _actors = new List<PhysXActor>();
|
||||||
|
|
||||||
|
public PhysXScene()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PhysicsActor AddAvatar(PhysicsVector position)
|
||||||
|
{
|
||||||
|
PhysXActor act = new PhysXActor();
|
||||||
|
act.Position = position;
|
||||||
|
_actors.Add(act);
|
||||||
|
return act;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Simulate(float timeStep)
|
||||||
|
{
|
||||||
|
foreach (PhysXActor actor in _actors)
|
||||||
|
{
|
||||||
|
actor.Position.X = actor.Position.X + actor.Velocity.X * timeStep;
|
||||||
|
actor.Position.Y = actor.Position.Y + actor.Velocity.Y * timeStep;
|
||||||
|
actor.Position.Z = actor.Position.Z + actor.Velocity.Z * timeStep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void GetResults()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsThreaded
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return(false); // for now we won't be multithreaded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PhysXActor : PhysicsActor
|
||||||
|
{
|
||||||
|
private PhysicsVector _position;
|
||||||
|
private PhysicsVector _velocity;
|
||||||
|
private PhysicsVector _acceleration;
|
||||||
|
|
||||||
|
public PhysXActor()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PhysicsVector Position
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _position;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_position = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PhysicsVector Velocity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _velocity;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_velocity = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PhysicsVector Acceleration
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void SetAcceleration (PhysicsVector accel)
|
||||||
|
{
|
||||||
|
this._acceleration = accel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AddForce(PhysicsVector force)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetMomentum(PhysicsVector momentum)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<RootNamespace>PhysXplugin</RootNamespace>
|
||||||
|
<AssemblyName>PhysXplugin</AssemblyName>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{ADB751AA-8426-4668-B1FA-43762126CEB3}</ProjectGuid>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<Optimize>False</Optimize>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugSymbols>True</DebugSymbols>
|
||||||
|
<DebugType>Full</DebugType>
|
||||||
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<Optimize>True</Optimize>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<DebugSymbols>False</DebugSymbols>
|
||||||
|
<DebugType>None</DebugType>
|
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="PhysicsManager">
|
||||||
|
<HintPath>..\..\PhysicsManager\bin\Release\PhysicsManager.dll</HintPath>
|
||||||
|
<SpecificVersion>False</SpecificVersion>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="PhysXplugin.cs" />
|
||||||
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||||
|
</Project>
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||||
|
# SharpDevelop 2.1.0.2017
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PhysXplugin", "PhysXplugin.csproj", "{ADB751AA-8426-4668-B1FA-43762126CEB3}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
EndGlobal
|
|
@ -0,0 +1,138 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.types
|
||||||
|
{
|
||||||
|
/* New Method
|
||||||
|
*
|
||||||
|
* 1. Get all the individual bytes and their bitlength, put them in a dictionary
|
||||||
|
* 2. Mash together when wanted.
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
public class Bits {
|
||||||
|
public byte[] data;
|
||||||
|
public int len;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class InverseBitPack
|
||||||
|
{
|
||||||
|
private List<Bits> bits;
|
||||||
|
|
||||||
|
public InverseBitPack()
|
||||||
|
{
|
||||||
|
bits = new List<Bits>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BitPack
|
||||||
|
{
|
||||||
|
private const int MAX_BITS = 8;
|
||||||
|
|
||||||
|
private byte[] Data;
|
||||||
|
private int bytePos;
|
||||||
|
private int bitPos;
|
||||||
|
|
||||||
|
public BitPack(byte[] data, int pos) // For libsl compatibility
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
bytePos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BitPack() // Encoding version
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadData(byte[] data, int pos) {
|
||||||
|
Data = data;
|
||||||
|
bytePos = pos;
|
||||||
|
bitPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PackBitsArray(byte[] bits, int bitLen)
|
||||||
|
{
|
||||||
|
int offset = bitPos % MAX_BITS;
|
||||||
|
int i;
|
||||||
|
byte temp1;
|
||||||
|
byte temp2;
|
||||||
|
|
||||||
|
for (i = 0; i < bits.Length; i++)
|
||||||
|
{
|
||||||
|
int Byte = bits[i];
|
||||||
|
Byte <<= offset;
|
||||||
|
temp1 = (byte)(Byte & 0xFF);
|
||||||
|
temp2 = (byte)((Byte >> 8) & 0xFF);
|
||||||
|
|
||||||
|
Data[Data.Length - 1] |= temp1;
|
||||||
|
// Data
|
||||||
|
|
||||||
|
bitPos += bitLen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float UnpackFloat()
|
||||||
|
{
|
||||||
|
byte[] output = UnpackBitsArray(32);
|
||||||
|
|
||||||
|
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||||
|
return BitConverter.ToSingle(output, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int UnpackBits(int totalCount)
|
||||||
|
{
|
||||||
|
byte[] output = UnpackBitsArray(totalCount);
|
||||||
|
|
||||||
|
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||||
|
return BitConverter.ToInt32(output, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] UnpackBitsArray(int totalCount)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
byte[] output = new byte[4];
|
||||||
|
int curBytePos = 0;
|
||||||
|
int curBitPos = 0;
|
||||||
|
|
||||||
|
while (totalCount > 0)
|
||||||
|
{
|
||||||
|
if (totalCount > MAX_BITS)
|
||||||
|
{
|
||||||
|
count = MAX_BITS;
|
||||||
|
totalCount -= MAX_BITS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = totalCount;
|
||||||
|
totalCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (count > 0)
|
||||||
|
{
|
||||||
|
// Shift the previous bits
|
||||||
|
output[curBytePos] <<= 1;
|
||||||
|
|
||||||
|
// Grab one bit
|
||||||
|
if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
|
||||||
|
++output[curBytePos];
|
||||||
|
|
||||||
|
--count;
|
||||||
|
++curBitPos;
|
||||||
|
|
||||||
|
if (bitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
bitPos = 0;
|
||||||
|
++bytePos;
|
||||||
|
}
|
||||||
|
if (curBitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
curBitPos = 0;
|
||||||
|
++curBytePos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.types
|
||||||
|
{
|
||||||
|
// TODO: This will need some performance tuning no doubt.
|
||||||
|
public class Mesh
|
||||||
|
{
|
||||||
|
public List<Triangle> mesh;
|
||||||
|
|
||||||
|
public Mesh()
|
||||||
|
{
|
||||||
|
mesh = new List<Triangle>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddTri(Triangle tri)
|
||||||
|
{
|
||||||
|
mesh.Add(tri);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Mesh operator +(Mesh a, Mesh b)
|
||||||
|
{
|
||||||
|
a.mesh.AddRange(b.mesh);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Axiom.MathLib;
|
||||||
|
|
||||||
|
namespace OpenSim.types
|
||||||
|
{
|
||||||
|
public class Triangle
|
||||||
|
{
|
||||||
|
Vector3 a;
|
||||||
|
Vector3 b;
|
||||||
|
Vector3 c;
|
||||||
|
|
||||||
|
public Triangle()
|
||||||
|
{
|
||||||
|
a = new Vector3();
|
||||||
|
b = new Vector3();
|
||||||
|
c = new Vector3();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Triangle(Vector3 A, Vector3 B, Vector3 C)
|
||||||
|
{
|
||||||
|
a = A;
|
||||||
|
b = B;
|
||||||
|
c = C;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
113
world/Avatar.cs
113
world/Avatar.cs
|
@ -4,7 +4,8 @@ using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using libsecondlife;
|
using libsecondlife;
|
||||||
using libsecondlife.Packets;
|
using libsecondlife.Packets;
|
||||||
using PhysicsManager;
|
using PhysicsSystem;
|
||||||
|
using Axiom.MathLib;
|
||||||
|
|
||||||
namespace OpenSim.world
|
namespace OpenSim.world
|
||||||
{
|
{
|
||||||
|
@ -23,7 +24,8 @@ namespace OpenSim.world
|
||||||
Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
||||||
ControllingClient=TheClient;
|
ControllingClient=TheClient;
|
||||||
SetupTemplate("avatar-template.dat");
|
SetupTemplate("avatar-template.dat");
|
||||||
}
|
position = new LLVector3(100.0f,100.0f,30.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public PhysicsActor PhysActor
|
public PhysicsActor PhysActor
|
||||||
{
|
{
|
||||||
|
@ -40,9 +42,9 @@ namespace OpenSim.world
|
||||||
{
|
{
|
||||||
NewForce force = this.forcesList[i];
|
NewForce force = this.forcesList[i];
|
||||||
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
|
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
|
||||||
this.PhysActor.Velocity = phyVector;
|
this._physActor.Velocity = phyVector;
|
||||||
this.updateflag = true;
|
this.updateflag = true;
|
||||||
this.velocity = new Axiom.MathLib.Vector3(force.X, force.Y, force.Z); //shouldn't really be doing this
|
this.velocity = new LLVector3(force.X, force.Y, force.Z); //shouldn't really be doing this
|
||||||
// but as we are setting the velocity (rather than using real forces) at the moment it is okay.
|
// but as we are setting the velocity (rather than using real forces) at the moment it is okay.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,6 +57,18 @@ namespace OpenSim.world
|
||||||
{
|
{
|
||||||
//need to send movement info
|
//need to send movement info
|
||||||
//so create the improvedterseobjectupdate packet
|
//so create the improvedterseobjectupdate packet
|
||||||
|
//use CreateTerseBlock()
|
||||||
|
ImprovedTerseObjectUpdatePacket.ObjectDataBlock terseBlock = CreateTerseBlock();
|
||||||
|
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
|
||||||
|
terse.RegionData.RegionHandle = OpenSim_Main.cfg.RegionHandle; // FIXME
|
||||||
|
terse.RegionData.TimeDilation = 0;
|
||||||
|
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
|
||||||
|
terse.ObjectData[0] = terseBlock;
|
||||||
|
foreach(OpenSimClient client in OpenSim_Main.sim.ClientThreads.Values) {
|
||||||
|
client.OutPacket(terse);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateflag =false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,13 +127,12 @@ namespace OpenSim.world
|
||||||
|
|
||||||
objupdate.ObjectData[0] = AvatarTemplate;
|
objupdate.ObjectData[0] = AvatarTemplate;
|
||||||
//give this avatar object a local id and assign the user a name
|
//give this avatar object a local id and assign the user a name
|
||||||
objupdate.ObjectData[0].ID = 8880000 + OpenSim_Main.local_world._localNumber;
|
objupdate.ObjectData[0].ID = this.localid;
|
||||||
//User_info.name="Test"+this.local_numer+" User";
|
|
||||||
objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
|
objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
|
||||||
objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
|
objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
|
||||||
|
|
||||||
libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100.0f, 23.0f);
|
libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
|
||||||
|
|
||||||
byte[] pb = pos2.GetBytes();
|
byte[] pb = pos2.GetBytes();
|
||||||
|
|
||||||
Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
|
Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
|
||||||
|
@ -157,7 +170,7 @@ namespace OpenSim.world
|
||||||
{
|
{
|
||||||
//we should add a new force to the list
|
//we should add a new force to the list
|
||||||
// but for now we will deal with velocities
|
// but for now we will deal with velocities
|
||||||
NewFoce newVelocity = new NewForce();
|
NewForce newVelocity = new NewForce();
|
||||||
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
|
Axiom.MathLib.Vector3 v3 = new Axiom.MathLib.Vector3(1, 0, 0);
|
||||||
Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
|
Axiom.MathLib.Quaternion q = new Axiom.MathLib.Quaternion(pack.AgentData.BodyRotation.W, pack.AgentData.BodyRotation.X, pack.AgentData.BodyRotation.Y, pack.AgentData.BodyRotation.Z);
|
||||||
Axiom.MathLib.Vector3 direc = q * v3;
|
Axiom.MathLib.Vector3 direc = q * v3;
|
||||||
|
@ -178,7 +191,12 @@ namespace OpenSim.world
|
||||||
{
|
{
|
||||||
if(walking)
|
if(walking)
|
||||||
{
|
{
|
||||||
|
NewForce newVelocity = new NewForce();
|
||||||
|
newVelocity.X = 0;
|
||||||
|
newVelocity.Y = 0;
|
||||||
|
newVelocity.Z = 0;
|
||||||
|
this.forcesList.Add(newVelocity);
|
||||||
|
walking = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,6 +236,81 @@ namespace OpenSim.world
|
||||||
Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
|
Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
|
||||||
this.ControllingClient.OutPacket(handshake);
|
this.ControllingClient.OutPacket(handshake);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock()
|
||||||
|
{
|
||||||
|
byte[] bytes = new byte[60];
|
||||||
|
int i=0;
|
||||||
|
ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
|
||||||
|
|
||||||
|
dat.TextureEntry = AvatarTemplate.TextureEntry;
|
||||||
|
libsecondlife.LLVector3 pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z);
|
||||||
|
|
||||||
|
uint ID = this.localid;
|
||||||
|
bytes[i++] = (byte)(ID % 256);
|
||||||
|
bytes[i++] = (byte)((ID >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)((ID >> 16) % 256);
|
||||||
|
bytes[i++] = (byte)((ID >> 24) % 256);
|
||||||
|
bytes[i++] = 0;
|
||||||
|
bytes[i++] = 1;
|
||||||
|
i += 14;
|
||||||
|
bytes[i++] = 128;
|
||||||
|
bytes[i++] = 63;
|
||||||
|
|
||||||
|
byte[] pb = pos2.GetBytes();
|
||||||
|
Array.Copy(pb, 0, bytes, i, pb.Length);
|
||||||
|
i += 12;
|
||||||
|
ushort InternVelocityX;
|
||||||
|
ushort InternVelocityY;
|
||||||
|
ushort InternVelocityZ;
|
||||||
|
Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(this.velocity.X, this.velocity.Y, this.velocity.Z);
|
||||||
|
internDirec = internDirec /128.0f;
|
||||||
|
internDirec.x += 1;
|
||||||
|
internDirec.y += 1;
|
||||||
|
internDirec.z += 1;
|
||||||
|
|
||||||
|
InternVelocityX = (ushort)(32768 * internDirec.x);
|
||||||
|
InternVelocityY = (ushort)(32768 * internDirec.y);
|
||||||
|
InternVelocityZ = (ushort)(32768 * internDirec.z);
|
||||||
|
|
||||||
|
|
||||||
|
ushort ac = 32767;
|
||||||
|
bytes[i++] = (byte)(InternVelocityX % 256);
|
||||||
|
bytes[i++] = (byte)((InternVelocityX >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(InternVelocityY % 256);
|
||||||
|
bytes[i++] = (byte)((InternVelocityY>> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(InternVelocityZ % 256);
|
||||||
|
bytes[i++] = (byte)((InternVelocityZ >> 8) % 256);
|
||||||
|
|
||||||
|
//accel
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
|
||||||
|
//rot
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
|
||||||
|
//rotation vel
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
bytes[i++] = (byte)(ac % 256);
|
||||||
|
bytes[i++] = (byte)((ac >> 8) % 256);
|
||||||
|
|
||||||
|
dat.Data=bytes;
|
||||||
|
return(dat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NewForce
|
public class NewForce
|
||||||
|
|
|
@ -3,14 +3,16 @@ using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Axiom.MathLib;
|
using Axiom.MathLib;
|
||||||
using OpenSim.types;
|
using OpenSim.types;
|
||||||
|
using libsecondlife;
|
||||||
|
|
||||||
namespace OpenSim.world
|
namespace OpenSim.world
|
||||||
{
|
{
|
||||||
public class Entity
|
public class Entity
|
||||||
{
|
{
|
||||||
protected libsecondlife.LLUUID uuid;
|
protected libsecondlife.LLUUID uuid;
|
||||||
public Vector3 position;
|
protected uint localid;
|
||||||
public Vector3 velocity;
|
public LLVector3 position;
|
||||||
|
public LLVector3 velocity;
|
||||||
public Quaternion rotation;
|
public Quaternion rotation;
|
||||||
protected string name;
|
protected string name;
|
||||||
protected List<Entity> children;
|
protected List<Entity> children;
|
||||||
|
@ -18,8 +20,9 @@ namespace OpenSim.world
|
||||||
public Entity()
|
public Entity()
|
||||||
{
|
{
|
||||||
uuid = new libsecondlife.LLUUID();
|
uuid = new libsecondlife.LLUUID();
|
||||||
position = new Vector3();
|
localid = 8880000 + (OpenSim_Main.local_world._localNumber++); // FIXME - race condition!
|
||||||
velocity = new Vector3();
|
position = new LLVector3();
|
||||||
|
velocity = new LLVector3();
|
||||||
rotation = new Quaternion();
|
rotation = new Quaternion();
|
||||||
name = "(basic entity)";
|
name = "(basic entity)";
|
||||||
children = new List<Entity>();
|
children = new List<Entity>();
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.world
|
||||||
|
{
|
||||||
|
public class ScriptEngine
|
||||||
|
{
|
||||||
|
public ScriptEngine(World env)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadScript()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.world
|
||||||
|
{
|
||||||
|
public class SurfacePatch
|
||||||
|
{
|
||||||
|
public float[] HeightMap;
|
||||||
|
|
||||||
|
public SurfacePatch() {
|
||||||
|
HeightMap = new float[16*16];
|
||||||
|
|
||||||
|
int xinc;
|
||||||
|
int yinc;
|
||||||
|
for(xinc=0; xinc<16; xinc++) for(yinc=0; yinc<16; yinc++) {
|
||||||
|
HeightMap[xinc+(yinc*16)]=100.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,683 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
|
||||||
|
*
|
||||||
|
* 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 <organization> 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 <copyright holder> ``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 <copyright holder> 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.Collections.Generic;
|
||||||
|
//using libsecondlife;
|
||||||
|
using libsecondlife.Packets;
|
||||||
|
|
||||||
|
namespace OpenSim
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Description of TerrainDecoder.
|
||||||
|
/// </summary>
|
||||||
|
public class TerrainDecode
|
||||||
|
{
|
||||||
|
|
||||||
|
public enum LayerType : byte
|
||||||
|
{
|
||||||
|
Land = 0x4C,
|
||||||
|
Water = 0x57,
|
||||||
|
Wind = 0x37,
|
||||||
|
Cloud = 0x38
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct GroupHeader
|
||||||
|
{
|
||||||
|
public int Stride;
|
||||||
|
public int PatchSize;
|
||||||
|
public LayerType Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct PatchHeader
|
||||||
|
{
|
||||||
|
public float DCOffset;
|
||||||
|
public int Range;
|
||||||
|
public int QuantWBits;
|
||||||
|
public int PatchIDs;
|
||||||
|
public uint WordBits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Patch
|
||||||
|
{
|
||||||
|
public float[] Heightmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="simulator"></param>
|
||||||
|
/// <param name="x"></param>
|
||||||
|
/// <param name="y"></param>
|
||||||
|
/// <param name="width"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
// public delegate void LandPatchCallback(Simulator simulator, int x, int y, int width, float[] data);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
//public event LandPatchCallback OnLandPatch;
|
||||||
|
|
||||||
|
private Random RandomClass = new Random();
|
||||||
|
|
||||||
|
private const byte END_OF_PATCHES = 97;
|
||||||
|
private const int PATCHES_PER_EDGE = 16;
|
||||||
|
private const float OO_SQRT2 = 0.7071067811865475244008443621049f;
|
||||||
|
|
||||||
|
//private SecondLife Client;
|
||||||
|
private Dictionary<ulong, Patch[]> SimPatches = new Dictionary<ulong, Patch[]>();
|
||||||
|
private float[] DequantizeTable16 = new float[16 * 16];
|
||||||
|
private float[] DequantizeTable32 = new float[32 * 32];
|
||||||
|
private float[] ICosineTable16 = new float[16 * 16];
|
||||||
|
private float[] ICosineTable32 = new float[32 * 32];
|
||||||
|
private int[] DeCopyMatrix16 = new int[16 * 16];
|
||||||
|
private int[] DeCopyMatrix32 = new int[32 * 32];
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
public TerrainDecode()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Initialize the decompression tables
|
||||||
|
BuildDequantizeTable16();
|
||||||
|
BuildDequantizeTable32();
|
||||||
|
SetupICosines16();
|
||||||
|
SetupICosines32();
|
||||||
|
BuildDecopyMatrix16();
|
||||||
|
BuildDecopyMatrix32();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void BuildDequantizeTable16()
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 16; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
DequantizeTable16[j * 16 + i] = 1.0f + 2.0f * (float)(i + j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildDequantizeTable32()
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 32; j++)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
DequantizeTable32[j * 32 + i] = 1.0f + 2.0f * (float)(i + j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupICosines16()
|
||||||
|
{
|
||||||
|
const float hposz = (float)Math.PI * 0.5f / 16.0f;
|
||||||
|
|
||||||
|
for (int u = 0; u < 16; u++)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < 16; n++)
|
||||||
|
{
|
||||||
|
ICosineTable16[u * 16 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetupICosines32()
|
||||||
|
{
|
||||||
|
const float hposz = (float)Math.PI * 0.5f / 32.0f;
|
||||||
|
|
||||||
|
for (int u = 0; u < 32; u++)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < 32; n++)
|
||||||
|
{
|
||||||
|
ICosineTable32[u * 32 + n] = (float)Math.Cos((2.0f * (float)n + 1.0f) * (float)u * hposz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildDecopyMatrix16()
|
||||||
|
{
|
||||||
|
bool diag = false;
|
||||||
|
bool right = true;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
while (i < 16 && j < 16)
|
||||||
|
{
|
||||||
|
DeCopyMatrix16[j * 16 + i] = count++;
|
||||||
|
|
||||||
|
if (!diag)
|
||||||
|
{
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
if (i < 16 - 1) i++;
|
||||||
|
else j++;
|
||||||
|
|
||||||
|
right = false;
|
||||||
|
diag = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (j < 16 - 1) j++;
|
||||||
|
else i++;
|
||||||
|
|
||||||
|
right = true;
|
||||||
|
diag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
j--;
|
||||||
|
if (i == 16 - 1 || j == 0) diag = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
j++;
|
||||||
|
if (j == 16 - 1 || i == 0) diag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildDecopyMatrix32()
|
||||||
|
{
|
||||||
|
bool diag = false;
|
||||||
|
bool right = true;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
while (i < 32 && j < 32)
|
||||||
|
{
|
||||||
|
DeCopyMatrix32[j * 32 + i] = count++;
|
||||||
|
|
||||||
|
if (!diag)
|
||||||
|
{
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
if (i < 32 - 1) i++;
|
||||||
|
else j++;
|
||||||
|
|
||||||
|
right = false;
|
||||||
|
diag = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (j < 32 - 1) j++;
|
||||||
|
else i++;
|
||||||
|
|
||||||
|
right = true;
|
||||||
|
diag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (right)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
j--;
|
||||||
|
if (i == 32 - 1 || j == 0) diag = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
j++;
|
||||||
|
if (j == 32 - 1 || i == 0) diag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EncodePatchHeader(BitPacker bitpack, PatchHeader header)
|
||||||
|
{
|
||||||
|
bitpack.PackBits(header.QuantWBits,8);
|
||||||
|
|
||||||
|
if (header.QuantWBits == END_OF_PATCHES)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bitpack.PackFloat(header.DCOffset);
|
||||||
|
bitpack.PackBits(header.Range,16);
|
||||||
|
bitpack.PackBits(header.PatchIDs,10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DCTLine16(float[] In, float[] Out, int line)
|
||||||
|
{
|
||||||
|
int N =16;
|
||||||
|
int lineSize = line * 16;
|
||||||
|
|
||||||
|
for(int k = 0; k < N;k++)
|
||||||
|
{
|
||||||
|
float sum = 0.0f;
|
||||||
|
for(int n = 0; n < N; n++)
|
||||||
|
{
|
||||||
|
float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N));
|
||||||
|
float cosine = (float)Math.Cos(num);
|
||||||
|
float product = In[lineSize +n] * cosine;
|
||||||
|
sum += product;
|
||||||
|
}
|
||||||
|
|
||||||
|
float alpha;
|
||||||
|
if(k == 0)
|
||||||
|
{
|
||||||
|
alpha = (float)(1.0f/Math.Sqrt(2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alpha = 1;
|
||||||
|
}
|
||||||
|
Out[lineSize + k] =(float)( sum * alpha );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void DCTColumn16(float[] In, float[] Out, int Column)
|
||||||
|
{
|
||||||
|
int N =16;
|
||||||
|
int uSize;
|
||||||
|
|
||||||
|
for(int k = 0; k < N; k++){
|
||||||
|
float sum = 0.0f;
|
||||||
|
for(int n = 0; n < N; n++)
|
||||||
|
{
|
||||||
|
uSize = n * 16;
|
||||||
|
float num = (float)(Math.PI*k*(2.0f*n+1)/(2*N));
|
||||||
|
float cosine = (float)Math.Cos(num);
|
||||||
|
float product = In[uSize + Column] * cosine;
|
||||||
|
sum += product;
|
||||||
|
}
|
||||||
|
|
||||||
|
float alpha;
|
||||||
|
if(k == 0)
|
||||||
|
{
|
||||||
|
alpha = (float)(1.0f/Math.Sqrt(2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
alpha = 1;
|
||||||
|
}
|
||||||
|
Out[16 * k + Column] = (float)( sum * alpha * (2.0f /N));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EncodePatch(int[] patches, BitPacker bitpack, int size)
|
||||||
|
{
|
||||||
|
int lastnum =0;
|
||||||
|
for(int n = 0; n < size * size; n++)
|
||||||
|
{
|
||||||
|
if(patches[n]!=0)
|
||||||
|
lastnum=n;
|
||||||
|
}
|
||||||
|
for (int n = 0; n < lastnum+1; n++)
|
||||||
|
{
|
||||||
|
if(patches[n] != 0)
|
||||||
|
{
|
||||||
|
bitpack.PackBits(1,1); //value or EOB
|
||||||
|
bitpack.PackBits(1,1); //value
|
||||||
|
if(patches[n] > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
bitpack.PackBits(0,1); // positive
|
||||||
|
bitpack.PackBits(patches[n],13);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitpack.PackBits(1,1); // negative
|
||||||
|
|
||||||
|
int temp = patches[n] * -1;
|
||||||
|
bitpack.PackBits(temp,13);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bitpack.PackBits(0,1); // no value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitpack.PackBits(1,1); //value or EOB
|
||||||
|
bitpack.PackBits(0,1); // EOB
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] CompressPatch(float[] patches)
|
||||||
|
{
|
||||||
|
int size = 16;
|
||||||
|
float[] block = new float[size * size];
|
||||||
|
int[] output = new int[size * size];
|
||||||
|
int prequant = (139 >> 4) + 2;
|
||||||
|
int quantize = 1 << prequant;
|
||||||
|
float ooq = 1.0f / (float)quantize;
|
||||||
|
float mult = ooq * (float)1;
|
||||||
|
float addval = mult * (float)(1 << (prequant - 1)) + 20.4989f;
|
||||||
|
|
||||||
|
if (size == 16)
|
||||||
|
{
|
||||||
|
for (int n = 0; n < 16 * 16; n++)
|
||||||
|
{
|
||||||
|
block[n] = (float)((patches[n] - addval)/ mult);
|
||||||
|
}
|
||||||
|
|
||||||
|
float[] ftemp = new float[32 * 32];
|
||||||
|
|
||||||
|
for (int o = 0; o < 16; o++)
|
||||||
|
this.DCTColumn16(block, ftemp, o);
|
||||||
|
for (int o = 0; o < 16; o++)
|
||||||
|
this.DCTLine16(ftemp, block, o);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < block.Length; j++)
|
||||||
|
{
|
||||||
|
output[DeCopyMatrix16[j]] = (int)(block[j] / DequantizeTable16[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Packet CreateLayerPacket(float[] heightmap, int minX, int minY, int maxX, int maxY)
|
||||||
|
{
|
||||||
|
//int minX = 0, maxX = 2, minY = 0, maxY = 1; //these should be passed to this function
|
||||||
|
LayerDataPacket layer = new LayerDataPacket();
|
||||||
|
byte[] Encoded = new byte[2048];
|
||||||
|
layer.LayerID.Type = 76;
|
||||||
|
GroupHeader header = new GroupHeader();
|
||||||
|
header.Stride = 264;
|
||||||
|
header.PatchSize = 16;
|
||||||
|
header.Type = LayerType.Land;
|
||||||
|
BitPacker newpack = new BitPacker(Encoded,0);
|
||||||
|
newpack.PackBits(header.Stride,16);
|
||||||
|
newpack.PackBits(header.PatchSize,8);
|
||||||
|
newpack.PackBits((int)header.Type,8);
|
||||||
|
|
||||||
|
|
||||||
|
float[] height;
|
||||||
|
for(int y = minY; y< maxY; y++)
|
||||||
|
{
|
||||||
|
for(int x = minX ; x < maxX ; x++)
|
||||||
|
{
|
||||||
|
height = new float[256];
|
||||||
|
Array.Copy(heightmap, (4096 *y) +(x *256), height, 0, 256);
|
||||||
|
|
||||||
|
this.CreatePatch(height, newpack, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PatchHeader headers = new PatchHeader();
|
||||||
|
headers.QuantWBits = END_OF_PATCHES;
|
||||||
|
this.EncodePatchHeader(newpack, headers);
|
||||||
|
|
||||||
|
int lastused=0;
|
||||||
|
for(int i = 0; i < 2048 ; i++)
|
||||||
|
{
|
||||||
|
if(Encoded[i] !=0)
|
||||||
|
lastused = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[lastused+1];
|
||||||
|
Array.Copy(Encoded, data, lastused+1);
|
||||||
|
layer.LayerData.Data =data;
|
||||||
|
|
||||||
|
return(layer);
|
||||||
|
}
|
||||||
|
public void CreatePatch(float[] heightmap, BitPacker newpack, int x, int y)
|
||||||
|
{
|
||||||
|
PatchHeader header = new PatchHeader();
|
||||||
|
header.DCOffset = 20.4989f;
|
||||||
|
header.QuantWBits = 139;
|
||||||
|
header.Range = 1;
|
||||||
|
header.PatchIDs = (y & 0x1F);
|
||||||
|
header.PatchIDs += x <<5 ;
|
||||||
|
|
||||||
|
this.EncodePatchHeader(newpack, header);
|
||||||
|
|
||||||
|
int[] newpatch = this.CompressPatch(heightmap);
|
||||||
|
this.EncodePatch(newpatch, newpack, 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//***************************************************
|
||||||
|
public class BitPacker
|
||||||
|
{
|
||||||
|
private const int MAX_BITS = 8;
|
||||||
|
|
||||||
|
private byte[] Data;
|
||||||
|
public int bytePos;
|
||||||
|
public int bitPos;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default constructor, initialize the bit packer / bit unpacker
|
||||||
|
/// with a byte array and starting position
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Byte array to pack bits in to or unpack from</param>
|
||||||
|
/// <param name="pos">Starting position in the byte array</param>
|
||||||
|
public BitPacker(byte[] data, int pos)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
bytePos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pack a floating point value in to the data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Floating point value to pack</param>
|
||||||
|
public void PackFloat(float data)
|
||||||
|
{
|
||||||
|
byte[] input = BitConverter.GetBytes(data);
|
||||||
|
PackBitArray(input, 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Pack part or all of an integer in to the data
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">Integer containing the data to pack</param>
|
||||||
|
/// <param name="totalCount">Number of bits of the integer to pack</param>
|
||||||
|
public void PackBits(int data, int totalCount)
|
||||||
|
{
|
||||||
|
byte[] input = BitConverter.GetBytes(data);
|
||||||
|
PackBitArray(input, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unpacking a floating point value from the data
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Unpacked floating point value</returns>
|
||||||
|
public float UnpackFloat()
|
||||||
|
{
|
||||||
|
byte[] output = UnpackBitsArray(32);
|
||||||
|
|
||||||
|
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||||
|
return BitConverter.ToSingle(output, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unpack a variable number of bits from the data in to integer format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="totalCount">Number of bits to unpack</param>
|
||||||
|
/// <returns>An integer containing the unpacked bits</returns>
|
||||||
|
/// <remarks>This function is only useful up to 32 bits</remarks>
|
||||||
|
public int UnpackBits(int totalCount)
|
||||||
|
{
|
||||||
|
byte[] output = UnpackBitsArray(totalCount);
|
||||||
|
|
||||||
|
if (!BitConverter.IsLittleEndian) Array.Reverse(output);
|
||||||
|
return BitConverter.ToInt32(output, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PackBitArray(byte[] data, int totalCount)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
int curBytePos = 0;
|
||||||
|
int curBitPos = 0;
|
||||||
|
|
||||||
|
while (totalCount > 0)
|
||||||
|
{
|
||||||
|
if (totalCount > (MAX_BITS ))
|
||||||
|
{
|
||||||
|
count = MAX_BITS ;
|
||||||
|
totalCount -= MAX_BITS ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = totalCount;
|
||||||
|
totalCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (count > 0)
|
||||||
|
{
|
||||||
|
switch(count)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if ((data[curBytePos] & (0x01)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if ((data[curBytePos] & (0x02)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if ((data[curBytePos] & (0x04)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if ((data[curBytePos] & (0x08)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
if ((data[curBytePos] & (0x10)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
if ((data[curBytePos] & (0x20)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
if ((data[curBytePos] & (0x40)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
if ((data[curBytePos] & (0x80)) != 0)
|
||||||
|
{
|
||||||
|
Data[bytePos] |= (byte)(0x80 >> bitPos);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
bitPos++;
|
||||||
|
--count;
|
||||||
|
++curBitPos;
|
||||||
|
|
||||||
|
if (bitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
bitPos = 0;
|
||||||
|
++bytePos;
|
||||||
|
}
|
||||||
|
if (curBitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
curBitPos = 0;
|
||||||
|
++curBytePos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private byte[] UnpackBitsArray(int totalCount)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
byte[] output = new byte[4];
|
||||||
|
int curBytePos = 0;
|
||||||
|
int curBitPos = 0;
|
||||||
|
|
||||||
|
while (totalCount > 0)
|
||||||
|
{
|
||||||
|
if (totalCount > MAX_BITS)
|
||||||
|
{
|
||||||
|
count = MAX_BITS;
|
||||||
|
totalCount -= MAX_BITS;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
count = totalCount;
|
||||||
|
totalCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (count > 0)
|
||||||
|
{
|
||||||
|
// Shift the previous bits
|
||||||
|
output[curBytePos] <<= 1;
|
||||||
|
|
||||||
|
// Grab one bit
|
||||||
|
if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
|
||||||
|
++output[curBytePos];
|
||||||
|
|
||||||
|
--count;
|
||||||
|
++curBitPos;
|
||||||
|
|
||||||
|
if (bitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
bitPos = 0;
|
||||||
|
++bytePos;
|
||||||
|
}
|
||||||
|
if (curBitPos >= MAX_BITS)
|
||||||
|
{
|
||||||
|
curBitPos = 0;
|
||||||
|
++curBytePos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ using libsecondlife;
|
||||||
using libsecondlife.Packets;
|
using libsecondlife.Packets;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using PhysicsManager;
|
using PhysicsSystem;
|
||||||
|
|
||||||
namespace OpenSim.world
|
namespace OpenSim.world
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ namespace OpenSim.world
|
||||||
Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
|
Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
|
||||||
NewAvatar.SendRegionHandshake(this);
|
NewAvatar.SendRegionHandshake(this);
|
||||||
|
|
||||||
NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.x, NewAvatar.position.y, NewAvatar.position.z));
|
NewAvatar.PhysActor = this.phyScene.AddAvatar(new PhysicsVector(NewAvatar.position.X, NewAvatar.position.Y, NewAvatar.position.Z));
|
||||||
//this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user
|
//this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenSim.world.scripting
|
||||||
|
{
|
||||||
|
public interface IScriptHost {
|
||||||
|
bool Register(IScript iscript);
|
||||||
|
}
|
||||||
|
public interface IScript
|
||||||
|
{
|
||||||
|
string Name{get;set;}
|
||||||
|
IScriptHost Host{get;set;}
|
||||||
|
void Show();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue