A example of how the physics plugins might work
parent
91c11314ac
commit
40a52b0f55
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Text;
|
||||
using libsecondlife;
|
||||
using libsecondlife.Packets;
|
||||
using PhysicsManager;
|
||||
|
||||
namespace OpenSim.world
|
||||
{
|
||||
|
@ -12,7 +13,11 @@ namespace OpenSim.world
|
|||
public string firstname;
|
||||
public string lastname;
|
||||
public OpenSimClient ControllingClient;
|
||||
private PhysicsActor _physActor;
|
||||
private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
|
||||
private bool updateflag;
|
||||
private bool walking;
|
||||
private List<NewForce> forcesList = new List<NewForce>();
|
||||
|
||||
public Avatar(OpenSimClient TheClient) {
|
||||
Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
|
||||
|
@ -20,6 +25,39 @@ namespace OpenSim.world
|
|||
SetupTemplate("avatar-template.dat");
|
||||
}
|
||||
|
||||
public PhysicsActor PhysActor
|
||||
{
|
||||
set
|
||||
{
|
||||
this._physActor = value;
|
||||
}
|
||||
}
|
||||
public override void addFroces()
|
||||
{
|
||||
if(this.forcesList.Count>0)
|
||||
{
|
||||
for(int i=0 ; i < this.forcesList.Count; i++)
|
||||
{
|
||||
NewForce force = this.forcesList[i];
|
||||
PhysicsVector phyVector = new PhysicsVector(force.X, force.Y, force.Z);
|
||||
this.PhysActor.Velocity = phyVector;
|
||||
this.updateflag = true;
|
||||
this.velocity = new Axiom.MathLib.Vector3(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.
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void update()
|
||||
{
|
||||
if(this.updateflag)
|
||||
{
|
||||
//need to send movement info
|
||||
//so create the improvedterseobjectupdate packet
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTemplate(string name)
|
||||
{
|
||||
|
||||
|
@ -113,6 +151,39 @@ namespace OpenSim.world
|
|||
ControllingClient.OutPacket(aw);
|
||||
}
|
||||
|
||||
public void HandleUpdate(AgentUpdatePacket pack) {
|
||||
if(((uint)pack.AgentData.ControlFlags & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) !=0) {
|
||||
if(!walking)
|
||||
{
|
||||
//we should add a new force to the list
|
||||
// but for now we will deal with velocities
|
||||
NewFoce newVelocity = new NewForce();
|
||||
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.Vector3 direc = q * v3;
|
||||
direc.Normalize();
|
||||
|
||||
Axiom.MathLib.Vector3 internDirec = new Vector3(direc.x, direc.y, direc.z);
|
||||
|
||||
//work out velocity for sim physics system
|
||||
direc = direc * ((0.03f) * 128f);
|
||||
newVelocity.X = direc.x;
|
||||
newVelocity.Y = direc.y;
|
||||
newVelocity.Z = direc.z;
|
||||
this.forcesList.Add(newVelocity);
|
||||
walking=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(walking)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//should be moved somewhere else
|
||||
public void SendRegionHandshake(World RegionInfo) {
|
||||
Console.WriteLine("Avatar.cs:SendRegionHandshake() - Creating empty RegionHandshake packet");
|
||||
System.Text.Encoding _enc = System.Text.Encoding.ASCII;
|
||||
|
@ -148,4 +219,16 @@ namespace OpenSim.world
|
|||
this.ControllingClient.OutPacket(handshake);
|
||||
}
|
||||
}
|
||||
|
||||
public class NewForce
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
|
||||
public NewForce()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace OpenSim.world
|
|||
public class Entity
|
||||
{
|
||||
protected libsecondlife.LLUUID uuid;
|
||||
protected Vector3 position;
|
||||
protected Vector3 velocity;
|
||||
protected Quaternion rotation;
|
||||
public Vector3 position;
|
||||
public Vector3 velocity;
|
||||
public Quaternion rotation;
|
||||
protected string name;
|
||||
protected List<Entity> children;
|
||||
|
||||
|
@ -24,7 +24,13 @@ namespace OpenSim.world
|
|||
name = "(basic entity)";
|
||||
children = new List<Entity>();
|
||||
}
|
||||
|
||||
public virtual void addFroces()
|
||||
{
|
||||
foreach (Entity child in children)
|
||||
{
|
||||
child.addFroces();
|
||||
}
|
||||
}
|
||||
public virtual void update() {
|
||||
// Do any per-frame updates needed that are applicable to every type of entity
|
||||
foreach (Entity child in children)
|
||||
|
|
|
@ -3,6 +3,7 @@ using libsecondlife;
|
|||
using libsecondlife.Packets;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using PhysicsManager;
|
||||
|
||||
namespace OpenSim.world
|
||||
{
|
||||
|
@ -13,6 +14,8 @@ namespace OpenSim.world
|
|||
public ScriptEngine Scripts;
|
||||
public TerrainDecode terrainengine = new TerrainDecode();
|
||||
public uint _localNumber=0;
|
||||
private PhysicsScene phyScene;
|
||||
private float timeStep= 0.1f;
|
||||
|
||||
private Random Rand = new Random();
|
||||
|
||||
|
@ -33,8 +36,29 @@ namespace OpenSim.world
|
|||
Scripts = new ScriptEngine(this);
|
||||
}
|
||||
|
||||
public PhysicsScene PhysScene
|
||||
{
|
||||
set
|
||||
{
|
||||
this.phyScene = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if(this.phyScene.IsThreaded)
|
||||
{
|
||||
this.phyScene.GetResults();
|
||||
|
||||
}
|
||||
|
||||
foreach (libsecondlife.LLUUID UUID in Entities.Keys)
|
||||
{
|
||||
Entities[UUID].addFroces();
|
||||
}
|
||||
|
||||
this.phyScene.Simulate(timeStep);
|
||||
|
||||
foreach (libsecondlife.LLUUID UUID in Entities.Keys)
|
||||
{
|
||||
Entities[UUID].update();
|
||||
|
@ -55,7 +79,9 @@ namespace OpenSim.world
|
|||
this.Entities.Add(AgentClient.AgentID, NewAvatar);
|
||||
Console.WriteLine("World.cs:AddViewerAgent() - Starting RegionHandshake ");
|
||||
NewAvatar.SendRegionHandshake(this);
|
||||
this.Update(); // will work for now, but needs to be optimised so we don't update everything in the sim for each new user
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
public bool Backup() {
|
||||
|
|
Loading…
Reference in New Issue