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(); }
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 ); }
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(); }