diff options
author | UbitUmarov | 2014-09-29 20:17:05 +0100 |
---|---|---|
committer | UbitUmarov | 2014-09-29 20:17:05 +0100 |
commit | 3052a5388954592861e0a55681844115485b6ae7 (patch) | |
tree | fa3fafcc33826448978f27e71bdf9151a755b23a /OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | |
parent | change permitions again (diff) | |
download | opensim-SC-3052a5388954592861e0a55681844115485b6ae7.zip opensim-SC-3052a5388954592861e0a55681844115485b6ae7.tar.gz opensim-SC-3052a5388954592861e0a55681844115485b6ae7.tar.bz2 opensim-SC-3052a5388954592861e0a55681844115485b6ae7.tar.xz |
change avatar physics and motion control. Still not that good :(
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | 210 |
1 files changed, 164 insertions, 46 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs index daf6c7c..4a98df4 100644 --- a/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs +++ b/OpenSim/Region/Physics/UbitOdePlugin/ODECharacter.cs | |||
@@ -79,6 +79,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
79 | private Vector3 _acceleration; | 79 | private Vector3 _acceleration; |
80 | private Vector3 m_rotationalVelocity; | 80 | private Vector3 m_rotationalVelocity; |
81 | private Vector3 m_size; | 81 | private Vector3 m_size; |
82 | private Vector3 m_collideNormal; | ||
82 | private Quaternion m_orientation; | 83 | private Quaternion m_orientation; |
83 | private Quaternion m_orientation2D; | 84 | private Quaternion m_orientation2D; |
84 | private float m_mass = 80f; | 85 | private float m_mass = 80f; |
@@ -109,6 +110,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
109 | 110 | ||
110 | private bool _zeroFlag = false; | 111 | private bool _zeroFlag = false; |
111 | 112 | ||
113 | |||
112 | private uint m_localID = 0; | 114 | private uint m_localID = 0; |
113 | public bool m_returnCollisions = false; | 115 | public bool m_returnCollisions = false; |
114 | // taints and their non-tainted counterparts | 116 | // taints and their non-tainted counterparts |
@@ -153,9 +155,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
153 | public UUID m_uuid; | 155 | public UUID m_uuid; |
154 | public bool bad = false; | 156 | public bool bad = false; |
155 | 157 | ||
156 | float mu; | 158 | float mu; |
157 | |||
158 | |||
159 | 159 | ||
160 | public OdeCharacter(uint localID, String avName, OdeScene parent_scene, Vector3 pos, Vector3 pSize, float pfeetOffset, float density, float walk_divisor, float rundivisor) | 160 | public OdeCharacter(uint localID, String avName, OdeScene parent_scene, Vector3 pos, Vector3 pSize, float pfeetOffset, float density, float walk_divisor, float rundivisor) |
161 | { | 161 | { |
@@ -864,11 +864,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
864 | x = tx * cos - y * sin; | 864 | x = tx * cos - y * sin; |
865 | y = tx * sin + y * cos; | 865 | y = tx * sin + y * cos; |
866 | } | 866 | } |
867 | 867 | ||
868 | 868 | public bool Collide(IntPtr me, IntPtr other, bool reverse, ref d.ContactGeom contact, | |
869 | public bool Collide(IntPtr me,IntPtr other, bool reverse, ref d.ContactGeom contact, ref bool feetcollision) | 869 | ref d.ContactGeom altContact , ref bool useAltcontact, ref bool feetcollision) |
870 | { | 870 | { |
871 | feetcollision = false; | 871 | feetcollision = false; |
872 | useAltcontact = false; | ||
872 | 873 | ||
873 | if (me == capsule) | 874 | if (me == capsule) |
874 | { | 875 | { |
@@ -899,31 +900,77 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
899 | { | 900 | { |
900 | feetcollision = true; | 901 | feetcollision = true; |
901 | if (h < boneOff) | 902 | if (h < boneOff) |
903 | { | ||
904 | m_collideNormal.X = contact.normal.X; | ||
905 | m_collideNormal.Y = contact.normal.Y; | ||
906 | m_collideNormal.Z = contact.normal.Z; | ||
902 | IsColliding = true; | 907 | IsColliding = true; |
908 | } | ||
903 | } | 909 | } |
904 | return true; | 910 | return true; |
905 | } | 911 | } |
912 | |||
913 | d.AABB aabb; | ||
914 | d.GeomGetAABB(other,out aabb); | ||
915 | float othertop = aabb.MaxZ - _position.Z; | ||
916 | |||
917 | if (offset.Z > 0 || othertop > -feetOff || contact.normal.Z > 0.35f) | ||
918 | { | ||
919 | if (offset.Z <= 0) | ||
920 | { | ||
921 | feetcollision = true; | ||
922 | if (h < boneOff) | ||
923 | { | ||
924 | m_collideNormal.X = contact.normal.X; | ||
925 | m_collideNormal.Y = contact.normal.Y; | ||
926 | m_collideNormal.Z = contact.normal.Z; | ||
927 | IsColliding = true; | ||
928 | } | ||
929 | } | ||
906 | 930 | ||
907 | if (offset.Z > 0) | 931 | if (contact.normal.Z < 0.2f) |
932 | { | ||
933 | contact.normal.Z = 0; | ||
934 | float t = contact.normal.X * contact.normal.X + contact.normal.Y * contact.normal.Y; | ||
935 | if (t > 0) | ||
936 | { | ||
937 | t = 1.0f / t; | ||
938 | contact.normal.X *= t; | ||
939 | contact.normal.Y *= t; | ||
940 | } | ||
941 | } | ||
908 | return true; | 942 | return true; |
943 | } | ||
944 | |||
945 | altContact = contact; | ||
946 | useAltcontact = true; | ||
909 | 947 | ||
910 | offset.Normalize(); | 948 | offset.Normalize(); |
911 | 949 | ||
950 | if (contact.depth > 0.1f) | ||
951 | contact.depth = 0.1f; | ||
952 | |||
912 | if (reverse) | 953 | if (reverse) |
913 | { | 954 | { |
914 | contact.normal.X = offset.X; | 955 | altContact.normal.X = offset.X; |
915 | contact.normal.Y = offset.Y; | 956 | altContact.normal.Y = offset.Y; |
916 | contact.normal.Z = offset.Z; | 957 | altContact.normal.Z = offset.Z; |
917 | } | 958 | } |
918 | else | 959 | else |
919 | { | 960 | { |
920 | contact.normal.X = -offset.X; | 961 | altContact.normal.X = -offset.X; |
921 | contact.normal.Y = -offset.Y; | 962 | altContact.normal.Y = -offset.Y; |
922 | contact.normal.Z = -offset.Z; | 963 | altContact.normal.Z = -offset.Z; |
923 | } | 964 | } |
965 | |||
924 | feetcollision = true; | 966 | feetcollision = true; |
925 | if (h < boneOff) | 967 | if (h < boneOff) |
968 | { | ||
969 | m_collideNormal.X = contact.normal.X; | ||
970 | m_collideNormal.Y = contact.normal.Y; | ||
971 | m_collideNormal.Z = contact.normal.Z; | ||
926 | IsColliding = true; | 972 | IsColliding = true; |
973 | } | ||
927 | return true; | 974 | return true; |
928 | } | 975 | } |
929 | return false; | 976 | return false; |
@@ -1003,6 +1050,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1003 | Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); | 1050 | Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); |
1004 | float velLengthSquared = vel.LengthSquared(); | 1051 | float velLengthSquared = vel.LengthSquared(); |
1005 | 1052 | ||
1053 | |||
1054 | Vector3 ctz = _target_velocity; | ||
1055 | |||
1006 | float movementdivisor = 1f; | 1056 | float movementdivisor = 1f; |
1007 | //Ubit change divisions into multiplications below | 1057 | //Ubit change divisions into multiplications below |
1008 | if (!m_alwaysRun) | 1058 | if (!m_alwaysRun) |
@@ -1010,13 +1060,16 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1010 | else | 1060 | else |
1011 | movementdivisor = 1 / runDivisor; | 1061 | movementdivisor = 1 / runDivisor; |
1012 | 1062 | ||
1063 | ctz.X *= movementdivisor; | ||
1064 | ctz.Y *= movementdivisor; | ||
1065 | |||
1013 | //****************************************** | 1066 | //****************************************** |
1014 | // colide with land | 1067 | // colide with land |
1015 | 1068 | ||
1016 | d.AABB aabb; | 1069 | d.AABB aabb; |
1017 | // d.GeomGetAABB(feetbox, out aabb); | 1070 | // d.GeomGetAABB(feetbox, out aabb); |
1018 | d.GeomGetAABB(capsule, out aabb); | 1071 | d.GeomGetAABB(capsule, out aabb); |
1019 | float chrminZ = aabb.MinZ; ; // move up a bit | 1072 | float chrminZ = aabb.MinZ; // move up a bit |
1020 | Vector3 posch = localpos; | 1073 | Vector3 posch = localpos; |
1021 | 1074 | ||
1022 | float ftmp; | 1075 | float ftmp; |
@@ -1031,15 +1084,18 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1031 | float terrainheight = _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y); | 1084 | float terrainheight = _parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y); |
1032 | if (chrminZ < terrainheight) | 1085 | if (chrminZ < terrainheight) |
1033 | { | 1086 | { |
1087 | if (ctz.Z < 0) | ||
1088 | ctz.Z = 0; | ||
1089 | |||
1090 | Vector3 n = _parent_scene.GetTerrainNormalAtXY(posch.X, posch.Y); | ||
1034 | float depth = terrainheight - chrminZ; | 1091 | float depth = terrainheight - chrminZ; |
1092 | |||
1093 | vec.Z = depth * PID_P * 50; | ||
1094 | |||
1035 | if (!flying) | 1095 | if (!flying) |
1036 | { | 1096 | vec.Z += -vel.Z * PID_D; |
1037 | vec.Z = -vel.Z * PID_D * 1.5f + depth * PID_P * 50; | ||
1038 | } | ||
1039 | else | ||
1040 | vec.Z = depth * PID_P * 50; | ||
1041 | 1097 | ||
1042 | if (depth < 0.1f) | 1098 | if (depth < 0.2f) |
1043 | { | 1099 | { |
1044 | m_colliderGroundfilter++; | 1100 | m_colliderGroundfilter++; |
1045 | if (m_colliderGroundfilter > 2) | 1101 | if (m_colliderGroundfilter > 2) |
@@ -1053,50 +1109,83 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1053 | m_freemove = false; | 1109 | m_freemove = false; |
1054 | } | 1110 | } |
1055 | 1111 | ||
1112 | m_collideNormal.X = n.X; | ||
1113 | m_collideNormal.Y = n.Y; | ||
1114 | m_collideNormal.Z = n.Z; | ||
1115 | |||
1056 | m_iscollidingGround = true; | 1116 | m_iscollidingGround = true; |
1057 | 1117 | ||
1118 | |||
1058 | ContactPoint contact = new ContactPoint(); | 1119 | ContactPoint contact = new ContactPoint(); |
1059 | contact.PenetrationDepth = depth; | 1120 | contact.PenetrationDepth = depth; |
1060 | contact.Position.X = localpos.X; | 1121 | contact.Position.X = localpos.X; |
1061 | contact.Position.Y = localpos.Y; | 1122 | contact.Position.Y = localpos.Y; |
1062 | contact.Position.Z = terrainheight; | 1123 | contact.Position.Z = terrainheight; |
1063 | contact.SurfaceNormal.X = 0.0f; | 1124 | contact.SurfaceNormal.X = -n.X; |
1064 | contact.SurfaceNormal.Y = 0.0f; | 1125 | contact.SurfaceNormal.Y = -n.Y; |
1065 | contact.SurfaceNormal.Z = -1f; | 1126 | contact.SurfaceNormal.Z = -n.Z; |
1066 | contact.RelativeSpeed = -vel.Z; | 1127 | contact.RelativeSpeed = -vel.Z; |
1067 | contact.CharacterFeet = true; | 1128 | contact.CharacterFeet = true; |
1068 | AddCollisionEvent(0, contact); | 1129 | AddCollisionEvent(0, contact); |
1069 | 1130 | ||
1070 | vec.Z *= 0.5f; | 1131 | // vec.Z *= 0.5f; |
1071 | } | 1132 | } |
1072 | } | 1133 | } |
1073 | 1134 | ||
1074 | else | 1135 | else |
1075 | { | 1136 | { |
1076 | m_colliderGroundfilter = 0; | 1137 | m_colliderGroundfilter -= 5; |
1077 | m_iscollidingGround = false; | 1138 | if (m_colliderGroundfilter <= 0) |
1139 | { | ||
1140 | m_colliderGroundfilter = 0; | ||
1141 | m_iscollidingGround = false; | ||
1142 | } | ||
1078 | } | 1143 | } |
1079 | } | 1144 | } |
1080 | else | 1145 | else |
1081 | { | 1146 | { |
1082 | m_colliderGroundfilter = 0; | 1147 | m_colliderGroundfilter -= 5; |
1083 | m_iscollidingGround = false; | 1148 | if (m_colliderGroundfilter <= 0) |
1149 | { | ||
1150 | m_colliderGroundfilter = 0; | ||
1151 | m_iscollidingGround = false; | ||
1152 | } | ||
1084 | } | 1153 | } |
1085 | 1154 | ||
1086 | 1155 | ||
1087 | //****************************************** | 1156 | //****************************************** |
1157 | if (!m_iscolliding) | ||
1158 | m_collideNormal.Z = 0; | ||
1159 | |||
1160 | bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f); | ||
1161 | |||
1088 | 1162 | ||
1089 | bool tviszero = (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f); | ||
1090 | 1163 | ||
1091 | // if (!tviszero || m_iscolliding || velLengthSquared <0.01) | ||
1092 | if (!tviszero) | 1164 | if (!tviszero) |
1165 | { | ||
1093 | m_freemove = false; | 1166 | m_freemove = false; |
1094 | 1167 | ||
1168 | // movement relative to surface if moving on it | ||
1169 | // dont disturbe vertical movement, ie jumps | ||
1170 | if (m_iscolliding && !flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f) | ||
1171 | { | ||
1172 | float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y; | ||
1173 | ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X); | ||
1174 | ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y); | ||
1175 | ctz.Z -= p; | ||
1176 | if (ctz.Z < 0) | ||
1177 | ctz.Z *= 2; | ||
1178 | |||
1179 | } | ||
1180 | |||
1181 | } | ||
1182 | |||
1183 | |||
1095 | if (!m_freemove) | 1184 | if (!m_freemove) |
1096 | { | 1185 | { |
1097 | 1186 | ||
1098 | // if velocity is zero, use position control; otherwise, velocity control | 1187 | // if velocity is zero, use position control; otherwise, velocity control |
1099 | if (tviszero && m_iscolliding) | 1188 | if (tviszero && m_iscolliding && !flying) |
1100 | { | 1189 | { |
1101 | // keep track of where we stopped. No more slippin' & slidin' | 1190 | // keep track of where we stopped. No more slippin' & slidin' |
1102 | if (!_zeroFlag) | 1191 | if (!_zeroFlag) |
@@ -1129,22 +1218,48 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1129 | { | 1218 | { |
1130 | if (!flying) | 1219 | if (!flying) |
1131 | { | 1220 | { |
1132 | if (_target_velocity.Z > 0.0f) | 1221 | // we are on a surface |
1222 | if (ctz.Z > 0f) | ||
1133 | { | 1223 | { |
1134 | // We're colliding with something and we're not flying but we're moving | 1224 | // moving up or JUMPING |
1135 | // This means we're walking or running. JUMPING | 1225 | vec.Z += (ctz.Z - vel.Z) * PID_D * 1.2f;// +(_zeroPosition.Z - localpos.Z) * PID_P; |
1136 | vec.Z += (_target_velocity.Z - vel.Z) * PID_D * 1.2f;// +(_zeroPosition.Z - localpos.Z) * PID_P; | 1226 | vec.X += (ctz.X - vel.X) * (PID_D); |
1227 | vec.Y += (ctz.Y - vel.Y) * (PID_D); | ||
1137 | } | 1228 | } |
1229 | else | ||
1230 | { | ||
1231 | // we are moving down on a surface | ||
1232 | if (ctz.Z == 0) | ||
1233 | { | ||
1234 | if (vel.Z > 0) | ||
1235 | vec.Z -= vel.Z * PID_D * 2.0f; | ||
1236 | vec.X += (ctz.X - vel.X) * (PID_D); | ||
1237 | vec.Y += (ctz.Y - vel.Y) * (PID_D); | ||
1238 | } | ||
1239 | // intencionally going down | ||
1240 | else | ||
1241 | { | ||
1242 | if (ctz.Z < vel.Z) | ||
1243 | vec.Z += (ctz.Z - vel.Z) * PID_D * 2.0f; | ||
1244 | else | ||
1245 | { | ||
1246 | } | ||
1247 | |||
1248 | if (Math.Abs(ctz.X) > Math.Abs(vel.X)) | ||
1249 | vec.X += (ctz.X - vel.X) * (PID_D); | ||
1250 | if (Math.Abs(ctz.Y) > Math.Abs(vel.Y)) | ||
1251 | vec.Y += (ctz.Y - vel.Y) * (PID_D); | ||
1252 | } | ||
1253 | } | ||
1254 | |||
1138 | // We're standing on something | 1255 | // We're standing on something |
1139 | vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D); | ||
1140 | vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D); | ||
1141 | } | 1256 | } |
1142 | else | 1257 | else |
1143 | { | 1258 | { |
1144 | // We're flying and colliding with something | 1259 | // We're flying and colliding with something |
1145 | vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D * 0.0625f); | 1260 | vec.X += (ctz.X - vel.X) * (PID_D * 0.0625f); |
1146 | vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D * 0.0625f); | 1261 | vec.Y += (ctz.Y - vel.Y) * (PID_D * 0.0625f); |
1147 | vec.Z += (_target_velocity.Z - vel.Z) * (PID_D); | 1262 | vec.Z += (ctz.Z - vel.Z) * (PID_D); |
1148 | } | 1263 | } |
1149 | } | 1264 | } |
1150 | else // ie not colliding | 1265 | else // ie not colliding |
@@ -1152,9 +1267,9 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1152 | if (flying) //(!m_iscolliding && flying) | 1267 | if (flying) //(!m_iscolliding && flying) |
1153 | { | 1268 | { |
1154 | // we're in mid air suspended | 1269 | // we're in mid air suspended |
1155 | vec.X = ((_target_velocity.X * movementdivisor) - vel.X) * (PID_D * 1.667f); | 1270 | vec.X += (ctz.X - vel.X) * (PID_D * 1.667f); |
1156 | vec.Y = ((_target_velocity.Y * movementdivisor) - vel.Y) * (PID_D * 1.667f); | 1271 | vec.Y += (ctz.Y - vel.Y) * (PID_D * 1.667f); |
1157 | vec.Z += (_target_velocity.Z - vel.Z) * (PID_D); | 1272 | vec.Z += (ctz.Z - vel.Z) * (PID_D); |
1158 | } | 1273 | } |
1159 | 1274 | ||
1160 | else | 1275 | else |
@@ -1163,8 +1278,11 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
1163 | // m_iscolliding includes collisions with the ground. | 1278 | // m_iscolliding includes collisions with the ground. |
1164 | 1279 | ||
1165 | // d.Vector3 pos = d.BodyGetPosition(Body); | 1280 | // d.Vector3 pos = d.BodyGetPosition(Body); |
1166 | vec.X = (_target_velocity.X - vel.X) * PID_D * 0.833f; | 1281 | vec.X += (ctz.X - vel.X) * PID_D * 0.833f; |
1167 | vec.Y = (_target_velocity.Y - vel.Y) * PID_D * 0.833f; | 1282 | vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f; |
1283 | // hack for breaking on fall | ||
1284 | if (ctz.Z == -9999f) | ||
1285 | vec.Z += -vel.Z * PID_D - _parent_scene.gravityz * m_mass; | ||
1168 | } | 1286 | } |
1169 | } | 1287 | } |
1170 | } | 1288 | } |