void TessellationSampleApp::createIcosahedron()
{
	const int faces[] = {
		2, 1, 0,
		3, 2, 0,
		4, 3, 0,
		5, 4, 0,
		1, 5, 0,
		
		11, 6,	7,
		11, 7,	8,
		11, 8,	9,
		11, 9,	10,
		11, 10, 6,
		
		1, 2, 6,
		2, 3, 7,
		3, 4, 8,
		4, 5, 9,
		5, 1, 10,
		
		2,	7, 6,
		3,	8, 7,
		4,	9, 8,
		5, 10, 9,
		1,	6, 10
	};
	
	const float verts[] = {
		0.000f,	 0.000f,  1.000f,
		0.894f,	 0.000f,  0.447f,
		0.276f,	 0.851f,  0.447f,
		-0.724f,  0.526f,  0.447f,
		-0.724f, -0.526f,  0.447f,
		0.276f, -0.851f,  0.447f,
		0.724f,	 0.526f, -0.447f,
		-0.276f,  0.851f, -0.447f,
		-0.894f,  0.000f, -0.447f,
		-0.276f, -0.851f, -0.447f,
		0.724f, -0.526f, -0.447f,
		0.000f,	 0.000f, -1.000f
	};
	
	mIndexCount = sizeof(faces) / sizeof(faces[0]);
	
	vertexArrayObject->bind();
	
	// Create the VBO for positions:
	GLsizei stride = 3 * sizeof(float);
	vertexBufferObject->bind();
	vertexBufferObject->bufferData(sizeof(verts), verts, GL_STATIC_DRAW);
	gl::enableVertexAttribArray( (GLuint)mPositionIndex );
	gl::vertexAttribPointer( (GLuint)mPositionIndex, 3, GL_FLOAT, GL_FALSE, stride, 0 );
	
	// Create the VBO for indices:
	indexBufferObject->bind();
	indexBufferObject->bufferData( sizeof(faces), faces, GL_STATIC_DRAW );
}
Exemplo n.º 2
0
void SinOrbitApp::reset(bool pShader)
{
	mColor = vec4(randVec3(), randFloat(0.005f, 0.025f));
	mAlpha = randFloat(0.01f, 0.1f);
	auto w = randFloat(5.0f,10.0f);
	auto maxR = randFloat(350.0f, 400.0f);
	auto numPtcls = randInt(500, 1000);

	mPtcls.clear();

	for (int i = 0; i < numPtcls; ++i) {
		mPtcls.push_back(
			ptcl(
				randFloat(0.2f, 0.8f),
				randFloat(400.0f-w, 400.0f+w),
				randFloat(0.01f, 0.05f),
				randFloat(-0.5f, 0.5f),
				randFloat(1.0f, 3.0f)
			)
		);
	}

	if (pShader) {
		mPointShader = gl::GlslProg::create(loadAsset("points.vert"), loadAsset("points.frag"));

		geom::BufferLayout attribs;
		attribs.append(geom::POSITION, 2, sizeof(ptcl), offsetof(ptcl, Pos), 0);
		mPointData = gl::Vbo::create(GL_ARRAY_BUFFER, mPtcls, GL_DYNAMIC_DRAW);
		mPointMesh = gl::VboMesh::create(mPtcls.size(), GL_POINTS, { {attribs, mPointData} });
	}
	else {
		mPointData->bufferData(mPtcls.size()*sizeof(ptcl), mPtcls.data(), GL_DYNAMIC_DRAW);
	}
}
Exemplo n.º 3
0
void PointCloudVAO::updateCloud()
{
	mDS->update();
	auto depth = mDS->getDepthFrame();
	auto iter = depth->getIter();

	mPoints.clear();
	while (iter.line())
	{
		while (iter.pixel())
		{
			if (iter.x() % mParamStep == 0 && iter.y() % mParamStep == 0)
			{
				float x = (float)iter.x();
				float y = (float)iter.y();
				float z = (float)iter.v();
				if (z > mParamDepthMin && z < mParamDepthMax)
				{
					auto world = mDS->getDepthSpacePoint(vec3(x, y, z));
					auto diffuse = mDS->getColorFromDepthSpace(world);
					mPoints.push_back(Pt(world, diffuse));
				}
			}
		}
	}

	mVbo->bufferData(mPoints.size()*sizeof(Pt), mPoints.data(), GL_DYNAMIC_DRAW);
}
void PointCloudApp::update()
{
	
	mCinderRS->update();
	mPoints.clear();
	Channel16u cChanDepth = mCinderRS->getDepthFrame();

	mTexRgb->update(mCinderRS->getRgbFrame());
	for (int dy = 0; dy < mDepthDims.y; ++dy)
	{
		for (int dx = 0; dx < mDepthDims.x; ++dx)
		{
			float cDepth = (float)*cChanDepth.getData(dx, dy);
			if (cDepth > 100 && cDepth < 1000)
			{
				vec3 cPos = mCinderRS->getDepthSpacePoint(vec3(dx, dy, cDepth));
				vec2 cUV = mCinderRS->getColorCoordsFromDepthImage(static_cast<float>(dx),
																	static_cast<float>(dy),
																	cDepth);
				mPoints.push_back(CloudPoint(cPos, cUV));
			}
		}
	}

	mBufferObj->bufferData(mPoints.size()*sizeof(CloudPoint), mPoints.data(), GL_DYNAMIC_DRAW);
	mMeshObj = gl::VboMesh::create(mPoints.size(), GL_POINTS, { { mAttribObj, mBufferObj } });
	mDrawObj->replaceVboMesh(mMeshObj);
}
Exemplo n.º 5
0
void SinOrbitApp::update()
{
	if (mStarted) {
		if (getElapsedFrames() % 300 == 0) {
			reset(false);
		}
		for (auto &p : mPtcls) {
			p.step();
		}
		mPointData->bufferData(mPtcls.size()*sizeof(ptcl), mPtcls.data(), GL_DYNAMIC_DRAW);
	}
}
Exemplo n.º 6
0
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);
}