예제 #1
0
void Draw(const GameObject& Object, const float Angle, const Texture& Texture)
{
    using namespace ci;

    gl::pushModelView();

    gl::translate(Object.GetCenterPos());
    gl::rotate(Angle);
    gl::translate(-Texture.getSize() / 2.f);

    Texture.enableAndBind();
    glEnableClientState(GL_VERTEX_ARRAY);
    GLfloat verts[8];
    glVertexPointer(2, GL_FLOAT, 0, verts);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    GLfloat texCoords[8];
    glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

    const Rectf destRect = Texture.getCleanBounds();
    verts[0 * 2 + 0] = destRect.getX2();
    verts[0 * 2 + 1] = destRect.getY1();
    verts[1 * 2 + 0] = destRect.getX1();
    verts[1 * 2 + 1] = destRect.getY1();
    verts[2 * 2 + 0] = destRect.getX2();
    verts[2 * 2 + 1] = destRect.getY2();
    verts[3 * 2 + 0] = destRect.getX1();
    verts[3 * 2 + 1] = destRect.getY2();

    const Rectf srcCoords = Texture.getAreaTexCoords(Texture.getCleanBounds());
    texCoords[0 * 2 + 0] = srcCoords.getX2();
    texCoords[0 * 2 + 1] = srcCoords.getY1();
    texCoords[1 * 2 + 0] = srcCoords.getX1();
    texCoords[1 * 2 + 1] = srcCoords.getY1();
    texCoords[2 * 2 + 0] = srcCoords.getX2();
    texCoords[2 * 2 + 1] = srcCoords.getY2();
    texCoords[3 * 2 + 0] = srcCoords.getX1();
    texCoords[3 * 2 + 1] = srcCoords.getY2();


    for (int i = 0; i != 2400; ++i) {
        gl::translate(Vec2f(10.f, 0.f));
        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        // gl::draw(Texture);
    }
    // for (int i = 0; i != 700; ++i) // 13
    //{
    //    gl::translate(Vec2f(10.f, 0.f));
    //    gl::draw(Texture);
    //    gl::draw(Object.m_Texture2);
    //}

    gl::popModelView();
}
예제 #2
0
void Context::copySurface( const SurfaceBase &surface, const Area &srcArea, const Rectf &dstRect )
{
	if( ( dstRect.getWidth() == 0 ) || ( dstRect.getHeight() == 0 ) )
		return;

	save();
	cairo_set_source_surface( mCairo, const_cast<SurfaceBase&>( surface ).getCairoSurface(), 0, 0 );
	cairo_pattern_t *sourcePattern = cairo_get_source( mCairo );
	cairo_matrix_t m;
	cairo_matrix_init_identity( &m );
	cairo_matrix_scale( &m, srcArea.getWidth() / (float)dstRect.getWidth(), srcArea.getHeight() / (float)dstRect.getHeight() );
	cairo_matrix_translate( &m, srcArea.getX1() - dstRect.getX1(), srcArea.getY1() - dstRect.getY1() );
	cairo_pattern_set_matrix( sourcePattern, &m );
	cairo_rectangle( mCairo, dstRect.getX1(), dstRect.getY1(), dstRect.getWidth(), dstRect.getHeight() );
	cairo_fill( mCairo );
	restore();
}
예제 #3
0
	void mouseDrag( MouseEvent event ) 
	{
		if (mEditMode == EditMode_RECORD) return;

		// 制御点の選択を行う
		if (event.isLeftDown()) {
			if (mSelectionMode == 0) return;

			float x1 = mSelectRegion.getX1();
			float y1 = mSelectRegion.getY1();
			mSelectRegion.set(x1, y1, event.getX()+5, event.getY()+5);

			for (int k = 0; k < mCtrlPointsNum; ++k) {
				if (mSelectRegion.contains(mCtrlPoints[k].pos)) {
					mCtrlPoints[k].isSelected = true;
				} else {
					mCtrlPoints[k].isSelected = false;
				}
			}
		}

		Vec2f d = event.getPos() - mMPPrev;	

		if (event.isRightDown()) {
			for (int k = 0; k < mCtrlPointsNum; ++k) {
				if (mCtrlPoints[k].isSelected) {
					mCtrlPoints[k].mag += d;
				}
			}
		}

		if (event.isMiddleDown()) {
			int ci = -1;
			int cj = -1;
			float nearest = 1.e+10;
			for (int j = 0; j < 2; ++j) {	
				for (int i = 0; i < 2; ++i) {
					Vec2f cp(distpoints[j][i][0], distpoints[j][i][1]);
					float dist = event.getPos().distance(cp);
					if (dist < nearest) {
						ci = i;
						cj = j;
						nearest = dist;
					}
				}
			}

			if (ci > -1 &&  cj > -1) {
				distpoints[cj][ci][0] += d.x;
				distpoints[cj][ci][1] += d.y;
			}
		}
		mMPPrev = event.getPos();
	}
예제 #4
0
void MapperOp::drawTexturedRect( const Rectf &srcRect,  const Rectf &destRec){
	glEnableClientState( GL_VERTEX_ARRAY );
	GLfloat verts[8];
	glVertexPointer( 2, GL_FLOAT, 0, verts );
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
	GLfloat texCoords[8];
	glTexCoordPointer( 2, GL_FLOAT, 0, texCoords );

	verts[0*2+0] = srcRect.getX2(); texCoords[0*2+0] = destRec.getX2();
	verts[0*2+1] = srcRect.getY1(); texCoords[0*2+1] = destRec.getY1();
	verts[1*2+0] = srcRect.getX1(); texCoords[1*2+0] = destRec.getX1();
	verts[1*2+1] = srcRect.getY1(); texCoords[1*2+1] = destRec.getY1();
	verts[2*2+0] = srcRect.getX2(); texCoords[2*2+0] = destRec.getX2();
	verts[2*2+1] = srcRect.getY2(); texCoords[2*2+1] = destRec.getY2();
	verts[3*2+0] = srcRect.getX1(); texCoords[3*2+0] = destRec.getX1();
	verts[3*2+1] = srcRect.getY2(); texCoords[3*2+1] = destRec.getY2();

	glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );

	glDisableClientState( GL_VERTEX_ARRAY );
	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
