aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs167
1 files changed, 156 insertions, 11 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
index 9bf2abe..2adbe01 100644
--- a/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/UbitOdePlugin/OdeScene.cs
@@ -935,18 +935,22 @@ namespace OpenSim.Region.Physics.OdePlugin
935 SharedTmpcontact.surface.mu = mu; 935 SharedTmpcontact.surface.mu = mu;
936 SharedTmpcontact.surface.bounce = bounce; 936 SharedTmpcontact.surface.bounce = bounce;
937 937
938 d.ContactGeom altContact = new d.ContactGeom();
939 bool useAltcontact = false;
940 bool noskip = true;
941
938 while (true) 942 while (true)
939 { 943 {
940// if (!(IgnoreNegSides && curContact.side1 < 0)) 944// if (!(IgnoreNegSides && curContact.side1 < 0))
941 { 945 {
942 bool noskip = true; 946 noskip = true;
947 useAltcontact = false;
948
943 if (dop1ava) 949 if (dop1ava)
944 { 950 {
945 if (!(((OdeCharacter)p1).Collide(g1, g2, false, ref curContact, ref FeetCollision))) 951 if ((((OdeCharacter)p1).Collide(g1, g2, false, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
946 noskip = false;
947 else
948 { 952 {
949 if(p2.PhysicsActorType == (int)ActorTypes.Agent) 953 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
950 { 954 {
951 p1.CollidingObj = true; 955 p1.CollidingObj = true;
952 p2.CollidingObj = true; 956 p2.CollidingObj = true;
@@ -954,18 +958,32 @@ namespace OpenSim.Region.Physics.OdePlugin
954 else if (p2.Velocity.LengthSquared() > 0.0f) 958 else if (p2.Velocity.LengthSquared() > 0.0f)
955 p2.CollidingObj = true; 959 p2.CollidingObj = true;
956 } 960 }
961 else
962 noskip = false;
957 } 963 }
958 else if (dop2ava) 964 else if (dop2ava)
959 { 965 {
960 if (!(((OdeCharacter)p2).Collide(g2,g1, true, ref curContact, ref FeetCollision))) 966 if ((((OdeCharacter)p2).Collide(g2, g1, true, ref curContact, ref altContact , ref useAltcontact, ref FeetCollision)))
967 {
968 if (p1.PhysicsActorType == (int)ActorTypes.Agent)
969 {
970 p1.CollidingObj = true;
971 p2.CollidingObj = true;
972 }
973 else if (p2.Velocity.LengthSquared() > 0.0f)
974 p1.CollidingObj = true;
975 }
976 else
961 noskip = false; 977 noskip = false;
962 else if (p1.Velocity.LengthSquared() > 0.0f)
963 p1.CollidingObj = true;
964 } 978 }
965 979
966 if (noskip) 980 if (noskip)
967 { 981 {
968 Joint = CreateContacJoint(ref curContact); 982 if(useAltcontact)
983 Joint = CreateContacJoint(ref altContact);
984 else
985 Joint = CreateContacJoint(ref curContact);
986
969 if (Joint == IntPtr.Zero) 987 if (Joint == IntPtr.Zero)
970 break; 988 break;
971 989
@@ -1924,12 +1942,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1924 dy = 0; 1942 dy = 0;
1925 } 1943 }
1926 } 1944 }
1927
1928 else 1945 else
1929 { 1946 {
1930 // we still have square fixed size regions 1947 // we still have square fixed size regions
1931 // also flip x and y because of how map is done for ODE fliped axis 1948 // also flip x and y because of how map is done for ODE fliped axis
1932 // so ix,iy,dx and dy are inter exchanged 1949 // so ix,iy,dx and dy are inter exchanged
1950
1933 if (x < regsize - 1) 1951 if (x < regsize - 1)
1934 { 1952 {
1935 iy = (int)x; 1953 iy = (int)x;
@@ -1976,7 +1994,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1976 */ 1994 */
1977 h0 = ((float)heights[iy]); // 0,0 vertice 1995 h0 = ((float)heights[iy]); // 0,0 vertice
1978 1996
1979 if ((dy > dx)) 1997 if (dy>dx)
1980 { 1998 {
1981 iy += regsize; 1999 iy += regsize;
1982 h2 = (float)heights[iy]; // 0,1 vertice 2000 h2 = (float)heights[iy]; // 0,1 vertice
@@ -1994,6 +2012,133 @@ namespace OpenSim.Region.Physics.OdePlugin
1994 return h0 + h1 + h2; 2012 return h0 + h1 + h2;
1995 } 2013 }
1996 2014
2015 public Vector3 GetTerrainNormalAtXY(float x, float y)
2016 {
2017 int offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2018 int offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2019
2020 IntPtr heightFieldGeom = IntPtr.Zero;
2021 Vector3 norm = new Vector3(0, 0, 1);
2022
2023 // get region map
2024 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom))
2025 return norm;
2026
2027 if (heightFieldGeom == IntPtr.Zero)
2028 return norm;
2029
2030 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
2031 return norm;
2032
2033 // TerrainHeightField for ODE as offset 1m
2034 x += 1f - offsetX;
2035 y += 1f - offsetY;
2036
2037 // make position fit into array
2038 if (x < 0)
2039 x = 0;
2040 if (y < 0)
2041 y = 0;
2042
2043 // integer indexs
2044 int ix;
2045 int iy;
2046 // interpolators offset
2047 float dx;
2048 float dy;
2049
2050
2051 int regsize = (int)Constants.RegionSize + 3; // map size see setterrain number of samples
2052 int xstep = 1;
2053 int ystep = regsize;
2054 bool firstTri = false;
2055
2056 if (OdeUbitLib)
2057 {
2058 if (x < regsize - 1)
2059 {
2060 ix = (int)x;
2061 dx = x - (float)ix;
2062 }
2063 else // out world use external height
2064 {
2065 ix = regsize - 2;
2066 dx = 0;
2067 }
2068 if (y < regsize - 1)
2069 {
2070 iy = (int)y;
2071 dy = y - (float)iy;
2072 }
2073 else
2074 {
2075 iy = regsize - 2;
2076 dy = 0;
2077 }
2078 firstTri = dy > dx;
2079 }
2080
2081 else
2082 {
2083 xstep = regsize;
2084 ystep = 1;
2085 // we still have square fixed size regions
2086 // also flip x and y because of how map is done for ODE fliped axis
2087 // so ix,iy,dx and dy are inter exchanged
2088 if (x < regsize - 1)
2089 {
2090 iy = (int)x;
2091 dy = x - (float)iy;
2092 }
2093 else // out world use external height
2094 {
2095 iy = regsize - 2;
2096 dy = 0;
2097 }
2098 if (y < regsize - 1)
2099 {
2100 ix = (int)y;
2101 dx = y - (float)ix;
2102 }
2103 else
2104 {
2105 ix = regsize - 2;
2106 dx = 0;
2107 }
2108 firstTri = dx > dy;
2109 }
2110
2111 float h0;
2112 float h1;
2113 float h2;
2114
2115 iy *= regsize;
2116 iy += ix; // all indexes have iy + ix
2117
2118 float[] heights = TerrainHeightFieldHeights[heightFieldGeom];
2119
2120 if (firstTri)
2121 {
2122 h1 = ((float)heights[iy]); // 0,0 vertice
2123 iy += ystep;
2124 h0 = (float)heights[iy]; // 0,1
2125 h2 = (float)heights[iy+xstep]; // 1,1 vertice
2126 norm.X = h0 - h2;
2127 norm.Y = h1 - h0;
2128 }
2129 else
2130 {
2131 h2 = ((float)heights[iy]); // 0,0 vertice
2132 iy += xstep;
2133 h0 = ((float)heights[iy]); // 1,0 vertice
2134 h1 = (float)heights[iy+ystep]; // vertice 1,1
2135 norm.X = h2 - h0;
2136 norm.Y = h0 - h1;
2137 }
2138 norm.Z = 1;
2139 norm.Normalize();
2140 return norm;
2141 }
1997 2142
1998 public override void SetTerrain(float[] heightMap) 2143 public override void SetTerrain(float[] heightMap)
1999 { 2144 {