void eff_expl_flash_2() { set(me, BRIGHT | TRANSLUCENT | ZNEAR | PASSABLE); my.blue = 150; my.green = 235; my.red = 255; my.alpha = 0; my.roll = random(360); vec_fill(my.scale_x, 3); vec_for_angle(vecEffectsTemp, vector( my.roll, 0, 0)); vec_rotate(vecEffectsTemp, vector(camera.pan, camera.tilt+90, 0)); vec_normalize(vecEffectsTemp, 40); vec_add(vecEffectsTemp, my.x); vec_set(my.x, vecEffectsTemp); while(my.alpha < 100) { if (my.lightrange < 1000 ) my.lightrange += 2000 * time_step; my.alpha += time_step * (random(20)+20); my.roll += time_step * sign(ang(my.roll)); vec_normalize ( my.blue, 150 + random(105) ); wait(1); } ent_create("explSmoke02.tga", my.x, eff_expl_smoke); while(my.alpha > 0) { if (my.lightrange > 0) my.lightrange -= 500 * time_step; my.alpha -= time_step * 20; my.roll += time_step * sign(ang(my.roll))*5; wait(1); } while (my.lightrange > 0) { my.lightrange -= 500 * time_step; wait(1); } ent_remove(me); }
void eff_expl_flash() { int i; set(me, BRIGHT | TRANSLUCENT | LIGHT | ZNEAR | PASSABLE); my.alpha = 50; my.roll = random(360); while(my.alpha < 100) { my.alpha += time_step * (random(20)+20); my.roll += time_step * sign(ang(my.roll)); vec_fill ( my.scale_x, my.alpha/13 ); wait(1); } for(i=0; i<4; i++) { ent_create("explFlash01.tga", my.x, eff_expl_flash_2); you = ent_create("explFlash02.tga", my.x, eff_expl_flash_2); if (i == 0) set(you, LIGHT); } for(i=0; i<5; i++) { ent_create ("explSmoke01.tga", my.x, eff_expl_smoke2); } effect(p_eff_expl_particle, 200, my.x, NULL); vec_add(my.scale_x, vector(3,3,3)); ent_create("explSmoke02.tga", my.x, eff_expl_smoke); while(my.alpha > 0) { my.alpha -= time_step * 25; my.roll += time_step * sign(ang(my.roll)); wait(1); } ent_remove(me); }
static void br_cairo_draw_section(duc_graph *g, double a1, double a2, double r1, double r2, double H, double S, double V, double line) { struct cairo_backend_data *bd = g->backend_data; cairo_t *cr = bd->cr; double R, G, B; hsv2rgb(H, S, V, &R, &G, &B); cairo_new_path(cr); cairo_arc(cr, g->cx, g->cy, r1, ang(a1), ang(a2)); cairo_arc_negative(cr, g->cx, g->cy, r2, ang(a2), ang(a1)); cairo_close_path(cr); if(R != 1.0 || G != 1.0 || B != 1.0) { cairo_pattern_t *pat; pat = cairo_pattern_create_radial(g->cx, g->cy, 0, g->cx, g->cy, g->cx-50); double off1 = r2 / g->cx; double off2 = r1 / g->cx; cairo_pattern_add_color_stop_rgb(pat, off1, R, G, B); cairo_pattern_add_color_stop_rgb(pat, off2, R * 0.6, G * 0.6, B * 0.6); cairo_set_source(cr, pat); cairo_fill_preserve(cr); cairo_pattern_destroy(pat); } if(line) { cairo_set_line_width(cr, 0.5); cairo_set_source_rgba(cr, 0, 0, 0, 0.9); cairo_stroke(cr); } }
int CCBO::ctcl_lunar_date(int y, int m, int d) { int lunar_date = -1; const double rpi = 180 / M_PI; const double zone=8.0; double t = (y - 1899.5) / 100.0; double ms = floor((y - 1900) * 12.3685); double f0 = ang(ms, t, 0, 0.75933, 2.172e-4, 1.55e-7) + 0.53058868 * ms - 8.37e-4 * t + zone / 24.0 + 0.5; double fc = 0.1734 - 3.93e-4 * t; double j0 = 693595 + 29 * ms; double aa0 = ang(ms, t, 0.08084821133, 359.2242 / rpi, 0.0000333 / rpi, 0.00000347 / rpi); double ab0 = ang(ms, t, 7.171366127999999e-2, 306.0253 / rpi, - 0.0107306 / rpi, -0.00001236 / rpi); double ac0 = ang(ms, t, 0.08519585128, 21.2964 / rpi, 0.0016528 / rpi, 0.00000239 / rpi); int i = 0; for (i = -1; i <= 13; i += 1) { double aa = aa0 + 0.507984293 * i; double ab = ab0 + 6.73377553 * i; double ac = ac0 + 6.818486628 * i; double f1 = f0 + 1.53058868 * i + fc * sin(aa) - 0.4068 * sin(ab) + 0.0021 * sin(2 * aa) + 0.0161 * sin(2 * ab) + 0.0104 * sin(2 * ac) - 0.0074 * sin(aa - ab) - 0.0051 * sin(aa + ab); double j = j0 + 28 * i + f1; int diff = ctcl_standard_days(y, m, d) - floor(j); if (diff >= 0 && diff <= 29) lunar_date = diff + 1; } return(lunar_date); }
void Ball::launch_ball(Paddle *ai_paddle) { std::uniform_int_distribution<int> dir(0, 1); int direction = 1+(-2)*(dir(gen)%2); // either 1 or -1 std::uniform_int_distribution<int> ang(-60, 60); angle = ang(gen); // between -60 and 60 dx = direction*speed*std::cos(angle*M_PI/180.0f); // speed on the x-axis dy = speed*std::sin(angle*M_PI/180.0f); // speed on the y-axis status = LAUNCHED; }
static cell_t smn_PbSetAngle(IPluginContext *pCtx, const cell_t *params) { GET_MSG_FROM_HANDLE_OR_ERR(); GET_FIELD_NAME_OR_ERR(); cell_t *angParams; if ((err=pCtx->LocalToPhysAddr(params[3], &angParams)) != SP_ERROR_NONE) { pCtx->ThrowNativeErrorEx(err, NULL); return 0; } QAngle ang( sp_ctof(angParams[0]), sp_ctof(angParams[1]), sp_ctof(angParams[2])); int index = params[0] >= 4 ? params[4] : -1; if (index < 0) { if (!msg->SetQAngle(strField, ang)) { return pCtx->ThrowNativeError("Invalid field \"%s\" for message \"%s\"", strField, msg->GetProtobufMessage()->GetTypeName().c_str()); } } else { if (!msg->SetRepeatedQAngle(strField, index, ang)) { return pCtx->ThrowNativeError("Invalid field \"%s\"[%d] for message \"%s\"", strField, index, msg->GetProtobufMessage()->GetTypeName().c_str()); } } return 1; }
void BodyRigid::dynamicAccumReset() { // std::cout << "before: " << m_sIhat << std::endl; // std::cout << "inertia: " << m_INERTIA << std::endl; Mat3x3 sIhat_m00 = m_inertia; Mat3x3 sIhat_m01; sIhat_m01 << 0.,0.,0., 0.,0.,0., 0.,0.,0.; Mat3x3 sIhat_m10; sIhat_m10 << 0.,0.,0., 0.,0.,0., 0.,0.,0.; Mat3x3 sIhat_m11; sIhat_m11 << m_mass, 0., 0., 0., m_mass, 0., 0., 0., m_mass; m_sIhat << sIhat_m00,sIhat_m01,sIhat_m10,sIhat_m11; // std::cout << "after: " << m_sIhat << std::endl; // std::cout << " lr after " << sIhat_m11 << std::endl; //inertia force and torque /// equation 21 page 47 Anderson Vect3 ang(-m_inertia*m_n_alpha_t_k-m_wl.cross(m_inertia*m_wl)); /// equation 19 page 47 Anderson Vect3 trans(m_n_a_t_k*(-m_mass)); m_sFhat << ang+m_appliedTorque, trans+m_q.inverse()*m_appliedForce; }
void CASW_Boomer_Blob::Detonate( ) { m_takedamage = DAMAGE_NO; DoExplosion(); while ( m_iClusters > 0 ) { float fYaw = random->RandomFloat( 0.0f, 360.0f ); QAngle ang( 0.0f, fYaw, 0.0f ); Vector newVel; AngleVectors( ang, &newVel ); newVel *= random->RandomFloat( 150.0f, 200.0f ); newVel.z = random->RandomFloat( 200.0f, 400.0f ); CASW_Boomer_Blob *pGrenade = CASW_Boomer_Blob::Boomer_Blob_Create( m_flDamage, m_DmgRadius, 0, GetAbsOrigin(), ang, newVel, AngularImpulse( 0.0f, 0.0f, 0.0f ), m_hFirer.Get() ); if (pGrenade) { pGrenade->m_fEarliestAOEDetonationTime = 0; // children can go whenever they want pGrenade->m_fEarliestTouchDetonationTime = 0; pGrenade->m_takedamage = DAMAGE_NO; pGrenade->SetFuseLength( random->RandomFloat( asw_boomer_blob_child_fuse_min.GetFloat(), asw_boomer_blob_child_fuse_max.GetFloat() ) ); pGrenade->SetClusters( 0, false ); pGrenade->m_bKicked = m_bKicked; } m_iClusters--; } UTIL_Remove( this ); }
NorthBearingAngle Vector3D::getBearingTo(const Vector3D &other) { Vector3D diff = getVectorTo(other); if (diff == Vector3D::ZERO) return NorthBearingAngle::NORTH; double x = diff.getX().getDoubleValue(Length::METERS); double y = diff.getY().getDoubleValue(Length::METERS); Angle ang( atan2(y,x), Angle::RADIANS ); return ang.toNorthBearing(); }
void vtWThread::threadRelease() { printMessage(0,"Deleting target from the iCubGui..\n"); deleteGuiEvents(); yDebug("Closing gaze controller.."); Vector ang(3,0.0); igaze -> lookAtAbsAngles(ang); igaze -> restoreContext(contextGaze); igaze -> stopControl(); ddG.close(); yDebug("Closing estimators.."); delete linEst_optFlow; linEst_optFlow = NULL; delete linEst_pf3dTracker; linEst_pf3dTracker = NULL; delete linEst_doubleTouch; linEst_doubleTouch = NULL; delete linEst_fgtTracker; linEst_fgtTracker = NULL; yDebug("Closing ports.."); optFlowPort.interrupt(); optFlowPort.close(); yTrace("optFlowPort successfully closed!"); pf3dTrackerPort.interrupt(); pf3dTrackerPort.close(); yTrace("pf3dTrackerPort successfully closed!"); doubleTouchPort.interrupt(); doubleTouchPort.close(); yTrace("doubleTouchPort successfully closed!"); genericObjectsPort.interrupt(); genericObjectsPort.close(); yTrace("genericObjectsPort successfully closed!"); sensManagerPort.interrupt(); sensManagerPort.close(); yTrace("sensManagerPort successfully closed!"); eventsPort.interrupt(); eventsPort.close(); yTrace("eventsPort successfully closed!"); depth2kinPort.interrupt(); depth2kinPort.close(); yTrace("depth2kinPort successfully closed!"); }
//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- AngularImpulse CRagdollProp::PhysGunLaunchAngularImpulse() { if( HasPhysgunInteraction( "onlaunch", "spin_zaxis" ) ) { // Don't add in random angular impulse if this object is supposed to spin in a specific way. AngularImpulse ang( 0, 0, 0 ); return ang; } return CDefaultPlayerPickupVPhysics::PhysGunLaunchAngularImpulse(); }
/*! angle_clamp(angle) Returns //angle// normalized to [0, 360). */ int l_angle_clamp(lua_State* L) { //lua_Number ang = lua_tonumber(L, 1); Angle ang((double)lua_tonumber(L, 1)); ang.clamp(); lua_pushnumber(L, ang.toDeg()); return 1; }
void doubleTouchThread::handleGaze() { if (step == 0 || step == 1 || step == 4) { Vector ang(3,0.0); igaze -> lookAtAbsAngles(ang); } else { cntctPosWRF = locateContact(cntctSkin); /*printf("cntctPosWRF: %s\n",cntctPosWRF.toString().c_str());*/ igaze -> lookAtFixationPoint(cntctPosWRF); } }
/*! angle_vector(angle[, length = 1]) Returns a tuple representing the angle with length //length//. */ int l_angle_vector(lua_State* L) { Angle ang((double)lua_tonumber(L, 1)); lua_Number len = 1.0; if(lua_gettop(L) >= 2) len = lua_tonumber(L, 2); Vec vec(ang, len); lua_pushnumber(L, vec.x); lua_pushnumber(L, vec.y); return 2; }
void eff_expl_smoke() { set(me, TRANSLUCENT | LIGHT | ZNEAR | PASSABLE); vec_set(my.blue, vector(200,255,255)); my.alpha = 40; my.roll = random(360); vec_fill(my.scale_x, 0.4); while(my.alpha > 0) { my.alpha -= time_step * 2; my.roll += time_step * sign(ang(my.roll))*1; vec_fill(vecEffectsTemp, time_step *0.01); vec_add(my.scale_x, vecEffectsTemp); wait(1); } ent_remove ( me ); }
SpatialAcc Axis::getRotationSpatialAcc(const double d2theta) const { SpatialAcc ret; Eigen::Map<Eigen::Vector3d> lin(ret.getLinearVec3().data()); Eigen::Map<Eigen::Vector3d> ang(ret.getAngularVec3().data()); Eigen::Map<const Eigen::Vector3d> dir(direction.data()); Eigen::Map<const Eigen::Vector3d> orig(origin.data()); lin = d2theta*(orig.cross(dir)); ang = dir*d2theta; return ret; }
Vector Localizer::getAbsAngles(const Vector &x) { Vector fp=x; fp.push_back(1.0); // impose homogeneous coordinates // get fp wrt head-centered system Vector fph=invEyeCAbsFrame*fp; fph.pop_back(); Vector ang(3); ang[0]=atan2(fph[0],fph[2]); ang[1]=-atan2(fph[1],fabs(fph[2])); ang[2]=2.0*atan2(eyesHalfBaseline,norm(fph)); return ang; }
Mat CmShow::Complex(CMat& _cmplx, CStr& title, float minMagShowAng, int flag) { CV_Assert(_cmplx.channels() == 2 && _cmplx.data != NULL); Mat ang(_cmplx.size(), CV_32FC1), mag(_cmplx.size(), CV_32FC1), cmplx; _cmplx.convertTo(cmplx, CV_32F); for (int y = 0; y < cmplx.rows; y++) { float* cpV = cmplx.ptr<float>(y); float* angV = ang.ptr<float>(y); float* magV = mag.ptr<float>(y); for (int x = 0; x < cmplx.cols; x++, cpV+=2) { magV[x] = sqrt(cpV[0] * cpV[0] + cpV[1] * cpV[1]); angV[x] = cvFastArctan(cpV[1], cpV[0]); } } return Complex(ang, mag, title, minMagShowAng, flag); }
/* =================== idPlayerView::AngleOffset kickVector, a world space direction that the attack should =================== */ idAngles idPlayerView::AngleOffset() const { idAngles ang( 0.0f, 0.0f, 0.0f ); if ( gameLocal.slow.time < kickFinishTime ) { float offset = kickFinishTime - gameLocal.slow.time; ang = kickAngles * offset * offset * g_kickAmplitude.GetFloat(); for ( int i = 0 ; i < 3 ; i++ ) { if ( ang[i] > 70.0f ) { ang[i] = 70.0f; } else if ( ang[i] < -70.0f ) { ang[i] = -70.0f; } } } return ang; }
static cell_t smn_BfWriteAngles(IPluginContext *pCtx, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); HandleError herr; HandleSecurity sec; bf_write *pBitBuf; sec.pOwner = NULL; sec.pIdentity = g_pCoreIdent; if ((herr=handlesys->ReadHandle(hndl, g_WrBitBufType, &sec, (void **)&pBitBuf)) != HandleError_None) { return pCtx->ThrowNativeError("Invalid bit buffer handle %x (error %d)", hndl, herr); } cell_t *pAng; pCtx->LocalToPhysAddr(params[2], &pAng); QAngle ang(sp_ctof(pAng[0]), sp_ctof(pAng[1]), sp_ctof(pAng[2])); pBitBuf->WriteBitAngles(ang); return 1; }
void Localizer::handleAnglesInput() { if (Bottle *angles=port_anglesIn.read(false)) { if (angles->size()>=4) { Vector ang(3); string type=angles->get(0).asString().c_str(); ang[0]=CTRL_DEG2RAD*angles->get(1).asDouble(); ang[1]=CTRL_DEG2RAD*angles->get(2).asDouble(); ang[2]=CTRL_DEG2RAD*angles->get(3).asDouble(); Vector xd=get3DPoint(type,ang); if (port_xd!=NULL) port_xd->set_xd(xd); else yError("Internal error occured!"); } else yError("Got wrong angles information!"); } }
void CTFGrenadeNailProjectile::StartEmittingNails( void ) { // 0.4 seconds later, emit nails IPhysicsObject *pPhysicsObject = VPhysicsGetObject(); if ( pPhysicsObject ) { m_pMotionController = physenv->CreateMotionController( &m_GrenadeController ); m_pMotionController->AttachObject( pPhysicsObject, true ); pPhysicsObject->EnableGravity( false ); pPhysicsObject->Wake(); } QAngle ang(0,0,0); Vector pos = GetAbsOrigin(); pos.z += 32; m_GrenadeController.SetDesiredPosAndOrientation( pos, ang ); m_flNailAngle = 0; m_iNumNailBurstsLeft = 40; int animDesired = SelectWeightedSequence( ACT_RANGE_ATTACK1 ); ResetSequence( animDesired ); SetPlaybackRate( 1.0 ); Vector soundPosition = GetAbsOrigin() + Vector( 0, 0, 5 ); CPASAttenuationFilter filter( soundPosition ); EmitSound( filter, entindex(), "Weapon_Grenade_Nail.Launch" ); #ifdef GAME_DLL SetThink( &CTFGrenadeNailProjectile::EmitNails ); SetNextThink( gpGlobals->curtime + 0.4 ); #endif }
void vtWThread::run() { optFlowPos.resize(3,0.0); pf3dTrackerPos.resize(3,0.0); doubleTouchPos.resize(3,0.0); fgtTrackerPos.resize(3,0.0); bool isTarget = false; events.clear(); // process the optFlow if (optFlowBottle = optFlowPort.read(false)) { if (optFlowBottle->size()>=3) { yDebug("Computing data from the optFlowTracker %g\n",getEstUsed()); optFlowPos.zero(); optFlowPos[0]=optFlowBottle->get(0).asDouble(); optFlowPos[1]=optFlowBottle->get(1).asDouble(); optFlowPos[2]=optFlowBottle->get(2).asDouble(); AWPolyElement el(optFlowPos,Time::now()); optFlowVelEstimate=linEst_optFlow->estimate(el); events.push_back(IncomingEvent(optFlowPos,optFlowVelEstimate,0.05,"optFlow")); isTarget=true; } } // process the pf3dTracker if (pf3dTrackerBottle = pf3dTrackerPort.read(false)) { if (pf3dTrackerBottle->size()>6) { if (pf3dTrackerBottle->get(6).asDouble()==1.0) { Vector fp(4); fp[0]=pf3dTrackerBottle->get(0).asDouble(); fp[1]=pf3dTrackerBottle->get(1).asDouble(); fp[2]=pf3dTrackerBottle->get(2).asDouble(); fp[3]=1.0; if (!gsl_isnan(fp[0]) && !gsl_isnan(fp[1]) && !gsl_isnan(fp[2])) { yDebug("Computing data from the pf3dTracker %g\n",getEstUsed()); Vector x,o; igaze->getLeftEyePose(x,o); Matrix T=axis2dcm(o); T(0,3)=x[0]; T(1,3)=x[1]; T(2,3)=x[2]; pf3dTrackerPos=T*fp; pf3dTrackerPos.pop_back(); AWPolyElement el(pf3dTrackerPos,Time::now()); pf3dTrackerVelEstimate=linEst_pf3dTracker->estimate(el); events.push_back(IncomingEvent(pf3dTrackerPos,pf3dTrackerVelEstimate,0.05,"pf3dTracker")); isTarget=true; } } } } if (!rf->check("noDoubleTouch")) { // processes the fingertipTracker if(fgtTrackerBottle = fgtTrackerPort.read(false)) { if (doubleTouchBottle = doubleTouchPort.read(false)) { if(fgtTrackerBottle != NULL && doubleTouchBottle != NULL) { if (doubleTouchBottle->get(3).asString() != "" && fgtTrackerBottle->get(0).asInt() != 0) { yDebug("Computing data from the fingertipTracker %g\n",getEstUsed()); doubleTouchStep = doubleTouchBottle->get(0).asInt(); fgtTrackerPos[0] = fgtTrackerBottle->get(1).asDouble(); fgtTrackerPos[1] = fgtTrackerBottle->get(2).asDouble(); fgtTrackerPos[2] = fgtTrackerBottle->get(3).asDouble(); AWPolyElement el2(fgtTrackerPos,Time::now()); fgtTrackerVelEstimate=linEst_fgtTracker->estimate(el2); if(doubleTouchStep<=1) { Vector ang(3,0.0); igaze -> lookAtAbsAngles(ang); } else if(doubleTouchStep>1 && doubleTouchStep<8) { events.clear(); events.push_back(IncomingEvent(fgtTrackerPos,fgtTrackerVelEstimate,-1.0,"fingertipTracker")); isTarget=true; } } } } } // processes the doubleTouch !rf->check("noDoubleTouch") if(doubleTouchBottle = doubleTouchPort.read(false)) { if(doubleTouchBottle != NULL) { if (doubleTouchBottle->get(3).asString() != "") { Matrix T = eye(4); Vector fingertipPos(4,0.0); doubleTouchPos.resize(4,0.0); currentTask = doubleTouchBottle->get(3).asString(); doubleTouchStep = doubleTouchBottle->get(0).asInt(); fingertipPos = iCub::skinDynLib::matrixFromBottle(*doubleTouchBottle,20,4,4).subcol(0,3,3); // fixed translation from the palm fingertipPos.push_back(1.0); if(doubleTouchStep<=1) { Vector ang(3,0.0); igaze -> lookAtAbsAngles(ang); } else if(doubleTouchStep>1 && doubleTouchStep<8) { if(currentTask=="LtoR" || currentTask=="LHtoR") //right to left -> the right index finger will be generating events { iencsR->getEncoders(encsR->data()); Vector qR=encsR->subVector(0,6); armR -> setAng(qR*CTRL_DEG2RAD); T = armR -> getH(3+6, true); // torso + up to wrist doubleTouchPos = T * fingertipPos; //optionally, get the finger encoders and get the fingertip position using iKin Finger based on the current joint values //http://wiki.icub.org/iCub/main/dox/html/icub_cartesian_interface.html#sec_cart_tipframe doubleTouchPos.pop_back(); //take out the last dummy value from homogenous form } else if(currentTask=="RtoL" || currentTask=="RHtoL") //left to right -> the left index finger will be generating events { iencsL->getEncoders(encsL->data()); Vector qL=encsL->subVector(0,6); armL -> setAng(qL*CTRL_DEG2RAD); T = armL -> getH(3+6, true); // torso + up to wrist doubleTouchPos = T * fingertipPos; //optionally, get the finger encoders and get the fingertip position using iKin Finger based on the current joint values //http://wiki.icub.org/iCub/main/dox/html/icub_cartesian_interface.html#sec_cart_tipframe doubleTouchPos.pop_back(); //take out the last dummy value from homogenous form } else { yError(" [vtWThread] Unknown task received from the double touch thread!"); } yDebug("Computing data from the doubleTouch %g\n",getEstUsed()); AWPolyElement el2(doubleTouchPos,Time::now()); doubleTouchVelEstimate=linEst_doubleTouch->estimate(el2); events.push_back(IncomingEvent(doubleTouchPos,doubleTouchVelEstimate,-1.0,"doubleTouch")); isTarget=true; } } } } } if (pf3dTrackerPos[0]!=0.0 && pf3dTrackerPos[1]!=0.0 && pf3dTrackerPos[2]!=0.0) igaze -> lookAtFixationPoint(pf3dTrackerPos); else if (doubleTouchPos[0]!=0.0 && doubleTouchPos[1]!=0.0 && doubleTouchPos[2]!=0.0) igaze -> lookAtFixationPoint(doubleTouchPos); else if (optFlowPos[0]!=0.0 && optFlowPos[1]!=0.0 && optFlowPos[2]!=0.0) igaze -> lookAtFixationPoint(optFlowPos); if (isTarget) { Bottle& eventsBottle = eventsPort.prepare(); eventsBottle.clear(); for (size_t i = 0; i < events.size(); i++) { eventsBottle.addList()= events[i].toBottle(); } eventsPort.write(); timeNow = yarp::os::Time::now(); sendGuiTarget(); } else if (yarp::os::Time::now() - timeNow > 1.0) { yDebug("No significant event in the last second. Resetting the velocity estimators.."); timeNow = yarp::os::Time::now(); linEst_optFlow -> reset(); linEst_pf3dTracker -> reset(); linEst_doubleTouch -> reset(); linEst_fgtTracker -> reset(); deleteGuiTarget(); } }
void QtGradientWidget::paintEvent(QPaintEvent *e) { Q_UNUSED(e) QPainter p(this); if (d_ptr->m_backgroundCheckered) { int pixSize = 40; QPixmap pm(2 * pixSize, 2 * pixSize); QPainter pmp(&pm); pmp.fillRect(0, 0, pixSize, pixSize, Qt::white); pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white); pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black); pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black); p.setBrushOrigin((size().width() % pixSize + pixSize) / 2, (size().height() % pixSize + pixSize) / 2); p.fillRect(rect(), pm); p.setBrushOrigin(0, 0); } QGradient *gradient = 0; switch (d_ptr->m_gradientType) { case QGradient::LinearGradient: gradient = new QLinearGradient(d_ptr->m_startLinear, d_ptr->m_endLinear); break; case QGradient::RadialGradient: gradient = new QRadialGradient(d_ptr->m_centralRadial, d_ptr->m_radiusRadial, d_ptr->m_focalRadial); break; case QGradient::ConicalGradient: gradient = new QConicalGradient(d_ptr->m_centralConical, d_ptr->m_angleConical); break; default: break; } if (!gradient) return; gradient->setStops(d_ptr->m_gradientStops); gradient->setSpread(d_ptr->m_gradientSpread); p.save(); p.scale(size().width(), size().height()); p.fillRect(QRect(0, 0, 1, 1), *gradient); p.restore(); p.setRenderHint(QPainter::Antialiasing); QColor c = QColor::fromRgbF(0.5, 0.5, 0.5, 0.5); QBrush br(c); p.setBrush(br); QPen pen(Qt::white); pen.setWidthF(1); p.setPen(pen); QPen dragPen = pen; dragPen.setWidthF(2); if (d_ptr->m_gradientType == QGradient::LinearGradient) { p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_startLinear, d_ptr->m_handleSize); p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_endLinear, d_ptr->m_handleSize); p.restore(); } else if (d_ptr->m_gradientType == QGradient::RadialGradient) { QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial); p.save(); QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3); QRectF r1(0, r.y(), size().width(), r.height()); QRectF r2(r.x(), 0, r.width(), r.y()); QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height()); p.fillRect(r1, c); p.fillRect(r2, c); p.fillRect(r3, c); p.setBrush(Qt::NoBrush); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralRadial, d_ptr->m_handleSize); p.restore(); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial * size().width(), central.y() - d_ptr->m_radiusRadial * size().height(), 2 * d_ptr->m_radiusRadial * size().width(), 2 * d_ptr->m_radiusRadial * size().height()); p.setClipRect(r1); p.setClipRect(r2, Qt::UniteClip); p.setClipRect(r3, Qt::UniteClip); p.drawEllipse(rect); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) { p.save(); p.setPen(dragPen); QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), central.y() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(), 2 * d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().height()); p.drawEllipse(rect); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::FocalRadialHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_focalRadial, 2 * d_ptr->m_handleSize / 3); p.restore(); } else if (d_ptr->m_gradientType == QGradient::ConicalGradient) { double radius = size().width(); if (size().height() < radius) radius = size().height(); radius /= 2; double corr = d_ptr->m_handleSize / 3; radius -= corr; QPointF central = d_ptr->toViewport(d_ptr->m_centralConical); p.save(); p.setBrush(Qt::NoBrush); QPen pen2(c); pen2.setWidthF(2 * d_ptr->m_handleSize / 3); p.setPen(pen2); p.drawEllipse(d_ptr->pointRect(central, 2 * radius)); p.restore(); p.save(); p.setBrush(Qt::NoBrush); int pointCount = 2; for (int i = 0; i < pointCount; i++) { QPointF ang(cos(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().width() / 2, -sin(M_PI * (i * 180.0 / pointCount + d_ptr->m_angleConical) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.drawLine(QPointF(central.x() - ang.x() * (radius - corr) / mod, central.y() - ang.y() * (radius - corr) / mod), QPointF(central.x() - ang.x() * (radius + corr) / mod, central.y() - ang.y() * (radius + corr) / mod)); } if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::AngleConicalHandle) { p.save(); p.setPen(dragPen); QPointF ang(cos(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().width() / 2, -sin(M_PI * (d_ptr->m_angleConical - d_ptr->m_angleOffset) / 180) * size().height() / 2); double mod = sqrt(ang.x() * ang.x() + ang.y() * ang.y()); p.drawLine(QPointF(central.x() + ang.x() * (radius - corr) / mod, central.y() + ang.y() * (radius - corr) / mod), QPointF(central.x() + ang.x() * (radius + corr) / mod, central.y() + ang.y() * (radius + corr) / mod)); p.restore(); } p.restore(); p.save(); if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralConicalHandle) p.setPen(dragPen); d_ptr->paintPoint(&p, d_ptr->m_centralConical, d_ptr->m_handleSize); p.restore(); } delete gradient; }
// uses: id, speed action rotating_platform() { set(my, is_platform); my->ptr_start = NULL; my->ptr_end = NULL; wait (1); for(you = ent_next(NULL); (you != NULL) && (my->ptr_end == NULL); you = ent_next(you)) { if ((your->id == my->id) && (my->id > 0) && is(you, is_marker)) { if (my->ptr_start == NULL) { my->ptr_start = handle(you); } else if (my->ptr_end == NULL) { my->ptr_end = handle(you); } else { //do nothing } } } if ((my->ptr_end == NULL) || (my->id <= 0)) { printf("incorrect platform marker for id %d", (int)my->id); return; } //platform start point VECTOR vecSpeed, vecTemp; ENTITY *ent1, *ent2, *entCenter; var vRadius; var vAngle; ent1 = ptr_for_handle(my->ptr_start); ent2 = ptr_for_handle(my->ptr_end); if (vec_dist(&ent1->x, &my->x) < vec_dist(&ent2->x, &my->x)) { vec_set(&my->x, &ent1->x); entCenter = ent2; ent2->y = ent1->y; } else { vec_set(&my->x, &ent2->x); entCenter = ent1; ent1->y = ent2->y; } //directional speed vec_set(&vecSpeed, nullvector); vRadius = vec_dist(&ent1->x, &ent2->x); //entity loop while(1) { vAngle += time_step * my->speed; vAngle = ang(vAngle); vec_set(&vecSpeed, nullvector); vecSpeed.x = vRadius; vec_rotate(&vecSpeed, vector(0, vAngle, 0)); vec_add(&vecSpeed, &entCenter->x); vec_sub(&vecSpeed, &my->x); vec_scale(&vecSpeed, time_step); vec_set(&my->absspeed_x, &vecSpeed); you = player; c_move(me, nullvector, &vecSpeed, IGNORE_MODELS | IGNORE_SPRITES | IGNORE_YOU | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS); wait (1); } }
VLD::VLD(const ImageScale& series, T const& P1, T const& P2) : contrast(0.0) { //============== initializing============// principleAngle.fill(0); descriptor.fill(0); weight.fill(0); begin_point[0]=P1.x; begin_point[1]=P1.y; end_point[0]=P2.x; end_point[1]=P2.y; float dy= float(end_point[1]- begin_point[1]), dx= float(end_point[0]- begin_point[0]); distance=sqrt(dy*dy+dx*dx); if (distance==0) std::cerr<<"Two SIFT points have the same coordinate"<<std::endl; float radius=std::max(distance/float(dimension+1), 2.0f);//at least 2 double mainAngle= get_orientation();//absolute angle int image_index=series.getIndex(radius); const Image<float> & ang = series.angles[image_index]; const Image<float> & m = series.magnitudes[image_index]; double ratio=series.ratios[image_index]; // std::cout<<std::endl<<"index of image "<<radius<<" "<<image_index<<" "<<ratio<<std::endl; int w=m.Width() ,h=m.Height(); float r=float(radius/ratio);//series.radius_size; float sigma2=r*r; //======Computing the descriptors=====// for (int i=0;i<dimension; i++){ double statistic[binNum]; std::fill_n(statistic, binNum, 0.0); float xi= float(begin_point[0]+ float(i+1)/(dimension+1)*(dx)); float yi= float(begin_point[1]+ float(i+1)/(dimension+1)*(dy)); yi/=float(ratio); xi/=float(ratio); for (int y=int(yi-r);y<=int(yi+r+0.5);y++){ for (int x=int(xi-r);x<=int(xi+r+0.5);x++){ float d=point_distance(xi,yi,float(x),float(y)); if (d<=r && inside(w,h,x,y,1)){ //================angle and magnitude==========================// double angle; if (ang(y,x)>=0) angle=ang(y,x)-mainAngle;//relative angle else angle=0.0; //cout<<angle<<endl; while (angle<0) angle +=2*PI; while (angle>=2*PI) angle -=2*PI; //===============principle angle==============================// int index=int(angle*binNum/(2*PI)+0.5); double Gweight=exp(-d*d/4.5/sigma2)*(m(y,x)); // std::cout<<"in number "<<image_index<<" "<<x<<" "<<y<<" "<<m(y,x)<<std::endl; if (index<binNum) statistic[index]+=Gweight; else // possible since the 0.5 statistic[0]+=Gweight; //==============the descriptor===============================// int index2=int(angle*subdirection/(2*PI)+0.5); assert(index2>=0 && index2<=subdirection); if (index2<subdirection) descriptor[subdirection*i+index2]+=Gweight; else descriptor[subdirection*i]+=Gweight;// possible since the 0.5 } } } //=====================find the biggest angle of ith SIFT==================// int index,second_index; max(statistic,weight[i],binNum,index,second_index); principleAngle[i]=index; } normalize_weight(descriptor); contrast= std::accumulate(weight.begin(), weight.end(), 0.0); contrast/=distance/ratio; normalize_weight(weight); }
/* ================ idTarget_SetInfluence::Event_Activate ================ */ void idTarget_SetInfluence::Event_Activate( idEntity *activator ) { int i, j; idEntity *ent; idLight *light; idSound *sound; idStaticEntity *generic; const char *parm; const char *skin; bool update; idVec3 color; idVec4 colorTo; idPlayer *player; player = gameLocal.GetLocalPlayer(); if( spawnArgs.GetBool( "triggerActivate" ) ) { if( restoreOnTrigger ) { ProcessEvent( &EV_RestoreInfluence ); restoreOnTrigger = false; return; } restoreOnTrigger = true; } float fadeTime = spawnArgs.GetFloat( "fadeWorldSounds" ); if( delay > 0.0f ) { PostEventSec( &EV_Activate, delay, activator ); delay = 0.0f; // start any sound fading now if( fadeTime ) { gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime ); soundFaded = true; } return; } else if( fadeTime && !soundFaded ) { gameSoundWorld->FadeSoundClasses( 0, -40.0f, fadeTime ); soundFaded = true; } if( spawnArgs.GetBool( "triggerTargets" ) ) { ActivateTargets( activator ); } if( flashIn ) { PostEventSec( &EV_Flash, 0.0f, flashIn, 0 ); } parm = spawnArgs.GetString( "snd_influence" ); if( parm && *parm ) { PostEventSec( &EV_StartSoundShader, flashIn, parm, SND_CHANNEL_ANY ); } if( switchToCamera ) { switchToCamera->PostEventSec( &EV_Activate, flashIn + 0.05f, this ); } int fov = spawnArgs.GetInt( "fov" ); if( fov ) { fovSetting.Init( gameLocal.time, SEC2MS( spawnArgs.GetFloat( "fovTime" ) ), player->DefaultFov(), fov ); BecomeActive( TH_THINK ); } for( i = 0; i < genericList.Num(); i++ ) { ent = gameLocal.entities[genericList[i]]; if( ent == NULL ) { continue; } generic = static_cast<idStaticEntity *>( ent ); color = generic->spawnArgs.GetVector( "color_demonic" ); colorTo.Set( color.x, color.y, color.z, 1.0f ); generic->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) ); } for( i = 0; i < lightList.Num(); i++ ) { ent = gameLocal.entities[lightList[i]]; if( ent == NULL || !ent->IsType( idLight::Type ) ) { continue; } light = static_cast<idLight *>( ent ); parm = light->spawnArgs.GetString( "mat_demonic" ); if( parm && *parm ) { light->SetShader( parm ); } color = light->spawnArgs.GetVector( "_color" ); color = light->spawnArgs.GetVector( "color_demonic", color.ToString() ); colorTo.Set( color.x, color.y, color.z, 1.0f ); light->Fade( colorTo, spawnArgs.GetFloat( "fade_time", "0.25" ) ); } for( i = 0; i < soundList.Num(); i++ ) { ent = gameLocal.entities[soundList[i]]; if( ent == NULL || !ent->IsType( idSound::Type ) ) { continue; } sound = static_cast<idSound *>( ent ); parm = sound->spawnArgs.GetString( "snd_demonic" ); if( parm && *parm ) { if( sound->spawnArgs.GetBool( "overlayDemonic" ) ) { sound->StartSound( "snd_demonic", SND_CHANNEL_DEMONIC, 0, false, NULL ); } else { sound->StopSound( SND_CHANNEL_ANY, false ); sound->SetSound( parm ); } } } for( i = 0; i < guiList.Num(); i++ ) { ent = gameLocal.entities[guiList[i]]; if( ent == NULL || ent->GetRenderEntity() == NULL ) { continue; } update = false; for( j = 0; j < MAX_RENDERENTITY_GUI; j++ ) { if( ent->GetRenderEntity()->gui[ j ] && ent->spawnArgs.FindKey( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j + 1 ) ) ) { #ifdef _D3XP //Backup the old one savedGuiList[i].gui[j] = ent->GetRenderEntity()->gui[ j ]; #endif ent->GetRenderEntity()->gui[ j ] = uiManager->FindGui( ent->spawnArgs.GetString( j == 0 ? "gui_demonic" : va( "gui_demonic%d", j + 1 ) ), true ); update = true; } } if( update ) { ent->UpdateVisuals(); ent->Present(); } } player->SetInfluenceLevel( spawnArgs.GetInt( "influenceLevel" ) ); int snapAngle = spawnArgs.GetInt( "snapAngle" ); if( snapAngle ) { idAngles ang( 0, snapAngle, 0 ); player->SetViewAngles( ang ); player->SetAngles( ang ); } if( spawnArgs.GetBool( "effect_vision" ) ) { parm = spawnArgs.GetString( "mtrVision" ); skin = spawnArgs.GetString( "skinVision" ); player->SetInfluenceView( parm, skin, spawnArgs.GetInt( "visionRadius" ), this ); } parm = spawnArgs.GetString( "mtrWorld" ); if( parm && *parm ) { gameLocal.SetGlobalMaterial( declManager->FindMaterial( parm ) ); } if( !restoreOnTrigger ) { PostEventMS( &EV_RestoreInfluence, SEC2MS( spawnArgs.GetFloat( "time" ) ) ); } }
float* FlowError::calcError(flowUV& UV, flowUV& GT, bool display){ int size = 0; cv::Mat mask(UV.getU().rows, UV.getU().cols, CV_8U,cv::Scalar(0)); float* gu = (float*)GT.getU().data; float* gv = (float*)GT.getV().data; uchar* m = mask.data; for (int i = 0 ; i < GT.getU().rows * GT.getU().cols; ++i, ++gu, ++gv, ++m){ if ((std::abs(*gv) == 0 && std::abs(*gu) == 0) | (std::abs(*gv) > 1000000000) | (std::abs(*gu) > 1000000000)) { *m = 0; } else { *m = 1; ++size; } } float* u = (float*)UV.getU().data; float* v = (float*)UV.getV().data; gu = (float*)GT.getU().data; gv = (float*)GT.getV().data; cv::Mat msu(size, 1, OPTFLOW_TYPE); cv::Mat msv(size, 1, OPTFLOW_TYPE); cv::Mat mstu(size, 1, OPTFLOW_TYPE); cv::Mat mstv(size, 1, OPTFLOW_TYPE); float* pmsu = (float*)msu.data; float* pmsv = (float*)msv.data; float* pmstu = (float*)mstu.data; float* pmstv = (float*)mstv.data; m = mask.data; for(int i = 0; i < UV.getU().rows * UV.getU().cols; ++i, ++u, ++v, ++gu, ++gv, ++m){ if (*m){ *(pmsu++) = *(u); *(pmsv++) = *(v); *(pmstu++) = *(gu); *(pmstv++) = *(gv); } } cv::Mat n(size, 1, OPTFLOW_TYPE,cv::Scalar(0)); pmsu = (float*)msu.data; pmsv = (float*)msv.data; float* pn = (float*)n.data; for(int i = 0; i < size; ++i, ++pmsu, ++pmsv, ++pn){ *pn = (1.0f/ std::sqrtf((*pmsu) * (*pmsu) + (*pmsv) * (*pmsv) + 1)); } cv::Mat un = msu.mul(n); cv::Mat vn = msv.mul(n); cv::Mat tn(size, 1, OPTFLOW_TYPE,cv::Scalar(0)); pmstu = (float*)mstu.data; pmstv = (float*)mstv.data; float* ptn = (float*)tn.data; for(int i = 0; i < size; ++i, ++pmstu, ++pmstv, ++ptn){ *ptn = (1.0f/ std::sqrtf((*pmstu) * (*pmstu) + (*pmstv) * (*pmstv) + 1)); } cv::Mat tun = mstu.mul(tn); cv::Mat tvn = mstv.mul(tn); cv::Mat ang(size, 1, OPTFLOW_TYPE,cv::Scalar(0)); cv::Mat angtmp = un.mul(tun)+ vn.mul(tvn) +(n.mul(tn)); float* pAng = (float*)ang.data; float* pAngtmp = (float*)angtmp.data; ptn = (float*)tn.data; for(int i = 0; i < size; ++i){ *(pAng++) = std::acos(std::max<float>(-1, std::min<float>(1,*(pAngtmp++)))); } float mang = (float)cv::mean(ang).val[0]; static float pi = 3.14159265358979323846f; mang = mang * 180 / pi; cv::Scalar meanTmp, meanStd; cv::meanStdDev(cv::Mat(ang*180/pi), meanTmp, meanStd); float stdang = (float)meanStd.val[0]; cv::Mat epe1 = (GT.getU() - UV.getU()).mul((GT.getU() - UV.getU())) + (GT.getV() - UV.getV()).mul((GT.getV() - UV.getV())); cv::Mat epe2(UV.getU().rows, UV.getU().cols, OPTFLOW_TYPE,cv::Scalar(0));; cv::sqrt(epe1, epe2); cv::Mat epe(size, 1, OPTFLOW_TYPE,cv::Scalar(0)); float* pepe2 = (float*)epe2.data; float* pepe = (float*)epe.data; m = mask.data; for(int i = 0; i < UV.getU().rows * UV.getU().cols; ++i, ++pepe2, ++m){ if (*m){ *(pepe++) = *(pepe2); } } float mepe = (float)cv::mean(epe).val[0]; float* ret = new float[3]; ret[0] = mang; ret[1] = stdang; ret[2] = mepe; if (display){ UtilsMat::clamp<float>(epe2,0,1); pepe2 = (float*)epe2.data; m = mask.data; for(int i = 0; i < epe2.cols * epe2.rows; ++i, ++pepe2, ++m) *(pepe2) = *(pepe2) * *(m); cv::imshow("End Point Error Visualization", epe2); cv::waitKey(1); } return ret; }
void CWeaponGravityGun::EffectUpdate( void ) { Vector start, angles, forward, right; trace_t tr; CBasePlayer *pOwner = ToBasePlayer( GetOwner() ); if ( !pOwner ) return; m_viewModelIndex = pOwner->entindex(); // Make sure I've got a view model CBaseViewModel *vm = pOwner->GetViewModel(); if ( vm ) { m_viewModelIndex = vm->entindex(); } pOwner->EyeVectors( &forward, &right, NULL ); start = pOwner->Weapon_ShootPosition(); Vector end = start + forward * 4096; UTIL_TraceLine( start, end, MASK_SHOT, pOwner, COLLISION_GROUP_NONE, &tr ); end = tr.endpos; float distance = tr.fraction * 4096; if ( tr.fraction != 1 ) { // too close to the player, drop the object if ( distance < 36 ) { DetachObject(); return; } } if ( m_hObject == NULL && tr.DidHitNonWorldEntity() ) { CBaseEntity *pEntity = tr.m_pEnt; // inform the object what was hit ClearMultiDamage(); pEntity->DispatchTraceAttack( CTakeDamageInfo( pOwner, pOwner, 0, DMG_PHYSGUN ), forward, &tr ); ApplyMultiDamage(); AttachObject( pEntity, start, tr.endpos, distance ); m_lastYaw = pOwner->EyeAngles().y; } // Add the incremental player yaw to the target transform matrix3x4_t curMatrix, incMatrix, nextMatrix; QAngle ang(0.0f, pOwner->EyeAngles().y - m_lastYaw, 0.0f); AngleMatrix( m_gravCallback.m_targetRotation, curMatrix ); AngleMatrix( ang, incMatrix ); ConcatTransforms( incMatrix, curMatrix, nextMatrix ); MatrixAngles( nextMatrix, m_gravCallback.m_targetRotation ); m_lastYaw = pOwner->EyeAngles().y; CBaseEntity *pObject = m_hObject; if ( pObject ) { if ( m_useDown ) { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = false; } } else { if ( pOwner->m_afButtonPressed & IN_USE ) { m_useDown = true; } } if ( m_useDown ) { pOwner->SetPhysicsFlag( PFLAG_DIROVERRIDE, true ); if ( pOwner->m_nButtons & IN_FORWARD ) { m_distance = UTIL_Approach( 1024, m_distance, gpGlobals->frametime * 100 ); } if ( pOwner->m_nButtons & IN_BACK ) { m_distance = UTIL_Approach( 40, m_distance, gpGlobals->frametime * 100 ); } } if ( pOwner->m_nButtons & IN_WEAPON1 ) { m_distance = UTIL_Approach( 1024, m_distance, m_distance * 0.1 ); } if ( pOwner->m_nButtons & IN_WEAPON2 ) { m_distance = UTIL_Approach( 40, m_distance, m_distance * 0.1 ); } // Send the object a physics damage message (0 damage). Some objects interpret this // as something else being in control of their physics temporarily. pObject->TakeDamage( CTakeDamageInfo( this, pOwner, 0, DMG_PHYSGUN ) ); Vector newPosition = start + forward * m_distance; // 24 is a little larger than 16 * sqrt(2) (extent of player bbox) // HACKHACK: We do this so we can "ignore" the player and the object we're manipulating // If we had a filter for tracelines, we could simply filter both ents and start from "start" Vector awayfromPlayer = start + forward * 24; UTIL_TraceLine( start, awayfromPlayer, MASK_SOLID, pOwner, COLLISION_GROUP_NONE, &tr ); if ( tr.fraction == 1 ) { UTIL_TraceLine( awayfromPlayer, newPosition, MASK_SOLID, pObject, COLLISION_GROUP_NONE, &tr ); Vector dir = tr.endpos - newPosition; float distance = VectorNormalize(dir); float maxDist = m_gravCallback.m_maxVel * gpGlobals->frametime; if ( distance > maxDist ) { newPosition += dir * maxDist; } else { newPosition = tr.endpos; } } else { newPosition = tr.endpos; } CreatePelletAttraction( phys_gunglueradius.GetFloat(), pObject ); // If I'm looking more than 20 degrees away from the glue point, then give up // This lets the player "gesture" for the glue to let go. Vector pelletDir = m_gravCallback.m_worldPosition - start; VectorNormalize(pelletDir); if ( DotProduct( pelletDir, forward ) < 0.939 ) // 0.939 ~= cos(20deg) { // lose attach for 2 seconds if you're too far away m_glueTime = gpGlobals->curtime + 1; } if ( m_pelletHeld >= 0 && gpGlobals->curtime > m_glueTime ) { CGravityPellet *pPelletAttract = m_activePellets[m_pelletAttract].pellet; g_pEffects->Sparks( pPelletAttract->GetAbsOrigin() ); } m_gravCallback.SetTargetPosition( newPosition ); Vector dir = (newPosition - pObject->GetLocalOrigin()); m_movementLength = dir.Length(); } else { m_gravCallback.SetTargetPosition( end ); } if ( m_pelletHeld >= 0 && gpGlobals->curtime > m_glueTime ) { Vector worldNormal, worldPos; GetPelletWorldCoords( m_pelletAttract, &worldPos, &worldNormal ); m_gravCallback.SetAutoAlign( m_activePellets[m_pelletHeld].localNormal, m_activePellets[m_pelletHeld].pellet->GetLocalOrigin(), worldNormal, worldPos ); } else { m_gravCallback.ClearAutoAlign(); } }
int main() { int i, j, k, l, r, t, x1, y1, x2, y2, f, ii, jj, kk; double sa; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]); scanf("%d%d%d%d", &x1, &y1, &x2, &y2); sa = 0; for (i = 0; i < n; i++) { j = (i + 1) % n; k = (j + 1) % n; sa += ang(x[j] - x[i], y[j] - y[i], x[k] - x[j], y[k] - y[j]); } if (sa < 0) { l = 0; r = n - 1; while (l < r) { swap(&x[l], &x[r]); swap(&y[l], &y[r]); l++; r--; } } memset(g, 0, sizeof(g)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) if (j != i && left(x[i], y[i], x[j], y[j], x1, y1) && left(x[i], y[i], x[j], y[j], x2, y2)) if (i == (j + 1) % n || (i + 1) % n == j) { g[i][j] = 1; } else if (inside(i, j) && inside(j, i)) { f = 1; for (k = 0; k < n; k++) { l = (k + 1) % n; if (l != j && k != j && l != i && k != i && inters(x[i], y[i], x[j], y[j], x[k], y[k], x[l], y[l])) { f = 0; break; } } if (f) g[i][j] = 1; } f = 1; for (i = 0; i < n && f; i++) for (j = 0; j < n && f; j++) for (k = 0; k < n && f; k++) if (g[i][j] && g[j][k] && g[k][i]) { ii = i; jj = j; kk= k; f = 0; } if (f) puts("Impossible"); else { if (sa < 0) { ii = n - 1 - ii; jj = n - 1 - jj; kk = n - 1 - kk; } printf("%d %d %d", ii + 1, jj + 1, kk + 1); } return 0; }