aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs169
1 files changed, 169 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs b/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
new file mode 100644
index 0000000..c3817ef
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ContentManagementSystem/SceneObjectGroupDiff.cs
@@ -0,0 +1,169 @@
1// SceneObjectGroupDiff.cs
2// User: bongiojp
3
4using System;
5using System.Collections.Generic;
6using System.Drawing;
7using libsecondlife;
8using Nini.Config;
9using OpenSim.Framework;
10using OpenSim.Region.Environment.Interfaces;
11using OpenSim.Region.Environment.Scenes;
12using log4net;
13using OpenSim.Region.Physics.Manager;
14using Axiom.Math;
15using System.Diagnostics;
16
17namespace OpenSim.Region.Environment.Modules.ContentManagement
18{
19 [Flags]
20 public enum Diff
21 {
22 NONE = 0,
23 FACECOLOR = 1,
24 SHAPE = 1<<1,
25 MATERIAL = 1<<2,
26 TEXTURE = 1<<3,
27 SCALE = 1<<4,
28 POSITION = 1<<5,
29 OFFSETPOSITION = 1<<6,
30 ROTATIONOFFSET = 1<<7,
31 ROTATIONALVELOCITY = 1<<8,
32 ACCELERATION = 1<<9,
33 ANGULARVELOCITY = 1<<10,
34 VELOCITY = 1<<11,
35 OBJECTOWNER = 1<<12,
36 PERMISSIONS = 1<<13,
37 DESCRIPTION = 1<<14,
38 NAME = 1<<15,
39 SCRIPT = 1<<16,
40 CLICKACTION = 1<<17,
41 PARTICLESYSTEM = 1<<18,
42 GLOW = 1<<19,
43 SALEPRICE = 1<<20,
44 SITNAME = 1<<21,
45 SITTARGETORIENTATION = 1<<22,
46 SITTARGETPOSITION = 1<<23,
47 TEXT = 1<<24,
48 TOUCHNAME = 1<<25
49 };
50
51 public static class Difference
52 {
53 static float TimeToDiff = 0;
54
55 private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
56
57 private static int TruncateSignificant(float num, int digits)
58 {
59 return (int) Math.Ceiling((Math.Truncate(num * 10 * digits)/10*digits));
60 // return (int) ((num * (10*digits))/10*digits);
61 }
62
63 private static bool AreVectorsEquivalent(LLVector3 first, LLVector3 second)
64 {
65 if(TruncateSignificant(first.X, 2) == TruncateSignificant(second.X, 2)
66 && TruncateSignificant(first.Y, 2) == TruncateSignificant(second.Y, 2)
67 && TruncateSignificant(first.Z, 2) == TruncateSignificant(second.Z, 2)
68 )
69 return true;
70 else
71 return false;
72 }
73
74 private static bool AreQuaternionsEquivalent(LLQuaternion first, LLQuaternion second)
75 {
76 LLVector3 firstVector = llRot2Euler(first);
77 LLVector3 secondVector = llRot2Euler(second);
78 return AreVectorsEquivalent(firstVector, secondVector);
79 }
80
81 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
82 // Also changed the original function from LSL_Types to LL types
83 private static LLVector3 llRot2Euler(LLQuaternion r)
84 {
85 LLQuaternion t = new LLQuaternion(r.X * r.X, r.Y * r.Y, r.Z * r.Z, r.W * r.W);
86 double m = (t.X + t.Y + t.Z + t.W);
87 if (m == 0) return new LLVector3();
88 double n = 2 * (r.Y * r.W + r.X * r.Z);
89 double p = m * m - n * n;
90 if (p > 0)
91 return new LLVector3((float)NormalizeAngle(Math.Atan2(2.0 * (r.X * r.W - r.Y * r.Z), (-t.X - t.Y + t.Z + t.W))),
92 (float)NormalizeAngle(Math.Atan2(n, Math.Sqrt(p))),
93 (float)NormalizeAngle(Math.Atan2(2.0 * (r.Z * r.W - r.X * r.Y), (t.X - t.Y - t.Z + t.W))));
94 else if (n > 0)
95 return new LLVector3(0.0f, (float)(Math.PI / 2), (float)NormalizeAngle(Math.Atan2((r.Z * r.W + r.X * r.Y), 0.5 - t.X - t.Z)));
96 else
97 return new LLVector3(0.0f, (float)(-Math.PI / 2), (float)NormalizeAngle(Math.Atan2((r.Z * r.W + r.X * r.Y), 0.5 - t.X - t.Z)));
98 }
99
100 // Taken from Region/ScriptEngine/Common/LSL_BuiltIn_Commands.cs
101 private static double NormalizeAngle(double angle)
102 {
103 angle = angle % (Math.PI * 2);
104 if (angle < 0) angle = angle + Math.PI * 2;
105 return angle;
106 }
107
108 /// <summary>
109 /// Compares the attributes (Vectors, Quaternions, Strings, etc.) between two scene object parts
110 /// and returns a Diff bitmask which details what the differences are.
111 /// </summary>
112 public static Diff FindDifferences(SceneObjectPart first, SceneObjectPart second)
113 {
114 Stopwatch x = new Stopwatch();
115 x.Start();
116
117 Diff result = 0;
118
119 // VECTOR COMPARISONS
120 if(! AreVectorsEquivalent(first.Acceleration, second.Acceleration))
121 result |= Diff.ACCELERATION;
122 if(! AreVectorsEquivalent(first.AbsolutePosition, second.AbsolutePosition))
123 result |= Diff.POSITION;
124 if(! AreVectorsEquivalent(first.AngularVelocity, second.AngularVelocity))
125 result |= Diff.ANGULARVELOCITY;
126 if(! AreVectorsEquivalent(first.OffsetPosition, second.OffsetPosition))
127 result |= Diff.OFFSETPOSITION;
128 if(! AreVectorsEquivalent(first.RotationalVelocity, second.RotationalVelocity))
129 result |= Diff.ROTATIONALVELOCITY;
130 if(! AreVectorsEquivalent(first.Scale, second.Scale))
131 result |= Diff.SCALE;
132 if(! AreVectorsEquivalent(first.Velocity, second.Velocity))
133 result |= Diff.VELOCITY;
134
135
136 // QUATERNION COMPARISONS
137 if(! AreQuaternionsEquivalent(first.RotationOffset, second.RotationOffset))
138 result |= Diff.ROTATIONOFFSET;
139
140
141 // MISC COMPARISONS (LLUUID, Byte)
142 if(first.ClickAction != second.ClickAction)
143 result |= Diff.CLICKACTION;
144 if(first.ObjectOwner != second.ObjectOwner)
145 result |= Diff.OBJECTOWNER;
146
147
148 // STRING COMPARISONS
149 if(first.Description != second.Description)
150 result |= Diff.DESCRIPTION;
151 if(first.Material != second.Material)
152 result |= Diff.MATERIAL;
153 if(first.Name != second.Name)
154 result |= Diff.NAME;
155 if(first.SitName != second.SitName)
156 result |= Diff.SITNAME;
157 if(first.Text != second.Text)
158 result |= Diff.TEXT;
159 if(first.TouchName != second.TouchName)
160 result |= Diff.TOUCHNAME;
161
162 x.Stop();
163 TimeToDiff += x.ElapsedMilliseconds;
164 //m_log.Info("[DIFFERENCES] Time spent diffing objects so far" + TimeToDiff);
165
166 return result;
167 }
168 }
169}