/*------------------------------------------------------------------------------* | <<< 直線と線分との交差判定 >>> | 入力 pvecLine0 - pvecLine1 = 調べたい直線 | pvecRay0 - pvecRay1 = 交差判定をする線分 | 戻り値 TRUE : 交差している | FALSE : 交差していない *------------------------------------------------------------------------------*/ BOOL collision_line_ray(VEC2 *pvecLine0, VEC2 *pvecLine1, VEC2 *pvecRay0, VEC2 *pvecRay1) { // (x0,y0)-(x1,y1)において、x0,y0が小さい値になるように並べ替え // 以下の矩形チェックに使うため、線の向きが変わっても気にしない float fLineX0 = pvecLine0->x; float fLineX1 = pvecLine1->x; if(fLineX0 > fLineX1){ SWAPF(fLineX0, fLineX1);} float fLineY0 = pvecLine0->y; float fLineY1 = pvecLine1->y; if(fLineY0 > fLineY1){ SWAPF(fLineY0, fLineY1);} float fRayX0 = pvecRay0->x; float fRayX1 = pvecRay1->x; if(fRayX0 > fRayX1){ SWAPF(fRayX0, fRayX1);} float fRayY0 = pvecRay0->y; float fRayY1 = pvecRay1->y; if(fRayY0 > fRayY1){ SWAPF(fRayY0, fRayY1);} //--- 調べる必要のないものはここではじく ----------------- // 矩形を作り枠の外にあるかをチェック if(fLineX0 < fRayX0 && fLineX1 < fRayX0){ return FALSE;} if(fLineX0 > fRayX1 && fLineX1 > fRayX1){ return FALSE;} if(fLineY0 < fRayY0 && fLineY1 < fRayY0){ return FALSE;} if(fLineY0 > fRayY1 && fLineY1 > fRayY1){ return FALSE;} //if(pvecLine0->x < pvecRay0->x && pvecLine1->x < pvecRay0->x){ return FALSE;} //if(pvecLine0->x > pvecRay1->x && pvecLine1->x > pvecRay1->x){ return FALSE;} //if(pvecLine0->y < pvecRay0->y && pvecLine1->y < pvecRay0->y){ return FALSE;} //if(pvecLine0->y > pvecRay1->y && pvecLine1->y > pvecRay1->y){ return FALSE;} //--- 外積を調べる --------------------------------------- VEC2 v0 = *pvecRay1 - *pvecRay0; VEC2 v1 = *pvecLine0 - *pvecRay0; VEC2 v2 = *pvecLine1 - *pvecRay0; //float a = D3DXVec2CCW(&v0, &v1); // 戻り値が正なら左 //float b = D3DXVec2CCW(&v0, &v2); // 戻り値が負なら右 float a = calc_vec2_cross(&v0, &v1); // 戻り値が正なら左 float b = calc_vec2_cross(&v0, &v2); // 戻り値が負なら右 if(a == 0.f || b == 0.f){ return TRUE;} // 直線の上 if(a > 0.f && b < 0.f){ return TRUE;} // 交差 if(a < 0.f && b > 0.f){ return TRUE;} // 交差 return FALSE; }
int awritefloat (char *file, float *data, int length) { int fd; int size; int offset; if ((fd = open (file, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0644)) < 0) { fprintf (stderr, "awritefloat: %s: can't create\n", file); perror(""); return -1; } SWAPL(&length); if (write (fd, (char *) &length, 4) != 4) { fprintf (stderr, "awritefloat: %s: can't write length\n", file); perror(""); close (fd); return -1; } SWAPL(&length); for(offset = 0; offset < length; offset++) SWAPF(data + offset); size = length * sizeof (float); if (write (fd, (char *) data, size) != size) { fprintf (stderr, "awritefloat: %s: can't write data\n", file); perror(""); close (fd); return (-1); } for(offset = 0; offset < length; offset++) SWAPF(data + offset); printf ("Wrote %d floats in %s.\n", length, file); close (fd); return length; }
void PIC::decodeCmd(int pc) { // { qDebug() << "CMDLIST" <<m_CmdList[pc]; //qDebug() << pc << "PC"; k_long=m_CmdList[pc] & 0x7FF; //qDebug() << k_long << "klong"; k=m_CmdList[pc] & 0xFF; qDebug() << k << "k"; f=m_CmdList[pc] & 0x7F; //qDebug() << f <<"f"; d=m_CmdList[pc] & 0x80; d=(d>>7); //Test l=d; b=m_CmdList[pc] & 0x380; b = b / 128; //qDebug() << b << "b"; qDebug() << PreScalerWert << "PreScalerWert"; PIC::getPreScaler(); PIC::SetBank(); PIC::ChkIndirect(); CheckIndirect(); int ByteCmd=m_CmdList[pc] & 0x3F00; //qDebug() << ByteCmd << "byteCMD"; int BitCmd=m_CmdList[pc] & 0x3C00; //qDebug() << BitCmd << "BitCMD"; int ShrtCmd=m_CmdList[pc] & 0x3800; //qDebug() << ShrtCmd << "ShrtCMD"; if(ByteCmd == 0x0700 ) ADDWF(); else if(ByteCmd == 0x0500) ANDWF(); else if((m_CmdList[pc] & 0x03F80) == 0x0180) CLRF(); else if(ByteCmd == 0x0100) CLRW(); else if(ByteCmd == 0x0900) COMF(); else if(ByteCmd == 0x0300) DECF(); else if(ByteCmd == 0x0B00) DECFSZ(); else if(ByteCmd == 0x0A00) INCF(); else if(ByteCmd == 0x0F00) INCFSZ(); else if(ByteCmd == 0x0400) IORWF(); else if(ByteCmd == 0x0800) MOVF(); else if((m_CmdList[pc] & 0x3F80) == 0x0080) MOVWF(); else if((m_CmdList[pc] & 0x3F9F) == 0x0000) NOP(); else if(ByteCmd == 0x0D00) RLF(); else if(ByteCmd == 0x0C00) RRF(); else if(ByteCmd == 0x0200) SUBWF(); else if(ByteCmd == 0x0E00) SWAPF(); else if(ByteCmd == 0x0600) XORWF(); else if(BitCmd == 0x1000) BCF(); else if(BitCmd == 0x1400) BSF(); else if(BitCmd == 0x1800) BTFSC(); else if(BitCmd == 0x1C00) BTFSS(); //ADDLW kann durch don't care Bit 3E bzw. 3F sein else if((m_CmdList[pc] & 0x3E00 ) == 0x3E00) ADDLW(); else if((m_CmdList[pc] & 0x3F00 ) == 0x3F00) ADDLW(); else if(ByteCmd == 0x3900) ANDLW(); else if(ShrtCmd == 0x2000) CALL(); else if((m_CmdList[pc]& 0XFFFF) == 0x0064) CLRWDT(); else if(ShrtCmd == 0x2800) GOTO(); else if((ByteCmd) == 0x3A00) XORLW(); else if((m_CmdList[pc] & 0x3E00 ) == 0x3C00) SUBLW(); else if((m_CmdList[pc] & 0xFFFF ) == 0x0063) SLEEP(); else if((m_CmdList[pc] & 0xFFFF ) == 0x0008) RETURN(); else if((BitCmd) == 0x3400) RETURNLW(); else if((m_CmdList[pc] & 0xFFFF ) == 0x0009) RETURNFIE(); else if((ByteCmd) == 0x3000) MOVLW(); else if((ByteCmd) == 0x3100) MOVLW(); else if((ByteCmd) == 0x3200) MOVLW(); else if((ByteCmd) == 0x3300) MOVLW(); else if((ShrtCmd) == 0x3800) IORLW(); //zählt nach jeder Befehlsabarbeitung einen Programmzyklus hoch, bizyklische Befehle zählen zusätzlich während des Befehls rauf PIC::ExtClock(); PIC::IncrementCycles(); PIC::setTmr0(); PIC::LaufZeit(); //PreScalerCounter++; PIC::SyncSpecialReg(); PIC::RBPeakAnalyzer(); PIC::InterruptAnalyzer(); //Diagnoseausgaben qDebug() << "---------------------------------"; //qDebug() << regModel->reg[bank][PORTB] << "PortB"; qDebug() << regModel->reg[bank][INDIRECT] << "INDIRECT"; qDebug() << regModel->reg[bank][FSR] << "FSR"; //qDebug() << regModel->reg[bank][0x15] << "15h"; qDebug() << cycles << "Programmzyklen"; qDebug() << "---------------------------------"; }