void doServe() { int flight, flight1, flight2; reset(); setParam(m_throwParam); getClissionSystem()->setHorizPlane(m_serveHight, true); getClissionSystem()->setDetectObjects(COLLISION_OBJECT_HORIZ_PLANE); flight = makeFlight(); if (getClissionType(flight) != COLLISION_OBJECT_HORIZ_PLANE) { // exception } findServeUpAngle (flight); // //m_detector->setDetecPlane(0, true); getClissionSystem()->setDetectObjects(COLLISION_OBJECT_TABLE|COLLISION_OBJECT_NET|COLLISION_OBJECT_FLOOR); flight1 = makeFlight(flight); if (getClissionType(flight1) != COLLISION_OBJECT_TABLE) { printf("flight1->getClissionType() != COLLISION_OBJECT_TABLE %d\n", getClissionType(flight1)); // return -1; } flight2 = rebound(flight1); if (getClissionType(flight2) != COLLISION_OBJECT_TABLE) { printf("flight2->getClissionType() != COLLISION_OBJECT_TABLE\n"); //return -1; } while (flight2 >= 0 ) { flight2 = rebound(flight2); if (flight2 < 0) { break; } f32 time = getSegDuration(flight2); if (time < 0.01 && getSegSequence(flight) > 6) { break; } } }
void doHit() { int flight; f32 flightTime = 0; reset(); setParam(m_hitParam); getClissionSystem()->setDetectObjects(COLLISION_OBJECT_TABLE|COLLISION_OBJECT_NET|COLLISION_OBJECT_FLOOR); // getClissionSystem()->setDetectObjects(COLLISION_OBJECT_TABLE|COLLISION_OBJECT_FLOOR); flight = makeFlight(); while (true) { flight = rebound(flight); if (flight < 0) { break; } f32 time = getSegDuration(flight); if (time < 0.01 && getSegSequence(flight) > 6) { break; } } }
int timestep(const t_param params, t_speed* cells, t_speed* tmp_cells, int* obstacles) { //accelerate_flow(params,cells,obstacles); propagate(params,cells,tmp_cells, obstacles); rebound(params,cells,tmp_cells,obstacles); collision(params,cells,tmp_cells,obstacles); return EXIT_SUCCESS; }
f32 findServeUpAngle(int throwFlight) { int flight1, flight2; f32 upTableAngle = 30; f32 downTableAngle = -60; f32 tableAngle = (upTableAngle + downTableAngle)/2; int maxTry = 5; setParam(m_hitParam); getClissionSystem()->setHorizPlane(0, true, true); getClissionSystem()->setDetectObjects(COLLISION_OBJECT_HORIZ_PLANE); while (maxTry > 0) { maxTry--; getParam().upAngle = tableAngle; flight1 = makeFlight(throwFlight); flight2 = rebound(flight1); _VECTOR3D & left = getSegmengNode(flight2, 0)->pos; _VECTOR3D & right = getSegmengNode(flight2, -1)->pos; _VECTOR3D center = (left + right)/2; _VECTOR3D distance = (right - left); // center accuracy; if (fabs(center._X/distance._X) < 0.2f) { break; } else if (getStartPos()._X * center._X > 0) { downTableAngle = tableAngle; } else { upTableAngle = tableAngle; } tableAngle = (upTableAngle + downTableAngle)/2; } removeAfter(throwFlight); return tableAngle; }
void ScrollView::inertia(float dt) { float _lastInertiaDuration = m_inertiaDuration; m_inertiaDuration += dt; float _speed = m_inertialOriginSpeed + INERTIA_ACCELERATION_SPEED * m_inertiaDuration; if (isNeedRebound()) { _speed += INERTIA_ACCELERATION_SPEED * m_inertiaDuration * 2.f; } if (_speed <= 0) { m_inertiaDuration = 0; m_isInertia = false; //如果已经超出拖动区域 if (isNeedRebound()) { //需要反弹 rebound(); } else { if (needSorption()) { sorption(); } else { handlerScrollEnd(); } } return; } float _timeParam = _lastInertiaDuration * 2 + dt; float _offset = (m_inertialOriginSpeed + INERTIA_ACCELERATION_SPEED * _timeParam * 0.5f) * dt; if (isNeedRebound()) _offset *= (1.f - m_inertiaDuration) * 0.5f; float _offsetX = _offset * m_dragDirection.x; float _offsetY = _offset * m_dragDirection.y; auto _newPos = Vec2(_offsetX, _offsetY) + m_container->getPosition(); updateContainerPos(_newPos); }
void ScrollView::onTouchEnded(Touch *touch, Event *unusedEvent) { Widget::onTouchEnded(touch, unusedEvent); m_isDrag = false; m_endedPos = touch->getLocation(); if (!checkCanScroll())return; auto _deltaPos = m_endedPos - m_beganPos; auto _distance = 0; //判断滚动方向 if (m_scrollDirection == ScrollDirection::HORIZONTAL) { _distance = m_endedPos.x - m_beganPos.x; m_dragDirection = (_distance > 0) ? Vec2(1, 0) : Vec2(-1, 0); } else if (m_scrollDirection == ScrollDirection::VERTICAL) { _distance = m_endedPos.y - m_beganPos.y; m_dragDirection = (_distance > 0) ? Vec2(0, 1) : Vec2(0, -1); } else if (m_scrollDirection == ScrollDirection::BOTH) { _distance = _deltaPos.length(); m_dragDirection = _deltaPos.getNormalized(); } m_inertialOriginSpeed = MIN(fabsf(_distance / m_dragDuration), MAX_DRAG_SPEED); if (isNeedRebound()) { rebound(); } else { //是否能产生惯性 if (m_inertialOriginSpeed > 500) { //如果使用了吸附模式 if (m_sorption != Vec2::ZERO && m_scrollDirection == ScrollDirection::HORIZONTAL && fabsf(m_dragDirection.x) > fabsf(m_dragDirection.y)) { int _inertiaNum = m_dragDirection.x; auto _sorption = m_sorption * _inertiaNum + getSorptionPosition(m_container->getPosition()) - m_container->getPosition(); scrollTo(_sorption); } else if (m_sorption != Vec2::ZERO && m_scrollDirection == ScrollDirection::VERTICAL && fabsf(m_dragDirection.y) > fabsf(m_dragDirection.x)) { int _inertiaNum = m_dragDirection.y; auto _sorption = m_sorption * _inertiaNum + getSorptionPosition(m_container->getPosition()) - m_container->getPosition(); scrollTo(_sorption); } else m_isInertia = true; } else { if (needSorption()) sorption(); else handlerScrollEnd(); } } }