你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios FlowCover效果demo

ios FlowCover效果demo

編輯:IOS開發綜合

demo功能:flowcover 效果,正反無限循環滾動,每個cover都有單獨的倒影

demo說明:項目中FlowCover Classes文件夾是存放核心類。


demo接圖:

 

 


demo主要代碼:繪制部分


[csharp] 
- (void)drawTile:(int)index atOffset:(double)off 

    FlowCoverRecord *fcr = [self getTileAtIndex:index]; 
    GLfloat m[16]; 
    memset(m,0,sizeof(m)); 
    m[10] = 1; 
    m[15] = 1; 
    m[0] = 1; 
    m[5] = 1; 
    double trans = off * SPREADIMAGE; 
     
    double f = off * FLANKSPREAD; 
    if (f < -FLANKSPREAD) { 
        f = -FLANKSPREAD; 
    } else if (f > FLANKSPREAD) { 
        f = FLANKSPREAD; 
    } 
    m[3] = -f; 
    m[0] = 1-fabs(f); 
    double sc = 0.45 * (1 - fabs(f)); 
    trans += f * 1; 
     
    glPushMatrix(); 
    glBindTexture(GL_TEXTURE_2D,fcr.texture); 
    glTranslatef(trans, 0, 0); 
    glScalef(sc,sc,1.0); 
    glMultMatrixf(m); 
    glDrawArrays(GL_TRIANGLE_STRIP,0,4); 
     
    // reflect  
    glTranslatef(0,-2,0); 
    glScalef(1,-1,1); 
    glColor4f(0.5,0.5,0.5,0.5); 
    glDrawArrays(GL_TRIANGLE_STRIP,0,4); 
    glColor4f(1,1,1,1); 
     
    glPopMatrix(); 

 
- (void)draw 

    /*
     *  Get the current aspect ratio and initialize the viewport
     */ 
     
    double aspect = ((double)backingWidth)/backingHeight; 
     
    glViewport(0,0,backingWidth,backingHeight); 
    glDisable(GL_DEPTH_TEST);               // using painters algorithm  
     
    glClearColor(0,0,0,0); 
    glVertexPointer(3,GL_FLOAT,0,GVertices); 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glTexCoordPointer(2, GL_SHORT, 0, GTextures); 
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
     
    glEnable(GL_TEXTURE_2D); 
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 
    glEnable(GL_BLEND); 
     
    /*
     *  Setup for clear
     */ 
     
    [EAGLContext setCurrentContext:context]; 
     
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); 
    glClear(GL_COLOR_BUFFER_BIT); 
     
    /*
     *  Set up the basic coordinate system
     */ 
     
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glScalef(1,aspect,1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
     
    //modify by chenwh 2010-01-06 for round view begin  
    /*
     *  Change from Alesandro Tagliati <[email protected]>:
     *  We don't need to draw all the tiles, just the visible ones. We guess
     *  there are 6 tiles visible; that can be adjusted by altering the 
     *  constant
     */ 
    /*
    int i,len = [self numTiles];
    int mid = (int)floor(offset + 0.5);
    int iStartPos = mid - VISTILES;
    if (iStartPos<0) {
        iStartPos=0;
    }
    for (i = iStartPos; i < mid; ++i) {
        [self drawTile:i atOffset:i-offset];
    }
    
    int iEndPos=mid + VISTILES;
    if (iEndPos >= len) {
        iEndPos = len-1;
    }
    for (i = iEndPos; i >= mid; --i) {
        [self drawTile:i atOffset:i-offset];
    }
    */ 
     
    int len = [self numTiles]; 
    int iStartPos = -VISTILES; 
    int iEndPos = VISTILES; 
    int mid = 0; 
     
    int pageCount = (int)offset; 
    double moveOffset; 
    if (offset < 0) { 
        moveOffset = offset - ceil(offset); 
    } else { 
        moveOffset = offset - floor(offset); 
    } 
     
    int index, position; 
    //NSLog(@"offset=%.2f, pageCount=%d, moveOffset=%.2f", offset, pageCount, moveOffset);  
    for (position = iStartPos; position < mid; ++position) { 
        index = (len + position + pageCount) % len; 
        if (index < 0) { 
            index = len + index; 
        } 
        //NSLog(@"index=%d, position=%d", index, position);  
        [self drawTile:index atOffset:position - moveOffset]; 
    } 
    for (position = iEndPos; position >= mid; --position) { 
        index = (position + pageCount) % len; 
        if (index < 0) { 
            index = len + index; 
        } 
        //NSLog(@"index=%d, position=%d", index, position);  
        [self drawTile:index atOffset:position - moveOffset]; 
    } 
    //modify by chenwh 2010-01-06 for round view end  
     
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer); 
    [context presentRenderbuffer:GL_RENDERBUFFER_OES]; 

