Пример #1
0
	btSoftBody*	SoftBody::createSoftMesh( btSoftBodyWorldInfo &info, const TriMesh &mesh, const Vec3f &scale, 
		const Vec3f &position, const Quatf &rotation )
	{
		Matrix44f transform;
		transform.setToIdentity();
		transform.translate( position );
		transform.rotate( rotation.v );
		transform.translate( position * -1.0f );
		transform.translate( position );

		btScalar* positions	= new btScalar[ mesh.getNumVertices() * 3 ];
		size_t i = 0;
		for ( vector<Vec3f>::const_iterator iter = mesh.getVertices().begin(); iter != mesh.getVertices().end(); ++iter, i += 3 ) {
			Vec3f position = transform.transformPoint( *iter );
			positions[ i + 0 ] = position.x;
			positions[ i + 1 ] = position.y;
			positions[ i + 2 ] = position.z;
		}
		
		int* indices		= new int[ mesh.getIndices().size() ];
		i = 0;
		for ( vector<size_t>::const_iterator iter = mesh.getIndices().begin(); iter != mesh.getIndices().end(); ++iter, ++i ) {
			indices[ i ] = (int)*iter;
		}
		
 		btSoftBody* body = btSoftBodyHelpers::CreateFromTriMesh( info, positions, indices, mesh.getNumTriangles() );
		//body->scale( toBulletVector3( scale ) );

		delete [] indices;
		delete [] positions;

		return body;
	}
Пример #2
0
// Render
void SkeletonApp::draw()
{

	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf::gray( 0.1f ) );

	// We're capturing
	if ( mKinect->isCapturing() ) {

		// Set up 3D view
		gl::setMatrices( mCamera );

		// Iterate through skeletons
		uint32_t i = 0;
		for ( vector<Skeleton>::const_iterator skeletonIt = mSkeletons.cbegin(); skeletonIt != mSkeletons.cend(); ++skeletonIt, i++ ) {

			// Set color
			Colorf color = mKinect->getUserColor( i );

			// Iterate through joints
			for ( Skeleton::const_iterator boneIt = skeletonIt->cbegin(); boneIt != skeletonIt->cend(); ++boneIt ) {

				// Set user color
				gl::color( color );

				// Get position and rotation
				const Bone& bone	= boneIt->second;
				Vec3f position		= bone.getPosition();
				Matrix44f transform	= bone.getAbsoluteRotationMatrix();
				Vec3f direction		= transform.transformPoint( position ).normalized();
				direction			*= 0.05f;
				position.z			*= -1.0f;

				// Draw bone
				glLineWidth( 2.0f );
				JointName startJoint = bone.getStartJoint();
				if ( skeletonIt->find( startJoint ) != skeletonIt->end() ) {
					Vec3f destination	= skeletonIt->find( startJoint )->second.getPosition();
					destination.z		*= -1.0f;
					gl::drawLine( position, destination );
				}

				// Draw joint
				gl::drawSphere( position, 0.025f, 16 );

				// Draw joint orientation
				glLineWidth( 0.5f );
				gl::color( ColorAf::white() );
				gl::drawVector( position, position + direction, 0.05f, 0.01f );

			}

		}

	}

}
Пример #3
0
	btSoftBody* SoftBody::createSoftCloth( btSoftBodyWorldInfo &info, const Vec2f &size, const Vec2i &resolution, 
		int32_t corners, const Vec3f &position, const Quatf &rotation )
	{
		Matrix44f transform;
		transform.setToIdentity();
		transform.translate( position );
		transform.rotate( rotation.v );
		transform.translate( position * -1.0f );
		transform.translate( position );

		float h = size.y * 0.5f;
		float w = size.x * 0.5f;
		btSoftBody* body = btSoftBodyHelpers::CreatePatch(
			info,
			toBulletVector3( transform.transformPoint( Vec3f( -w, 0.0f, -h ) ) ), 
			toBulletVector3( transform.transformPoint( Vec3f(  w, 0.0f, -h ) ) ), 
			toBulletVector3( transform.transformPoint( Vec3f( -w, 0.0f,  h ) ) ), 
			toBulletVector3( transform.transformPoint( Vec3f(  w, 0.0f,  h ) ) ),
			resolution.x, resolution.y, 
			corners, true
			);

		return body;
	}
