void Looper::smoothLin() { for (size_t i = 0; i < data.size() - 1; i++) { data.at(i) = LinearInterpolate(data.at(i), data.at(i + 1), 0.5); } data.back() = LinearInterpolate(data.back(), data.front(), 0.5); }
bool RayVsAABB(const std::pair<Float3, Float3>& ray, const Float3& mins, const Float3& maxs) { // if both points are rejected by the same plane, then it's an early out unsigned inside = 0; for (unsigned c=0; c<3; ++c) { if ( (ray.first[c] < mins[c] && ray.second[c] < mins[c]) || (ray.first[c] > maxs[c] && ray.second[c] > maxs[c])) return false; inside |= unsigned(ray.first[c] >= mins[c] && ray.first[c] <= maxs[c] && ray.second[c] >= mins[c] && ray.second[c] <= maxs[c]) << c; } // if completely inside, let's consider it an intersection if (inside == 7) return true; // there's a potential intersection. Find the planes that the ray crosses, and find the intersection // point. If the intersection point is inside the aabb, then we have an intersection for (unsigned c=0; c<3; ++c) { { float a = ray.first[c] - mins[c]; float b = ray.second[c] - mins[c]; if ((a<0) != (b<0)) { float alpha = a / (a-b); Float3 intersection = LinearInterpolate(ray.first, ray.second, alpha); // don't test element "c", because we might get floating point creep if ( intersection[(c+1)%3] >= mins[(c+1)%3] && intersection[(c+1)%3] <= maxs[(c+1)%3] && intersection[(c+2)%3] >= mins[(c+2)%3] && intersection[(c+2)%3] <= maxs[(c+2)%3]) return true; } } { float a = ray.first[c] - maxs[c]; float b = ray.second[c] - maxs[c]; if ((a<0) != (b<0)) { float alpha = a / (a-b); Float3 intersection = LinearInterpolate(ray.first, ray.second, alpha); if ( intersection[(c+1)%3] >= mins[(c+1)%3] && intersection[(c+1)%3] <= maxs[(c+1)%3] && intersection[(c+2)%3] >= mins[(c+2)%3] && intersection[(c+2)%3] <= maxs[(c+2)%3]) return true; } } } return false; }
Eigen::VectorXd MyWindow::samplePose(const vector<SimFrame>& frames, double time) { int nFrames = static_cast<int>(frames.size()); int i = 0; if (time <= frames[i].mTime) { return frames[0].mPose; } else { for (i = 0; i < nFrames - 1; ++i) { if (time > frames[i].mTime && time <= frames[i + 1].mTime) { break; } } } if (i + 1 >= nFrames) { return frames[nFrames - 1].mPose; } else { double alpha = (time - frames[i].mTime) / (frames[i + 1].mTime - frames[i].mTime); Eigen::VectorXd result = LinearInterpolate(frames[i].mPose, frames[i + 1].mPose, alpha); return result; } }
double CubicInterpolate(double a, double b, double x) { double x2 = x * x; double x3 = x2 * x; double f = (3 * x2) - (2 * x3); return LinearInterpolate(a, b, f); }
float GetMappedValue(float value, ScalingMap *scalingMap){ unsigned short *bins; unsigned int bin, nextBin; bins = scalingMap->rawValues + ANALOG_SCALING_BINS - 1; bin = nextBin = ANALOG_SCALING_BINS - 1; while (value < *bins && bin > 0){ bins--; bin--; } if (bin == 0 && value < *bins){ return scalingMap->scaledValues[0]; } else{ nextBin = bin; if (bin < ANALOG_SCALING_BINS - 1){ nextBin++; } else{ return scalingMap->scaledValues[ANALOG_SCALING_BINS - 1]; } } float x1 = (float)scalingMap->rawValues[bin]; float y1 = scalingMap->scaledValues[bin]; float x2 = (float)scalingMap->rawValues[nextBin]; float y2 = scalingMap->scaledValues[nextBin]; float scaled = LinearInterpolate(value,x1,y1,x2,y2); return scaled; }
void Contour::linearInterpolate( double z, int ei, DT_Point& p ) { // 获取第ni条边的端点坐标 DT_Point p1, p2; getEdgePoint( ei, p1, p2 ); // 线性插值 p.z = z; LinearInterpolate( p1, p2, p ); }
// for Chugins extending UGen SAMPLE tick ( SAMPLE in ) { // default: this passes whatever input is patched into Chugin if (sync == 0) { if (in > 0) { freq = in; step = table_size * freq / srate; } table_pos += step; } else if (sync == 1) table_pos = table_size * in; while (table_pos > table_size) table_pos -= table_size; int y0, y1, y2, y3; y0 = (int) table_pos; y1 = (y0 + 1) % table_size; y2 = (y0 + 2) % table_size; y3 = (y0 + 3) % table_size; if (interpolate==1) { return LinearInterpolate(current_table[y0], current_table[y1], table_pos - y0); } else if (interpolate==2) { return LagrangeInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } if (interpolate==3) { return CubicInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } else if (interpolate==4) { return HermiteInterpolate(current_table[y0], current_table[y1], current_table[y2], current_table[y3], table_pos - y0); } return current_table[y0]; }
float DeCasteljau( float q1, float q2, float q3, float q4, float t ) { float p1,p2,p3,p12,p23,p; p1 = LinearInterpolate(t,q1,q2); p2 = LinearInterpolate(t,q2,q3); p3 = LinearInterpolate(t,q3,q4); p12 = LinearInterpolate(t,p1,p2); p23 = LinearInterpolate(t,p2,p3); p= LinearInterpolate(t,p12,p23); return p; }
double InterpolatorValue(interpolator_t *interpolator, int subchannel, char *valid) { // Check for invalid if (!interpolator->valid || interpolator->seg == NULL || subchannel < 0 || subchannel >= interpolator->seg->channels) { if (valid != NULL) { *valid = 0; } return 0.0; } //if (t >= interpolator->seg->startTime) double val; if (interpolator->mode == 1) { val = NearestInterpolate(interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->prop); } else if (interpolator->mode == 2) { val = LinearInterpolate(interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->prop); } else if (interpolator->mode == 3) { val = CubicInterpolate(interpolator->values[0][subchannel], interpolator->values[1][subchannel], interpolator->values[2][subchannel], interpolator->values[3][subchannel], interpolator->prop); } else { val = 0.0; } if (valid != NULL) { *valid = 1; } return val; }
void AnimationPath::LinearInterpolatePath(float& increment, int& iter, DataPointListF& DPLF, DataPointList& NewDPL) { float mu = 0; DebugPrint("Increment = ", increment); for(; mu < 1; mu += increment) { DebugPrint("Computing interpolation for mu = ", mu); float newValue = LinearInterpolate(mu, DPLF[iter].value, DPLF[iter+1].value); DebugPrint("Value is: ", newValue); DebugPrint("Creating new data point"); DataPoint dp; dp.value = Utils::ToString(newValue); dp.interpType = DPLF[iter].interpType; dp.time = DPLF[iter].time; DebugPrint("Pushing to new dpl"); NewDPL.push_back(dp); } }
BezierPoint BezierCurve::getPointOnCurve (double timeIndex) { BezierPoint pointAB; BezierPoint pointBC; BezierPoint pointCD; BezierPoint pointABBC; BezierPoint pointBCCD; BezierPoint outputPoint; pointAB = LinearInterpolate (mPointA, mPointB, timeIndex); pointBC = LinearInterpolate (mPointB, mPointC, timeIndex); pointCD = LinearInterpolate (mPointC, mPointD, timeIndex); pointABBC = LinearInterpolate (pointAB, pointBC, timeIndex); pointBCCD = LinearInterpolate (pointBC, pointCD, timeIndex); outputPoint = LinearInterpolate (pointABBC, pointBCCD, timeIndex); return outputPoint; }
double CosineInterpolate(double a, double b, double x) { double ft = x * PI; double f = (1 - cos(ft)) * 0.5; return LinearInterpolate(a, b, f); }
void GeneratePrimitive(OBJECT *Object) { int x,y; int x1,x2,y1,y2; VECTOR3 v; #ifdef INCLUDE_OBJ_STORED if (Object->Primitive!=aDDict_STORED) { Object->VertexNum=0; Object->PolygonNum=0; } #else Object->VertexNum=0; Object->PolygonNum=0; #endif //M_Identity(Object->ModelView); //Object->Primitive=PrimitiveID; switch (Object->Primitive) { #ifdef INCLUDE_OBJ_BOX case aDDict_BOX: { for (int x=0; x<14; x++) Object->AddVertex(BoxVertexData[x*5]/10.0f,BoxVertexData[x*5+1]/10.0f,BoxVertexData[x*5+2]/10.0f,BoxVertexData[x*5+3]/10.0f,BoxVertexData[x*5+4]/10.0f); for (int x=0; x<24; x++) Object->AddPolygon(BoxPolyData[x*7],BoxPolyData[x*7+1],BoxPolyData[x*7+2],BoxPolyData[x*7+3],BoxPolyData[x*7+4],BoxPolyData[x*7+5],BoxPolyData[x*7+6],0.5f,0.5f,1,0,0); } break; #endif #ifdef INCLUDE_OBJ_SPHERE case aDDict_SPHERE: Object->AddVertex(0,-0.5,0,0.5,0); Object->AddVertex(0,0.5,0,0.5,0); float theta,phi; for (x=1; x<Object->Param1-1; x++) { theta=(float)((x/(float)(Object->Param1-1)*180-90)*radtheta); for (int y=0; y<Object->Param2; y++) { phi=y/(float)Object->Param2*360.0f*(float)radtheta; v.x=(float)cos(theta)*(float)cos(phi)*0.5f; v.y=(float)cos(theta)*(float)sin(phi)*0.5f; v.z=(float)sin(theta)*0.5f; Object->AddVertex(v.x,v.z,-v.y,x/(float)Object->Param1,y/(float)Object->Param2); } } for (x=0; x<Object->Param1-1; x++) { x1=(x-1)*Object->Param2; x2=x*Object->Param2; for (int y=0; y<Object->Param2; y++) { y1=y+2; y2=(y+1)%Object->Param2+2; if (x>0 && x<Object->Param1-2) { Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,(x+1)/(float)(Object->Param1),y/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,0,1); Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,x/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,1,1); } else if (x==0) Object->AddPolygon(y2,0,y1,aDDict_GOURAUDSHADE,(1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,(y+1)/(float)Object->Param2,(1)/(float)(Object->Param1),(y)/(float)Object->Param2,1,1,1); else Object->AddPolygon(x1+y1,1,x1+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,1,(y+1)/(float)Object->Param2,(x)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,1,1); } } break; #endif #ifdef INCLUDE_OBJ_CYLINDER case aDDict_CYLINDER: Object->AddVertex(0,-0.5,0,0.5,0.5); Object->AddVertex(0,0.5,0,0.5,0.5); for (y=0; y<Object->Param2+1; y++) { for (x=0; x<Object->Param1; x++) { float theta=(float)((x/(float)Object->Param1*360.0f)*radtheta); v.x=(float)cos(theta)*0.5f; v.y=(float)sin(theta)*0.5f; v.z=-0.5f+y/(float)Object->Param2; Object->AddVertex(v.x,v.z,-v.y,x/(float)Object->Param1,v.z+0.5f); } } for (x=0; x<Object->Param1; x++) { x1=x; x2=(x+1)%Object->Param1; if (Object->Param3) { Object->AddPolygon(0,x1+2,x2+2,0.5f,0.5f,(float)sin(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)sin((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,1,1,1); Object->AddPolygon(x1+Object->Param1*Object->Param2+2,1,x2+Object->Param1*Object->Param2+2,(float)sin(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,0.5f,0.5f,(float)sin((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,1,1,1); } for (int y=0; y<Object->Param2; y++) { y1=y*Object->Param1+2; y2=(y+1)*Object->Param1+2; Object->AddPolygon(x2+y1,x1+y1,x2+y2,aDDict_GOURAUDSHADE,(x+1)/(float)(Object->Param1),y/(float)Object->Param2,x/(float)(Object->Param1),y/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,1,0); Object->AddPolygon(x2+y2,x1+y1,x1+y2,aDDict_GOURAUDSHADE,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,x/(float)(Object->Param1),y/(float)Object->Param2,x/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,1,1); } } break; #endif #ifdef INCLUDE_OBJ_CONE case aDDict_CONE: Object->AddVertex(0,0.5,0,0.5,0.5); Object->AddVertex(0,-0.5,0,0.5,0.5); for (y=1; y<=Object->Param3; y++) { for (x=0; x<Object->Param1; x++) { float theta=(float)((x/(float)Object->Param1*360.0f)*radtheta); v.x=(float)cos(theta)*0.5f*y/(float)Object->Param3; v.y=(float)sin(theta)*0.5f*y/(float)Object->Param3; v.z=-(-0.5f+y/(float)Object->Param3); Object->AddVertex(v.x,v.z,-v.y,v.x+0.5f,v.y+0.5f); } } for (x=0; x<Object->Param1; x++) { x1=x; x2=(x+1)%Object->Param1; Object->AddPolygon(x1+2,0,x2+2,aDDict_GOURAUDSHADE,1,1,1); if (Object->Param2) Object->AddPolygon(1,x1+Object->Param1*(Object->Param3-1)+2,x2+Object->Param1*(Object->Param3-1)+2,1,1,1); for (int y=0; y<Object->Param3-1; y++) { y1=y*Object->Param1+2; y2=(y+1)*Object->Param1+2; Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_GOURAUDSHADE,1,0,1); Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_GOURAUDSHADE,0,1,1); } } break; #endif #ifdef INCLUDE_OBJ_PLANE case aDDict_PLANE: for (x=0; x<=Object->Param1; x++) for (y=0; y<=Object->Param2; y++) Object->AddVertex(x/(float)Object->Param1-0.5f,0,y/(float)Object->Param2-0.5f,x/(float)Object->Param1,y/(float)Object->Param2); for (x=0; x<Object->Param1; x++) { x1=x*(Object->Param2+1); x2=(x+1)*(Object->Param2+1); for (int y=0; y<Object->Param2; y++) { y1=y; y2=(y+1)%(Object->Param2+1); Object->AddPolygon(x1+y1,x2+y1,x2+y2,1,0,1); Object->AddPolygon(x1+y1,x2+y2,x1+y2,0,1,1); } } break; #endif #ifdef INCLUDE_OBJ_CIRCLE case aDDict_CIRCLE: for (x=0; x<Object->Param1; x++) { theta=(float)((x/(float)Object->Param1*360.0f)*radtheta); v.x=(float)cos(theta); v.y=(float)sin(theta); v.z=0; float p=Object->Param2/255.0f*0.5f; Object->AddVertex(v.x*0.5f,v.z,-v.y*0.5f,x/(float)Object->Param1,0); Object->AddVertex(v.x*p,v.z,-v.y*p,x/(float)Object->Param1,1); } for (x=0; x<Object->Param1; x++) { x1=(x)%Object->Param1*2; x2=(x+1)%Object->Param1*2; y1=0; y2=1; Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_FLATSHADE,x/(float)Object->Param1,0,(x+1)/(float)Object->Param1,0,(x+1)/(float)Object->Param1,1,1,0,1); Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_FLATSHADE,x/(float)Object->Param1,0,(x+1)/(float)Object->Param1,1,x/(float)Object->Param1,1,0,1,1); } break; #endif #ifdef INCLUDE_OBJ_LINE case aDDict_LINE: for (x=-1; x<=Object->Param1; x++) { Object->AddVertex(0,0,-0.5f+x/(float)(Object->Param1-1),0,0); /*if (x>0 && x<Object->Param1) Object->AddEdge(x,x+1,-1);*/ } break; #endif #ifdef INCLUDE_OBJ_ARC case aDDict_ARC: for (x=-1; x<=Object->Param1; x++) { float phase=x/(float)(Object->Param1-1)*(float)Object->Param2*radtheta; Object->AddVertex((float)(0.5f*cos(phase)),0,(float)(0.5f*sin(phase)),0,0); /*if (x>0 && x<Object->Param1) Object->AddEdge(x,x+1,-1);*/ } break; #endif #ifdef INCLUDE_OBJ_LOFT case aDDict_LOFT: { VECTOR3 Up=V3_Make(0,1,0); Object->Backface=false; OBJECT *v1,*v2; v1=(OBJECT*)Object->Param1; v2=(OBJECT*)Object->Param2; if (v1 && v2) { bool xc=v1->Param2==360, yc=v2->Param2==360; int v1v=v1->VertexNum-2; int v2v=v2->VertexNum-2; if (xc) v1v--; if (yc) v2v--; int xx=0; if ((v1->VertexNum>1) && (v2->VertexNum>1)) { int xa,ya; for (xa=1;xa<=v1v;xa++) { VECTOR3 va,vb,vc; va=v1->VertexList[xa-1].Position; vb=v1->VertexList[xa].Position; vc=v1->VertexList[xa+1].Position; M_Xformd(v1->ModelView,va,va); M_Xformd(v1->ModelView,vb,vb); M_Xformd(v1->ModelView,vc,vc); VECTOR3 a1=V3_Normalize(V3_Sub(vb,va)); VECTOR3 a2=V3_Normalize(V3_Sub(vc,va)); VECTOR3 dir=V3_Normalize(V3_Add(a1,a2)); VECTOR3 nx=V3_Cross(Up,dir); VECTOR3 ny=V3_Cross(nx,dir); int yy=0; for (ya=1;ya<=v2v;ya++) { VECTOR3 yv=v2->VertexList[ya].Position; M_Xformd(v2->ModelView,yv,yv); VECTOR3 nv=V3_Add(V3_Mults(nx,yv.x),V3_Mults(ny,yv.z)); nv=V3_Add(nv,vb); Object->AddVertex(nv.x,nv.y,nv.z,xx/(float)(v1v-1),yy/(float)(v2v-1)); yy++; } xx++; } if (xc) v1v++; if (yc) v2v++; for (xx=0;xx<=v2v-2;xx++) for (int yy=0;yy<=v1v-2;yy++) { int xa=xx, ya=yy; int x1=xx+1,y1=yy+1; int v2vs=v2v; if (yc) { v2vs--; xa%=v2v-1; x1%=v2v-1; } if (xc) { ya%=v1v-1; y1%=v1v-1; } Object->AddPolygon(ya*v2vs+xa,ya*v2vs+x1,y1*v2vs+x1,aDDict_GOURAUDSHADE,xx/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),(yy+1)/((float)v1v-1),1,0,1); Object->AddPolygon(ya*v2vs+xa,y1*v2vs+x1,y1*v2vs+xa,aDDict_GOURAUDSHADE,xx/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),(yy+1)/((float)v1v-1),xx/((float)v2v-1),(yy+1)/((float)v1v-1),0,1,1); } } } } break; #endif #ifdef INCLUDE_OBJ_FUR case aDDict_FUR: { srand(115); //9,26,30,35,39,46,62,75,79,115,116,126 //135 volt az utolso OBJECT *Host=(OBJECT*)Object->Param5; for (int x=0; x<Host->PolygonNum; x++) { VECTOR3 Ha,Hb,Hc; Ha=Host->VertexList[Host->PolygonList[x].v[0]].Position; Hb=Host->VertexList[Host->PolygonList[x].v[1]].Position; Hc=Host->VertexList[Host->PolygonList[x].v[2]].Position; MATRIX m; memcpy(&m,Host->ModelView,sizeof(MATRIX)); //for (int a=0; a<4; a++) for (int b=0; b<4; b++) m[a][b]=KillFloat(m[a][b],2); M_Xformd(m,Ha,Ha); M_Xformd(m,Hb,Hb); M_Xformd(m,Hc,Hc); VECTOR3 Origin=V3_Mults(V3_Add(V3_Add(Ha,Hb),Hc),1/3.0f); VECTOR3 i=V3_Normalize(V3_Cross(V3_Sub(Hc,Ha),V3_Sub(Hb,Ha))); for (int y=0; y<Object->Param2; y++) { VECTOR3 Random=V3_Normalize(V3_Make((float)rand(),(float)rand(),(float)rand())); VECTOR3 j=V3_Cross(i,Random); VECTOR3 k=V3_Mults(V3_Cross(i,j),0.5f); VECTOR3 a,b,c,d; float r=((rand()/(float)RAND_MAX)-0.5f)*2.0f; i=V3_Mults(i,Object->Param3/255.0f); k=V3_Mults(k,Object->Param1/255.0f); a=V3_Add(Origin,k); b=V3_Add(V3_Add(Origin,k),i); c=V3_Add(V3_Sub(Origin,k),i); d=V3_Sub(Origin,k); Object->AddVertex(a.x,a.y,a.z,0,0); Object->AddVertex(b.x,b.y,b.z,0,1); Object->AddVertex(c.x,c.y,c.z,1,1); Object->AddVertex(d.x,d.y,d.z,1,0); Object->AddPolygon((x*Object->Param2+y)*4,(x*Object->Param2+y)*4+1,(x*Object->Param2+y)*4+2,aDDict_GOURAUDSHADE,1,0,1); Object->AddPolygon((x*Object->Param2+y)*4,(x*Object->Param2+y)*4+2,(x*Object->Param2+y)*4+3,aDDict_GOURAUDSHADE,0,1,1); } } } break; #endif #ifdef INCLUDE_OBJ_SUPERSHAPE case aDDict_SUPERSHAPE: { SUPERSHAPE *s=(SUPERSHAPE*)Object->Param1; for (int x=0; x<=s->Xres; x++) { float phi=LinearInterpolate((float)s->Rangex1,(float)s->Rangex2,x/(float)(s->Xres))/180.0f*3.1415f; float r0=0; if (!s->Sphere) r0=s->Trad0; float r1a=SuperShapeRad(s->SuperShape1.mint+s->SuperShape1.mfloat/255.0f,s->SuperShape1.n1,s->SuperShape1.n2,s->SuperShape1.n3,s->SuperShape1.a,s->SuperShape1.b,phi)+r0; if (s->RadFunc) { float r1; if (s->RadFunc==1) r1=s->Rada*phi; if (s->RadFunc==2) r1=(float)(s->Rada*exp(s->Radb*phi)); r1a*=r1; } float r1=s->Verta*phi; for (int y=0; y<=s->Yres; y++) { float ro=LinearInterpolate((float)s->Rangey1,(float)s->Rangey2,y/(float)(s->Yres))/180.0f*3.1415f; float r2a=SuperShapeRad(s->SuperShape2.mint+s->SuperShape2.mfloat/255.0f,s->SuperShape2.n1,s->SuperShape2.n2,s->SuperShape2.n3,s->SuperShape2.a,s->SuperShape2.b,ro); VECTOR3 pos; if (s->Sphere) pos=V3_Make((float)(r1a*cos(phi )*r2a*cos(ro )),(float)(r1a*sin(phi )*r2a*cos(ro )),(float)(r2a*sin(ro ))); else pos=V3_Make((float)(cos(phi )*(r1a+r2a*cos(ro ))),(float)(sin(phi )*(r1a+r2a*cos(ro ))),(float)(r2a*sin(ro ))); if (s->VertFunc) pos.z*=r1; Object->AddVertex(pos.x,pos.y,pos.z,x/(float)(s->Xres),y/(float)(s->Yres)); } } for (x=0; x<s->Xres; x++) { for (int y=0; y<s->Yres; y++) { Object->AddPolygon(x*(s->Yres+1)+y,(x+1)*(s->Yres+1)+y+1,(x+1)*(s->Yres+1)+y,aDDict_GOURAUDSHADE,0,1,1); Object->AddPolygon(x*(s->Yres+1)+y,(x)*(s->Yres+1)+y+1,(x+1)*(s->Yres+1)+y+1,aDDict_GOURAUDSHADE,1,0,1); } } } break; #endif case -25472: default: break; } #ifdef INCLUDE_OBJ_STORED if (Object->Primitive!=aDDict_STORED) { Object->CalculateTextureCoordinates(); } #else Object->CalculateTextureCoordinates(); #endif for (x=0; x<Object->PolygonNum; x++) { if (Object->Shading!=aDDict_DEFAULTSHADE) Object->PolygonList[x].CurrentShading=Object->Shading; } }
NOISE_DATATYPE cNoise::LinearNoise1D(NOISE_DATATYPE a_X) const { int BaseX = FAST_FLOOR(a_X); NOISE_DATATYPE FracX = a_X - BaseX; return LinearInterpolate(IntNoise1D(BaseX), IntNoise1D(BaseX + 1), FracX); }
/* Refine a triangular mesh by bisecting each edge Forms 3 new triangles for each existing triangle on each iteration Could be made more efficient for drawing if the triangles were ordered in a fan or strip! */ void DomeSplitFace(DOMEFACE *f,int *n) { int i; int n1,n2; n1 = *n; n2 = *n; for (i=0;i<n1;i++) { f[n2].p[0] = MidPoint(f[i].p[0],f[i].p[1]); f[n2].p[1] = f[i].p[1]; f[n2].p[2] = MidPoint(f[i].p[1],f[i].p[2]); f[n2].u[0] = LinearInterpolate(f[i].u[0],f[i].u[1],0.5); f[n2].u[1] = f[i].u[1]; f[n2].u[2] = LinearInterpolate(f[i].u[1],f[i].u[2],0.5); f[n2].v[0] = LinearInterpolate(f[i].v[0],f[i].v[1],0.5); f[n2].v[1] = f[i].v[1]; f[n2].v[2] = LinearInterpolate(f[i].v[1],f[i].v[2],0.5); f[n2+1].p[0] = MidPoint(f[i].p[1],f[i].p[2]); f[n2+1].p[1] = f[i].p[2]; f[n2+1].p[2] = MidPoint(f[i].p[2],f[i].p[0]); f[n2+1].u[0] = LinearInterpolate(f[i].u[1],f[i].u[2],0.5); f[n2+1].u[1] = f[i].u[2]; f[n2+1].u[2] = LinearInterpolate(f[i].u[2],f[i].u[0],0.5); f[n2+1].v[0] = LinearInterpolate(f[i].v[1],f[i].v[2],0.5); f[n2+1].v[1] = f[i].v[2]; f[n2+1].v[2] = LinearInterpolate(f[i].v[2],f[i].v[0],0.5); f[n2+2].p[0] = MidPoint(f[i].p[0],f[i].p[1]); f[n2+2].p[1] = MidPoint(f[i].p[1],f[i].p[2]); f[n2+2].p[2] = MidPoint(f[i].p[2],f[i].p[0]); f[n2+2].u[0] = LinearInterpolate(f[i].u[0],f[i].u[1],0.5); f[n2+2].u[1] = LinearInterpolate(f[i].u[1],f[i].u[2],0.5); f[n2+2].u[2] = LinearInterpolate(f[i].u[2],f[i].u[0],0.5); f[n2+2].v[0] = LinearInterpolate(f[i].v[0],f[i].v[1],0.5); f[n2+2].v[1] = LinearInterpolate(f[i].v[1],f[i].v[2],0.5); f[n2+2].v[2] = LinearInterpolate(f[i].v[2],f[i].v[0],0.5); //f[i].p[0] = f[i].p[0]; f[i].p[1] = MidPoint(f[i].p[0],f[i].p[1]); f[i].p[2] = MidPoint(f[i].p[0],f[i].p[2]); //f[i].u[0] = f[i].u[0]; f[i].u[1] = LinearInterpolate(f[i].u[0],f[i].u[1],0.5); f[i].u[2] = LinearInterpolate(f[i].u[0],f[i].u[2],0.5); //f[i].v[0] = f[i].v[0]; f[i].v[1] = LinearInterpolate(f[i].v[0],f[i].v[1],0.5); f[i].v[2] = LinearInterpolate(f[i].v[0],f[i].v[2],0.5); n2 += 3; } *n = n2; }
void BaseZone::BaseLevelTerrain_ (float32 maxSmoothingFactor, uint32 aboveGroundHeightLimit) { // SNOW: store sector locations that have had level terrain called on them. if this method is called many times over the same area, various problems in the terrain will result uint32 averageTerraHeight; uint32 minHeight = revisedHeightMap_[0]; uint32 maxHeight = minHeight; { uint32 sum = 0; for (uint32 y = 0; y < GetLengthY (); ++y) { for (uint32 x = 0; x < GetLengthX (); ++x) { uint32 height = revisedHeightMap_[x + y * GetLengthX ()]; if (height < minHeight) minHeight = height; if (height > maxHeight) maxHeight = height; sum += height; } } averageTerraHeight = sum / (GetLengthX () * GetLengthY ()); } UPoint3D centerPoint; centerPoint.x = min_.x + GetLengthX () / 2; centerPoint.y = min_.y + GetLengthY () / 2; GetWorld()->BeginModify (); for (uint32 y = min_.y; y <= max_.y; ++y) { for (uint32 x = min_.x; x <= max_.x; ++x) { uint32 distFromCenter = Max (Abs (int32(x) - int32(min_.x + GetLengthX () / 2)), Abs (int32(y) - int32(min_.y + GetLengthY () / 2))); uint32 height = (uint16)revisedHeightMap_[(x - min_.x) + (y - min_.y) * GetLengthX ()]; uint32 smoothHeight = uint32(LinearInterpolate( CosineInterpolate (float(averageTerraHeight), float(height), float(distFromCenter) / float(Max (GetLengthX () / 2, GetLengthY () / 2))), float(height), maxSmoothingFactor) + 0.5f); // slide blocks up or down. some compression or expansion of terrain layers will occur. if (height < smoothHeight) { uint32 difference = smoothHeight - height; Vector<uint32> blockStack; Vector<uint32> aboveGroundBStack; for (uint32 z = height - difference; z <= height; ++z) blockStack.InsertBack (GetWorld()->GetSCube (x, y, z)); for (uint32 z = height + 1; z <= height + aboveGroundHeightLimit; ++z) aboveGroundBStack.InsertBack (GetWorld()->GetSCube (x, y, z)); // expand terrain stack bool incrementI = false; uint32 i = 0; for (uint32 z = height - difference; z <= smoothHeight; ++z) { GetWorld()->SetSCube (x, y, z, blockStack[i]); if (incrementI) ++i; incrementI = !incrementI; } i = 0; for (uint32 z = smoothHeight + 1; z <= smoothHeight + aboveGroundHeightLimit; ++z) { GetWorld()->SetSCube (x, y, z, aboveGroundBStack[i]); ++i; } } else if (height > smoothHeight) { uint32 difference = height - smoothHeight; Vector<uint32> blockStack; Vector<uint32> aboveGroundBStack; for (uint32 z = smoothHeight - difference; z <= height; ++z) blockStack.InsertBack (GetWorld()->GetSCube (x, y, z)); for (uint32 z = height + 1; z <= height + aboveGroundHeightLimit; ++z) aboveGroundBStack.InsertBack (GetWorld()->GetSCube (x, y, z)); // compress terrain stack uint32 i = 0; for (uint32 z = smoothHeight - difference; z <= height; ++z) { if (z <= smoothHeight) { if (z == height || i >= blockStack.GetCount ()) GetWorld()->SetSCube (x, y, z, blockStack[blockStack.GetCount () - 1]); else GetWorld()->SetSCube (x, y, z, blockStack[i]); i += 2; } else { GetWorld()->SetSCube (x, y, z, 0); } } i = 0; for (uint32 z = smoothHeight + 1; z <= smoothHeight + aboveGroundHeightLimit; ++z) { GetWorld()->SetSCube (x, y, z, aboveGroundBStack[i]); ++i; } } // correct revised height map values revisedHeightMap_[(x - min_.x) + (y - min_.y) * GetLengthX ()] = (uint16)smoothHeight; } } GetWorld()->EndModify (); }
cOneParameter cMorph::Linear(const int key, const double factor, const bool angular) { int k1, k2; if (key == dataSets.size() - 1) return dataSets[key].parameter; cOneParameter interpolated = dataSets[key].parameter; cMultiVal val; k1 = key; k2 = key + 1; switch (dataSets[key].parameter.GetValueType()) { case typeNull: case typeString: case typeBool: return None(key); case typeDouble: case typeInt: { double v1, v2; dataSets[k1].parameter.GetMultival(valueActual).Get(v1); dataSets[k2].parameter.GetMultival(valueActual).Get(v2); val.Store(LinearInterpolate(factor, v1, v2, angular)); break; } case typeRgb: { sRGB v1, v2; dataSets[k1].parameter.GetMultival(valueActual).Get(v1); dataSets[k2].parameter.GetMultival(valueActual).Get(v2); val.Store(sRGB(LinearInterpolate(factor, v1.R, v2.R, angular), LinearInterpolate(factor, v1.G, v2.G, angular), LinearInterpolate(factor, v1.B, v2.B, angular))); break; } case typeVector3: { CVector3 v1, v2; dataSets[k1].parameter.GetMultival(valueActual).Get(v1); dataSets[k2].parameter.GetMultival(valueActual).Get(v2); val.Store(CVector3(LinearInterpolate(factor, v1.x, v2.x, angular), LinearInterpolate(factor, v1.y, v2.y, angular), LinearInterpolate(factor, v1.z, v2.z, angular))); break; } case typeVector4: { CVector4 v1, v2; dataSets[k1].parameter.GetMultival(valueActual).Get(v1); dataSets[k2].parameter.GetMultival(valueActual).Get(v2); val.Store(CVector4(LinearInterpolate(factor, v1.x, v2.x, angular), LinearInterpolate(factor, v1.y, v2.y, angular), LinearInterpolate(factor, v1.z, v2.z, angular), LinearInterpolate(factor, v1.w, v2.w, angular))); break; } case typeColorPalette: { cColorPalette v1, v2; cColorPalette out; dataSets[k1].parameter.GetMultival(valueActual).Get(v1); dataSets[k2].parameter.GetMultival(valueActual).Get(v2); for (int i = 0; i < v1.GetSize(); i++) { out.AppendColor(sRGB(LinearInterpolate(factor, v1.GetColor(i).R, v2.GetColor(i).R, angular), LinearInterpolate(factor, v1.GetColor(i).G, v2.GetColor(i).G, angular), LinearInterpolate(factor, v1.GetColor(i).B, v2.GetColor(i).B, angular))); } val.Store(out); break; } } interpolated.SetMultival(val, valueActual); return interpolated; }
double AxisPhysicsModel::GetPosition() { return LinearInterpolate(mPrevState.p, mNextState.p, mProgress); }
double AxisPhysicsModel::GetVelocity() { return LinearInterpolate(mPrevState.v, mNextState.v, mProgress); }
bool CAnimationSpooler::RenderJob_Flat(const CAnimJobUI* pJob, LPDIRECT3DSURFACE9 /*pSurface*/, DWORD dwTick) { RECT rc = pJob->data.plot.rcFrom; FLOAT mu = (FLOAT)(pJob->dwStartTick + pJob->dwDuration - dwTick) / (FLOAT) pJob->dwDuration; FLOAT scale1 = 0.0; if( pJob->data.plot.iInterpolate == CAnimJobUI::INTERPOLATE_LINEAR ) scale1 = (FLOAT) LinearInterpolate(0.0, 1.0, mu); if( pJob->data.plot.iInterpolate == CAnimJobUI::INTERPOLATE_COS ) scale1 = (FLOAT) CosineInterpolate(0.0, 1.0, mu); FLOAT scale2 = 1.0f - scale1; D3DVECTOR ptCenter = { rc.left + ((rc.right - rc.left) / 2.0f), rc.top + ((rc.bottom - rc.top) / 2.0f) }; FLOAT xtrans = (FLOAT) pJob->data.plot.mFrom.xtrans * scale1; FLOAT ytrans = (FLOAT) pJob->data.plot.mFrom.ytrans * scale1; FLOAT ztrans = 1.0f + ((FLOAT) abs(pJob->data.plot.mFrom.ztrans) * (pJob->data.plot.mFrom.ztrans >= 0.0 ? scale1 : scale2)); FLOAT fSin = (FLOAT) sin(pJob->data.plot.mFrom.zrot * scale1); FLOAT fCos = (FLOAT) cos(pJob->data.plot.mFrom.zrot * scale1); DWORD clrAlpha = ((DWORD)(0xFF - (FLOAT) abs(pJob->data.plot.mFrom.alpha) * (pJob->data.plot.mFrom.alpha >= 0 ? scale1 : scale2)) << 24) | 0xffffff; HRESULT Hr = 0; for( int iBuffer = pJob->iBufferStart; iBuffer < pJob->iBufferEnd; iBuffer++ ) { // Lock the vertex buffer and apply transformation LPDIRECT3DVERTEXBUFFER9 pVBuffer = m_p3DVertices[iBuffer]; LPVOID pVertices = NULL; Hr = pVBuffer->Lock(0, sizeof(CUSTOMFAN), &pVertices, 0); if( FAILED(Hr) ) return false; CUSTOMFAN verts; memcpy(verts, m_fans[iBuffer], sizeof(CUSTOMFAN)); for( int i = 0; i < sizeof(CUSTOMFAN) / sizeof(CUSTOMVERTEX); i++ ) { verts[i].x -= ptCenter.x; verts[i].y -= ptCenter.y; verts[i].x += xtrans; // Translate verts[i].y += ytrans; verts[i].x = verts[i].x * ztrans; // Scale verts[i].y = verts[i].y * ztrans; FLOAT x = verts[i].x; FLOAT y = verts[i].y; // Rotate around Z verts[i].x = x * fCos - y * fSin; verts[i].y = x * fSin + y * fCos; verts[i].x += ptCenter.x; verts[i].y += ptCenter.y; verts[i].color = clrAlpha; } memcpy(pVertices, verts, sizeof(CUSTOMFAN)); pVBuffer->Unlock(); // Paint it Hr = m_p3DDevice->SetStreamSource(0, pVBuffer, 0, sizeof(CUSTOMVERTEX)); Hr = m_p3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX); Hr = m_p3DDevice->SetTexture(0, m_p3DTextures[iBuffer]); Hr = m_p3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2); } return true; }