diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 101 |
1 files changed, 66 insertions, 35 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index fe85118..389a82b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -660,18 +660,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
660 | m_host.AddScriptLPS(1); | 660 | m_host.AddScriptLPS(1); |
661 | 661 | ||
662 | double x,y,z,s; | 662 | double x,y,z,s; |
663 | 663 | v.x *= 0.5; | |
664 | double c1 = Math.Cos(v.x * 0.5); | 664 | v.y *= 0.5; |
665 | double c2 = Math.Cos(v.y * 0.5); | 665 | v.z *= 0.5; |
666 | double c3 = Math.Cos(v.z * 0.5); | 666 | double c1 = Math.Cos(v.x); |
667 | double s1 = Math.Sin(v.x * 0.5); | 667 | double c2 = Math.Cos(v.y); |
668 | double s2 = Math.Sin(v.y * 0.5); | 668 | double c1c2 = c1 * c2; |
669 | double s3 = Math.Sin(v.z * 0.5); | 669 | double s1 = Math.Sin(v.x); |
670 | 670 | double s2 = Math.Sin(v.y); | |
671 | x = s1 * c2 * c3 + c1 * s2 * s3; | 671 | double s1s2 = s1 * s2; |
672 | y = c1 * s2 * c3 - s1 * c2 * s3; | 672 | double c1s2 = c1 * s2; |
673 | z = s1 * s2 * c3 + c1 * c2 * s3; | 673 | double s1c2 = s1 * c2; |
674 | s = c1 * c2 * c3 - s1 * s2 * s3; | 674 | double c3 = Math.Cos(v.z); |
675 | double s3 = Math.Sin(v.z); | ||
676 | |||
677 | x = s1c2 * c3 + c1s2 * s3; | ||
678 | y = c1s2 * c3 - s1c2 * s3; | ||
679 | z = s1s2 * c3 + c1c2 * s3; | ||
680 | s = c1c2 * c3 - s1s2 * s3; | ||
675 | 681 | ||
676 | return new LSL_Rotation(x, y, z, s); | 682 | return new LSL_Rotation(x, y, z, s); |
677 | } | 683 | } |
@@ -1911,11 +1917,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1911 | Primitive.TextureEntry tex = part.Shape.Textures; | 1917 | Primitive.TextureEntry tex = part.Shape.Textures; |
1912 | Color4 texcolor; | 1918 | Color4 texcolor; |
1913 | LSL_Vector rgb = new LSL_Vector(); | 1919 | LSL_Vector rgb = new LSL_Vector(); |
1920 | int nsides = GetNumberOfSides(part); | ||
1921 | |||
1914 | if (face == ScriptBaseClass.ALL_SIDES) | 1922 | if (face == ScriptBaseClass.ALL_SIDES) |
1915 | { | 1923 | { |
1916 | int i; | 1924 | int i; |
1917 | 1925 | for (i = 0; i < nsides; i++) | |
1918 | for (i = 0 ; i < GetNumberOfSides(part); i++) | ||
1919 | { | 1926 | { |
1920 | texcolor = tex.GetFace((uint)i).RGBA; | 1927 | texcolor = tex.GetFace((uint)i).RGBA; |
1921 | rgb.x += texcolor.R; | 1928 | rgb.x += texcolor.R; |
@@ -1923,13 +1930,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1923 | rgb.z += texcolor.B; | 1930 | rgb.z += texcolor.B; |
1924 | } | 1931 | } |
1925 | 1932 | ||
1926 | rgb.x /= (float)GetNumberOfSides(part); | 1933 | float invnsides = 1.0f / (float)nsides; |
1927 | rgb.y /= (float)GetNumberOfSides(part); | 1934 | |
1928 | rgb.z /= (float)GetNumberOfSides(part); | 1935 | rgb.x *= invnsides; |
1936 | rgb.y *= invnsides; | ||
1937 | rgb.z *= invnsides; | ||
1929 | 1938 | ||
1930 | return rgb; | 1939 | return rgb; |
1931 | } | 1940 | } |
1932 | if (face >= 0 && face < GetNumberOfSides(part)) | 1941 | if (face >= 0 && face < nsides) |
1933 | { | 1942 | { |
1934 | texcolor = tex.GetFace((uint)face).RGBA; | 1943 | texcolor = tex.GetFace((uint)face).RGBA; |
1935 | rgb.x = texcolor.R; | 1944 | rgb.x = texcolor.R; |
@@ -2328,13 +2337,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2328 | // (root prim). ParentID may be nonzero in attachments and | 2337 | // (root prim). ParentID may be nonzero in attachments and |
2329 | // using it would cause attachments and HUDs to rotate | 2338 | // using it would cause attachments and HUDs to rotate |
2330 | // to the wrong positions. | 2339 | // to the wrong positions. |
2340 | |||
2331 | SetRot(m_host, Rot2Quaternion(rot)); | 2341 | SetRot(m_host, Rot2Quaternion(rot)); |
2332 | } | 2342 | } |
2333 | else | 2343 | else |
2334 | { | 2344 | { |
2335 | // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. | 2345 | // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. |
2336 | SceneObjectPart rootPart = m_host.ParentGroup.RootPart; | 2346 | SceneObjectPart rootPart;// = m_host.ParentGroup.RootPart; |
2337 | if (rootPart != null) // better safe than sorry | 2347 | if (m_host.ParentGroup != null && ((rootPart = m_host.ParentGroup.RootPart) != null)) // better safe than sorry |
2338 | { | 2348 | { |
2339 | SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot)); | 2349 | SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot)); |
2340 | } | 2350 | } |
@@ -2346,6 +2356,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2346 | public void llSetLocalRot(LSL_Rotation rot) | 2356 | public void llSetLocalRot(LSL_Rotation rot) |
2347 | { | 2357 | { |
2348 | m_host.AddScriptLPS(1); | 2358 | m_host.AddScriptLPS(1); |
2359 | |||
2349 | SetRot(m_host, Rot2Quaternion(rot)); | 2360 | SetRot(m_host, Rot2Quaternion(rot)); |
2350 | ScriptSleep(200); | 2361 | ScriptSleep(200); |
2351 | } | 2362 | } |
@@ -2355,25 +2366,43 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2355 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | 2366 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) |
2356 | return; | 2367 | return; |
2357 | 2368 | ||
2358 | part.UpdateRotation(rot); | 2369 | bool isroot = (part == part.ParentGroup.RootPart); |
2359 | // Update rotation does not move the object in the physics scene if it's a linkset. | 2370 | bool isphys; |
2360 | 2371 | ||
2361 | //KF: Do NOT use this next line if using ODE physics engine. This need a switch based on .ini Phys Engine type | ||
2362 | // part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition; | ||
2363 | |||
2364 | // So, after thinking about this for a bit, the issue with the part.ParentGroup.AbsolutePosition = part.ParentGroup.AbsolutePosition line | ||
2365 | // is it isn't compatible with vehicles because it causes the vehicle body to have to be broken down and rebuilt | ||
2366 | // It's perfectly okay when the object is not an active physical body though. | ||
2367 | // So, part.ParentGroup.ResetChildPrimPhysicsPositions(); does the thing that Kitto is warning against | ||
2368 | // but only if the object is not physial and active. This is important for rotating doors. | ||
2369 | // without the absoluteposition = absoluteposition happening, the doors do not move in the physics | ||
2370 | // scene | ||
2371 | PhysicsActor pa = part.PhysActor; | 2372 | PhysicsActor pa = part.PhysActor; |
2372 | 2373 | ||
2373 | if (pa != null && !pa.IsPhysical && part == part.ParentGroup.RootPart) | 2374 | // keep using physactor ideia of isphysical |
2375 | // it should be SOP ideia of that | ||
2376 | // not much of a issue with ubitODE | ||
2377 | if (pa != null && pa.IsPhysical) | ||
2378 | isphys = true; | ||
2379 | else | ||
2380 | isphys = false; | ||
2381 | |||
2382 | // SL doesn't let scripts rotate root of physical linksets | ||
2383 | if (isroot && isphys) | ||
2384 | return; | ||
2385 | |||
2386 | part.UpdateRotation(rot); | ||
2387 | |||
2388 | // Update rotation does not move the object in the physics engine if it's a non physical linkset | ||
2389 | // so do a nasty update of parts positions if is a root part rotation | ||
2390 | if (isroot && pa != null) // with if above implies non physical root part | ||
2374 | { | 2391 | { |
2375 | part.ParentGroup.ResetChildPrimPhysicsPositions(); | 2392 | part.ParentGroup.ResetChildPrimPhysicsPositions(); |
2376 | } | 2393 | } |
2394 | else // fix sitting avatars. This is only needed bc of how we link avas to child parts, not root part | ||
2395 | { | ||
2396 | List<ScenePresence> sittingavas = part.ParentGroup.GetLinkedAvatars(); | ||
2397 | if (sittingavas.Count > 0) | ||
2398 | { | ||
2399 | foreach (ScenePresence av in sittingavas) | ||
2400 | { | ||
2401 | if (isroot || part.LocalId == av.ParentID) | ||
2402 | av.SendTerseUpdateToAllClients(); | ||
2403 | } | ||
2404 | } | ||
2405 | } | ||
2377 | } | 2406 | } |
2378 | 2407 | ||
2379 | /// <summary> | 2408 | /// <summary> |
@@ -2422,7 +2451,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2422 | public LSL_Rotation llGetLocalRot() | 2451 | public LSL_Rotation llGetLocalRot() |
2423 | { | 2452 | { |
2424 | m_host.AddScriptLPS(1); | 2453 | m_host.AddScriptLPS(1); |
2425 | return new LSL_Rotation(m_host.RotationOffset.X, m_host.RotationOffset.Y, m_host.RotationOffset.Z, m_host.RotationOffset.W); | 2454 | Quaternion rot = m_host.RotationOffset; |
2455 | return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); | ||
2426 | } | 2456 | } |
2427 | 2457 | ||
2428 | public void llSetForce(LSL_Vector force, int local) | 2458 | public void llSetForce(LSL_Vector force, int local) |
@@ -8534,6 +8564,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8534 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: | 8564 | case (int)ScriptBaseClass.PRIM_ROT_LOCAL: |
8535 | if (remain < 1) | 8565 | if (remain < 1) |
8536 | return; | 8566 | return; |
8567 | |||
8537 | LSL_Rotation lr = rules.GetQuaternionItem(idx++); | 8568 | LSL_Rotation lr = rules.GetQuaternionItem(idx++); |
8538 | SetRot(part, Rot2Quaternion(lr)); | 8569 | SetRot(part, Rot2Quaternion(lr)); |
8539 | break; | 8570 | break; |