예제 #5
0
void TutorialApp::update()
{
	// Animation speed, velocity decay, and epsilon (margin) for all tranform types.
	static const float decay	= 0.96f;
	static const float epsilon	= 0.1f;
	static const float speed	= 0.1f;

	for ( auto& iter : mUiTree.getChildren() ) {
		UiTree& node = iter.second;

		// Get the animation bounds for this node
		Rectf bounds = calcBounds( node );

		// Get the node's transform values
		const float r = node.getRotation().z;
		const vec2& s = vec2( node.getScale() );
		const vec2& t = vec2( node.getTranslate() );

		/* 
			* Switch on this node's animation type, then animate using 
			* either velocity or sequencing.
			*/
		switch ( node.getData().mTransform ) {
		case Transform_Rotate:
			if ( node.getData().mUseVelocity ) {

				// Get the velocity values.
				const float v = node.getRotationVelocity().z;

				/*
					* Accelerate the node's rotation CW or CCW randomly when its velocity 
					* gets too low.
					*/
				if ( math<float>::abs( v ) < 0.001f ) {
					node.rotationVelocity( randFloat( -0.1f, 0.1f ), decay );
				}

			} else {

				// If we're not using velocity, rotate the node CW and CCW.
				if ( math<float>::abs( node.getRotationTarget().z ) - math<float>::abs( r ) < epsilon ) {
					const float z = r > 0.0f ? -1.0f : 1.0f;
					node.setRotation( z, speed );
				}

			}
			break;
		case Transform_Scale:
			if ( node.getData().mUseVelocity ) {

				/*
					* Accelerate the node's scale in a random direction when its velocity 
					* gets too low.
					*/
				if ( glm::length( node.getScaleVelocity() ) <= epsilon ) {
					node.scaleVelocity( randVec2() * randFloat( 5.0f, 20.0f ), decay );
				}

				// Get the new scale value.
				const vec2& scale = vec2( node.getScale() );

				// Keep the node centered
				node.setTranslate( bounds.getCenter() - scale * 0.5f );

				// Clamp the node's scale.
				if ( node.getScale().x > mSize * 2.0f ) {
					node.setScale( vec2( mSize * 2.0f, scale.y ) );
				} else if ( node.getScale().x < mSize * 0.5f ) {
					node.setScale( vec2( mSize * 0.5f, scale.y ) );
				}
				if ( node.getScale().y > mSize * 2.0f ) {
					node.setScale( vec2( scale.x, mSize * 2.0f ) );
				} else if ( node.getScale().y < mSize * 0.5f ) {
					node.setScale( vec2( scale.x, mSize * 0.5f ) );
				}

			} else {

				/*
					* If we're not using velocity, scale the node up and down.
					* Keep the node centered in its bounds.
					*/
				if ( glm::length( s - vec2( node.getScaleTarget() ) ) < epsilon ) {
					vec2 scale( s.x > mSize ? mSize * 0.5f : mSize * 2.0f );
					node
						.scale( scale, speed )
						.translate( bounds.getCenter() - scale * 0.5f, speed );
				}
			}
			break;
		case Transform_Translate:
			if ( node.getData().mUseVelocity ) {

				// Get the velocity values.
				const vec2& v = vec2( node.getTranslateVelocity() );
				const float d = node.getTranslateVelocityDecay();

				/*
					* Accelerate the node in a random direction when its velocity 
					* gets too low.
					*/
				if ( glm::length( node.getTranslateVelocity() ) <= epsilon ) {
					node.translateVelocity( randVec2() * randFloat( 5.0f, 20.0f ), decay );
				}

				// Bounce off of bounding box edges.
				if ( t.x <= bounds.getX1() ) {
					node
						.translate( vec2( bounds.getX1() + epsilon, t.y ) )
						.translateVelocity( v * vec2( -1.0f, 1.0f ), d );
				} else if ( t.x + s.x >= bounds.getX2() ) {
					node
						.translate( vec2( ( bounds.getX2() - s.x ) - epsilon, t.y ) )
						.translateVelocity( v * vec2( -1.0f, 1.0f ), d );
				}
				if ( t.y <= bounds.getY1() ) {
					node
						.translate( vec2( t.x, bounds.getY1() + epsilon ) )
						.translateVelocity( v * vec2( 1.0f, -1.0f ), d );
				} else if ( t.y + s.y >= bounds.getY2() ) {
					node
						.translate( vec2( t.x, ( bounds.getY2() - s.y ) - epsilon ) )
						.translateVelocity( v * vec2( 1.0f, -1.0f ), d );
				}
			} else {

				/*
					* If we're not using velocity, animate left to right as the 
					* target position is reached.
					*/
				if ( glm::length( t - vec2( node.getTranslateTarget() ) ) < epsilon ) {
					float x = t.x > bounds.getX1() + epsilon ? bounds.getX1() : bounds.getX2() - s.x;
					node.setTranslate( vec2( x, t.y ), speed );
				}
			}
			break;
		default:
			break;
		}
	}

	mUiTree.update();
}