void QDeclarativeAnchorsPrivate::centerInChanged() { Q_Q(QDeclarativeAnchors); if (!centerIn || fill || !isItemComplete()) return; if (updatingCenterIn < 2) { ++updatingCenterIn; qreal effectiveHCenterOffset = q->mirrored() ? -hCenterOffset : hCenterOffset; if (centerIn == item->parentItem()) { QPointF p(hcenter(item->parentItem()) - hcenter(item) + effectiveHCenterOffset, vcenter(item->parentItem()) - vcenter(item) + vCenterOffset); setItemPos(p); } else if (centerIn->parentItem() == item->parentItem()) { QPointF p(centerIn->x() + hcenter(centerIn) - hcenter(item) + effectiveHCenterOffset, centerIn->y() + vcenter(centerIn) - vcenter(item) + vCenterOffset); setItemPos(p); } --updatingCenterIn; } else { // ### Make this certain :) qmlInfo(item) << QDeclarativeAnchors::tr("Possible anchor loop detected on centerIn."); } }
//### const item? //local position static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine) { qreal ret = 0.0; QGraphicsItemPrivate *d = QGraphicsItemPrivate::get(item); switch(anchorLine) { case QDeclarativeAnchorLine::Left: ret = item->x(); break; case QDeclarativeAnchorLine::Right: ret = item->x() + d->width(); break; case QDeclarativeAnchorLine::Top: ret = item->y(); break; case QDeclarativeAnchorLine::Bottom: ret = item->y() + d->height(); break; case QDeclarativeAnchorLine::HCenter: ret = item->x() + hcenter(item); break; case QDeclarativeAnchorLine::VCenter: ret = item->y() + vcenter(item); break; case QDeclarativeAnchorLine::Baseline: if (d->isDeclarativeItem) ret = item->y() + static_cast<QDeclarativeItem*>(item)->baselineOffset(); break; default: break; } return ret; }
//### const item? //local position static qreal position(QSGItem *item, QSGAnchorLine::AnchorLine anchorLine) { qreal ret = 0.0; switch(anchorLine) { case QSGAnchorLine::Left: ret = item->x(); break; case QSGAnchorLine::Right: ret = item->x() + item->width(); break; case QSGAnchorLine::Top: ret = item->y(); break; case QSGAnchorLine::Bottom: ret = item->y() + item->height(); break; case QSGAnchorLine::HCenter: ret = item->x() + hcenter(item); break; case QSGAnchorLine::VCenter: ret = item->y() + vcenter(item); break; case QSGAnchorLine::Baseline: ret = item->y() + item->baselineOffset(); break; default: break; } return ret; }
void TouchTracker::Calibrator::makeDefaultTemplate() { mDefaultTemplate.setDims (kTemplateSize, kTemplateSize); int w = mDefaultTemplate.getWidth(); int h = mDefaultTemplate.getHeight(); Vec2 vcenter(h/2.f, w/2.f); // default scale -- not important because we want to calibrate. Vec2 vscale(3.5, 3.); for(int j=0; j<h; ++j) { for(int i=0; i<w; ++i) { Vec2 vdistance = Vec2(i + 0.5f, j + 0.5f) - vcenter; vdistance /= vscale; float d = clamp(vdistance.magnitude(), 0.f, 1.f); mDefaultTemplate(i, j) = 1.0*(1.0f - d); } } }
void QDeclarativeAnchorsPrivate::updateVerticalAnchors() { if (fill || centerIn || !isItemComplete()) return; if (updatingVerticalAnchor < 2) { ++updatingVerticalAnchor; QGraphicsItemPrivate *itemPrivate = QGraphicsItemPrivate::get(item); if (usedAnchors & QDeclarativeAnchors::TopAnchor) { //Handle stretching bool invalid = true; qreal height = 0.0; if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { invalid = calcStretch(top, bottom, topMargin, -bottomMargin, QDeclarativeAnchorLine::Top, height); } else if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { invalid = calcStretch(top, vCenter, topMargin, vCenterOffset, QDeclarativeAnchorLine::Top, height); height *= 2; } if (!invalid) setItemHeight(height); //Handle top if (top.item == item->parentItem()) { setItemY(adjustedPosition(top.item, top.anchorLine) + topMargin); } else if (top.item->parentItem() == item->parentItem()) { setItemY(position(top.item, top.anchorLine) + topMargin); } } else if (usedAnchors & QDeclarativeAnchors::BottomAnchor) { //Handle stretching (top + bottom case is handled above) if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { qreal height = 0.0; bool invalid = calcStretch(vCenter, bottom, vCenterOffset, -bottomMargin, QDeclarativeAnchorLine::Top, height); if (!invalid) setItemHeight(height*2); } //Handle bottom if (bottom.item == item->parentItem()) { setItemY(adjustedPosition(bottom.item, bottom.anchorLine) - itemPrivate->height() - bottomMargin); } else if (bottom.item->parentItem() == item->parentItem()) { setItemY(position(bottom.item, bottom.anchorLine) - itemPrivate->height() - bottomMargin); } } else if (usedAnchors & QDeclarativeAnchors::VCenterAnchor) { //(stetching handled above) //Handle vCenter if (vCenter.item == item->parentItem()) { setItemY(adjustedPosition(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset); } else if (vCenter.item->parentItem() == item->parentItem()) { setItemY(position(vCenter.item, vCenter.anchorLine) - vcenter(item) + vCenterOffset); } } else if (usedAnchors & QDeclarativeAnchors::BaselineAnchor) { //Handle baseline if (baseline.item == item->parentItem()) { if (itemPrivate->isDeclarativeItem) setItemY(adjustedPosition(baseline.item, baseline.anchorLine) - static_cast<QDeclarativeItem *>(item)->baselineOffset() + baselineOffset); } else if (baseline.item->parentItem() == item->parentItem()) { if (itemPrivate->isDeclarativeItem) setItemY(position(baseline.item, baseline.anchorLine) - static_cast<QDeclarativeItem *>(item)->baselineOffset() + baselineOffset); } } --updatingVerticalAnchor; } else { // ### Make this certain :) qmlInfo(item) << QDeclarativeAnchors::tr("Possible anchor loop detected on vertical anchor."); } }
/** Drawing main scene and bounding box */ inline void drawScene() { // [7]----[6] // / | /| // [3]----[2] | // | [4]--|-[5] // | / | / // [0]----[1] Vector3D vcenter(0,0,0); Vector3D vbox[8]; float s_v = 1 /(simulationScale);// = 1 m in simulation float order = 0; while(s_v >= 1){ s_v /= 10; if(s_v < 1) { s_v *= 10; break; } ++order; } vbox[0] = Vector3D(localConfig->xmin,localConfig->ymin,localConfig->zmin); vbox[1] = Vector3D(localConfig->xmax,localConfig->ymin,localConfig->zmin); vbox[2] = Vector3D(localConfig->xmax,localConfig->ymax,localConfig->zmin); vbox[3] = Vector3D(localConfig->xmin,localConfig->ymax,localConfig->zmin); vbox[4] = Vector3D(localConfig->xmin,localConfig->ymin,localConfig->zmax); vbox[5] = Vector3D(localConfig->xmax,localConfig->ymin,localConfig->zmax); vbox[6] = Vector3D(localConfig->xmax,localConfig->ymax,localConfig->zmax); vbox[7] = Vector3D(localConfig->xmin,localConfig->ymax,localConfig->zmax); // Display user interface if enabled bool displayInfos = true; if (displayInfos) { glDisable(GL_DEPTH_TEST); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color glEnable(GL_BLEND); renderInfo(0, 0); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } glBegin(GL_LINES); sc *=10; glColor3ub(255, 0, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x+sc,vcenter.y,vcenter.z); glColor3ub(0,255, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y+sc,vcenter.z); glColor3ub(0, 0, 255); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y,vcenter.z+sc); sc /=10; vcenter = Vector3D(-(localConfig->xmin+localConfig->xmax)/2,-(localConfig->ymin+localConfig->ymax)/2,-(localConfig->zmin+localConfig->zmax)/2); vcenter *= sc; Vector3D v1,v2,v3,v4,v5,v6,v7,v8; v1 = Vector3D( -localConfig->xmax/2, -localConfig->ymax/2, -localConfig->zmax/2)*sc; v2 = Vector3D( localConfig->xmax/2, -localConfig->ymax/2, -localConfig->zmax/2)*sc; v3 = Vector3D( localConfig->xmax/2, localConfig->ymax/2, -localConfig->zmax/2)*sc; v4 = Vector3D( -localConfig->xmax/2, localConfig->ymax/2, -localConfig->zmax/2)*sc; v5 = Vector3D( -localConfig->xmax/2, -localConfig->ymax/2, localConfig->zmax/2)*sc; v6 = Vector3D( localConfig->xmax/2, -localConfig->ymax/2, localConfig->zmax/2)*sc; v7 = Vector3D( localConfig->xmax/2, localConfig->ymax/2, localConfig->zmax/2)*sc; v8 = Vector3D( -localConfig->xmax/2, localConfig->ymax/2, localConfig->zmax/2)*sc; glColor3ub(255,255,255);//yellow glVertex3d(v1.x,v1.y,v1.z); glVertex3d(v2.x,v2.y,v2.z); glColor3ub(255,255,255);//yellow glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v4.x,v4.y,v4.z); //glColor3ub(0,255,0);//green glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(0,0,255);//blue glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(255,255,0);//yellow glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v8.x + s_v*sc,v8.y,v8.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glEnd(); // glBegin(GL_LINES); glColor3ub(0,0,0);//black Vector3D v_s = Vector3D( -localConfig->xmax/2 + s_v, localConfig->ymax/2, localConfig->zmax/2)*sc; glVertex3d(v_s.x, v_s.y, v_s.z); glVertex3d(v_s.x, v_s.y - 0.5f * sc , v_s.z); glLineWidth((GLfloat)10.0); glVertex3d( v8.x, v8.y, v8.z); glVertex3d(v_s.x, v_s.y, v_s.z); glEnd(); glLineWidth((GLfloat)1.0); void * m_font = GLUT_BITMAP_8_BY_13; std::stringstream ss; std::string s; ss << order; s = "1E-" + ss.str() + "m"; glPrint3D( (float)v8.x + 0.4f*sc , (float)v8.y - 2.f * sc, (float)v8.z, "0", m_font); glPrint3D( (float)v_s.x , (float)v_s.y - 2.f * sc, (float)v_s.z, s.c_str(), m_font); ss.str(""); while(v_s.x < localConfig->xmax/2*sc){ v_s.x += s_v * sc; if(v_s.x < localConfig->xmax/2*sc){ glBegin(GL_LINES); glVertex3d(v_s.x, v_s.y, v_s.z); glVertex3d(v_s.x, v_s.y - 0.5f * sc , v_s.z); glEnd(); } } }
void layout(center, cell & x) { layout(hcenter(), x); layout(vcenter(), x); }
void display(void) { helper->refreshTime(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Vector3D vcenter(0,0,0); Vector3D vbox[8]; // [7]----[6] // / | /| // [3]----[2] | // | [4]--|-[5] // | / | / // [0]----[1] vbox[0] = Vector3D(XMIN,YMIN,ZMIN); vbox[1] = Vector3D(XMAX,YMIN,ZMIN); vbox[2] = Vector3D(XMAX,YMAX,ZMIN); vbox[3] = Vector3D(XMIN,YMAX,ZMIN); vbox[4] = Vector3D(XMIN,YMIN,ZMAX); vbox[5] = Vector3D(XMAX,YMIN,ZMAX); vbox[6] = Vector3D(XMAX,YMAX,ZMAX); vbox[7] = Vector3D(XMIN,YMAX,ZMAX); glBegin(GL_LINES); sc *=10; glColor3ub(255, 0, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x+sc,vcenter.y,vcenter.z); glColor3ub(0,255, 0); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y+sc,vcenter.z); glColor3ub(0, 0, 255); glVertex3d(vcenter.x,vcenter.y,vcenter.z); glVertex3d(vcenter.x,vcenter.y,vcenter.z+sc); sc /=10; vcenter = Vector3D(-(XMIN+XMAX)/2,-(YMIN+YMAX)/2,-(ZMIN+ZMAX)/2); vcenter *= sc; Vector3D v1,v2,v3,v4,v5,v6,v7,v8; v1 = Vector3D( -XMAX/2, -YMAX/2, -ZMAX/2)*sc; v2 = Vector3D( XMAX/2, -YMAX/2, -ZMAX/2)*sc; v3 = Vector3D( XMAX/2, YMAX/2, -ZMAX/2)*sc; v4 = Vector3D( -XMAX/2, YMAX/2, -ZMAX/2)*sc; v5 = Vector3D( -XMAX/2, -YMAX/2, ZMAX/2)*sc; v6 = Vector3D( XMAX/2, -YMAX/2, ZMAX/2)*sc; v7 = Vector3D( XMAX/2, YMAX/2, ZMAX/2)*sc; v8 = Vector3D( -XMAX/2, YMAX/2, ZMAX/2)*sc; glColor3ub(255,255,255);//yellow glVertex3d(v1.x,v1.y,v1.z); glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v4.x,v4.y,v4.z); //glColor3ub(0,255,0);//green glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(0,0,255);//blue glVertex3d(v1.x,v1.y,v1.z); //glColor3ub(255,255,0);//yellow glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v2.x,v2.y,v2.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v3.x,v3.y,v3.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v4.x,v4.y,v4.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v6.x,v6.y,v6.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v7.x,v7.y,v7.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v8.x,v8.y,v8.z); glVertex3d(v5.x,v5.y,v5.z); glEnd(); //glColor3ub(255,255,255);//yellow p_indexb = fluid_simulation->getParticleIndexBuffer(); int pib; for(int i=0; i<PARTICLE_COUNT; i++) { pib = p_indexb[2*i + 1]; p_indexb[2*pib + 0] = i; } glPointSize(3.f); glBegin(GL_POINTS); p_b = fluid_simulation->getPositionBuffer(); d_b = fluid_simulation->getDensityBuffer(); float dc, rho; for(int i = 0; i<PARTICLE_COUNT; i++) { rho = d_b[ p_indexb[ i * 2 + 0 ] ]; if( rho < 0 ) rho = 0; if( rho > 2 * rho0) rho = 2 * rho0; dc = 100.0 * ( rho - rho0 ) / rho0 ; if(dc>1.f) dc = 1.f; // R G B glColor4f( 0, 0, 1, 1.0f);//blue if( (dc=100*(rho-rho0*1.00f)/rho0) >0 ) glColor4f( 0, dc, 1,1.0f);//cyan if( (dc=100*(rho-rho0*1.01f)/rho0) >0 ) glColor4f( 0, 1,1-dc,1.0f);//green if( (dc=100*(rho-rho0*1.02f)/rho0) >0 ) glColor4f( dc, 1, 0,1.0f);//yellow if( (dc=100*(rho-rho0*1.03f)/rho0) >0 ) glColor4f( 1,1-dc, 0,1.0f);//red if( (dc=100*(rho-rho0*1.04f)/rho0) >0 ) glColor4f( 1, 0, 0,1.0f); if((int)p_b[i*4 + 3] != BOUNDARY_PARTICLE) { glBegin(GL_POINTS); if((int)p_b[i*4+3]==2) glColor4f( 1, 1, 0, 1.0f); glVertex3f( (p_b[i*4]-XMAX/2)*sc , (p_b[i*4+1]-YMAX/2)*sc, (p_b[i*4+2]-ZMAX/2)*sc ); glEnd(); } } glEnd(); glutSwapBuffers(); helper->watch_report("graphics: \t\t%9.3f ms\n====================================\n"); renderTime = helper->get_elepasedTime(); totalTime += calculationTime + renderTime; calculateFPS(); }