Пример #1
0
void BloomingNeonApp::update()
{
	mTransform.setToIdentity();
	mTransform.rotate( Vec3f::xAxis(), sinf( (float) getElapsedSeconds() * 3.0f ) * 0.08f );
	mTransform.rotate( Vec3f::yAxis(), (float) getElapsedSeconds() * 0.1f );
	mTransform.rotate( Vec3f::zAxis(), sinf( (float) getElapsedSeconds() * 4.3f ) * 0.09f );
}
Пример #2
0
void MeshViewApp::update()
{
	// Track the time
	float elapsed = (float) getElapsedSeconds() - m_time;
	m_time += elapsed;

	if (m_fileMonitorConfig->hasChanged())
	{
		loadConfig(m_configFileName, true);
	}

	if(m_fileMonitorVert->hasChanged() || m_fileMonitorFrag->hasChanged())
	{
		loadShader(m_shaderFileName);
	}

	if(m_rotateMesh)
	{
		float rotateAngle = elapsed * 0.2f;
		m_matrix.rotate(Vec3f::yAxis(), rotateAngle);
	}

	if(isInitialized())
	{
		m_assimpLoader.setTime(elapsed);
		m_assimpLoader.update();
	}
}
Пример #3
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;
	}
Пример #4
0
void FBOMultipleTargetsApp::update()
{
	// Rotate the torus by .06 radians around an arbitrary axis
	mTorusRotation.rotate( Vec3f( 0.16666f, 0.333333f, 0.666666f ).normalized(), 0.06f );
	
	// render into our FBO
	renderSceneToFbo();
}
/**
 * Transform the coordinate system to match the surface of the wall
 */ 
void Dodecahedron::transformToWallCoordinateSystem( int wall )
{
	Vec3f vCenter = wallCenters[wall];
	Vec3f coordinateSystem[3] = wallCoordinateSystems[wall];
	
	//transform the model matrix to place (0,0,0) in the middle of the wall. this is awesome, took me a while to figure out
	//...probably done the wrong way :)	
	gl::pushModelView();
	Matrix44f transformation = gl::getModelView();
	transformation = transformation.createTranslation(vCenter);
	transformation.rotate(Vec3f::zAxis(), coordinateSystem[2], coordinateSystem[1]);	
	gl::multModelView(transformation);
}
Пример #6
0
 // if you're doing 2D drawing, this matrix moves the origin to the correct device corner
 // to get the window size, use app::getWindowSize(), test for 
 // isLandscape(event.getInterfaceOrientation()) and apply a .yx() swizzle 
 Matrix44f getOrientationMatrix44(const Orientation &orientation, const Vec2f &deviceSize)
 {
     Matrix44f orientationMtx;
     switch ( orientation )
     {
         case UPSIDE_DOWN_PORTRAIT_ORIENTATION:
             orientationMtx.translate( Vec3f( deviceSize.x, deviceSize.y, 0 ) );            
             orientationMtx.rotate( Vec3f( 0, 0, M_PI ) );
             break;
         case LANDSCAPE_LEFT_ORIENTATION:
             orientationMtx.translate( Vec3f( deviceSize.x, 0, 0 ) );
             orientationMtx.rotate( Vec3f( 0, 0, M_PI/2.0 ) );
             break;
         case LANDSCAPE_RIGHT_ORIENTATION:
             orientationMtx.translate( Vec3f( 0, deviceSize.y, 0 ) );
             orientationMtx.rotate( Vec3f( 0, 0, -M_PI/2.0 ) );
             break;
         default:
             break;
     }
     
     return orientationMtx;          
 }
Пример #7
0
void MeshViewApp::setup()
{
	loadConfig("configs/gaztank.ini");

	setupCamera();

	// Create lights
	m_light1 = new gl::Light(gl::Light::DIRECTIONAL, 0);
	m_light1->setDirection(Vec3f(0, 0, 1).normalized());
	m_light1->setAmbient(Color(0.0f, 0.0f, 0.1f));
	m_light1->setDiffuse(Color(0.9f, 0.6f, 0.3f));
	m_light1->setSpecular(Color(0.9f, 0.6f, 0.3f));

	m_light2 = new gl::Light(gl::Light::DIRECTIONAL, 1);
	m_light2->setDirection(Vec3f(0, 0, -1).normalized());
	m_light2->setAmbient(Color(0.0f, 0.0f, 0.0f));
	m_light2->setDiffuse(Color(0.2f, 0.6f, 1.0f));
	m_light2->setSpecular(Color(0.2f, 0.2f, 0.2f));

	// Setup matrix
	m_matrix.setToIdentity();
	m_matrix.translate(Vec3f::zero());
	m_matrix.rotate(Vec3f::zero());
	m_matrix.scale(Vec3f::one());

	m_rotateMesh = false;

	// Create a parameter window
	m_params = params::InterfaceGl::create(getWindow(), "Properties", Vec2i(180, 240));
	m_params->addText("LMB + drag - rotate");
	m_params->addText("RMB + drag - zoom");
	m_params->addSeparator();
	m_params->addButton("Full screen", [&] { setFullScreen(!isFullScreen()); });
	m_params->addParam("Auto rotate", &m_rotateMesh);
	m_params->addSeparator();
	m_params->addParam("Diffuse", &m_diffuseEnabled);
	m_params->addParam("Normal", &m_normalEnabled);
	m_params->addParam("Specular", &m_specularEnabled);
	m_params->addParam("AO", &m_aoEnabled);
	m_params->addParam("Emissive", &m_emissiveEnabled);
	m_params->addSeparator();
	m_params->addParam("Gamma", &m_gamma, "min=0.0 max=10.0 step=0.1");

	m_time = (float)getElapsedSeconds();
}
Пример #8
0
	btSoftBody*	SoftBody::createSoftHull( 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 );

		btVector3* positions = new btVector3[ mesh.getNumVertices() ];
		size_t i = 0;
		for ( vector<Vec3f>::const_iterator iter = mesh.getVertices().begin(); iter != mesh.getVertices().end(); ++iter, ++i ) {
			positions[ i ] = toBulletVector3( *iter );
		}

		btSoftBody* body = btSoftBodyHelpers::CreateFromConvexHull( info, positions, mesh.getNumIndices(), false );
		body->transform( toBulletTransform( transform ) );
		body->scale( toBulletVector3( scale ) );

		delete [] positions;

		return body;
	}
Пример #9
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;
	}
Пример #10
0
void BloomingNeonApp::update()
{
	mTransform.setToIdentity();
	mTransform.rotate( Vec3f::yAxis(), (float) getElapsedSeconds() * 0.2f );
}
Пример #11
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;
}
Пример #12
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();
}
Пример #13
0
void iosAppTestApp::update()
{
	tester.setState( TestCallbackOrder::UPDATE );

	mCubeRotation.rotate( Vec3f( 1, 1, 1 ), 0.03f );
}