示例#1
0
void GerberReader::createNext(bool inMove)
{
    if(mCurrentAperture) {
        GShape *shape;
        if(inMove) {
            shape = new GLine(GPoint(mX,mY),GPoint(mReadX, mReadY), mCurrentAperture->x, (mCurrentAperture->sh==SHAPE_ROUND)?mCurrentAperture->x:mCurrentAperture->y, mCurrentAperture->sh==SHAPE_ROUND);
            checkMinMax(mX, mY, mCurrentAperture->x, mCurrentAperture->y);
            checkMinMax(mReadX, mReadY, mCurrentAperture->x, mCurrentAperture->y);
        } else{
            if(mCurrentAperture->sh==SHAPE_ROUND)
                shape = new GCircle(GPoint(mX,mY),mCurrentAperture->x/2.0L);
            else
                shape = new GRect(GPoint(mX,mY), mCurrentAperture->x, mCurrentAperture->y);
             checkMinMax(mX, mY, mCurrentAperture->x, mCurrentAperture->y);
        }
        shape->next = 0;
         if(mFirst==0) {
             mFirst = shape;
             mLast = mFirst;
         } else {
             mLast->next = shape;
             mLast = shape;
         }
    }
    if(inMove) {
        mX = mReadX;
        mY = mReadY;
    }
}
示例#2
0
void Collider::addMesh(Mesh* model) {
	float4x4 modelMatrix = model->m_modelMatrix;
	for (int i = 0; i < model->m_chunks.size(); i++) {

		for (int j = 0; j < model->m_chunks[i].m_positions.size(); j += 3) {


			float4 p1 = modelMatrix * make_vector(model->m_chunks[i].m_positions[j + 0].x,
				model->m_chunks[i].m_positions[j + 0].y,
				model->m_chunks[i].m_positions[j + 0].z, 1.0f);

			float4 p2 = modelMatrix * make_vector(model->m_chunks[i].m_positions[j + 1].x,
				model->m_chunks[i].m_positions[j + 1].y,
				model->m_chunks[i].m_positions[j + 1].z, 1.0f);

			float4 p3 = modelMatrix * make_vector(model->m_chunks[i].m_positions[j + 2].x,
				model->m_chunks[i].m_positions[j + 2].y,
				model->m_chunks[i].m_positions[j + 2].z, 1.0f);

			Triangle* t = new Triangle(make_vector(p1.x, p1.y, p1.z), make_vector(p2.x, p2.y, p2.z), make_vector(p3.x, p3.y, p3.z));

			ts.push_back(t);
		}
	}
	checkMinMax(model->m_aabb.maxV.x, model->m_aabb.maxV.y, model->m_aabb.maxV.z, &aabb_coll.minV, &aabb_coll.maxV);
	checkMinMax(model->m_aabb.minV.x, model->m_aabb.minV.y, model->m_aabb.minV.z, &aabb_coll.minV, &aabb_coll.maxV);
}
void PeakBar::drawContents(QPainter *p)
{
	QRect size= contentsRect();

	checkMinMax();
	
	p->setBrush(clipped ? darkRed : darkBlue);
	p->setPen(NoPen);
	p->drawRect(size);
		
	QRect bar= size;
	p->setBrush(clipped ? red : blue);
	if (horizontalMode) {
		bar.setWidth((int)(bar.width()*currentValue));
	} else {
		int newHeight= (int)(bar.height()*currentValue);
		bar.moveBy(0, bar.height()-newHeight);
		bar.setHeight(newHeight);
	}
	p->drawRect(bar);
		
	int y;
	// TODO: if (horizontalMode)
	if (displayMinPeak) {
		y= frameWidth()+size.height()-((int)(size.height()*minValue));
		p->setPen(white);
		p->drawLine(frameWidth(), y, frameWidth()+size.width()-1, y);
	}
	y= frameWidth()+size.height()-((int)(size.height()*maxValue));
	p->setPen(white);
	p->drawLine(frameWidth(), y, frameWidth()+size.width()-1, y);
}
static bool calibrateSensor(sensorRaw_t *zeroValues, uint8_t regAddr, int16_t maxDifference) {
    static int32_t sensorBuffer[3][25];
    static const uint8_t bufLength = 25;
    uint8_t buf[6];

    for (uint8_t i = 0; i < bufLength; i++) {
        while (!dataReadyMPU6500()) {
            // Wait until new date is ready
        }
        i2cReadData(MPU6500_ADDRESS, regAddr, buf, 6);
        sensorBuffer[0][i] = (int16_t)((buf[0] << 8) | buf[1]); // X
        sensorBuffer[1][i] = (int16_t)((buf[2] << 8) | buf[3]); // Y
        sensorBuffer[2][i] = (int16_t)((buf[4] << 8) | buf[5]); // Z
        delay(10);
    }

    for (uint8_t axis = 0; axis < 3; axis++) {
        if (!checkMinMax(sensorBuffer[axis], bufLength, maxDifference))
            return 1; // Return error
    }

    for (uint8_t axis = 0; axis < 3; axis++) {
        for (uint8_t i = 1; i < bufLength; i++)
            sensorBuffer[axis][0] += sensorBuffer[axis][i]; // Sum up all readings
        zeroValues->data[axis] = sensorBuffer[axis][0] / bufLength; // Get average
    }

    mpu6500BoardOrientation(zeroValues); // Apply board orientation

    return 0; // No error
}