DiffuseUVMaterial::DiffuseUVMaterial() : DiffuseMaterial() { setAlbedo([this](const RayIntersection & isect) { float u = clamp01(isect.u); float v = clamp01(isect.v); return RGBColor(u, v, 0.0f); }); }
DiffuseTextureMaterial::DiffuseTextureMaterial( std::shared_ptr<SurfaceTexture> & tex ) : DiffuseMaterial(), texture(tex) { setAlbedo([this](const RayIntersection & isect) { float u = clamp01(isect.u); float v = clamp01(isect.v); return texture->image.sampleRGB(u, v); }); }
bytearrayset_t* make_masks2(int scales, int width, int height) { char filename[80]; bytearrayset_t*masks = bytearrayset_new_alloc((scales-1)*3+1,width,height); int t; int pos = 0; for(t=0;t<scales;t++) { int dir=0; int s=0; if(t==scales-1) s = 2; //highband for(dir=s;dir<=2;dir++) { int x,y; int mx=width/2,my=height/2; //double r = (1<<(t+1+highband-(t==scales-1 && highband)))/(double)(2<<scales); double r = (t+1-(t==scales-1))/(double)(scales-1); double pr = t/(double)(scales-1); memset(masks->m[pos]->data, 0, width*height); if(t==scales-1 && dir==2) { memset(masks->m[pos]->data, 255, width*height); } for(y=0;y<my;y++) for(x=0;x<mx;x++) { double xx = x/(double)mx; double yy = y/(double)my; double rr = sqrt(xx*xx+yy*yy); double lr = log(rr) / log(2) + (scales-t); double m = cos(clamp01(lr) * M_PI/2); unsigned char dot = clamp01(m)*255; dot = (rr*1.1)<r?255:0; if(dir<2) { if(rr*1.1<pr) dot = 0; } if(t==scales-1 && dir==2) { dot = (rr*1.1)>=r?255:0; } if(dir == 0 || dir==2) masks->m[pos]->data[(height-y)%height*masks->m[t]->width+(width-x)%width] = dot; if(dir == 0 || dir==2) masks->m[pos]->data[(y)*masks->m[t]->width+(x)] = dot; if(dir == 1 || dir==2) masks->m[pos]->data[(y)*masks->m[t]->width+(width-x)%width] = dot; if(dir == 1 || dir==2) masks->m[pos]->data[(height-y)%height*masks->m[t]->width+(x)] = dot; } pos++; } } return masks; }
bytearrayset_t* make_masks(int scales, int width, int height) { char highband=1; char filename[80]; bytearrayset_t*masks = bytearrayset_new_alloc(scales,width,height); int t; highband = !!highband; for(t=0;t<scales;t++) { int x,y; int mx=width/2,my=height/2; double r = (1<<(t+1+highband-(t==scales-1 && highband)))/(double)(1<<scales); //double r = (t+1-(t==scales-1 && highband))/(double)(scales-1); memset(masks->m[t]->data, 0, width*height); if(t==scales-1 && highband) memset(masks->m[t]->data, 255, width*height); int highx = 0; for(y=0;y<my;y++) for(x=0;x<mx;x++) { double xx = x/(double)mx; double yy = y/(double)my; double rr = sqrt(xx*xx+yy*yy); unsigned char dot = 0; if(config_spyr) { double lr = log(rr) / log(2) + (scales-t-highband+(t==scales-1 && highband)); double m = cos(clamp01(lr) * M_PI/2); dot = clamp01(m)*255; if(t==scales-1 && highband) { dot = 255-dot; } } else { dot = (rr*1.1)<r?255:0; if(t==scales-1 && highband) { dot = (rr*1.1)>=r?255:0; } } if(dot && x>highx) highx = x; masks->m[t]->data[(height-y)%height*masks->m[t]->width+(width-x)%width] = dot; masks->m[t]->data[(y)*masks->m[t]->width+(x)] = dot; masks->m[t]->data[(y)*masks->m[t]->width+(width-x)%width] = dot; masks->m[t]->data[(height-y)%height*masks->m[t]->width+(x)] = dot; } //printf("%d %d/%d %d\n", t, highx, mx); } return masks; }
// Stolen from: http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment // Return minimum distance point on line segment vw minimizing the distance to point p PD nearestPointOnLineSegment(PD v, PD w, PD p) { if(epsEq(v, w)) return v; // v == w case. Avoid division by zero. double l2 = distSquared(v, w); // Consider the line extending the segment, parameterized as v + t (w - v). // We find projection of point p onto the line. // It falls where t = [(p-v) . (w-v)] / |w-v|^2 // We clamp t from [0,1] to handle points outside the segment vw. PD wv = w-v; double t = clamp01(dotProduct(p-v, wv) / l2); PD projection = v + (wv * t); // Projection falls on the segment return projection; }
void DominationPointController::Update(double milliseconds) { if (isDominated) { return; } int count = 0; for (auto exp : mExplorers) { if (exp == nullptr || exp->mIsDead) { continue; } // Success only if no predicate was assigned or the assigned predicate is true. if (!mActivationPredicate || mActivationPredicate(exp)) { count++; } } auto dom = static_cast<DominationPoint*>(mSceneObject); auto dt = static_cast<float>(milliseconds) * 0.001f; auto rad = dom->mCollider->mCollider.radius; auto pos = dom->mTransform->GetPosition(); //TRACE_LINE(pos + vec3f(0, rad, 0), pos + vec3f(0, -rad, 0), Colors::red); //TRACE_LINE(pos + vec3f(rad, 0, 0), pos + vec3f(-rad, 0, 0), Colors::red); auto prog = rad * mProgress * 0.72f; //TRACE_LINE(pos + vec3f( prog, prog, 0), pos + vec3f(-prog, -prog, 0), Colors::green); //TRACE_LINE(pos + vec3f( prog, -prog, 0), pos + vec3f(-prog, prog, 0), Colors::green); // progress variation float dp = 0; if (count > 0) { switch (mActivationType) { case ActivationType::Single: dp += dt * mBaseProgressRate; break; case ActivationType::Multiple: dp += dt * (mBaseProgressRate + mBonusProgressRate * (count - 1)); break; } } else { dp -= dt * mDecayRate; } float newProgress = clamp01(mProgress + dp); if (mProgress == newProgress) { return; } // TODO: Fire ChangeProgress callback mProgress = newProgress; if (mProgress == 1) { // TODO: Fire Dominated callback isDominated = true; } }