/** az egér koordinátái alapján kiszámítja a kiválasztandó texturát **/ int CircularTextureSelect::SelectTexture(sf::RenderWindow* target) { float x = target->GetInput().GetMouseX(); float y = target->GetInput().GetMouseY(); for(int i = 0; i < _texturePerCurrentCircle; i++) { sf::Vector2<float> p2 = _RectSelects[i].GetPointPosition(_RectSelects[i].GetNbPoints()-2); sf::Vector2<float> p3 = _RectSelects[i].GetPointPosition(_RectSelects[i].GetNbPoints()-1); // std::cout << p2.x << " " << p2.y << endl; sf::Vector2<float> origo(_Circle.GetCenter()); sf::Vector2<float> mouse(x,y); float angle = ComputeAngle(origo,p2); float angle2 = ComputeAngle(origo,p3); float angle_mouse = ComputeAngle(origo,mouse); if(angle2 == 0) angle2 = 360; if(angle_mouse > angle && angle_mouse < angle2) { return i + RemainingTexture(); // ha már a 2. , 3. körbe vagyunk } // std::cout << "m: " << angle_mouse << " 3 " << angle2 << " 2 " << angle << endl; } return 0; }
WeightInfo ComputeWeight(const FaceType &f, int edge, ScalarType & weight) { typedef typename FaceType::VertexType VertexType; assert(edge >= 0 && edge < 3); // get the adjacent face const FaceType * fp = f.cFFp(edge); if (fp == NULL || fp == &f) { // Mesh not closed, border found return BorderEdge; } if (fp->IsV()) return EdgeAlreadyVisited; // Get an edge (a pair of vertices) VertexType * v0 = f.cV0(edge); VertexType * v1 = f.cV1(edge); // Get the vertices opposite to the edge VertexType * va = f.cV2(edge); VertexType * vb = fp->cV2(f.cFFi(edge)); ScalarType angleA = ComputeAngle(v0, va, v1); ScalarType angleB = ComputeAngle(v0, vb, v1); ScalarType cotA = vcg::math::Cos(angleA) / vcg::math::Sin(angleA); ScalarType cotB = vcg::math::Cos(angleB) / vcg::math::Sin(angleB); weight = (cotA + cotB) / 2; return Success; }
int main(void) { /* Configure the oscillator both devices */ ConfigureOscillator(); /* Initialize IO ports and peripherals for both devices */ InitGPIO(); InitUART(); InitI2c(); InitI2cCompass(); /* Program for the bracelet */ #ifdef PROTECTED /* Initialize IO ports and peripherals */ InitTimerUS(); /* The values of the magnetic field will be save in x and y */ s16 x = 0; s16 y = 0; while(1) { I2cReadData(&x, &y); ComputeAngle(&angle, x, y); PutData16(angle); __delay_ms(500); } #endif /* Program for the bodyguard*/ #ifdef BODY_GUARD /* Initialize IO ports and peripherals */ InitADC(); InitPWM(); InitLcd(); InitTimerServo(); /* TODO <INSERT USER APPLICATION CODE HERE> */ u16 ADC_values[NMB_SENSORS]; u16 average[NMB_SENSORS]; u8 i; u8 j; /* The values of the magnetic field will be save in x and y */ s16 x = 0; s16 y = 0; u16 angle2=0; char T[5]; memset(ADC_values,0x00,sizeof(ADC_values)); memset(average, 0x00,sizeof(average)); /* for(i=0; i<NMB_SENSORS; i++) { ADC_values[i]=0; }*/ LcdClear(); #if MAGNETIC_SENSOR while(1) { I2cReadData(&x, &y); angle2=((-atan2(x,y)*180)/3.14)+180; /* Computes the angle using the arctan2 which provides an angle * between -180° and 180°, then converts the result that is in radian * into degree (*180/pi) and in the end add 180° so the angle is between * 0° and 360° */ //LcdPutFloat(angle2,0); LcdPutFloat(angle2,0); LcdGoto(1,2); LcdPutFloat(angle,0); __delay_ms(500); LcdClear(); } #endif #ifdef BODY_GUARD_MODE while(1) { for(j=0; j<NMB_MEASURES; j++) { /* SENSORS SAMPLING */ for(i=0; i<NMB_SENSORS; i++) { StartADC(ADC_values); } ObjectDetection(ADC_values, average); } LcdClear(); LcdPutFloat(CCP2RB, 0); //__delay_ms(1000); LcdClear(); /* Set Flags */ ObjectReaction(average); DistanceFlag(average[US]); /* react */ AutoBodyGuard(); } #endif #ifdef AUTO_FLEE while(1) { for(j=0; j<NMB_MEASURES; j++) { /* SENSORS SAMPLING */ for(i=0; i<NMB_SENSORS; i++) { StartADC(ADC_values); } ObjectDetection(ADC_values, average); } LcdClear(); /* Set Flags */ ObjectReaction(average); //DistanceFlag(average[US]); AutoFLee(); } #endif #endif return 0; }