00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <PVLE/Physics/SurfaceParams.h>
00028 #include <PVLE/Util/TracedException.h>
00029
00030 namespace Physics {
00031
00033 void SurfaceParams::mergeInto(const SurfaceParams & s1, const SurfaceParams & s2) {
00034 mode = 0;
00036
00037
00038
00039 if ((s1.mode & APPROX1_1) || (s2.mode & APPROX1_1)) mode |= APPROX1_1;
00040 if ((s1.mode & APPROX1_2) || (s2.mode & APPROX1_2)) mode |= APPROX1_2;
00041
00042
00043
00044
00045 mu = (s1.mu == PHY_INFINITY || s2.mu == PHY_INFINITY) ? PHY_INFINITY : (s1.mu * s2.mu);
00046
00047 if ((s1.mode & MU2) || (s2.mode & MU2)) {
00048 mode |= MU2;
00049 if (s1.mu2 == PHY_INFINITY || s2.mu2 == PHY_INFINITY) mu2 = PHY_INFINITY;
00050 else mu2 = ((s1.mode & MU2 ? s1.mu2 : s2.mu2) * (s2.mode & MU2 ? s2.mu2 : s1.mu2));
00051
00052 }
00053
00054
00055
00056
00057 if ((s1.mode & BOUNCE) || (s2.mode & BOUNCE)) {
00058 mode |= BOUNCE;
00059 bounce = ((s1.mode & BOUNCE ? s1.bounce : s2.bounce) + (s2.mode & BOUNCE ? s2.bounce : s1.bounce)) / static_cast<dReal>(2);
00060 bounce_vel = osg::minimum((s1.mode & BOUNCE ? s1.bounce_vel : s2.bounce_vel), (s2.mode & BOUNCE ? s2.bounce_vel : s1.bounce_vel));
00061 }
00062
00063
00064
00065 if ((s1.mode & SOFT_CFM) || (s2.mode & SOFT_CFM)) {
00066 mode |= SOFT_CFM;
00067 soft_cfm = powf(10, (log10f(s1.mode & SOFT_CFM ? s1.soft_cfm : s2.soft_cfm) + log10f(s2.mode & SOFT_CFM ? s2.soft_cfm : s1.soft_cfm)) /2.f);
00068 }
00069
00070
00071 if ((s1.mode & SOFT_ERP) || (s2.mode & SOFT_ERP)) {
00072 mode |= SOFT_ERP;
00073 soft_erp = ((s1.mode & SOFT_ERP ? s1.soft_erp : s2.soft_erp) + (s2.mode & SOFT_ERP ? s2.soft_erp : s1.soft_erp)) / static_cast<dReal>(2);
00074 }
00075
00076
00077
00078
00079
00080
00081 if ((s1.mode & SLIP1) || (s2.mode & SLIP1)) {
00082 mode |= SLIP1;
00083 slip1 = ((s1.mode & SLIP1 ? s1.slip1 : s2.slip1) + (s2.mode & SLIP1 ? s2.slip1 : s1.slip1)) / static_cast<dReal>(2);
00084 }
00085 if ((s1.mode & SLIP2) || (s2.mode & SLIP2)) {
00086 mode |= SLIP2;
00087 slip2 = ((s1.mode & SLIP2 ? s1.slip2 : s2.slip2) + (s2.mode & SLIP2 ? s2.slip2 : s1.slip2)) / static_cast<dReal>(2);
00088 }
00089
00090
00091
00092 if ((s1.mode & MOTION1) || (s2.mode & MOTION1)) { THROW_TRACED_EXCEPTION("Not implemented"); }
00093 if ((s1.mode & MOTION2) || (s2.mode & MOTION2)) { THROW_TRACED_EXCEPTION("Not implemented"); }
00094 }
00095
00096 }