Пример #4
0
TriMesh MeshHelper::createCube( const Vec3i &resolution )
{
	vector<uint32_t> indices;
	vector<Vec3f> normals;
	vector<Vec3f> positions;
	vector<Vec2f> texCoords;

	ci::TriMesh front	= createSquare( Vec2i( resolution.x, resolution.y ) );
	ci::TriMesh left	= createSquare( Vec2i( resolution.z, resolution.y ) );
	ci::TriMesh top		= createSquare( Vec2i( resolution.x, resolution.z ) );
	
	Vec3f normal;
	Vec3f offset;
	Matrix44f transform;

	// Back
	normal = Vec3f( 0.0f, 0.0f, -1.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = front.getVertices().begin(); iter != front.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = front.getTexCoords().begin(); iter != front.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	// Bottom
	normal = Vec3f( 0.0f, -1.0f, 0.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	transform.rotate( Vec3f( -(float)M_PI * 0.5f, 0.0f, 0.0f ) );
	transform.translate( offset * -1.0f );
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = top.getVertices().begin(); iter != top.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = top.getTexCoords().begin(); iter != top.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	normal = Vec3f( 0.0f, 0.0f, 1.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = front.getVertices().begin(); iter != front.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = front.getTexCoords().begin(); iter != front.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	normal = Vec3f( -1.0f, 0.0f, 0.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	transform.rotate( Vec3f( 0.0f, -(float)M_PI * 0.5f, 0.0f ) );
	transform.translate( offset * -1.0f );
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = left.getVertices().begin(); iter != left.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = left.getTexCoords().begin(); iter != left.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	// Right
	normal = Vec3f( 1.0f, 0.0f, 0.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	transform.rotate( Vec3f( 0.0f, (float)M_PI * 0.5f, 0.0f ) );
	transform.translate( offset * -1.0f );
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = left.getVertices().begin(); iter != left.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = left.getTexCoords().begin(); iter != left.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	normal = Vec3f( 0.0f, 1.0f, 0.0f );
	offset = normal * 0.5f;
	transform.setToIdentity();
	transform.translate( offset );
	transform.rotate( Vec3f( (float)M_PI * 0.5f, 0.0f, 0.0f ) );
	transform.translate( offset * -1.0f );
	transform.translate( offset );
	for ( vector<Vec3f>::iterator iter = top.getVertices().begin(); iter != top.getVertices().end(); ++iter ) {
		positions.push_back( transform.transformPoint( *iter ) );
		normals.push_back( normal );
	}
	for ( vector<Vec2f>::iterator iter = top.getTexCoords().begin(); iter != top.getTexCoords().end(); ++iter ) {
		texCoords.push_back( *iter );
	}

	for ( uint32_t i = 0; i < positions.size(); ++i ) {
		indices.push_back( i );
	}

	TriMesh mesh = MeshHelper::create( indices, positions, normals, texCoords );

	indices.clear();
	normals.clear();
	positions.clear();
	texCoords.clear();

	return mesh;
}
Пример #5
0
void SecondStudy::TheApp::draw() {
	// clear out the window with black
	gl::clear(ColorAf(0.0f, 0.0f, 0.0f, 1.0f));
	
	gl::color(0.0f, 0.0f, 0.0f);
	gl::drawSolidRect(getWindowBounds());
	
	gl::color(1.0f, 1.0f, 1.0f, 1.0f);
	glLineWidth(5.0f);
	
	gl::pushModelView();
	Matrix44f st;
	//st.scale(Vec2f(_screenZoom, _screenZoom));
	//st.translate(Vec3f(_screenOffset));
	//gl::multModelView(st);
	
	_sequencesMutex.lock();
	for(auto& s : _sequences) {
		if(s.size() > 1) {
			for(auto it = s.begin(); it != prev(s.end()); ++it) {
				shared_ptr<MeasureWidget> a = *it;
				shared_ptr<MeasureWidget> b = *(next(it));

				Matrix44f at;
				at.translate(Vec3f(a->position()));
				at.rotate(Vec3f(0.0f, 0.0f, a->angle()));
				
				Matrix44f bt;
				bt.translate(Vec3f(b->position()));
				bt.rotate(Vec3f(0.0f, 0.0f, b->angle()));
				
				Vec3f ap3 = at.transformPoint(Vec3f(a->outletIcon().getCenter()));
				Vec3f bp3 = bt.transformPoint(Vec3f(b->inletIcon().getCenter()));
				
				Vec2f ap(ap3.x, ap3.y);
				Vec2f bp(bp3.x, bp3.y);

				gl::drawLine(ap, bp);
			}
		}
	}
	_sequencesMutex.unlock();

	_widgetsMutex.lock();
	for(auto w : _widgets) {
		w->draw();
	}
	_widgetsMutex.unlock();
	
	gl::popModelView();
		
	// Let's draw the traces as they are being created
	_tracesMutex.lock();
	_groupsMutex.lock();
	for(int i = 0; i < _groups.size(); i++) {
		for(auto trace : _groups[i]) {
			if(trace->isVisible) {
				gl::color(1.0f, 1.0f, 1.0f, 0.25f);
			} else {
				float c = (trace->lifespan() / 10.0f) * 0.25f;
				gl::color(1.0f, 1.0f, 1.0f, c);
			}
			if(trace->touchPoints.size() > 1) {
				for(auto cursorIt = trace->touchPoints.begin(); cursorIt != prev(trace->touchPoints.end()); ++cursorIt) {
					Vec2f a = tuioToWindow(cursorIt->getPos());
					Vec2f b = tuioToWindow(next(cursorIt)->getPos());
					gl::lineWidth(2.0f);
					gl::drawLine(a, b);
				}
			}
			if(trace->isVisible) {
				gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 8.0f);
				gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 50.0f);
			} else {
				gl::drawSolidCircle(tuioToWindow(trace->currentPosition()), 4.0f);
			}
		}
	}
	_groupsMutex.unlock();
	_tracesMutex.unlock();
}
Пример #6
0
void TextTestApp::drawSkeleton(){
	
	//if(mSkeletons.size()<1)
//	{
//		return;
//	}

	// We're capturing
	if ( mKinect->isCapturing() ) {

		// Set up 3D view
		//gl::pushMatrices();
		//gl::setMatrices( mCamera );
		

		// Iterate through skeletons
		uint32_t i = 0;

		int skeletonCount = 0;

		for ( vector<Skeleton>::const_iterator skeletonIt = mSkeletons.cbegin(); skeletonIt != mSkeletons.cend(); ++skeletonIt, i++ )
		{

			if (skeletonIt->size() > 0){
				skeletonCount +=1;
			}

			if (significantInteractionTimer.isStopped()){
				significantInteractionTimer.start();
			}


			
			if (activeUserPresent != true && significantInteractionTimer.getSeconds() > 3.0){
				activeUserPresent = true;
				//if we are in passive mode, tell the existing scene to exit.
				currentScene->exitNow();

				// clear any old references to this timer incase it doubles up
				timeline().remove( mCue );

				// TODO - should be an event given back from exit now. not a timer. for now this will do ill sort later.
				mCue = timeline().add( boost::bind(&TextTestApp::beginActiveScene, this), timeline().getCurrentTime() + 2 );
	
			}
			

			// Set color
			Colorf color = mKinect->getUserColor( i );
			int boneIndex = 0;
			// Iterate through joints
			for ( Skeleton::const_iterator boneIt = skeletonIt->cbegin(); boneIt != skeletonIt->cend(); ++boneIt, boneIndex++ ) {

				// Set user color
				//gl::color( color );

				// Get position and rotation
				const Bone& bone = boneIt->second;
				Vec3f position = bone.getPosition();
				
				Matrix44f transform	= bone.getAbsoluteRotationMatrix();
				Vec3f direction		= transform.transformPoint( position ).normalized();
				direction *= 0.05f;
				position.z *= -1.0f;

				Vec3f destination = skeletonIt->at( bone.getStartJoint() ).getPosition();

				Vec3f end = skeletonIt->at( bone.getEndJoint() ).getPosition();
				

				//add the current bone position to the gesture tracker history
				gestureTracker->addPoint(boneIndex,end);
				

				Vec2f endScreen	= Vec2f( mKinect->getSkeletonVideoPos( end ) );
				
				Vec2f positionScreen = Vec2f( mKinect->getSkeletonVideoPos( position ) );
				Vec2f destinationScreen	= Vec2f( mKinect->getSkeletonVideoPos( destination ) );


				
				//boneIt->first

				//draw bone specific stuff here


				
				repelClips[boneIndex].x = endScreen.x * 2;
				repelClips[boneIndex].y = endScreen.y * 2;
				repelClips[boneIndex].zDist = position.z;
				

				float midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
				Vec2f midPoint = getPointOnLine(destinationScreen,endScreen,midPointDist );
				
				if (midPointDist == 0){
					//if the distance is 0, the joint doesn't need a midpoint.
					repelClips[boneIndex+20].x = -200;
					repelClips[boneIndex+20].y = -200;
					repelClips[boneIndex+20].zDist = position.z;
				}else{
					repelClips[boneIndex+20].x = midPoint.x*2;
					repelClips[boneIndex+20].y = midPoint.y*2;
					repelClips[boneIndex+20].zDist = position.z;
				}

				switch(boneIt->first){
						case NUI_SKELETON_POSITION_HIP_CENTER:
							//draw hip center
							break;
					 
						case NUI_SKELETON_POSITION_SPINE:
							//draw spine
				 			break;
						case NUI_SKELETON_POSITION_SHOULDER_CENTER:
							//draw shoulder center
				 			break;
						case NUI_SKELETON_POSITION_HEAD:
							//draw head
				 			break;
						case NUI_SKELETON_POSITION_SHOULDER_LEFT:
							//draw left shoulder
				


							break;				 
						case NUI_SKELETON_POSITION_ELBOW_LEFT:
							//draw left elbow
							
							midPoint = getPointOnLine(destinationScreen,endScreen,0.25  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[20].x = midPoint.x*2;
							repelClips[20].y = midPoint.y*2;
							repelClips[20].zDist = position.z;


							midPoint = getPointOnLine(destinationScreen,endScreen,0.75  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[21].x = midPoint.x*2;
							repelClips[21].y = midPoint.y*2;
							repelClips[21].zDist = position.z;
							break;				 
						case NUI_SKELETON_POSITION_WRIST_LEFT:
							//draw left wrist
							break;				 
						case NUI_SKELETON_POSITION_HAND_LEFT:
							//draw left hand
							break;				 
						case NUI_SKELETON_POSITION_SHOULDER_RIGHT:
							//draw right shoulder
							break;				 
						case NUI_SKELETON_POSITION_ELBOW_RIGHT:
							//draw right elbow
							
							midPoint = getPointOnLine(destinationScreen,endScreen,0.25  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[23].x = midPoint.x*2;
							repelClips[23].y = midPoint.y*2;
							repelClips[23].zDist = position.z;


							midPoint = getPointOnLine(destinationScreen,endScreen,0.75  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[24].x = midPoint.x*2;
							repelClips[24].y = midPoint.y*2;
							repelClips[24].zDist = position.z;
							break;				 
						case NUI_SKELETON_POSITION_WRIST_RIGHT:
							//draw right wrist
							break;				 
						case NUI_SKELETON_POSITION_HAND_RIGHT:
							//draw right hand
							break;				 
						case NUI_SKELETON_POSITION_HIP_LEFT:
							//draw left hip
							break;
						case NUI_SKELETON_POSITION_KNEE_LEFT:
							//draw left knee
							midPoint = getPointOnLine(destinationScreen,endScreen,0.25  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[27].x = midPoint.x*2;
							repelClips[27].y = midPoint.y*2;
							repelClips[27].zDist = position.z;


							midPoint = getPointOnLine(destinationScreen,endScreen,0.75  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[31].x = midPoint.x*2;
							repelClips[31].y = midPoint.y*2;
							repelClips[31].zDist = position.z;

							break;
						case NUI_SKELETON_POSITION_ANKLE_LEFT:
							//draw left ankle
							break;
						case NUI_SKELETON_POSITION_FOOT_LEFT:
							//draw left foot
							break;
						case NUI_SKELETON_POSITION_HIP_RIGHT:
							//draw right hip
							break;
						case NUI_SKELETON_POSITION_KNEE_RIGHT:
							//draw right knee
							
							midPoint = getPointOnLine(destinationScreen,endScreen,0.25  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[32].x = midPoint.x*2;
							repelClips[32].y = midPoint.y*2;
							repelClips[32].zDist = position.z;


							midPoint = getPointOnLine(destinationScreen,endScreen,0.75  );
							midPointDist = OutlineParams::getInstance()->getMidpointForIndex(boneIndex);
							
							repelClips[35].x = midPoint.x*2;
							repelClips[35].y = midPoint.y*2;
							repelClips[35].zDist = position.z;

							break;
						case NUI_SKELETON_POSITION_ANKLE_RIGHT:
							//draw right ankle
							break;
						case NUI_SKELETON_POSITION_FOOT_RIGHT:
							//draw right foot
							break;
						default :

							

						break;
				}

			}

		}


		//if there are no skeletons, there's nobody in the frame, so clean up the skeleton stuff.
		if (skeletonCount == 0){
			
			activeUserPresent = false;// reset the active user timer
			significantInteractionTimer = Timer();

			//first clip is reserved for random background
			for(unsigned int k=1;k<repelClips.size();k++){
				repelClips[k].x = -200;
				repelClips[k].y = -200;
			}

			if (bgAnimationTimer.isStopped()){
				bgAnimationTimer.start();
			}

			if (bgAnimationTimer.getSeconds() > 2.0){
				repelClips[0].x = randFloat(0,1280);
				repelClips[0].y = randFloat(0,800);

				//bgAnimationTimer = Timer();
			}
			if (bgAnimationTimer.getSeconds() > 3.0){
				bgAnimationTimer = Timer();
				repelClips[0].x = -200;
				repelClips[0].y = -200;
			}
		}
		
	}

	
	gl::enableAlphaBlending();
	//show the repel clip forces
	if (OutlineParams::getInstance()->showForces == true){
		for (int i = 0;i < repelClips.size(); i++){
			
			repelClips[i].k = OutlineParams::getInstance()->getForceForIndex(i);
			repelClips[i].minDist = OutlineParams::getInstance()->getMinDistForIndex(i);
			
			float alpha = 0.8 / repelClips.size() * i;
			//gl::color(ColorA(1.0,0.0,0.0,0.2));
			//gl::drawSolidCircle(ci::Vec2f(repelClips[i].x, repelClips[i].y),OutlineParams::getInstance()->getForceForIndex(i) + (repelClips[i].zDist*repelClips[i].zDist));
			gl::color(ColorA(0.0,1.0,0.0,0.2 + alpha));
			gl::drawSolidCircle(ci::Vec2f(repelClips[i].x, repelClips[i].y),OutlineParams::getInstance()->getMinDistForIndex(i) + (repelClips[i].zDist*repelClips[i].zDist));
		}
		gl::color(ColorA(1.0,1.0,1.0,1.0));
	}

	//draw the user in particles 
	bool drawUser = false; 
	if (drawUser==true){
		for (int i = 0;i < repelClips.size(); i++){
			userParticles[i].xpos = repelClips[i].x;
			userParticles[i].ypos = repelClips[i].y;

			userParticles[i].rad = OutlineParams::getInstance()->getMinDistForIndex(i) - (repelClips[i].zDist*repelClips[i].zDist);
			userParticles[i].update(getElapsedSeconds());
			userParticles[i].draw();
		}
	}

	gl::enableAlphaBlending();
	gl::disableAlphaBlending();
};