void RandomSpawn::updateParticles() { mCinderDS->update(); mChanDepth = mCinderDS->getDepthFrame(); //Channel16u::Iter cIter = mChanDepth.getIter(); for (int sp = 0; sp < S_SPAWN_COUNT; ++sp) { if (mPointsParticles.size() < S_MAX_COUNT) { int cX = randInt(0, mDepthDims.x); int cY = randInt(0, mDepthDims.y); float cZ = (float)mChanDepth.getValue(ivec2(cX, cY)); if (cZ > S_MIN_Z&&cZ < S_MAX_Z) { vec3 cWorld = mCinderDS->getDepthSpacePoint(static_cast<float>(mDepthDims.x-cX), static_cast<float>(cY), static_cast<float>(cZ)); // pos, acc size life vec3 cAcc(randFloat(-5.f, 5.f), randFloat(0.5f, 3.5f), randFloat(-5.f, 5.f)); float cSize = randFloat(S_POINT_SIZE*0.25f, S_POINT_SIZE); int cLife = randInt(60, 120); ColorA cColor = ColorA(randFloat(), 0.1f, randFloat(), 1.0f); mPointsParticles.push_back(CloudParticle(cWorld, cSize, cLife, cColor)); } } } //now update particles for (auto pit = mPointsParticles.begin(); pit != mPointsParticles.end();) { if (pit->PAge == 0) pit = mPointsParticles.erase(pit); else { pit->step(mPerlin); ++pit; } } mDataInstance_P->bufferData(mPointsParticles.size()*sizeof(CloudParticle), mPointsParticles.data(), GL_DYNAMIC_DRAW); }
Channel16u mapDepthFrameToColor( const Channel16u& depth, ICoordinateMapper* mapper ) { size_t numPoints = depth.getWidth() * depth.getHeight(); Channel16u channel( depth.getWidth(), depth.getHeight() ); vector<ColorSpacePoint> colorSpacePoints( numPoints ); long hr = mapper->MapDepthFrameToColorSpace( (UINT)numPoints, depth.getData(), numPoints, &colorSpacePoints[ 0 ] ); if ( SUCCEEDED( hr ) ) { Channel16u::Iter iter = channel.getIter(); size_t i = 0; while ( iter.line() ) { while ( iter.pixel() ) { Vec2i pos = Vec2i( toVec2f( colorSpacePoints[ i ] ) ); uint16_t v = 0x0000; if ( pos.x >= 0 && pos.x < depth.getWidth() && pos.y >= 0 && pos.y < depth.getHeight() ) { v = depth.getValue( pos ); } iter.v() = v; } } } return channel; }