void fillMesh(Geometry *geometry) { const char routineName[] = "fillMesh"; register int mu, k, l, m; int quadrant; double mux, muy, muz, dz, frac1, frac2, longfracx, longfracy; enum intersect plane; getCPU(2, TIME_START, NULL); if (geometry->x_boundary != PERIODIC || geometry->y_boundary != PERIODIC) { Error(ERROR_LEVEL_2, routineName, "Horizontal boundary conditions in x AND y must be PERIODIC"); } /* --- Allocate space for interpolation stencils and longchar structures -- -------------- */ geometry->stencil_uw = (Stencil **) malloc(geometry->Nrays * sizeof(Stencil *)); geometry->stencil_dw = (Stencil **) malloc(geometry->Nrays * sizeof(Stencil *)); for (mu = 0; mu < geometry->Nrays; mu++) { geometry->stencil_uw[mu] = (Stencil *) malloc(geometry->Nz * sizeof(Stencil)); geometry->stencil_dw[mu] = (Stencil *) malloc(geometry->Nz * sizeof(Stencil)); } geometry->Nlongchar = 0; /* --- Evaluate the interpolation bases and kernels for linear interpolation or cubic convolution. In general we sweep DOWN and then UP. The convention here will be that we store the UPWIND base for the DOWN sweep in the uw_stencil array, and the DOWNWIND in the dw_stencil array. For the UP sweep UPWIND and DOWNWIND are reversed. -- -------------- */ for (mu = 0; mu < geometry->Nrays; mu++) { for (k = 1; k < geometry->Nz; k++) { /* --- First, the UPWIND bases for the DOWN sweep. These will be the DOWNWIND bases for the final UP sweep. -- ---------- */ setStencil(geometry, mu, k, UPWIND); } for (k = 0; k < geometry->Nz - 1; k++) { setStencil(geometry, mu, k, DOWNWIND); } } if (geometry->Nlongchar) { sprintf(messageStr, "\n-Used %d Long Characteristics\n\n", geometry->Nlongchar); Error(MESSAGE, NULL, messageStr); } getCPU(2, TIME_POLL, "Geometry"); }
void NestedTest::setup() { static int depth = 9; Node* parent = this; for (int i = 0; i < depth; i++) { int size = 225 - i * (225 / (depth * 2)); auto clipper = ClippingNode::create(); clipper->setContentSize(Size(size, size)); clipper->setAnchorPoint(Vec2(0.5, 0.5)); clipper->setPosition(parent->getContentSize().width / 2, parent->getContentSize().height / 2); clipper->setAlphaThreshold(0.05f); clipper->runAction(RepeatForever::create(RotateBy::create(i % 3 ? 1.33 : 1.66, i % 2 ? 90 : -90))); parent->addChild(clipper); auto stencil = Sprite::create(s_pathGrossini); stencil->setScale( 2.5 - (i * (2.5 / depth)) ); stencil->setAnchorPoint( Vec2(0.5, 0.5) ); stencil->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2); stencil->setVisible(false); stencil->runAction(Sequence::createWithTwoActions(DelayTime::create(i), Show::create())); clipper->setStencil(stencil); clipper->addChild(stencil); parent = clipper; } }
void PlayStage::countAnimeBoom(Point position) { auto mask = ClippingNode::create(); mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f)); mask->setAlphaThreshold(255); mask->setInverted(false); auto count_boom_anime = ParticleSystemQuad::create("count_boom_ver2.plist"); count_boom_anime->setAutoRemoveOnFinish(true); count_boom_anime->setPosition(position); count_boom_anime->setLifeVar(0.2f); auto chainLabel = Label::createWithBMFont("ui_font.fnt", std::to_string(chains) + " Chains!!"); chainLabel->setScale(0); chainLabel->runAction(Sequence::create(EaseBackIn::create(ScaleTo::create(0.4f, 2.0f)), EaseBackOut::create(ScaleTo::create(0.18f, 1.0f)), DelayTime::create(0.4f), FadeOut::create(0.3f), CallFunc::create(CC_CALLBACK_0(Label::removeFromParentAndCleanup, chainLabel, true)), NULL)); chainLabel->setPosition(position); //anime_sprite->addChild(count_anime); mask->addChild(count_boom_anime); mask->addChild(chainLabel); ballSheetMask->addChild(mask, 500); }
void ScrollViewDemo::setup() { auto clipper = ClippingNode::create(); clipper->setTag( kTagClipperNode ); clipper->setContentSize( Size(200, 200) ); clipper->setAnchorPoint( Vec2(0.5, 0.5) ); clipper->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2); clipper->runAction(RepeatForever::create(RotateBy::create(1, 45))); this->addChild(clipper); auto stencil = DrawNode::create(); Vec2 rectangle[4]; rectangle[0] = Vec2(0, 0); rectangle[1] = Vec2(clipper->getContentSize().width, 0); rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height); rectangle[3] = Vec2(0, clipper->getContentSize().height); Color4F white(1, 1, 1, 1); stencil->drawPolygon(rectangle, 4, white, 1, white); clipper->setStencil(stencil); auto content = Sprite::create(s_back2); content->setTag( kTagContentNode ); content->setAnchorPoint( Vec2(0.5, 0.5) ); content->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2); clipper->addChild(content); _scrolling = false; auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(ScrollViewDemo::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(ScrollViewDemo::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(ScrollViewDemo::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); }
/*! Set the preferred stencil buffer size to \a size. \sa stencilBufferSize(), setStencil(), stencil() */ void QPlatformWindowFormat::setStencilBufferSize(int size) { detach(); if (size < 0) { qWarning("QPlatformWindowFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); return; } d->stencilSize = size; setStencil(size > 0); }
void ClippingToRenderTextureTest::reproduceBug() { auto director = Director::getInstance(); Size visibleSize = director->getVisibleSize(); Point origin = director->getVisibleOrigin(); // add "HelloWorld" splash screen" auto sprite = Sprite::create("Images/grossini.png"); // position the sprite on the center of the screen sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); // container node that will contain the clippingNode auto container = Node::create(); container->retain(); auto stencil = DrawNode::create(); Point triangle[3]; triangle[0] = Point(-50, -50); triangle[1] = Point(50, -50); triangle[2] = Point(0, 50); Color4F green(0, 1, 0, 1); stencil->drawPolygon(triangle, 3, green, 0, green); auto clipper = ClippingNode::create(); clipper->setAnchorPoint(Point(0.5, 0.5)); clipper->setPosition( Point(visibleSize.width/2, visibleSize.height/2) ); clipper->setStencil(stencil); clipper->setInverted(true); container->addChild(clipper, 1); auto img = DrawNode::create(); triangle[0] = Point(-200, -200); triangle[1] = Point(200, -200); triangle[2] = Point(0, 200); Color4F red(1, 0, 0, 1); img->drawPolygon(triangle, 3, red, 0, red); clipper->addChild(img); // container rendered on Texture the size of the screen and because Clipping node use stencil buffer so we need to // create RenderTexture with depthStencil format parameter RenderTexture* rt = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8); rt->setPosition(visibleSize.width/2, visibleSize.height/2); this->addChild(rt); rt->begin(); container->visit(); rt->end(); }
void ClippingToRenderTextureTest::expectedBehaviour() { auto director = Director::getInstance(); Size visibleSize = director->getVisibleSize(); Point origin = director->getVisibleOrigin(); // add "HelloWorld" splash screen" auto sprite = Sprite::create("Images/grossini.png"); // position the sprite on the center of the screen sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); sprite->setName("remove me 0"); // container node that will contain the clippingNode auto container = Node::create(); this->addChild(container); container->setName("remove me 1"); auto stencil = DrawNode::create(); Point triangle[3]; triangle[0] = Point(-50, -50); triangle[1] = Point(50, -50); triangle[2] = Point(0, 50); Color4F green(0, 1, 0, 1); stencil->drawPolygon(triangle, 3, green, 0, green); auto clipper = ClippingNode::create(); clipper->setAnchorPoint(Point(0.5, 0.5)); clipper->setPosition( Point(visibleSize.width/2, visibleSize.height/2) ); clipper->setStencil(stencil); clipper->setInverted(true); container->addChild(clipper, 1); auto img = DrawNode::create(); triangle[0] = Point(-200, -200); triangle[1] = Point(200, -200); triangle[2] = Point(0, 200); Color4F red(1, 0, 0, 1); img->drawPolygon(triangle, 3, red, 0, red); clipper->addChild(img); }
void JigTile::setEdges(const std::vector<EdgeType>& edges) { TempShadow* shadow = TempShadow::create(); shadow->setSquareSize( getContentSize() ); shadow->setPosition( getContentSize()/2 ); shadow->setEdgeType(edges); setStencil(shadow); Sprite* red = ShadowCommand::createShadowByEdges(edges); red->setPosition( getContentSize()/2 ); BlendFunc bf; bf.src = GL_ONE; bf.dst = GL_ONE; red->setScale( shadow->getSquareScale() ); red->setBlendFunc(bf); this->addChild(red); }
NewClippingNodeTest::NewClippingNodeTest() { auto s = Director::getInstance()->getWinSize(); auto clipper = ClippingNode::create(); clipper->setTag( kTagClipperNode ); clipper->setContentSize( Size(200, 200) ); clipper->setAnchorPoint( Vec2(0.5, 0.5) ); clipper->setPosition( Vec2(s.width / 2, s.height / 2) ); clipper->runAction(RepeatForever::create(RotateBy::create(1, 45))); this->addChild(clipper); // TODO: Fix draw node as clip node // auto stencil = NewDrawNode::create(); // Vec2 rectangle[4]; // rectangle[0] = Vec2(0, 0); // rectangle[1] = Vec2(clipper->getContentSize().width, 0); // rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height); // rectangle[3] = Vec2(0, clipper->getContentSize().height); // // Color4F white(1, 1, 1, 1); // stencil->drawPolygon(rectangle, 4, white, 1, white); // clipper->setStencil(stencil); //Test with alpha Test clipper->setAlphaThreshold(0.05f); auto stencil = Sprite::create("Images/grossini.png"); stencil->setPosition(s.width/2, s.height/2); clipper->setStencil(stencil); auto content = Sprite::create("Images/background2.png"); content->setTag( kTagContentNode ); content->setAnchorPoint( Vec2(0.5, 0.5) ); content->setPosition( Vec2(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) ); clipper->addChild(content); _scrolling = false; auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(NewClippingNodeTest::onTouchesBegan, this); listener->onTouchesMoved = CC_CALLBACK_2(NewClippingNodeTest::onTouchesMoved, this); listener->onTouchesEnded = CC_CALLBACK_2(NewClippingNodeTest::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); }
void PlayStage::countAnime(Point position) { //auto anime_sprite = Sprite::create(); auto mask = ClippingNode::create(); mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f)); mask->setAlphaThreshold(255); mask->setInverted(false); auto count_anime = ParticleSystemQuad::create("Count_anime.plist"); count_anime->setAutoRemoveOnFinish(true); count_anime->setPosition(position); //anime_sprite->addChild(count_anime); mask->addChild(count_anime); ballSheetMask->addChild(mask, 500); }
void getError(LevelData<double, 1> & a_error, double & a_maxError, const double & a_dx) { BoxLayout layout = a_error.getBoxLayout(); LevelData<double, 1> phi(layout, s_nghost); LevelData<double, 1> lphcalc(layout, 0); LevelData<double, 1> lphexac(layout, 0); // cout << "initializing phi to sum_dir(sin 2*pi*xdir)" << endl; initialize(phi,lphexac, a_dx); //set ghost cells of phi phi.exchange(); // dumpLevelRDA(&phi); Stencil<double> laplace; setStencil(laplace, a_dx); //apply stencil operator independently on each box a_maxError = 0; for(BLIterator blit(layout); blit != blit.end(); ++blit) { RectMDArray<double>& phiex = phi[*blit]; RectMDArray<double>& lphca = lphcalc[*blit]; RectMDArray<double>& lphex = lphexac[*blit]; RectMDArray<double>& error = a_error[*blit]; //apply is set as an increment so need to set this to zero initially lphca.setVal(0.); Box bxdst=layout[*blit]; Stencil<double>::apply(laplace, phiex, lphca, bxdst); //error = lphicalc -lphiexac lphca.copyTo(error); //here err holds lphi calc double maxbox = forall_max(error, lphex, &errorF, bxdst); a_maxError = max(maxbox, a_maxError); } }
void ClippingNode::setSquareStencil() { isSquareStencil = true; if(getStencil() == nullptr || dynamic_cast<DrawNode*>(getStencil()) == nullptr) { setStencil(DrawNode::create()); //addChild(getStencil()); //If you need to see what the stencil is like, for debug purpose } DrawNode* stencil = (DrawNode*)getStencil(); stencil->clear(); Vec2 rectangle[4]; rectangle[0] = Vec2(0, 0); rectangle[1] = Vec2(this->getContentSize().width / this->getScaleX(), 0); rectangle[2] = Vec2(this->getContentSize().width / this->getScaleX(), this->getContentSize().height / this->getScaleY()); rectangle[3] = Vec2(0, this->getContentSize().height / this->getScaleY()); Color4F white(1, 1, 1, 1); stencil->drawPolygon(rectangle, 4, white, 1, white); }
void BasicTest::setup() { auto s = Director::getInstance()->getWinSize(); auto stencil = this->stencil(); stencil->setTag( kTagStencilNode ); stencil->setPosition(50, 50); auto clipper = this->clipper(); clipper->setTag( kTagClipperNode ); clipper->setAnchorPoint(Vec2(0.5, 0.5)); clipper->setPosition(s.width / 2 - 50, s.height / 2 - 50); clipper->setStencil(stencil); this->addChild(clipper); auto content = this->content(); content->setPosition(50, 50); clipper->addChild(content); }
void HoleDemo::setup() { auto target = Sprite::create(s_pathBlock); target->setAnchorPoint(Vec2::ZERO); target->setScale(3); _outerClipper = ClippingNode::create(); _outerClipper->retain(); AffineTransform tranform = AffineTransform::IDENTITY; tranform = AffineTransformScale(tranform, target->getScale(), target->getScale()); _outerClipper->setContentSize( SizeApplyAffineTransform(target->getContentSize(), tranform)); _outerClipper->setAnchorPoint( Vec2(0.5, 0.5) ); _outerClipper->setPosition(Vec2(this->getContentSize()) * 0.5f); _outerClipper->runAction(RepeatForever::create(RotateBy::create(1, 45))); _outerClipper->setStencil( target ); auto holesClipper = ClippingNode::create(); holesClipper->setInverted(true); holesClipper->setAlphaThreshold( 0.05f ); holesClipper->addChild(target); _holes = Node::create(); _holes->retain(); holesClipper->addChild(_holes); _holesStencil = Node::create(); _holesStencil->retain(); holesClipper->setStencil( _holesStencil); _outerClipper->addChild(holesClipper); this->addChild(_outerClipper); auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(HoleDemo::onTouchesBegan, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); }
void CanvasContextAttributes::setFrom(const QVariantMap &options) { for (QVariantMap::const_iterator iter = options.begin(); iter != options.end(); ++iter) { if (iter.key() == "alpha") setAlpha(iter.value().toBool()); else if (iter.key() == "depth") setDepth(iter.value().toBool()); else if (iter.key() == "stencil") setStencil(iter.value().toBool()); else if (iter.key() == "antialias") setAntialias(iter.value().toBool()); else if (iter.key() == "premultipliedAlpha") setPremultipliedAlpha(iter.value().toBool()); else if (iter.key() == "preserveDrawingBuffer") setPreserveDrawingBuffer(iter.value().toBool()); else if (iter.key() == "preferLowPowerToHighPerformance") setPreferLowPowerToHighPerformance(iter.value().toBool()); else if (iter.key() == "failIfMajorPerformanceCaveat") setFailIfMajorPerformanceCaveat(iter.value().toBool()); } }
ClippingNode* HelloWorld::_makeClippingNode(Point* mask, int count, Point* physicBody, int p_count, Sprite* content) { auto sprite = _duplicateSprite(content); //复制精灵 auto _clipper = ClippingNode::create(); _clipper->setPosition(content->getPosition()); _clipper->setInverted(true);// //显示切割后剩余部分 _clipper->setOpacity(0); //设置透明度 _clipper->setAnchorPoint(Point::ZERO); //设置定位点,显示图层 参考http://www.cnblogs.com/pengyingh/articles/2433081.html _clipper->addChild(sprite); auto shape = _makeDrawNode(mask, count); //这里画形状 _clipper->addChild(shape); //然后将这形状模板加到遮罩类子类里,这步可能只是用来保存遮罩形状,以免以后用到吧 _clipper->setStencil(shape);//创建裁剪模板 参考 http://www.gulumiao.com/blog/2013/11/%E5%85%B3%E4%BA%8Ecocos2dx%E9%81%AE%E7%BD%A9ccclippingnode/ //_clipper->setPhysicsBody(PhysicsBody::createPolygon(physicBody, p_count, // PHYSICSBODY_MATERIAL_DEFAULT)); sprite->setPosition(Point::ZERO); return _clipper; }
bool ScrollText::initClipper( cocos2d::Sprite* &pMask,cocos2d::Node* &pMoveChild) { auto clipper = ClippingNode::create(); IF_RETURN_FALSE(!clipper); IF_RETURN_FALSE(!pMask); setContentSize(pMask->getContentSize()); IF_RETURN_FALSE(!pMask->getTexture()); auto _clipperStencil = Sprite::createWithTexture(pMask->getTexture()); //_clipperStencil->setAnchorPoint((0.5,0.5)); IF_RETURN_FALSE(!_clipperStencil); _clipperStencil->retain(); clipper->setAlphaThreshold(0.1f); clipper->setStencil(_clipperStencil); clipper->addChild(pMoveChild,1); addChild(clipper); for (auto child:_mNodes) { IF_RETURN_FALSE(!child); clipper->addChild(child); } return true; }
bool TestController::init() { Layer::init(); Sprite *hello = Sprite::create("HelloWorld.png"); hello->setPosition(Vec2(240, 160)); this->addChild(hello); std::string text = std::string() + "Police have said they plan" + "to dismantle the camp of colorful" + "tents and art installations Thursday" + "morning, urging protesters to leave" + "peacefully."+ "On Thursday morning," + "bailiffs read out the court injunction," + "telling demonstrators to pack up and" + "leave on their own accord. They then" "began dismantling and removing barricades" "at the far western end of the protest area." + "The bailiffs carried off metal and plastic" + "barriers that had been lashed together, as" + "well as broken umbrellas -- wilted versions" + "of the protest movement's symbol."; textLabel = Label::createWithTTF(text, "fonts/Skranji-Regular.ttf", 24); textLabel->setAnchorPoint(Vec2(0, 1)); textLabel->setPosition(Vec2(0, 300)); textLabel->setDimensions(300, 500); textLabel->setAlignment(TextHAlignment::LEFT, TextVAlignment::TOP); // textLabel->enableOutline(Color4B(52, 26, 7, 255), 1); textLabel->enableShadow(Color4B(52, 26, 7, 255), Size(-0.5f, -0.5f)); // this->addChild(textLabel); CCLOG("content size = (%f, %f)", textLabel->getContentSize().width, textLabel->getContentSize().height); auto clipper = ClippingNode::create(); clipper->setTag( 98 ); clipper->setContentSize( Size(300, 300) ); clipper->setAnchorPoint( Vec2(0.5, 0.5) ); clipper->setPosition(this->getContentSize().width / 2, this->getContentSize().height / 2); // clipper->runAction(RepeatForever::create(RotateBy::create(1, 45))); this->addChild(clipper); auto stencil = DrawNode::create(); Vec2 rectangle[4]; rectangle[0] = Vec2(0, 0); rectangle[1] = Vec2(clipper->getContentSize().width, 0); rectangle[2] = Vec2(clipper->getContentSize().width, clipper->getContentSize().height); rectangle[3] = Vec2(0, clipper->getContentSize().height); Color4F white(1, 1, 1, 1); stencil->drawPolygon(rectangle, 4, white, 1, white); clipper->setStencil(stencil); // auto content = Sprite::create(); // content->setContentSize(Size(300, 300)); // content->setTag( 97 ); // content->setAnchorPoint( Vec2(0.5, 0.5) ); // content->setPosition(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2); clipper->addChild(textLabel); // content->addChild(textLabel); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(TestController::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(TestController::onTouchMoved, this); listener->onTouchEnded = CC_CALLBACK_2(TestController::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); rapidjson::Document json; std::string stdstr = std::string("{ \"hello\" : \"world\" }").c_str(); char str[2048]; sprintf(str, "%s", stdstr.c_str()); json.Parse<0>(str); const char key[] = "hello"; CCLOG("json value = %s", json[key].GetString()); return true; }
void fillMesh(Geometry *geometry) { register int mu, k, l; enum triplet vtriplet, htriplet; enum SC_order horder, vorder; enum boundary hboundary = geometry->hboundary; int Nx = geometry->Nx, Nz = geometry->Nz, Nrays = geometry->Nrays, count, Nlongchar = 0, Nstart, Nend; double mux, muz, dx, dz, fraction; Stencil *st; LongChar *lc; if (input.Eddington) return; getCPU(2, TIME_START, NULL); /* --- Allocate space for interpolation stencils -- -------------- */ geometry->stencil = (Stencil **) malloc(Nrays * sizeof(Stencil *)); for (mu = 0; mu < Nrays; mu++) { geometry->stencil[mu] = (Stencil *) malloc(Nx*Nz * sizeof(Stencil)); } /* --- If the horizontal boundary conditions are PERIODIC allocate space for possible long characteristics -- -------------- */ if (hboundary == PERIODIC) { geometry->longchar = (LongChar **) malloc(Nrays * sizeof(LongChar *)); for (mu = 0; mu < Nrays; mu++) geometry->longchar[mu] = (LongChar *) malloc(2*Nz * sizeof(LongChar)); } else geometry->longchar = NULL; horder = SC_QUADRATIC; /* --- For each direction ray go through the x-z grid and store the stencil of interpolation indices and coefficients in the Geometry structure -- -------------- */ for (mu = 0; mu < Nrays; mu++) { mux = geometry->mux[mu]; muz = geometry->muz[mu]; /* --- Distinguish between mux > 0.0, mu = 0.0, and mux < 0.0. Rays with mux > 0.0 run from right to left in the downsweep, ie. with decreasing l. -- -------------- */ if (mux > 0.0) { /* --- First evaluate the UPWIND interpolation weigths and indices for the DOWN sweep. These will be the DOWNWIND ones in the reverse (UP) sweep of the formal solution -- -------------- */ vtriplet = LOWER_TRIPLET; for (k = 1; k < Nz; k++) { dz = geometry->dz[k-1]; if (k == 1) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; count = 0; if (hboundary == PERIODIC) Nend = Nx; else Nend = Nx - 1; for (l = 0; l < Nend; l++) { st = &geometry->stencil[mu][k*Nx + l]; dx = geometry->dx[l]; if (hboundary == FIXED && l == Nx-2) htriplet = LOWER_TRIPLET; else htriplet = UPPER_TRIPLET; fraction = mux*dz / (muz*dx); /* --- Characteristic intersects horizontal grid line? -- - */ if (fraction <= 1.0) { count++; setStencil(geometry, st, UPWIND, HORIZONTAL, dz/muz, fraction, l, k-1, htriplet, horder); } else { setStencil(geometry, st, UPWIND, VERTICAL, dx/mux, 1.0 - 1.0/fraction, l+1, k-1, vtriplet, vorder); } } /* --- If no horizontal intersection occurred use long characteristic, otherwise find proper starting point - */ if (geometry->longchar != NULL) { lc = &geometry->longchar[mu][DOWN*Nz + k]; if (count == 0) { lc->lstart = Nx-1; fillLongChar(geometry, mu, k, DOWN); Nlongchar++; } else { lc->Nlc = 0; lc->lstart = 0; st = &geometry->stencil[mu][k*Nx + lc->lstart]; while(st->intersect[UPWIND] == VERTICAL) { lc->lstart++; st++; } } } } /* --- Evaluate the DOWNWIND interpolation weights and indices for the DOWN sweep. These will be the UPWIND ones in the reverse (UP) sweep. -- ------------ */ vtriplet = UPPER_TRIPLET; for (k = 0; k < Nz-1; k++) { dz = geometry->dz[k]; if (k == Nz - 2) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; count = 0; if (hboundary == PERIODIC) Nstart = 0; else Nstart = 1; for (l = Nstart; l < Nx; l++) { st = &geometry->stencil[mu][k*Nx + l]; if (hboundary == FIXED) { dx = geometry->dx[l-1]; if (l == 1) htriplet = UPPER_TRIPLET; else htriplet = LOWER_TRIPLET; } else { dx = geometry->dx[MODULO(l-1, Nx)]; htriplet = LOWER_TRIPLET; } fraction = mux*dz / (muz*dx); /* --- Characteristic intersects horizontal grid line? -- - */ if (fraction <= 1.0) { count++; setStencil(geometry, st, DOWNWIND, HORIZONTAL, dz/muz, 1.0 - fraction, l-1, k+1, htriplet, horder); } else { setStencil(geometry, st, DOWNWIND, VERTICAL, dx/mux, 1.0/fraction, l-1, k, vtriplet, vorder); } } /* --- If no horizontal intersection occurred use long characteristic, otherwise find proper starting point - */ if (geometry->longchar != NULL) { lc = &geometry->longchar[mu][UP*Nz + k]; if (count == 0) { lc->lstart = 0; fillLongChar(geometry, mu, k, UP); Nlongchar++; } else { lc->Nlc = 0; lc->lstart = Nx - 1; st = &geometry->stencil[mu][k*Nx + lc->lstart]; while(st->intersect[DOWNWIND] == VERTICAL) { lc->lstart--; st--; } } } } } else if (mux == 0.0) { /* --- Case for purely vertical rays -- -------------- */ for (k = 1; k < Nz; k++) { dz = geometry->dz[k-1]; for (l = 0; l < Nx; l++) { st = &geometry->stencil[mu][k*Nx + l]; setVertStencil(geometry, st, UPWIND, dz, l, k-1); } if (geometry->hboundary == PERIODIC) { lc = &geometry->longchar[mu][DOWN*Nz + k]; lc->Nlc = 0; lc->lstart = 0; } } for (k = 0; k < Nz-1; k++) { dz = geometry->dz[k]; for (l = 0; l < Nx; l++) { st = &geometry->stencil[mu][k*Nx + l]; setVertStencil(geometry, st, DOWNWIND, dz, l, k+1); } if (geometry->hboundary == PERIODIC) { lc = &geometry->longchar[mu][UP*Nz + k]; lc->Nlc = 0; lc->lstart = 0; } } } else { /* --- Rays with mux < 0.0 run from left to right in the downsweep, ie. with increasing l. First evaluate the UPWIND interpolation weigths and indices for the DOWN sweep. These will be the DOWNWIND ones in the reverse (UP) sweep of the formal solution -- -------------- */ vtriplet = LOWER_TRIPLET; for (k = 1; k < Nz; k++) { dz = geometry->dz[k-1]; if (k == 1) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; count = 0; if (hboundary == PERIODIC) Nstart = 0; else Nstart = 1; for (l = Nstart; l < Nx; l++) { st = &geometry->stencil[mu][k*Nx + l]; if (hboundary == FIXED) { dx = geometry->dx[l-1]; if (l == 1) htriplet = UPPER_TRIPLET; else htriplet = LOWER_TRIPLET; } else { dx = geometry->dx[MODULO(l-1, Nx)]; htriplet = LOWER_TRIPLET; } fraction = -mux*dz / (muz*dx); /* --- Characteristic intersects horizontal grid line? -- - */ if (fraction <= 1.0) { count++; setStencil(geometry, st, UPWIND, HORIZONTAL, dz/muz, 1.0 - fraction, l-1, k-1, htriplet, horder); } else { setStencil(geometry, st, UPWIND, VERTICAL, -dx/mux, 1.0 - 1.0/fraction, l-1, k-1, vtriplet, vorder); } } /* --- If no horizontal intersection occurred use long characteristic, otherwise find proper starting point - */ if (geometry->longchar != NULL) { lc = &geometry->longchar[mu][DOWN*Nz + k]; if (count == 0) { lc->lstart = 0; fillLongChar(geometry, mu, k, DOWN); Nlongchar++; } else { lc->Nlc = 0; lc->lstart = Nx-1; st = &geometry->stencil[mu][k*Nx + lc->lstart]; while(st->intersect[UPWIND] == VERTICAL) { lc->lstart--; st--; } } } } /* --- Evaluate the DOWNWIND interpolation weights and indices for the DOWN sweep. These will be the UPWIND ones in the reverse (UP) sweep. -- ------------ */ vtriplet = UPPER_TRIPLET; for (k = 0; k < Nz-1; k++) { dz = geometry->dz[k]; if (k == Nz - 2) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; count = 0; if (hboundary == PERIODIC) Nend = Nx; else Nend = Nx - 1; for (l = 0; l < Nend; l++) { st = &geometry->stencil[mu][k*Nx + l]; dx = geometry->dx[l]; if (hboundary == FIXED && l == Nx - 2) htriplet = LOWER_TRIPLET; else htriplet = UPPER_TRIPLET; fraction = -mux*dz / (muz*dx); /* --- Characteristic intersects horizontal grid line? -- - */ if (fraction <= 1.0) { count++; setStencil(geometry, st, DOWNWIND, HORIZONTAL, dz/muz, fraction, l, k+1, htriplet, horder); } else { setStencil(geometry, st, DOWNWIND, VERTICAL, -dx/mux, 1.0/fraction, l+1, k, vtriplet, vorder); } } /* --- If no horizontal intersection occurred use long characteristic, otherwise find proper starting point - */ if (geometry->longchar != NULL) { lc =&geometry->longchar[mu][UP*Nz + k]; if (count == 0) { lc->lstart = Nx-1; fillLongChar(geometry, mu, k, UP); Nlongchar++; } else { lc->Nlc = 0; lc->lstart = 0; st = &geometry->stencil[mu][k*Nx + lc->lstart]; while(st->intersect[DOWNWIND] == VERTICAL) { lc->lstart++; st++; } } } } } } sprintf(messageStr, "\n-Used %d Long Characteristics\n\n", Nlongchar); Error(MESSAGE, NULL, messageStr); getCPU(2, TIME_POLL, "Geometry"); }
void poOpenGLState::popStencilState() { setStencil(stencilStack.top()); stencilStack.pop(); }
bool TeachLayer::init(const cocos2d::Vec2 &stencilWorldPos, FingerDirection fingerDirection) { if (!Layer::init()) { return false; } _stencilPosition = stencilWorldPos; _fingerDirection = fingerDirection; Size winSize = Director::getInstance()->getWinSize(); // bind touch event auto touchListener = EventListenerTouchOneByOne::create(); touchListener->setSwallowTouches(true); // bind touch event touchListener->onTouchBegan = CC_CALLBACK_2(TeachLayer::onTouchBegan, this); touchListener->onTouchEnded = CC_CALLBACK_2(TeachLayer::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); // 裁剪图层 auto pClip = ClippingNode::create(); // 设置反相 pClip->setInverted(true); // 蒙版 auto colorLayer = LayerColor::create(Color4B(0, 0, 0, 180)); pClip->addChild(colorLayer); // 模板初始化 _stencilNode = DrawNode::create(); // 绘制圆形区域 float fRadius = 55.0f; // 圆的半径 const int nCount = 100; // 圆形其实可以看做正多边形,我们这里用正100边型来模拟园 const float coef = 2.0f * (float)M_PI / nCount; // 计算每两个相邻顶点与中心的夹角 Vec2 circle[nCount]; // 顶点数组 for(int i = 0;i < nCount; i++) { float rads = i*coef;//弧度 circle[i].x = fRadius * cosf(rads); // 对应顶点的x circle[i].y = fRadius * sinf(rads); // 对应顶点的y } // 绘制这个多边形! _stencilNode->drawPolygon(circle, nCount, Color4F::GREEN, 0, Color4F::GREEN); _stencilNode->setPosition(winSize.width * 0.5, winSize.height * 0.5); // 设模板 pClip->setStencil(_stencilNode); addChild(pClip); _stencilButton = SpriteButton::create("guide_circle.png", CC_CALLBACK_1(TeachLayer::stencilTouchCallBack, this)); _stencilButton->setOpacity(0); _stencilButton->setPosition(winSize.width * 0.5, winSize.height * 0.5); addChild(_stencilButton); _fingerSprite = Sprite::createWithSpriteFrameName("finger_1.png"); addChild(_fingerSprite); _fingerEffSprite = Sprite::createWithSpriteFrameName("finger_2.png"); addChild(_fingerEffSprite); setStencilPosition(_stencilPosition); runMoveAction(); return true; }
void fillLongChar(Geometry *geometry, int mu, int k, enum sweep sweep) { register int l, n; enum triplet htriplet, vtriplet; enum SC_order vorder; int Nx = geometry->Nx, Nz = geometry->Nz, dl, k_upwind, count, l_intersect; double mux, muz, dx_total, dx_intersect, dz, dz_total, ds_total, ds, fraction; LongChar *lc; /* --- Fills the appropriate LongChar structure of the interpolation mesh with indices and quadratic coefficients to solve along a long characteristic when, with periodic or even boundary conditions, no shortcharacteristic intersects a horizontal grid line for a given k. -- -------------- */ lc = geometry->longchar[mu]+(sweep*Nz + k); mux = geometry->mux[mu]; muz = geometry->muz[mu]; l = lc->lstart; if (sweep == DOWN) { vtriplet = LOWER_TRIPLET; if (k == 1) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; k_upwind = k-1; dz = geometry->dz[k_upwind]; if (mux >= 0.0) { htriplet = UPPER_TRIPLET; dl = 1; } else { htriplet = LOWER_TRIPLET; dl = -1; } } else { vtriplet = UPPER_TRIPLET; if (k == Nz-2) vorder = SC_LINEAR; else vorder = SC_QUADRATIC; k_upwind = k+1; dz = geometry->dz[k]; if (mux >= 0.0) { htriplet = LOWER_TRIPLET; dl = -1; } else { htriplet = UPPER_TRIPLET; dl = 1; } } /* --- Find first intersection with horizontal grid line -- ------- */ count = 0; dx_total = 0.0; dx_intersect = dz/muz * fabs(mux); if (dl > 0) { while (dx_total < dx_intersect) { dx_total += geometry->dx[l]; l = MODULO(l + 1, Nx); count++; } l = MODULO(l - 1, Nx); } else { while (dx_total < dx_intersect) { l = MODULO(l - 1, Nx); dx_total += geometry->dx[l]; count++; } } /* --- Allocate space for long characteristic indices, interpolation coefficients, and pathlength. Note: Interpolation data is stored in an array of Stencil structures so that the setStencil function can be used to determine the interpolation coefficients, and Quadr can be used to do the actual interpolation. Only the UPWIND half of each stencil is used because the long characteristic is solved only in one direction, towards the root. -- -------------- */ lc->Nlc = count; lc->stencil = (Stencil *) malloc(count * sizeof(Stencil)); /* --- Store the interpolation in the horizontal grid line -- ----- */ if (dl > 0) { fraction = 1.0 - (dx_total - dx_intersect)/geometry->dx[l]; ds = fraction * geometry->dx[l] / fabs(mux); } else { fraction = (dx_total - dx_intersect)/geometry->dx[l]; ds = (1.0 - fraction)*geometry->dx[l] / fabs(mux); } setStencil(geometry, &lc->stencil[0], UPWIND, HORIZONTAL, ds, fraction, l, k_upwind, htriplet, SC_QUADRATIC); /* --- Then segment for segment the vertical crossings -- --------- */ ds_total = 0.0; for (n = 1; n < count; n++) { ds_total += lc->stencil[n-1].ds[UPWIND]; dz_total = ds_total * muz; if (dl > 0) l_intersect = l; else l_intersect = MODULO(l + 1, Nx); l = MODULO(l - dl, Nx); ds = geometry->dx[l] / fabs(mux); if (sweep == DOWN) { fraction = dz_total / dz; setStencil(geometry, &lc->stencil[n], UPWIND, VERTICAL, ds, fraction, l_intersect, k_upwind, vtriplet, vorder); } else { fraction = 1.0 - dz_total / dz; setStencil(geometry, &lc->stencil[n], UPWIND, VERTICAL, ds, fraction, l_intersect, k, vtriplet, vorder); } } }
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } CReadFile::getInstance()->init(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto closeItem = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png" , CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setScale(0.3f); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2-310 , origin.y + closeItem->getContentSize().height/2+160)); auto closeItem1 = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback1, this)); closeItem1->setScale(0.5f); closeItem1->setPosition(Vec2(origin.x + visibleSize.width - closeItem1->getContentSize().width/2-310 , origin.y + closeItem1->getContentSize().height/2+330)); auto SetMenu = MenuItemImage::create( "picture/shezhi2_cover.png", "picture/shezhi1_cover.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback3, this)); SetMenu->setScale(0.8f); SetMenu->setPosition(Vec2(origin.x + visibleSize.width - SetMenu->getContentSize().width/2-390 , origin.y + SetMenu->getContentSize().height/2+260)); auto menu = Menu::create(closeItem,closeItem1,SetMenu, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label = Label::createWithTTF(Tools::Unicode2Utf8(L"开始游戏"), "fonts/msyh.ttc", 24); #else auto label = Label::createWithTTF("开始游戏", "fonts/msyh.ttc", 24); #endif label->setPosition(Vec2(closeItem1->getPositionX(), closeItem1->getPositionY())); label->setScale(0.8f); this->addChild(label, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label1 = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"), "fonts/msyh.ttc", 24); #else auto label1 = Label::createWithTTF("退出", "fonts/msyh.ttc", 24); #endif label1->setPosition(Vec2(closeItem->getPositionX(), closeItem->getPositionY())); label1->setScale(0.8f); this->addChild(label1,1); auto sprite = Sprite::create("picture/shumabaobei.jpg"); Size sprSize = sprite->getContentSize(); sprite->setScaleX(visibleSize.width/sprSize.width); sprite->setScaleY(visibleSize.height/sprSize.height); sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sprite, 0); auto logo = Sprite::create("picture/logo.png"); Size logoSize = logo->getContentSize(); auto spark = Sprite::create("picture/spark.png"); spark->setPosition(-logoSize.width,0); auto clippingNode = ClippingNode::create(); clippingNode->setPosition(500,560); this->addChild(clippingNode); clippingNode->setAlphaThreshold(0.05f); clippingNode->setContentSize(logoSize); clippingNode->setStencil(logo); clippingNode->addChild(logo,1); clippingNode->addChild(spark,2); auto moveAction = MoveTo::create(2.0f,Vec2(logoSize.width,0)); auto moveBackAction = MoveTo::create(2.0f,Vec2(-logoSize.width,0)); spark->runAction(RepeatForever::create(Sequence::create(moveAction,moveBackAction,NULL))); if (CReadFile::getInstance()->getshuomingkg()) { CReadFile::getInstance()->setshuomingkg(false); CSound::getInstance()->playBG("Butter-Fly.mp3",CSound::getInstance()->getIsPlay()); CSound::getInstance()->setIsPlay(true); auto shuominglayer = LayerColor::create(Color4B(120,120,120,200)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto wenzi = Label::createWithTTF(Tools::Unicode2Utf8(L"欢迎来到宝库设计的数码宝贝记忆消除游戏"),"fonts/msyh.ttc", 28); #else auto wenzi = Label::createWithTTF("欢迎来到宝库设计的数码宝贝记忆消除游戏","fonts/msyh.ttc", 28); #endif wenzi->setMaxLineWidth(460); wenzi->setLineBreakWithoutSpace(true); wenzi->setPosition(480,520); wenzi->setColor(ccc3(0,0,0)); shuominglayer->runAction(FadeOut::create(5)); wenzi->runAction(FadeOut::create(3)); shuominglayer->addChild(wenzi,2); this->addChild(shuominglayer,2); } return true; }
void getError(LevelData<double, 1> & a_error, double & a_maxError, const double & a_dx) { BoxLayout layout = a_error.getBoxLayout(); LevelData<double, 1> phi(layout, s_nghost); LevelData<double, 1> lphcalc(layout, 0); LevelData<double, 1> lphexac(layout, 0); // cout << "initializing phi to sum_dir(sin 2*pi*xdir)" << endl; initialize(phi,lphexac, a_dx); //set ghost cells of phi phi.exchange(); // dumpLevelRDA(&phi); Stencil<double> laplace; setStencil(laplace, a_dx); //apply stencil operator independently on each box a_maxError = 0; for(BLIterator blit(layout); blit != blit.end(); ++blit) { RectMDArray<double>& phiex = phi[*blit]; RectMDArray<double>& lphca = lphcalc[*blit]; RectMDArray<double>& lphex = lphexac[*blit]; RectMDArray<double>& error = a_error[*blit]; //apply is set as an increment so need to set this to zero initially lphca.setVal(0.); Box bxdst=layout[*blit]; // Stencil<double>::apply(laplace, phiex, lphca, bxdst); const class Box sourceBoxRef = phiex . getBox(); const class Box destinationBoxRef = lphca . getBox(); int iter_lb2 = bxdst . getLowCorner ()[2]; int src_lb2 = sourceBoxRef . getLowCorner ()[2]; int dest_lb2 = destinationBoxRef . getLowCorner ()[2]; int k = 0; int iter_ub2 = bxdst . getHighCorner ()[2]; int src_ub2 = sourceBoxRef . getHighCorner ()[2]; int dest_ub2 = destinationBoxRef . getHighCorner ()[2]; int arraySize_X = bxdst . size (0); int arraySize_X_src = sourceBoxRef . size (0); int iter_lb1 = bxdst . getLowCorner ()[1]; int src_lb1 = sourceBoxRef . getLowCorner ()[1]; int dest_lb1 = destinationBoxRef . getLowCorner ()[1]; int j = 0; int iter_ub1 = bxdst . getHighCorner ()[1]; int src_ub1 = sourceBoxRef . getHighCorner ()[1]; int dest_ub1 = destinationBoxRef . getHighCorner ()[1]; int arraySize_Y = bxdst . size (1); int arraySize_Y_src = sourceBoxRef . size (1); int iter_lb0 = bxdst . getLowCorner ()[0]; int src_lb0 = sourceBoxRef . getLowCorner ()[0]; int dest_lb0 = destinationBoxRef . getLowCorner ()[0]; int i = 0; int iter_ub0 = bxdst . getHighCorner ()[0]; int src_ub0 = sourceBoxRef . getHighCorner ()[0]; int dest_ub0 = destinationBoxRef . getHighCorner ()[0]; int arraySize_Z = bxdst . size (2); int arraySize_Z_src = sourceBoxRef . size (2); double *sourceDataPointer = phiex . getPointer(); double *destinationDataPointer = lphca . getPointer(); for (k = iter_lb2; k < iter_ub2; ++k) { for (j = iter_lb1; j < iter_ub1; ++j) { for (i = iter_lb0; i < iter_ub0; ++i) { destinationDataPointer[arraySize_X * (arraySize_Y * (k - dest_lb2) + (j - dest_lb1)) + (i - dest_lb0)] = (1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2 + -1) + (j - src_lb1)) + (i - src_lb0)] + 1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2 + 1) + (j - src_lb1)) + (i - src_lb0)] + 1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2) + (j - src_lb1 + -1)) + (i - src_lb0)] + 1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2) + (j - src_lb1 + 1)) + (i - src_lb0)] + 1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2) + (j - src_lb1)) + (i - src_lb0 + -1)] + 1.0*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2) + (j - src_lb1)) + (i - src_lb0 + 1)] + (-2.0*DIM)*sourceDataPointer[arraySize_X_src * (arraySize_Y_src * (k - src_lb2) + (j - src_lb1)) + (i - src_lb0)]) * (1.0/a_dx/a_dx); //cout << destinationDataPointer[arraySize_X * (arraySize_Y * (k - dest_lb2) + (j - dest_lb1)) + (i - dest_lb0)] << " " << lphex.getPointer()[arraySize_X * (arraySize_Y * (k - dest_lb2) + (j - dest_lb1)) + (i - dest_lb0)] << endl; } } } //error = lphicalc -lphiexac lphca.copyTo(error); //here err holds lphi calc double maxbox = forall_max(error, lphex, &errorF, bxdst); cout << "maxbox= " << maxbox << endl; a_maxError = max(maxbox, a_maxError); } }
bool ClippingNode::init(Node *stencil) { setStencil(stencil); return true; }