void Ripple3D::update(float time) { int i, j; for (i = 0; i < (_gridSize.width+1); ++i) { for (j = 0; j < (_gridSize.height+1); ++j) { Vec3 v = getOriginalVertex(Vec2(i, j)); Vec2 vect = _position - Vec2(v.x,v.y); float r = vect.getLength(); if (r < _radius) { r = _radius - r; float rate = powf(r / _radius, 2); v.z += (sinf( time*(float)M_PI * _waves * 2 + r * 0.1f) * _amplitude * _amplitudeRate * rate); } setVertex(Vec2(i, j), v); } } }
void Waves::update(float time) { int i, j; for (i = 0; i < _gridSize.width + 1; ++i) { for (j = 0; j < _gridSize.height + 1; ++j) { Vec3 v = getOriginalVertex(Vec2(i, j)); if (_vertical) { v.x = (v.x + (sinf(time * (float)M_PI * _waves * 2 + v.y * .01f) * _amplitude * _amplitudeRate)); } if (_horizontal) { v.y = (v.y + (sinf(time * (float)M_PI * _waves * 2 + v.x * .01f) * _amplitude * _amplitudeRate)); } setVertex(Vec2(i, j), v); } } }
/* * Update each tick * Time is the percentage of the way through the duration */ void PageTurn3D::update(float time) { float tt = MAX(0, time - 0.25f); float deltaAy = (tt * tt * 500); float ay = -100 - deltaAy; float deltaTheta = sqrtf(time); float theta = deltaTheta>0.5?(float)M_PI_2*deltaTheta:(float)M_PI_2*(1-deltaTheta); float rotateByYAxis = (2-time)* M_PI; float sinTheta = sinf(theta); float cosTheta = cosf(theta); for (int i = 0; i <= _gridSize.width; ++i) { for (int j = 0; j <= _gridSize.height; ++j) { // Get original vertex Vec3 p = getOriginalVertex(Vec2(i ,j)); p.x -= getGridRect().origin.x; float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay))); float r = R * sinTheta; float alpha = asinf( p.x / R ); float beta = alpha / sinTheta; float cosBeta = cosf( beta ); // If beta > PI then we've wrapped around the cone // Reduce the radius to stop these points interfering with others if (beta <= M_PI) { p.x = ( r * sinf(beta)); } else { // Force X = 0 to stop wrapped // points p.x = 0; } p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta)); // We scale z here to avoid the animation being // too much bigger than the screen due to perspective transform p.z = (r * ( 1 - cosBeta ) * cosTheta);// "100" didn't work for p.x = p.z * sinf(rotateByYAxis) + p.x * cosf(rotateByYAxis); p.z = p.z * cosf(rotateByYAxis) - p.x * sinf(rotateByYAxis); p.z/=7; // Stop z coord from dropping beneath underlying page in a transition // issue #751 if( p.z < 0.5f ) { p.z = 0.5f; } // Set new coords p.x += getGridRect().origin.x; setVertex(Vec2(i, j), p); } } }
void FlipY3D::update(float time) { float angle = (float)M_PI * time; // 180 degrees float mz = sinf( angle ); angle = angle / 2.0f; // x calculates degrees from 0 to 90 float my = cosf(angle); Vec3 v0, v1, v, diff; v0 = getOriginalVertex(Vec2(1, 1)); v1 = getOriginalVertex(Vec2(0, 0)); float y0 = v0.y; float y1 = v1.y; float y; Vec2 a, b, c, d; if (y0 > y1) { // Normal Grid a = Vec2(0,0); b = Vec2(0,1); c = Vec2(1,0); d = Vec2(1,1); y = y0; } else { // Reversed Grid b = Vec2(0,0); a = Vec2(0,1); d = Vec2(1,0); c = Vec2(1,1); y = y1; } diff.y = y - y * my; diff.z = fabsf(floorf((y * mz) / 4.0f)); // bottom-left v = getOriginalVertex(a); v.y = diff.y; v.z += diff.z; setVertex(a, v); // upper-left v = getOriginalVertex(b); v.y -= diff.y; v.z -= diff.z; setVertex(b, v); // bottom-right v = getOriginalVertex(c); v.y = diff.y; v.z += diff.z; setVertex(c, v); // upper-right v = getOriginalVertex(d); v.y -= diff.y; v.z -= diff.z; setVertex(d, v); }
void FlipX3D::update(float time) { float angle = (float)M_PI * time; // 180 degrees float mz = sinf(angle); angle = angle / 2.0f; // x calculates degrees from 0 to 90 float mx = cosf(angle); Vec3 v0, v1, v, diff; v0 = getOriginalVertex(Vec2(1, 1)); v1 = getOriginalVertex(Vec2(0, 0)); float x0 = v0.x; float x1 = v1.x; float x; Vec2 a, b, c, d; if ( x0 > x1 ) { // Normal Grid a = Vec2(0,0); b = Vec2(0,1); c = Vec2(1,0); d = Vec2(1,1); x = x0; } else { // Reversed Grid c = Vec2(0,0); d = Vec2(0,1); a = Vec2(1,0); b = Vec2(1,1); x = x1; } diff.x = ( x - x * mx ); diff.z = fabsf( floorf( (x * mz) / 4.0f ) ); // bottom-left v = getOriginalVertex(a); v.x = diff.x; v.z += diff.z; setVertex(a, v); // upper-left v = getOriginalVertex(b); v.x = diff.x; v.z += diff.z; setVertex(b, v); // bottom-right v = getOriginalVertex(c); v.x -= diff.x; v.z -= diff.z; setVertex(c, v); // upper-right v = getOriginalVertex(d); v.x -= diff.x; v.z -= diff.z; setVertex(d, v); }
// Overrides void CFlip3DYEx::update(float time) { // float angle = (float)M_PI * time; // 180 degrees float angle = m_from + (m_from - m_to) * time; float mz = sinf( angle ); angle = angle / 2.0f; // x calculates degrees from 0 to 90 float my = cosf(angle); Vertex3F v0, v1, v, diff; v0 = getOriginalVertex(Point(1, 1)); v1 = getOriginalVertex(Point(0, 0)); float y0 = v0.y; float y1 = v1.y; float y; Point a, b, c, d; if (y0 > y1) { // Normal Grid a = Point(0,0); b = Point(0,1); c = Point(1,0); d = Point(1,1); y = y0; } else { // Reversed Grid b = Point(0,0); a = Point(0,1); d = Point(1,0); c = Point(1,1); y = y1; } diff.y = y - y * my; diff.z = fabsf(floorf((y * mz) / 4.0f)); // bottom-left v = getOriginalVertex(a); // v.y = diff.y; v.z += 0;//diff.z; setVertex(a, v); // upper-left v = getOriginalVertex(b); v.y -= 2 * diff.y; v.z -= 2* diff.z; setVertex(b, v); // bottom-right v = getOriginalVertex(c); // v.y = diff.y; v.z += 0;//diff.z; setVertex(c, v); // upper-right v = getOriginalVertex(d); v.y -= 2 * diff.y; v.z -= 2 * diff.z; setVertex(d, v); }