aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorUbitUmarov2017-03-31 20:55:48 +0100
committerUbitUmarov2017-03-31 20:55:48 +0100
commit6a35a965ff7085b5962745437a10d798c0fb611d (patch)
tree029843113cec9fe04e733049c6232d2d36c2a106 /OpenSim/Region/ScriptEngine
parentAdapt to a variable name that has changed in core (diff)
downloadopensim-SC_OLD-6a35a965ff7085b5962745437a10d798c0fb611d.zip
opensim-SC_OLD-6a35a965ff7085b5962745437a10d798c0fb611d.tar.gz
opensim-SC_OLD-6a35a965ff7085b5962745437a10d798c0fb611d.tar.bz2
opensim-SC_OLD-6a35a965ff7085b5962745437a10d798c0fb611d.tar.xz
add OSSL functions to override linksets total mass, center of mass and inertia. replacing the crude automatic estimation based on prims known to physics and density. Changed parameters are still not saved, and are lost on region crossings. only suported by UbODE. EXPERIMENTAL feature, only test it for now.. don't try to use in products.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs213
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs26
3 files changed, 247 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 4c3f7ee..6c094ee 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -4404,5 +4404,218 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4404 m_host.ScriptSetVolumeDetect(detect != 0); 4404 m_host.ScriptSetVolumeDetect(detect != 0);
4405 } 4405 }
4406 4406
4407 /// <summary>
4408 /// Get inertial data
4409 /// </summary>
4410 /// <remarks>
4411 /// </remarks>
4412 /// <returns>
4413 /// a LSL list with contents:
4414 /// LSL_Float mass, the total mass of a linkset
4415 /// LSL_Vector CenterOfMass, center mass relative to root prim
4416 /// LSL_Vector Inertia, elements of diagonal of inertia Ixx,Iyy,Izz divided by total mass
4417 /// LSL_Vector aux, elements of upper triagle of inertia Ixy (= Iyx), Ixz (= Izx), Iyz(= Izy) divided by total mass
4418 /// </returns>
4419 public LSL_List osGetInertiaData()
4420 {
4421 LSL_List result = new LSL_List();
4422 float TotalMass;
4423 Vector3 CenterOfMass;
4424 Vector3 Inertia;
4425 Vector4 aux;
4426
4427 SceneObjectGroup sog = m_host.ParentGroup;
4428 if(sog== null || sog.IsDeleted)
4429 return result;
4430
4431 sog.GetInertiaData(out TotalMass, out CenterOfMass, out Inertia, out aux );
4432 if(TotalMass > 0)
4433 {
4434 float t = 1.0f/TotalMass;
4435 Inertia.X *= t;
4436 Inertia.Y *= t;
4437 Inertia.Z *= t;
4438
4439 aux.X *= t;
4440 aux.Y *= t;
4441 aux.Z *= t;
4442 }
4443
4444 result.Add(new LSL_Float(TotalMass));
4445 result.Add(new LSL_Vector(CenterOfMass.X, CenterOfMass.Y, CenterOfMass.Z));
4446 result.Add(new LSL_Vector(Inertia.X, Inertia.Y, Inertia.Z));
4447 result.Add(new LSL_Vector(aux.X, aux.Y, aux.Z));
4448 return result;
4449 }
4450
4451 /// <summary>
4452 /// set inertial data
4453 /// replaces the automatic calculation of mass, center of mass and inertia
4454 ///
4455 /// </summary>
4456 /// <param name="Mass">total mass of linkset</param>
4457 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4458 /// <param name="principalInertiaScaled">moment of inertia relative to principal axis and center of mass,Ixx, Iyy, Izz divided by mass</param>
4459 /// <param name="lslrot">rotation of the inertia, relative to local axis</param>
4460 /// <remarks>
4461 /// the inertia argument is is inertia divided by mass, so corresponds only to the geometric distribution of mass and both can be changed independently.
4462 /// </remarks>
4463
4464 public void osSetInertia(LSL_Float mass, LSL_Vector centerOfMass, LSL_Vector principalInertiaScaled, LSL_Rotation lslrot)
4465 {
4466 SceneObjectGroup sog = m_host.ParentGroup;
4467 if(sog== null || sog.IsDeleted)
4468 return;
4469
4470 if(mass < 0 || principalInertiaScaled.x < 0 || principalInertiaScaled.y < 0 || principalInertiaScaled.z < 0)
4471 return;
4472
4473 // need more checks
4474
4475 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4476 Vector3 Inertia;
4477 float m = (float)mass;
4478
4479 Inertia.X = m * (float)principalInertiaScaled.x;
4480 Inertia.Y = m * (float)principalInertiaScaled.y;
4481 Inertia.Z = m * (float)principalInertiaScaled.z;
4482
4483 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.y, (float)lslrot.s);
4484 rot.Normalize();
4485
4486 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4487 }
4488
4489 /// <summary>
4490 /// set inertial data as a sphere
4491 /// replaces the automatic calculation of mass, center of mass and inertia
4492 ///
4493 /// </summary>
4494 /// <param name="Mass">total mass of linkset</param>
4495 /// <param name="boxsize">size of the Box</param>
4496 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4497 /// <param name="lslrot">rotation of the box, and so inertia, relative to local axis</param>
4498 /// <remarks>
4499 /// </remarks>
4500 public void osSetInertiaAsBox(LSL_Float mass, LSL_Vector boxSize, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4501 {
4502 SceneObjectGroup sog = m_host.ParentGroup;
4503 if(sog== null || sog.IsDeleted)
4504 return;
4505
4506 if(mass < 0)
4507 return;
4508
4509 // need more checks
4510
4511 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4512 Vector3 Inertia;
4513 float lx = (float)boxSize.x;
4514 float ly = (float)boxSize.y;
4515 float lz = (float)boxSize.z;
4516 float m = (float)mass;
4517 float t = m / 12.0f;
4518
4519 Inertia.X = t * (ly*ly + lz*lz);
4520 Inertia.Y = t * (lx*lx + lz*lz);
4521 Inertia.Z = t * (lx*lx + ly*ly);
4522
4523 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4524 rot.Normalize();
4525
4526 sog.SetInertiaData(m, CenterOfMass, Inertia, rot );
4527 }
4528
4529 /// <summary>
4530 /// set inertial data as a sphere
4531 /// replaces the automatic calculation of mass, center of mass and inertia
4532 ///
4533 /// </summary>
4534 /// <param name="Mass">total mass of linkset</param>
4535 /// <param name="radius">radius of the sphere</param>
4536 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4537 /// <remarks>
4538 /// </remarks>
4539 public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, LSL_Vector centerOfMass)
4540 {
4541 SceneObjectGroup sog = m_host.ParentGroup;
4542 if(sog== null || sog.IsDeleted)
4543 return;
4544
4545 if(mass < 0)
4546 return;
4547
4548 // need more checks
4549
4550 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4551 Vector3 Inertia;
4552 float r = (float)radius;
4553 float m = (float)mass;
4554 float t = 0.4f * m * r * r;
4555
4556 Inertia.X = t;
4557 Inertia.Y = t;
4558 Inertia.Z = t;
4559
4560 sog.SetInertiaData(m, CenterOfMass, Inertia, new Vector4(0f, 0f, 0f,1.0f));
4561 }
4562
4563 /// <summary>
4564 /// set inertial data as a cylinder
4565 /// replaces the automatic calculation of mass, center of mass and inertia
4566 ///
4567 /// </summary>
4568 /// <param name="Mass">total mass of linkset</param>
4569 /// <param name="radius">radius of the cylinder</param>
4570 /// <param name="lenght">lenght of the cylinder</param>
4571 /// <param name="centerOfMass">location of center of mass relative to root prim in local coords</param>
4572 /// <param name="lslrot">rotation of the cylinder, and so inertia, relative to local axis</param>
4573 /// <remarks>
4574 /// cylinder axis aligned with Z axis. For other orientations provide the rotation.
4575 /// </remarks>
4576 public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, LSL_Vector centerOfMass, LSL_Rotation lslrot)
4577 {
4578 SceneObjectGroup sog = m_host.ParentGroup;
4579 if(sog== null || sog.IsDeleted)
4580 return;
4581
4582 if(mass < 0)
4583 return;
4584
4585 // need more checks
4586
4587 Vector3 CenterOfMass = new Vector3((float)centerOfMass.x,(float)centerOfMass.y,(float)centerOfMass.z);
4588 Vector3 Inertia;
4589 float m = (float)mass;
4590 float r = (float)radius;
4591 r *= r;
4592 Inertia.Z = 0.5f * m * r;
4593 float t = (float)lenght;
4594 t *= t;
4595 t += 3.0f * r;
4596 t *= 8.333333e-2f * m;
4597
4598 Inertia.X = t;
4599 Inertia.Y = t;
4600
4601 Vector4 rot = new Vector4((float)lslrot.x, (float)lslrot.y, (float)lslrot.z, (float)lslrot.s);
4602 rot.Normalize();
4603
4604 sog.SetInertiaData(m, CenterOfMass, Inertia, rot);
4605 }
4606
4607 /// <summary>
4608 /// removes inertial data manual override
4609 /// default automatic calculation is used again
4610 ///
4611 /// </summary>
4612 public void osClearInertia()
4613 {
4614 SceneObjectGroup sog = m_host.ParentGroup;
4615 if(sog== null || sog.IsDeleted)
4616 return;
4617
4618 sog.SetInertiaData(-1, Vector3.Zero, Vector3.Zero, Vector4.Zero );
4619 }
4407 } 4620 }
4408} 4621}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index bee060a..f76ff7f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -38,6 +38,7 @@ using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
38using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; 38using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
39using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString; 39using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
40 40
41
41namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces 42namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
42{ 43{
43 /// <summary> 44 /// <summary>
@@ -486,6 +487,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
486 LSL_String osRequestURL(LSL_List options); 487 LSL_String osRequestURL(LSL_List options);
487 LSL_String osRequestSecureURL(LSL_List options); 488 LSL_String osRequestSecureURL(LSL_List options);
488 void osCollisionSound(string impact_sound, double impact_volume); 489 void osCollisionSound(string impact_sound, double impact_volume);
490
489 void osVolumeDetect(int detect); 491 void osVolumeDetect(int detect);
492
493 LSL_List osGetInertiaData();
494 void osClearInertia();
495 void osSetInertiaAsBox(LSL_Float mass, vector boxSize, vector centerOfMass, rotation rot);
496 void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, vector centerOfMass);
497 void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, vector centerOfMass,rotation lslrot);
490 } 498 }
491} 499}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 6164734..09337e5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -1114,5 +1114,31 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
1114 { 1114 {
1115 m_OSSL_Functions.osVolumeDetect(detect); 1115 m_OSSL_Functions.osVolumeDetect(detect);
1116 } 1116 }
1117
1118 public LSL_List osGetInertiaData()
1119 {
1120 return m_OSSL_Functions.osGetInertiaData();
1121 }
1122
1123 public void osSetInertiaAsBox(LSL_Float mass, vector boxSize, vector centerOfMass, rotation rot)
1124 {
1125 m_OSSL_Functions.osSetInertiaAsBox(mass, boxSize, centerOfMass, rot);
1126 }
1127
1128 public void osSetInertiaAsSphere(LSL_Float mass, LSL_Float radius, vector centerOfMass)
1129 {
1130 m_OSSL_Functions.osSetInertiaAsSphere(mass, radius, centerOfMass);
1131 }
1132
1133 public void osSetInertiaAsCylinder(LSL_Float mass, LSL_Float radius, LSL_Float lenght, vector centerOfMass,rotation lslrot)
1134 {
1135 m_OSSL_Functions.osSetInertiaAsCylinder( mass, radius, lenght, centerOfMass, lslrot);
1136 }
1137
1138 public void osClearInertia()
1139 {
1140 m_OSSL_Functions.osClearInertia();
1141 }
1142
1117 } 1143 }
1118} 1144}