- (void)drawTile:(int)index atOffset:(double)off
{
 FlowCoverRecord *fcr = [self getTileAtIndex:index];
 GLfloat m[16];
 memset(m,0,sizeof(m));
 m[10] = 1;
 m[15] = 1;
 m[0] = 1;
 m[5] = 1;
 double trans = off * SPREADIMAGE;
 
 double f = off * FLANKSPREAD;
 if (f < -FLANKSPREAD) {
  f = -FLANKSPREAD;
 } else if (f > FLANKSPREAD) {
  f = FLANKSPREAD;
 }
 m[3] = -f;
 m[0] = 1-fabs(f);
 double sc = 0.45 * (1 - fabs(f));
 trans += f * 1;
 
 glPushMatrix();
 glBindTexture(GL_TEXTURE_2D,fcr.texture);
 glTranslatef(trans, 0, 0);
 glScalef(sc,sc,1.0);
 glMultMatrixf(m);
 glDrawArrays(GL_TRIANGLE_STRIP,0,4);
 
 // reflect
 glTranslatef(0,-2,0);
 glScalef(1,-1,1);
 glColor4f(0.5,0.5,0.5,0.5);
 glDrawArrays(GL_TRIANGLE_STRIP,0,4);
 glColor4f(1,1,1,1);
 
 glPopMatrix();
}

- (void)draw
{
 /*
  * Get the current aspect ratio and initialize the viewport
  */
 
 double aspect = ((double)backingWidth)/backingHeight;
 
 glViewport(0,0,backingWidth,backingHeight);
 glDisable(GL_DEPTH_TEST);    // using painters algorithm
 
 glClearColor(0,0,0,0);
 glVertexPointer(3,GL_FLOAT,0,GVertices);
 glEnableClientState(GL_VERTEX_ARRAY);
 glTexCoordPointer(2, GL_SHORT, 0, GTextures);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
 glEnable(GL_TEXTURE_2D);
 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 glEnable(GL_BLEND);
 
 /*
  * Setup for clear
  */
 
 [EAGLContext setCurrentContext:context];
 
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glClear(GL_COLOR_BUFFER_BIT);
 
 /*
  * Set up the basic coordinate system
  */
 
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glScalef(1,aspect,1);
    glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 
 //modify by chenwh 2010-01-06 for round view begin
 /*
  * Change from Alesandro Tagliati <[email protected]>:
  * We don't need to draw all the tiles, just the visible ones. We guess
  * there are 6 tiles visible; that can be adjusted by altering the
  * constant
  */
 /*
 int i,len = [self numTiles];
 int mid = (int)floor(offset + 0.5);
 int iStartPos = mid - VISTILES;
 if (iStartPos<0) {
  iStartPos=0;
 }
 for (i = iStartPos; i < mid; ++i) {
  [self drawTile:i atOffset:i-offset];
 }
 
 int iEndPos=mid + VISTILES;
 if (iEndPos >= len) {
  iEndPos = len-1;
 }
 for (i = iEndPos; i >= mid; --i) {
  [self drawTile:i atOffset:i-offset];
 }
 */
 
 int len = [self numTiles];
 int iStartPos = -VISTILES;
 int iEndPos = VISTILES;
 int mid = 0;
 
 int pageCount = (int)offset;
 double moveOffset;
 if (offset < 0) {
  moveOffset = offset - ceil(offset);
 } else {
  moveOffset = offset - floor(offset);
 }
 
 int index, position;
 //NSLog(@"offset=%.2f, pageCount=%d, moveOffset=%.2f", offset, pageCount, moveOffset);
 for (position = iStartPos; position < mid; ++position) {
  index = (len + position + pageCount) % len;
  if (index < 0) {
   index = len + index;
  }
  //NSLog(@"index=%d, position=%d", index, position);
  [self drawTile:index atOffset:position - moveOffset];
 }
 for (position = iEndPos; position >= mid; --position) {
  index = (position + pageCount) % len;
  if (index < 0) {
   index = len + index;
  }
  //NSLog(@"index=%d, position=%d", index, position);
  [self drawTile:index atOffset:position - moveOffset];
 }
 //modify by chenwh 2010-01-06 for round view end
 
 glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
 [context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved