aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/world/Avatar.cs
diff options
context:
space:
mode:
authorgareth2007-03-04 00:44:26 +0000
committergareth2007-03-04 00:44:26 +0000
commit572ab939369de8ccb666b31029cad119a965a57a (patch)
tree2c70798e4e33bc712fbe7bab7742944ef5215001 /src/world/Avatar.cs
parentRollback to r117 (diff)
downloadopensim-SC_OLD-572ab939369de8ccb666b31029cad119a965a57a.zip
opensim-SC_OLD-572ab939369de8ccb666b31029cad119a965a57a.tar.gz
opensim-SC_OLD-572ab939369de8ccb666b31029cad119a965a57a.tar.bz2
opensim-SC_OLD-572ab939369de8ccb666b31029cad119a965a57a.tar.xz
Merged makomk's patch as per bug #61
Rescued my brain ready to implement animations and proper velocity encoding
Diffstat (limited to 'src/world/Avatar.cs')
-rw-r--r--src/world/Avatar.cs107
1 files changed, 101 insertions, 6 deletions
diff --git a/src/world/Avatar.cs b/src/world/Avatar.cs
index f3905cd..68606c4 100644
--- a/src/world/Avatar.cs
+++ b/src/world/Avatar.cs
@@ -4,6 +4,7 @@ using System.IO;
4using System.Text; 4using System.Text;
5using libsecondlife; 5using libsecondlife;
6using libsecondlife.Packets; 6using libsecondlife.Packets;
7using Axiom.MathLib;
7 8
8namespace OpenSim.world 9namespace OpenSim.world
9{ 10{
@@ -12,16 +13,37 @@ namespace OpenSim.world
12 public string firstname; 13 public string firstname;
13 public string lastname; 14 public string lastname;
14 public OpenSimClient ControllingClient; 15 public OpenSimClient ControllingClient;
16 public uint CurrentKeyMask;
17
15 private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate; 18 private libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock AvatarTemplate;
16 19
17 public Avatar(OpenSimClient TheClient) { 20 public Avatar(OpenSimClient TheClient) {
18 Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)"); 21 Console.WriteLine("Avatar.cs - Loading details from grid (DUMMY)");
19 ControllingClient=TheClient; 22 ControllingClient=TheClient;
20 SetupTemplate("avatar-template.dat"); 23 SetupTemplate("avatar-template.dat");
24
25 position = new LLVector3(100.0f,100.0f,60.0f);
21 } 26 }
22 27
23 public void update() { 28 public override void update() {
24 base.update(); 29 lock(this) {
30 base.update();
31
32 Console.WriteLine("KeyMask: " + this.CurrentKeyMask);
33
34 if((this.CurrentKeyMask & (uint)MainAvatar.AgentUpdateFlags.AGENT_CONTROL_AT_POS) != 0) {
35 Vector3 tmpVelocity = this.rotation * new Vector3(1.0f,0.0f,0.0f);
36 tmpVelocity.Normalize(); tmpVelocity = tmpVelocity * 0.3f;
37 this.velocity.X = tmpVelocity.x;
38 this.velocity.Y = tmpVelocity.y;
39 this.velocity.Z = tmpVelocity.z;
40 Console.WriteLine("Walking at "+ this.velocity.ToString());
41 } else {
42 this.velocity.X=0;
43 this.velocity.Y=0;
44 this.velocity.Z=0;
45 }
46 }
25 } 47 }
26 48
27 private void SetupTemplate(string name) 49 private void SetupTemplate(string name)
@@ -41,7 +63,7 @@ namespace OpenSim.world
41 System.Text.Encoding enc = System.Text.Encoding.ASCII; 63 System.Text.Encoding enc = System.Text.Encoding.ASCII;
42 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16); 64 libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16);
43 pos.X = 100f; 65 pos.X = 100f;
44 objdata.ID = 8880000; 66 objdata.ID = this.localid;
45 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); 67 objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0");
46 libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f); 68 libsecondlife.LLVector3 pos2 = new LLVector3(100f,100f,23f);
47 //objdata.FullID=user.AgentID; 69 //objdata.FullID=user.AgentID;
@@ -60,7 +82,7 @@ namespace OpenSim.world
60 mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle; 82 mov.Data.RegionHandle = OpenSim_Main.cfg.RegionHandle;
61 // TODO - dynamicalise this stuff 83 // TODO - dynamicalise this stuff
62 mov.Data.Timestamp = 1172750370; 84 mov.Data.Timestamp = 1172750370;
63 mov.Data.Position = new LLVector3(100f, 100f, 23f); 85 mov.Data.Position = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
64 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0); 86 mov.Data.LookAt = new LLVector3(0.99f, 0.042f, 0);
65 87
66 Console.WriteLine("Sending AgentMovementComplete packet"); 88 Console.WriteLine("Sending AgentMovementComplete packet");
@@ -79,12 +101,12 @@ namespace OpenSim.world
79 101
80 objupdate.ObjectData[0] = AvatarTemplate; 102 objupdate.ObjectData[0] = AvatarTemplate;
81 //give this avatar object a local id and assign the user a name 103 //give this avatar object a local id and assign the user a name
82 objupdate.ObjectData[0].ID = 8880000 + OpenSim_Main.local_world._localNumber; 104 objupdate.ObjectData[0].ID = this.localid;
83 //User_info.name="Test"+this.local_numer+" User"; 105 //User_info.name="Test"+this.local_numer+" User";
84 objupdate.ObjectData[0].FullID = ControllingClient.AgentID; 106 objupdate.ObjectData[0].FullID = ControllingClient.AgentID;
85 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); 107 objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0");
86 108
87 libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100.0f, 23.0f); 109 libsecondlife.LLVector3 pos2 = new LLVector3((float)this.position.X, (float)this.position.Y, (float)this.position.Z);
88 110
89 byte[] pb = pos2.GetBytes(); 111 byte[] pb = pos2.GetBytes();
90 112
@@ -92,6 +114,68 @@ namespace OpenSim.world
92 OpenSim_Main.local_world._localNumber++; 114 OpenSim_Main.local_world._localNumber++;
93 this.ControllingClient.OutPacket(objupdate); 115 this.ControllingClient.OutPacket(objupdate);
94 } 116 }
117
118 public override ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() {
119 byte[] bytes = new byte[60];
120 int i=0;
121 ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
122
123 dat.TextureEntry = AvatarTemplate.TextureEntry;
124 libsecondlife.LLVector3 pos2 = new LLVector3(this.position.X, this.position.Y, this.position.Z);
125
126 uint ID = this.localid;
127 bytes[i++] = (byte)(ID % 256);
128 bytes[i++] = (byte)((ID >> 8) % 256);
129 bytes[i++] = (byte)((ID >> 16) % 256);
130 bytes[i++] = (byte)((ID >> 24) % 256);
131 bytes[i++] = 0;
132 bytes[i++] = 1;
133 i += 14;
134 bytes[i++] = 128;
135 bytes[i++] = 63;
136
137 byte[] pb = pos2.GetBytes();
138 Array.Copy(pb, 0, bytes, i, pb.Length);
139 i += 12;
140
141 ushort ac = 32767;
142 bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityX
143 bytes[i++] = (byte)((ac>> 8) % 256);
144 bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityY
145 bytes[i++] = (byte)((ac >> 8) % 256);
146 bytes[i++] = (byte)(ac % 256); // avatar.InternVelocityZ
147 bytes[i++] = (byte)((ac >> 8) % 256);
148
149 //accel
150 bytes[i++] = (byte)(ac % 256);
151 bytes[i++] = (byte)((ac >> 8) % 256);
152 bytes[i++] = (byte)(ac % 256);
153 bytes[i++] = (byte)((ac >> 8) % 256);
154 bytes[i++] = (byte)(ac % 256);
155 bytes[i++] = (byte)((ac >> 8) % 256);
156
157 //rot
158 bytes[i++] = (byte)(ac % 256);
159 bytes[i++] = (byte)((ac >> 8) % 256);
160 bytes[i++] = (byte)(ac % 256);
161 bytes[i++] = (byte)((ac >> 8) % 256);
162 bytes[i++] = (byte)(ac % 256);
163 bytes[i++] = (byte)((ac >> 8) % 256);
164 bytes[i++] = (byte)(ac % 256);
165 bytes[i++] = (byte)((ac >> 8) % 256);
166
167 //rotation vel
168 bytes[i++] = (byte)(ac % 256);
169 bytes[i++] = (byte)((ac >> 8) % 256);
170 bytes[i++] = (byte)(ac % 256);
171 bytes[i++] = (byte)((ac >> 8) % 256);
172 bytes[i++] = (byte)(ac % 256);
173 bytes[i++] = (byte)((ac >> 8) % 256);
174
175 dat.Data=bytes;
176 return(dat);
177
178 }
95 179
96 public void SendInitialAppearance() { 180 public void SendInitialAppearance() {
97 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket(); 181 AgentWearablesUpdatePacket aw = new AgentWearablesUpdatePacket();
@@ -151,5 +235,16 @@ namespace OpenSim.world
151 Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet"); 235 Console.WriteLine("Avatar.cs:SendRegionHandshake() - Sending RegionHandshake packet");
152 this.ControllingClient.OutPacket(handshake); 236 this.ControllingClient.OutPacket(handshake);
153 } 237 }
238
239 public void HandleAgentUpdate(AgentUpdatePacket update) {
240 lock(this) {
241 // FIXME: shouldn't update these direction
242 this.rotation = new Quaternion(update.AgentData.BodyRotation.W, update.AgentData.BodyRotation.X, update.AgentData.BodyRotation.Y, update.AgentData.BodyRotation.Z);
243
244 this.CurrentKeyMask = update.AgentData.ControlFlags;
245 this.needupdate = true;
246 }
247 }
248
154 } 249 }
155} 250}