float filterinteg(float bmin, float bmax, float blurf) { int i1, i2; float f1, f2; float *tab; float mult; bmin /= blurf; bmax /= blurf; tab = shape->tab; mult = (FILTTABSIZE - 1.0) / (2.0 * shape->rad); f1 = ((bmin - shape->min) * mult); i1 = floor(f1); f1 = f1 - i1; if (i1 < 0) f1 = 0.0; else if (i1 >= (FILTTABSIZE - 1)) f1 = 1.0; else f1 = flerp(tab[i1], tab[i1 + 1], f1); f2 = ((bmax - shape->min) * mult); i2 = floor(f2); f2 = f2 - i2; if (i2 < 0) f2 = 0.0; else if (i2 >= (FILTTABSIZE - 1)) f2 = 1.0; else f2 = flerp(tab[i2], tab[i2 + 1], f2); return f2 - f1; }
void game_lerp_apply(struct game_lerp *gl, struct game_draw *gd) { float a = gl->alpha; /* Solid. */ sol_lerp_apply(&gl->lerp, a); /* Particles. */ part_lerp_apply(a); /* Tilt. */ v_lerp(gd->tilt.x, gl->tilt[PREV].x, gl->tilt[CURR].x, a); v_lerp(gd->tilt.z, gl->tilt[PREV].z, gl->tilt[CURR].z, a); gd->tilt.rx = flerp(gl->tilt[PREV].rx, gl->tilt[CURR].rx, a); gd->tilt.rz = flerp(gl->tilt[PREV].rz, gl->tilt[CURR].rz, a); /* View. */ v_lerp(gd->view.c, gl->view[PREV].c, gl->view[CURR].c, a); v_lerp(gd->view.p, gl->view[PREV].p, gl->view[CURR].p, a); e_lerp(gd->view.e, gl->view[PREV].e, gl->view[CURR].e, a); /* Effects. */ gd->goal_k = flerp(gl->goal_k[PREV], gl->goal_k[CURR], a); gd->jump_dt = flerp(gl->jump_dt[PREV], gl->jump_dt[CURR], a); }
void rgba::set_lerp(const rgba& a, const rgba& b, float f) { m_r = (Uint8) frnd(flerp(a.m_r, b.m_r, f)); m_g = (Uint8) frnd(flerp(a.m_g, b.m_g, f)); m_b = (Uint8) frnd(flerp(a.m_b, b.m_b, f)); m_a = (Uint8) frnd(flerp(a.m_a, b.m_a, f)); }
vec3 axial_box::get_random_point() const // Return a random point inside this box. { return vec3( flerp(m_min[0], m_max[0], tu_random::get_unit_float()), flerp(m_min[1], m_max[1], tu_random::get_unit_float()), flerp(m_min[2], m_max[2], tu_random::get_unit_float())); }
void rect::set_lerp(const rect& a, const rect& b, float t) // Set this to the lerp of a and b. { m_x_min = flerp(a.m_x_min, b.m_x_min, t); m_y_min = flerp(a.m_y_min, b.m_y_min, t); m_x_max = flerp(a.m_x_max, b.m_x_max, t); m_y_max = flerp(a.m_y_max, b.m_y_max, t); }
// dyna algorithm int KisToolDyna::applyFilter(qreal mx, qreal my) { /* calculate mass and drag */ qreal mass = flerp(MIN_MASS, MAX_MASS, m_curmass); qreal drag = flerp(MIN_DRAG, MAX_DRAG, m_curdrag * m_curdrag); /* calculate force and acceleration */ qreal fx = mx - m_mouse.curx; qreal fy = my - m_mouse.cury; m_mouse.acc = sqrt(fx * fx + fy * fy); if (m_mouse.acc < MIN_ACC) { return 0; } m_mouse.accx = fx / mass; m_mouse.accy = fy / mass; /* calculate new velocity */ m_mouse.velx += m_mouse.accx; m_mouse.vely += m_mouse.accy; m_mouse.vel = sqrt(m_mouse.velx * m_mouse.velx + m_mouse.vely * m_mouse.vely); m_mouse.angx = -m_mouse.vely; m_mouse.angy = m_mouse.velx; if (m_mouse.vel < MIN_VEL) { return 0; } /* calculate angle of drawing tool */ if (m_mouse.fixedangle) { m_mouse.angx = m_xangle; m_mouse.angy = m_yangle; } else { m_mouse.angx /= m_mouse.vel; m_mouse.angy /= m_mouse.vel; } m_mouse.velx = m_mouse.velx * (1.0 - drag); m_mouse.vely = m_mouse.vely * (1.0 - drag); m_mouse.lastx = m_mouse.curx; m_mouse.lasty = m_mouse.cury; m_mouse.curx = m_mouse.curx + m_mouse.velx; m_mouse.cury = m_mouse.cury + m_mouse.vely; return 1; }
filterapply(filter *f, float mx, float my) { float mass, drag; float fx, fy, force; /* calculate mass and drag */ mass = flerp(1.0,160.0,curmass); drag = flerp(0.00,0.5,curdrag*curdrag); /* calculate force and acceleration */ fx = mx-f->curx; fy = my-f->cury; f->acc = sqrt(fx*fx+fy*fy); if(f->acc<0.000001) return 0; f->accx = fx/mass; f->accy = fy/mass; /* calculate new velocity */ f->velx += f->accx; f->vely += f->accy; f->vel = sqrt(f->velx*f->velx+f->vely*f->vely); f->angx = -f->vely; f->angy = f->velx; if(f->vel<0.000001) return 0; /* calculate angle of drawing tool */ f->angx /= f->vel; f->angy /= f->vel; if(f->fixedangle) { f->angx = 0.6; f->angy = 0.2; } /* apply drag */ f->velx = f->velx*(1.0-drag); f->vely = f->vely*(1.0-drag); /* update position */ f->lastx = f->curx; f->lasty = f->cury; f->curx = f->curx+f->velx; f->cury = f->cury+f->vely; return 1; }
void sol_lerp_apply(struct s_lerp *fp, float a) { int i; for (i = 0; i < fp->mc; i++) { if (fp->mv[i][PREV].pi == fp->mv[i][CURR].pi) fp->vary->mv[i].t = flerp(fp->mv[i][PREV].t, fp->mv[i][CURR].t, a); else fp->vary->mv[i].t = fp->mv[i][CURR].t * a; fp->vary->mv[i].pi = fp->mv[i][CURR].pi; } for (i = 0; i < fp->uc; i++) { e_lerp(fp->vary->uv[i].e, fp->uv[i][PREV].e, fp->uv[i][CURR].e, a); v_lerp(fp->vary->uv[i].p, fp->uv[i][PREV].p, fp->uv[i][CURR].p, a); e_lerp(fp->vary->uv[i].E, fp->uv[i][PREV].E, fp->uv[i][CURR].E, a); fp->vary->uv[i].r = flerp(fp->uv[i][PREV].r, fp->uv[i][CURR].r, a); } }
static void software_trapezoid( float y0, float y1, float xl0, float xl1, float xr0, float xr1) // Fill the specified trapezoid in the software output buffer. { assert(s_render_buffer); int iy0 = (int) ceilf(y0); int iy1 = (int) ceilf(y1); float dy = y1 - y0; for (int y = iy0; y < iy1; y++) { if (y < 0) { continue; } if (y >= s_rendering_box) { return; } float f = (y - y0) / dy; int xl = (int) ceilf(flerp(xl0, xl1, f)); int xr = (int) ceilf(flerp(xr0, xr1, f)); xl = iclamp(xl, 0, s_rendering_box - 1); xr = iclamp(xr, 0, s_rendering_box - 1); if (xr > xl) { memset(s_render_buffer + y * s_rendering_box + xl, 255, xr - xl); } } }
void matrix::set_lerp(const matrix& m1, const matrix& m2, float t) // Set this matrix to a blend of m1 and m2, parameterized by t. { m_[0][0] = flerp(m1.m_[0][0], m2.m_[0][0], t); m_[1][0] = flerp(m1.m_[1][0], m2.m_[1][0], t); m_[0][1] = flerp(m1.m_[0][1], m2.m_[0][1], t); m_[1][1] = flerp(m1.m_[1][1], m2.m_[1][1], t); m_[0][2] = flerp(m1.m_[0][2], m2.m_[0][2], t); m_[1][2] = flerp(m1.m_[1][2], m2.m_[1][2], t); }
void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _numVertices, uint32_t _stride, float _step) { bx::RngMwc rng; uint8_t* vertex = (uint8_t*)_vertices; float center[3]; float* position = (float*)&vertex[0]; center[0] = position[0]; center[1] = position[1]; center[2] = position[2]; position = (float*)&vertex[1*_stride]; center[0] += position[0]; center[1] += position[1]; center[2] += position[2]; center[0] *= 0.5f; center[1] *= 0.5f; center[2] *= 0.5f; float xx = position[0] - center[0]; float yy = position[1] - center[1]; float zz = position[2] - center[2]; float maxDistSq = xx*xx + yy*yy + zz*zz; float radiusStep = _step * 0.37f; bool done; do { done = true; for (uint32_t ii = 0, index = rng.gen()%_numVertices; ii < _numVertices; ++ii, index = (index + 1)%_numVertices) { position = (float*)&vertex[index*_stride]; float xx = position[0] - center[0]; float yy = position[1] - center[1]; float zz = position[2] - center[2]; float distSq = xx*xx + yy*yy + zz*zz; if (distSq > maxDistSq) { done = false; center[0] += xx * radiusStep; center[1] += yy * radiusStep; center[2] += zz * radiusStep; maxDistSq = flerp(maxDistSq, distSq, _step); break; } } } while (!done); _sphere.m_center[0] = center[0]; _sphere.m_center[1] = center[1]; _sphere.m_center[2] = center[2]; _sphere.m_radius = sqrtf(maxDistSq); }
void morph2_character_def::display(character* inst) { int i; float ratio = inst->m_ratio; // bounds rect new_bound; new_bound.set_lerp(m_shape1->get_bound_local(), m_shape2->get_bound_local(), ratio); set_bound(new_bound); // fill styles for (i=0; i < m_fill_styles.size(); i++) { fill_style* fs = &m_fill_styles[i]; const fill_style& fs1 = m_shape1->get_fill_styles()[i]; const fill_style& fs2 = m_shape2->get_fill_styles()[i]; fs->set_lerp(fs1, fs2, ratio); } // line styles for (i=0; i < m_line_styles.size(); i++) { line_style& ls = m_line_styles[i]; const line_style& ls1 = m_shape1->get_line_styles()[i]; const line_style& ls2 = m_shape2->get_line_styles()[i]; ls.m_width = (Uint16)frnd(flerp(ls1.get_width(), ls2.get_width(), ratio)); ls.m_color.set_lerp(ls1.get_color(), ls2.get_color(), ratio); } // shape int k = 0, n = 0; for (i = 0; i < m_paths.size(); i++) { path& p = m_paths[i]; const path& p1 = m_shape1->get_paths()[i]; // Swap fill styles -- for some reason, morph // shapes seem to be defined with their fill // styles backwards! p.m_fill0 = p1.m_fill1; p.m_fill1 = p1.m_fill0; p.m_line = p1.m_line; p.m_ax = flerp(p1.m_ax, m_shape2->get_paths()[n].m_ax, ratio); p.m_ay = flerp(p1.m_ay, m_shape2->get_paths()[n].m_ay, ratio); // edges; int len = p1.m_edges.size(); p.m_edges.resize(len); for (int j=0; j < p.m_edges.size(); j++) { p.m_edges[j].m_cx = flerp(p1.m_edges[j].m_cx, m_shape2->get_paths()[n].m_edges[k].m_cx, ratio); p.m_edges[j].m_cy = flerp(p1.m_edges[j].m_cy, m_shape2->get_paths()[n].m_edges[k].m_cy, ratio); p.m_edges[j].m_ax = flerp(p1.m_edges[j].m_ax, m_shape2->get_paths()[n].m_edges[k].m_ax, ratio); p.m_edges[j].m_ay = flerp(p1.m_edges[j].m_ay, m_shape2->get_paths()[n].m_edges[k].m_ay, ratio); k++; if (m_shape2->get_paths()[n].m_edges.size() <= k) { k = 0; n++; } } } // display matrix mat = inst->get_world_matrix(); cxform cx = inst->get_world_cxform(); float max_error = 20.0f / mat.get_max_scale() / inst->get_parent()->get_pixel_scale(); if (ratio != m_last_ratio) { delete m_mesh; m_last_ratio = ratio; m_mesh = new mesh_set(this, max_error * 0.75f); } m_mesh->display(mat, cx, m_fill_styles, m_line_styles); }
int InterpretCameraForUse(NVAnimObject *Cam, double Moment, osg::Vec3 &EyePoint, osg::Quat &Orientation, float &HFOV) { int NumValid; float HFOV_S, HFOV_N, HFOV_E; NumValid = Cam->GetBracketingKeyFrames(Moment, PrevKey, NextKey, false); // don't use caching yet, we're not set up for it if(NumValid) { if(NumValid == 2) { // interpolate double KeyTimeDif, MomentTimeDif; //determine interpolation fraction KeyTimeDif = NextKey->GetTimeValue() - PrevKey->GetTimeValue(); MomentTimeDif = Moment - PrevKey->GetTimeValue(); if(KeyTimeDif > 0.0 && MomentTimeDif >= 0.0) // do rationality checking before a risky divide { double MomentFrac; osg::Vec3 EyePoint_S, EyePoint_E; osg::Quat Orientation_S, Orientation_E; MomentFrac = MomentTimeDif / KeyTimeDif; // divide by zero prevented by rationality checking above MiscReadout = MomentFrac; if(MomentFrac > 1.0) { Cam->GetBracketingKeyFrames(Moment, PrevKey, NextKey, false); // trace only } // if // HFOV HFOV_S = PrevKey->ChannelValues[NVAnimObject::CANONHANGLE]; HFOV_E = NextKey->ChannelValues[NVAnimObject::CANONHANGLE]; HFOV_N = flerp(MomentFrac, HFOV_S, HFOV_E); HFOV = HFOV_N; // create start and end eye/orient pairs InterpretCameraConfiguration(PrevKey, EyePoint_S, Orientation_S); InterpretCameraConfiguration(NextKey, EyePoint_E, Orientation_E); // Eye position EyePoint = EyePoint_S + ((EyePoint_E - EyePoint_S) * MomentFrac); // Orientation quat via slerp Orientation.slerp(MomentFrac, Orientation_S, Orientation_E); return(1); } // if else { // drop back ten and punt by going with NumValid == 1 code below NumValid = 1; } // else } // if if(NumValid == 1) // not an else-if, this is a fail-safe case if the above NumValid=2 fails somehow { // only have one, only use PrevKey, NextKey is identical and tweening would be a waste of time InterpretCameraConfiguration(PrevKey, EyePoint, Orientation); HFOV = PrevKey->ChannelValues[NVAnimObject::CANONHANGLE]; } // else } // if return(0); } // InterpretCameraForUse