bool CIKFoot::make_shift( Fmatrix &xm,const Fvector &cl_point, bool collide, const Fplane &p, const Fvector &pick_dir )const { Fvector shift = pick_dir; //Fvector toe; ToePosition( toe ); xm.transform_tiny( toe ); Fvector point; xm.transform_tiny( point, cl_point ); float dot = p.n.dotproduct( shift ); if( _abs( dot ) < min_dot ) { shift.add( Fvector( ).mul( p.n, min_dot - _abs( dot ) ) ); dot = p.n.dotproduct( shift ); } VERIFY( !fis_zero( dot ) ); float shift_m = ( -p.d - p.n.dotproduct( point ) )/dot; if(collide && shift_m > 0.f ) return false; clamp( shift_m, -collide_dist, collide_dist ); shift.mul( shift_m ); xm.c.add( shift ); #if 0 if(shift_m > 0.f) { DBG_OpenCashedDraw(); DBG_DrawLine( toe, Fvector().add( toe, shift ), D3DCOLOR_XRGB( 255, 255, 255 ) ); DBG_ClosedCashedDraw( 1000 ); } #endif return true; }
Point::Point(int row, int column) : Axis(row, column), PointColor(Color::Empty) { this->Row = row; this->Column = column; this->LeftOblique = row + column; this->RightOblique = (row > column) ? 14 + _abs(row - column) : 14 - _abs(row - column); }
void CActor::IR_OnMouseMove(int dx, int dy) { if(hud_adj_mode) { g_player_hud->tune (Ivector().set(dx,dy,0)); return; } PIItem iitem = inventory().ActiveItem(); if(iitem && iitem->cast_hud_item()) iitem->cast_hud_item()->ResetSubStateTime(); if (Remote()) return; if(m_holder) { m_holder->OnMouseMove(dx,dy); return; } float LookFactor = GetLookFactor(); CCameraBase* C = cameras [cam_active]; float scale = (C->f_fov/g_fov)*psMouseSens * psMouseSensScale/50.f / LookFactor; if (dx){ float d = float(dx)*scale; cam_Active()->Move((d<0)?kLEFT:kRIGHT, _abs(d)); } if (dy){ float d = ((psMouseInvert.test(1))?-1:1)*float(dy)*scale*3.f/4.f; cam_Active()->Move((d>0)?kUP:kDOWN, _abs(d)); } }
void CDestroyablePhysicsObject::Destroy() { VERIFY(!physics_world()->Processing()); const CGameObject *who_object = smart_cast<const CGameObject*>(FatalHit().initiator()); callback(GameObject::eDeath)(lua_game_object(),who_object ? who_object : 0); CPHDestroyable::Destroy(ID(),"physic_destroyable_object"); if(m_destroy_sound._handle()) { m_destroy_sound.play_at_pos(this,Position()); } if(*m_destroy_particles) { //Fvector dir;dir.set(0,1,0); Fmatrix m;m.identity(); ///////////////////////////////////////////////// m.j.set(0,1.f,0); /////////////////////////////////////////////// Fvector hdir;hdir.set(CPHDestroyable::FatalHit().direction()); if(fsimilar(_abs(m.j.dotproduct(hdir)),1.f,EPS_L)) { do { hdir.random_dir(); } while(fsimilar(_abs(m.j.dotproduct(hdir)),1.f,EPS_L)); } m.i.crossproduct(m.j,hdir);m.i.normalize(); m.k.crossproduct(m.i,m.j); StartParticles(m_destroy_particles,m,ID()); } SheduleRegister(); }
IC int calcSphereSector(Fvector& dir) { Fvector2 flat; // flatten flat.set (dir.x,dir.z); flat.norm (); // analyze if (_abs(flat.x)>_abs(flat.y)) { // sector 0,7,3,4 if (flat.x<0) { // sector 3,4 if (flat.y>0) return 3; else return 4; } else { // sector 0,7 if (flat.y>0) return 0; else return 7; } } else { // sector 1,2,6,5 if (flat.x<0) { // sector 2,5 if (flat.y>0) return 2; else return 5; } else { // sector 1,6 if (flat.y>0) return 1; else return 6; } } }
void CWeaponShotEffector::Relax() { float time_to_relax = _abs(m_angle_vert) / m_cam_recoil.RelaxSpeed; float relax_speed_horz = ( fis_zero(time_to_relax) )? 0.0f : _abs(m_angle_horz) / time_to_relax; float dt = Device.fTimeDelta; if ( m_angle_horz >= 0.0f ) // h { m_angle_horz -= relax_speed_horz * dt; } else { m_angle_horz += relax_speed_horz * dt; } if ( m_angle_vert >= 0.0f ) // v { m_angle_vert -= m_cam_recoil.RelaxSpeed * dt; if ( m_angle_vert < 0.0f ) { m_angle_vert = 0.0f; m_actived = false; } } else { m_angle_vert += m_cam_recoil.RelaxSpeed * dt; if ( m_angle_vert > 0.0f ) { m_angle_vert = 0.0f; m_actived = false; } } }
void CSoundRender_TargetD::fill_parameters() { inherited::fill_parameters(); // 1. Set 3D params (including mode) { Fvector& p_pos = pEmitter->p_source.position; R_CHK(pControl->SetMode (pEmitter->b2D ? DS3DMODE_HEADRELATIVE : DS3DMODE_NORMAL,DS3D_DEFERRED)); R_CHK(pControl->SetMinDistance (pEmitter->p_source.min_distance, DS3D_DEFERRED)); R_CHK(pControl->SetMaxDistance (pEmitter->p_source.max_distance, DS3D_DEFERRED)); R_CHK(pControl->SetPosition (p_pos.x,p_pos.y,p_pos.z, DS3D_DEFERRED)); } // 2. Set 2D params (volume, freq) + position(rewind) { float _volume = pEmitter->smooth_volume; clamp (_volume,EPS_S,1.f); s32 hw_volume = iFloor (7000.f*logf(_volume)/5.f); clamp (hw_volume,DSBVOLUME_MIN,DSBVOLUME_MAX); if (_abs(hw_volume-cache_hw_volume)>50){ cache_hw_volume = hw_volume; R_CHK(pBuffer->SetVolume(hw_volume)); } float _freq = pEmitter->p_source.freq; s32 hw_freq = iFloor (_freq * float(wfx.nSamplesPerSec) + EPS); if (_abs(hw_freq-cache_hw_freq)>50) { cache_hw_freq = hw_freq; s32 hw_freq_set = hw_freq; clamp (hw_freq_set,s32(SoundRenderD->dsCaps.dwMinSecondarySampleRate),s32(SoundRenderD->dsCaps.dwMaxSecondarySampleRate)); R_CHK (pBuffer->SetFrequency ( hw_freq_set )); } } }
void i_edge ( int x1, int y1, int x2, int y2) { int dx = _abs(x2 - x1); int dy = _abs(y2 - y1); int sx = x2 >= x1 ? 1 : -1; int sy = y2 >= y1 ? 1 : -1; if ( dy <= dx ){ int d = ( dy << 1 ) - dx; int d1 = dy << 1; int d2 = ( dy - dx ) << 1; i_test(x1,y1); for (int x = x1 + sx, y = y1, i = 1; i <= dx; i++, x += sx){ if ( d > 0) { d += d2; y += sy; } else d += d1; i_test(x,y); } }else{ int d = ( dx << 1 ) - dy; int d1 = dx << 1; int d2 = ( dx - dy ) << 1; i_test(x1,y1); for (int x = x1, y = y1 + sy, i = 1; i <= dy; i++, y += sy ){ if ( d > 0) { d += d2; x += sx; } else d += d1; i_test(x,y); } } }
bool CMonsterEnemyManager::is_faced(const CEntityAlive *object0, const CEntityAlive *object1) { if (object0->Position().distance_to(object1->Position()) > object0->ffGetRange()) { return false; } float yaw1, pitch1, yaw2, pitch2, fYawFov, fPitchFov, fRange; Fvector tPosition = object0->Position(); yaw1 = object0->Orientation().yaw; pitch1 = object0->Orientation().pitch; fYawFov = angle_normalize_signed(object0->ffGetFov()*PI/180.f); fRange = object0->ffGetRange(); fYawFov = angle_normalize_signed((_abs(fYawFov) + _abs(atanf(1.f/tPosition.distance_to(object1->Position()))))/2.f); fPitchFov = angle_normalize_signed(fYawFov*1.f); tPosition.sub (object1->Position()); tPosition.mul (-1); tPosition.getHP (yaw2,pitch2); yaw1 = angle_normalize_signed(yaw1); pitch1 = angle_normalize_signed(pitch1); yaw2 = angle_normalize_signed(yaw2); pitch2 = angle_normalize_signed(pitch2); if ((angle_difference(yaw1,yaw2) <= fYawFov) && (angle_difference(pitch1,pitch2) <= fPitchFov)) return (true); return (false); }
Ivector vpack (Fvector src) { Fvector _v; int bx = fpack (src.x); int by = fpack (src.y); int bz = fpackZ(src.z); // dumb test float e_best = flt_max; int r=bx,g=by,b=bz; #ifdef DEBUG int d=0; #else int d=3; #endif for (int x=_max(bx-d,0); x<=_min(bx+d,255); x++) for (int y=_max(by-d,0); y<=_min(by+d,255); y++) for (int z=_max(bz-d,0); z<=_min(bz+d,255); z++) { _v = vunpack(x,y,z); float m = _v.magnitude(); float me = _abs(m-1.f); if (me>0.03f) continue; _v.div (m); float e = _abs(src.dotproduct(_v)-1.f); if (e<e_best) { e_best = e; r=x,g=y,b=z; } } Ivector ipck; ipck.set (r,g,b); return ipck; }
void CAI_Rat::SelectAnimation(const Fvector& /**_view/**/, const Fvector& /**_move/**/, float /**speed/**/) { IKinematicsAnimated *tpVisualObject = smart_cast<IKinematicsAnimated*>(Visual()); MotionID tpGlobalAnimation; if (!g_Alive()) { for (int i=0 ;i<2; ++i) { if (m_tRatAnimations.tNormal.tGlobal.tpaDeath[i] == m_tpCurrentGlobalAnimation) { tpGlobalAnimation = m_tpCurrentGlobalAnimation; break; } } if (!tpGlobalAnimation) { if (m_tpCurrentGlobalAnimation == m_tRatAnimations.tNormal.tGlobal.tpaIdle[1]) tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaDeath[0]; else tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaDeath[::Random.randI(0,2)]; } } else { if (m_bFiring) tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaAttack[2]; else if (angle_difference(movement().m_body.target.yaw,movement().m_body.current.yaw) <= MIN_TURN_ANGLE) if (m_fSpeed < 0.2f) { if (m_bStanding) tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaIdle[1]; else tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaIdle[0]; } else if (_abs(m_fSpeed - m_fAttackSpeed) < EPS_L) tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tRunAttack; else if (_abs(m_fSpeed - m_fMaxSpeed) < EPS_L) tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tRun.fwd; else tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tWalk.fwd; else { if (left_angle(-movement().m_body.target.yaw,-movement().m_body.current.yaw)) // tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaIdle[0]; tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpTurnLeft; else // tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpaIdle[0]; tpGlobalAnimation = m_tRatAnimations.tNormal.tGlobal.tpTurnRight; } } if (tpGlobalAnimation != m_tpCurrentGlobalAnimation) m_tpCurrentGlobalBlend = tpVisualObject->PlayCycle(m_tpCurrentGlobalAnimation = tpGlobalAnimation); #ifdef DEBUG if (psAI_Flags.is(aiAnimation)) { IKinematicsAnimated *skeleton_animated = smart_cast<IKinematicsAnimated*>(Visual()); Msg ("%6d %s animation : %s (%f,%f)",Device.dwTimeGlobal,"Global",skeleton_animated->LL_MotionDefName_dbg(m_tpCurrentGlobalAnimation),movement().m_body.current.yaw,movement().m_body.target.yaw); } #endif }
void CDrawUtilities::DrawAABB(const Fvector& p0, const Fvector& p1, u32 clr_s, u32 clr_w, BOOL bSolid, BOOL bWire) { Fmatrix R; Fvector C; C.set((p1.x+p0.x)*0.5f,(p1.y+p0.y)*0.5f,(p1.z+p0.z)*0.5f); R.scale (_abs(p1.x-p0.x),_abs(p1.y-p0.y),_abs(p1.z-p0.z)); R.translate_over(C); RCache.set_xform_world(R); DrawIdentBox (bSolid,bWire,clr_s,clr_w); }
extern void my_convert_tz(sqlite3_context * context, int argc, sqlite3_value ** argv) { KSU_TM_T time_str; KSU_TM_T *bdp; KSU_TIME_T clock; int tzlen; int from_tz_hour; int from_tz_minute; int to_tz_hour; int to_tz_minute; char *q; char date[DATE_LEN]; int secdiff; _ksu_null_if_null_param(argc, argv); if (my_is_datetime((const char *)sqlite3_value_text(argv[0]), &clock, (char)0)) { q = (char *)sqlite3_value_text(argv[1]); tzlen = strlen(q); if ((tzlen != TZ_LEN) || (sscanf(q, "%d:%d", &from_tz_hour, &from_tz_minute) != 2)) { ksu_err_msg(context, KSU_ERR_INV_TZ_FORMAT, "convert_tz"); return; } if (from_tz_hour < 0) { from_tz_minute = -1 * _abs(from_tz_minute); } q = (char *)sqlite3_value_text(argv[2]); tzlen = strlen(q); if ((tzlen != TZ_LEN) ||(sscanf(q, "%d:%d", &to_tz_hour, &to_tz_minute) != 2)) { ksu_err_msg(context, KSU_ERR_INV_TZ_FORMAT, "convert_tz"); return; } if (to_tz_hour < 0) { to_tz_minute = -1 * _abs(to_tz_minute); } secdiff = (to_tz_hour - from_tz_hour) * 3600 + (to_tz_minute - from_tz_minute) * 60; clock = ksu_add_secs(clock, secdiff); bdp = ksu_localtime(clock, &time_str); if (bdp) { sprintf(date, "%4d-%02d-%02d %02d:%02d:%02d", (int)bdp->year, (int)(1 + bdp->mon), (int)bdp->mday, (int)bdp->hour, (int)bdp->min, (int)bdp->sec); sqlite3_result_text(context, date, -1, SQLITE_TRANSIENT); } else { sqlite3_result_null(context); } } else { sqlite3_result_null(context); } }
Fraction Fraction::frac_abs() { Fraction tmp; tmp.l = _abs(l); tmp.u = _abs(u); tmp.lg_u = lg_u; tmp.lg_l = lg_l; return tmp; }
Fraction Fraction::upload(int64 upper, int64 lower) { u = upper; l = lower; lg_u = log10((double)_abs(u)); lg_l = log10((double)_abs(l)); is_sharp = true; return *this; }
// Returns determinant of a, and b=a inverse. // If matrix is singular, returns 0 and leaves trash in b. // // Uses Gaussian elimination with partial pivoting. // static double internal_invert(double *_a, double *_b, const int N) { unsigned int i, j=0, k; double max, t, det, pivot; /*---------- forward elimination ----------*/ for (i=0; i<(unsigned int)N; i++) /* put identity matrix in B */ for (j=0; j<(unsigned int)N; j++) B(i, j) = (double)(i==j); det = 1.0; for (i=0; i<(unsigned int)N; i++) { /* eliminate in column i, below diag */ max = -1.; for (k=i; k<(unsigned int)N; k++) /* find pivot for column i */ if (_abs(A(k, i)) > max) { max = _abs(A(k, i)); j = k; } if (max<=0.) return 0.; /* if no nonzero pivot, PUNT */ if (j!=i) { /* swap rows i and j */ for (k=i; k<(unsigned int)N; k++) SWAP(A(i, k), A(j, k), t); for (k=0; k<(unsigned int)N; k++) SWAP(B(i, k), B(j, k), t); det = -det; } pivot = A(i, i); det *= pivot; for (k=i+1; k<(unsigned int)N; k++) /* only do elems to right of pivot */ A(i, k) /= pivot; for (k=0; k<(unsigned int)N; k++) B(i, k) /= pivot; /* we know that A(i, i) will be set to 1, so don't bother to do it */ for (j=i+1; j<(unsigned int)N; j++) { /* eliminate in rows below i */ t = A(j, i); /* we're gonna zero this guy */ for (k=i+1; k<(unsigned int)N; k++) /* subtract scaled row i from row j */ A(j, k) -= A(i, k)*t; /* (ignore k<=i, we know they're 0) */ for (k=0; k<(unsigned int)N; k++) B(j, k) -= B(i, k)*t; } } /*---------- backward elimination ----------*/ for (i=N-1; i>0; i--) { /* eliminate in column i, above diag */ for (j=0; j<i; j++) { /* eliminate in rows above i */ t = A(j, i); /* we're gonna zero this guy */ for (k=0; k<(unsigned int)N; k++) /* subtract scaled row i from row j */ B(j, k) -= B(i, k)*t; } } return det; }
int sin_q15(int theta) { if ( theta == 0 || _abs(theta) == 180 || _abs(theta) == 360) return 0; int sin_result,dummy; cordic_sincos(theta,14,&sin_result,&dummy); return sin_result; }
Fraction::Fraction(int64 upper, int64 lower) : u(upper), lg_u(log10((double)_abs(u))), is_sharp(true) { if(lower != 0) { l = lower; lg_l = log10((double)_abs(l)); } else throw (char *) "Exception: divide on zero in fraction number."; }
void CWeaponShotEffector::Initialize(float max_angle, float relax_speed, float max_angle_horz, float step_angle_horz, float angle_frac) { fRelaxSpeed = _abs(relax_speed); VERIFY(!fis_zero(fRelaxSpeed)); fAngleVertMax = _abs(max_angle); VERIFY(!fis_zero(fAngleVertMax)); fAngleVertFrac = _abs(angle_frac); fAngleHorzMax = max_angle_horz; fAngleHorzStep = step_angle_horz; }
template<typename T> inline T moveValueTowards(T val, T target, T incr) { incr = _abs(incr); T delta = _abs(target-val); if(val<target) val += incr; else if(val>target) val -= incr; T newDelta = _abs(target-val); if(newDelta >= delta) val = target; return val; }
void CPHMovementControl::SetPathDir( const Fvector& v) { _vPathDir = v; if(_abs(_vPathDir.x)>1000 || _abs(_vPathDir.y)>1000 || _abs(_vPathDir.z)>1000) { Log ("_vPathDir", _vPathDir ); } VERIFY2 ( _abs(_vPathDir.x)<1000," incorrect SetPathDir "); }
void CActor::cam_Lookout ( const Fmatrix &xform, float camera_height ) { if (!fis_zero(r_torso_tgt_roll)) { float w,h; float c = viewport_near(w,h); w/=2.f;h/=2.f; float alpha = r_torso_tgt_roll/2.f; float radius = camera_height*0.5f; // init valid angle float valid_angle = alpha; Fvector bc,bd; Fmatrix33 mat; get_cam_oob( bc, bd, mat, xform, r_torso, alpha, radius, c ); /* xrXRC xrc ; xrc.box_options (0) ; xrc.box_query (Level().ObjectSpace.GetStaticModel(), bc, bd) ; u32 tri_count = xrc.r_count(); */ //if (tri_count) { float da = 0.f; BOOL bIntersect = FALSE; Fvector ext = {w,h,VIEWPORT_NEAR/2}; Fvector pt; calc_gl_point ( pt, xform, radius, alpha ); if ( test_point( pt, mat, ext, this ) ) { da = PI/1000.f; if (!fis_zero(r_torso.roll)) da *= r_torso.roll/_abs(r_torso.roll); for (float angle=0.f; _abs(angle)<_abs(alpha); angle+=da) { Fvector pt; calc_gl_point( pt, xform, radius, angle ); if (test_point( pt, mat,ext, this )) { bIntersect=TRUE; break; } } valid_angle = bIntersect?angle:alpha; } } r_torso.roll = valid_angle*2.f; r_torso_tgt_roll = r_torso.roll; } else { r_torso_tgt_roll = 0.f; r_torso.roll = 0.f; } }
// Vista+ only BOOL apiSetConsoleFontSize(HANDLE hOutput, int inSizeY, int inSizeX, const wchar_t *asFontName) { HMODULE hKernel = GetModuleHandle(L"kernel32.dll"); if (!hKernel) { _ASSERTE(hKernel!=NULL); return FALSE; } BOOL lbRc = FALSE; //typedef BOOL (WINAPI *PSetCurrentConsoleFontEx)(HANDLE /*hConsoleOutput*/, BOOL /*bMaximumWindow*/, MY_CONSOLE_FONT_INFOEX* /*lpConsoleCurrentFontEx*/); PSetCurrentConsoleFontEx SetCurrentConsoleFontEx = (PSetCurrentConsoleFontEx) GetProcAddress(hKernel, "SetCurrentConsoleFontEx"); //typedef BOOL (WINAPI *PGetCurrentConsoleFontEx)(HANDLE /*hConsoleOutput*/, BOOL /*bMaximumWindow*/, MY_CONSOLE_FONT_INFOEX* /*lpConsoleCurrentFontEx*/); PGetCurrentConsoleFontEx GetCurrentConsoleFontEx = (PGetCurrentConsoleFontEx) GetProcAddress(hKernel, "GetCurrentConsoleFontEx"); if (SetCurrentConsoleFontEx) // We have Vista { MY_CONSOLE_FONT_INFOEX cfi = {sizeof(cfi)}; //GetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi); cfi.dwFontSize.X = inSizeX; cfi.dwFontSize.Y = inSizeY; lstrcpynW(cfi.FaceName, asFontName ? asFontName : L"Lucida Console", countof(cfi.FaceName)); HANDLE hConOut = GetStdHandle(STD_OUTPUT_HANDLE); lbRc = SetCurrentConsoleFontEx(hConOut, FALSE, &cfi); // Store for further comparison if (lbRc) { MY_CONSOLE_FONT_INFOEX cfiSet = {sizeof(cfiSet)}; if (GetCurrentConsoleFontEx && GetCurrentConsoleFontEx(hConOut, FALSE, &cfiSet)) { // Win10 can't set "Lucida Console 3x5" and we get "4x6" _ASSERTE(_abs(cfiSet.dwFontSize.X-cfi.dwFontSize.X)<=1 && _abs(cfiSet.dwFontSize.Y-cfi.dwFontSize.Y)<=1); g_LastSetConsoleFont = cfiSet; } else { DEBUGTEST(DWORD dwErr = GetLastError()); _ASSERTE(FALSE && "apiGetConsoleScreenBufferInfoEx failed"); g_LastSetConsoleFont = cfi; } } } return lbRc; }
void Point::smart() { int64 local_gcd = gcd(_abs(s), gcd(_abs(x), _abs(y))); x /= local_gcd; y /= local_gcd; s /= local_gcd; if(s < 0) { x = -x; y = -y; s = -s; } }
void CSpectator::IR_OnMouseMove(int dx, int dy) { if (Remote()) return; CCameraBase* C = cameras [cam_active]; float scale = (C->f_fov/g_fov)*psMouseSens * psMouseSensScale/50.f; if (dx){ float d = float(dx)*scale; cameras[cam_active]->Move((d<0)?kLEFT:kRIGHT, _abs(d)); } if (dy){ float d = ((psMouseInvert.test(1))?-1:1)*float(dy)*scale*3.f/4.f; cameras[cam_active]->Move((d>0)?kUP:kDOWN, _abs(d)); } }
void bonesBone::Turn(u32 dt) { float PI_DIV_2m = 8 * PI_DIV_6 / 3; float PIm = PI_DIV_2m * 2; float cur_speed = params.r_speed * _cos(PI_DIV_2m - PIm * _abs(params.target_yaw - params.cur_yaw) / params.dist_yaw); float dy; dy = cur_speed * dt / 1000; // учитываем милисек и радианную меры if (_abs(params.target_yaw - params.cur_yaw) < dy) params.cur_yaw = params.target_yaw; else params.cur_yaw += ((params.target_yaw > params.cur_yaw) ? dy : -dy); }
bool CControlAnimationBase::accel_chain_get(float cur_speed, EMotionAnim target_anim, EMotionAnim &new_anim, float &a_speed) { VERIFY2(_abs(cur_speed)<1000, "CControlAnimationBase cur_speed too big"); VELOCITY_CHAIN_VEC_IT B = m_accel.chain.begin(), I; VELOCITY_CHAIN_VEC_IT E = m_accel.chain.end(); // пройти по всем Chain-векторам for (I = B; I != E; I++) { SEQ_VECTOR_IT IT_B = I->begin(), IT; SEQ_VECTOR_IT IT_E = I->end(); SEQ_VECTOR_IT best_anim = IT_E; SVelocityParam *best_param = 0; bool found = false; // Пройти по текущему вектору for (IT = IT_B; IT != IT_E; IT++) { SAnimItem *item_it = m_anim_storage[*IT]; VERIFY(item_it); SVelocityParam *param = &item_it->velocity; float from = param->velocity.linear * param->min_factor; float to = param->velocity.linear * param->max_factor; if ( ((from <= cur_speed+EPS_L) && (cur_speed <= to + EPS_L)) || ((cur_speed < from) && (IT == I->begin())) || ((cur_speed + EPS_L >= to) && (IT+1 == I->end())) ) { best_anim = IT; best_param = &item_it->velocity; } if ((*IT) == target_anim) found = true; if (found && best_param) break; } if (!found) continue; R_ASSERT2(best_param,"probably incompatible speed ranges"); // calc anim_speed new_anim = *best_anim; float tmp = GetAnimSpeed(new_anim); VERIFY2(_abs(tmp)<1000, "CControlAnimationBase GetAnimSpeed returns too big speed"); a_speed = tmp * cur_speed / best_param->velocity.linear; VERIFY2(_abs(a_speed)<1000, "CControlAnimationBase a_speed too big"); return true; } return false; }
// Solve nxn system Ax=b. // Leaves solution x in b, and destroys original A and b vectors. // Return value is determinant of A. // If system is singular, returns 0 and leaves trash in b // // Uses Gaussian elimination with partial pivoting. // static double internal_solve(double *_a, double *b, const int N) { int i, j=0, k; double max, t, det, sum, pivot; /*---------- forward elimination ----------*/ det = 1.0; for (i=0; i<N; i++) { /* eliminate in column i */ max = -1.0; for (k=i; k<N; k++) /* find pivot for column i */ if (_abs(A(k, i)) > max) { max = _abs(A(k, i)); j = k; } if (max<=0.) return 0.0; /* if no nonzero pivot, PUNT */ if (j!=i) { /* swap rows i and j */ for (k=i; k<N; k++) SWAP(A(i, k), A(j, k), t); det = -det; SWAP(b[i], b[j], t); /* swap elements of column vector */ } pivot = A(i, i); det *= pivot; for (k=i+1; k<N; k++) /* only do elems to right of pivot */ A(i, k) /= pivot; /* we know that A(i, i) will be set to 1, so don't bother to do it */ b[i] /= pivot; for (j=i+1; j<N; j++) { /* eliminate in rows below i */ t = A(j, i); /* we're gonna zero this guy */ for (k=i+1; k<N; k++) /* subtract scaled row i from row j */ A(j, k) -= A(i, k)*t; /* (ignore k<=i, we know they're 0) */ b[j] -= b[i]*t; } } /*---------- back substitution ----------*/ for (i=N-1; i>=0; i--) { /* solve for x[i] (put it in b[i]) */ sum = b[i]; for (k=i+1; k<N; k++) /* really A(i, k)*x[k] */ sum -= A(i, k)*b[k]; b[i] = sum; } return det; }
void CWeaponStatMgun::Load(LPCSTR section) { inheritedPH::Load(section); inheritedShooting::Load (section); m_sounds.LoadSound(section,"snd_shoot", "sndShot", false, SOUND_TYPE_WEAPON_SHOOTING); m_Ammo->Load(pSettings->r_string(section, "ammo_class"), 0); camMaxAngle = pSettings->r_float (section,"cam_max_angle" ); camMaxAngle = _abs( deg2rad (camMaxAngle) ); camRelaxSpeed = pSettings->r_float (section,"cam_relax_speed" ); camRelaxSpeed = _abs( deg2rad (camRelaxSpeed) ); VERIFY( !fis_zero(camMaxAngle) ); VERIFY( !fis_zero(camRelaxSpeed) ); }
float CIKLimbsController::StaticObjectShift ( const SCalculateData cd[max_size] ) { const float current_shift = _object_shift.shift(); u16 cnt = 0; float shift_up =0; const u16 sz =(u16)_bone_chains.size(); for(u16 j = 0; sz > j; ++j ) if( cd[j].state.foot_step ) { float s_up = cd[j].cl_shift.y + current_shift; if( 0.f < s_up ) { shift_up += s_up; ++cnt; } } if( 0 < cnt ) shift_up /= cnt; float shift_down = LegLengthShiftLimit( current_shift, cd ); float shift = 0; if( shift_down > 0.f ) shift = -shift_down; else if( -shift_down < shift_up ) shift = -shift_down; else shift = shift_up; VERIFY( _valid( shift ) ); _object_shift.set_taget( shift , _abs( current_shift - shift ) / static_shift_object_speed ); return shift; }