ios FlowCover效果demo
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 <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 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, posit
补充:移动开发 , IOS ,