Ios FlowCover effect demo

Source: Internet
Author: User

Demo function: flowcover effect, positive and negative infinite loop scrolling, each cover has a separate reflection

Demo Description: The FlowCover Classes folder in the project stores the core Classes.


Demo diagram:

 

 


Demo main code: drawing part


[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 );

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 );
GlVertexPointer (3, GL_FLOAT, 0, GVertices );
GlEnableClientState (GL_VERTEX_ARRAY );
GlTexCoordPointer (2, GL_SHORT, 0, GTextures );
GlEnableClientState (GL_TEXTURE_COORD_ARRAY );

Glable (GL_TEXTURE_2D );
GlBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
Glable (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 <alessandro.tagliati@gmail.com>:
* 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
* 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 );
 
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 );
GlVertexPointer (3, GL_FLOAT, 0, GVertices );
GlEnableClientState (GL_VERTEX_ARRAY );
GlTexCoordPointer (2, GL_SHORT, 0, GTextures );
GlEnableClientState (GL_TEXTURE_COORD_ARRAY );
 
Glable (GL_TEXTURE_2D );
GlBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
Glable (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 <alessandro.tagliati@gmail.com>:
* 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
* 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];
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.