📄 global.h
字号:
} void setr(double d) {r=d;} void setg(double d) {g=d;} void setb(double d) {b=d;} void setf(double d) {f=d;} double filter() {return f;} color operator*(color& c){return color(r*c.r,g*c.g,b*c.b,f*c.f);} operator intensity() {return intensity(r,g,b);} intensity operator*(intensity& i) {return intensity(r*i.r,g*i.g,b*i.b);}};class finish;class fog {};class pigment { friend ostream& operator<<(ostream& o, pigment& p);protected: color q; // QUICK COLOR vector t; // TURBULENCE int o; // OCTAVES double m; // OMEGA double l; // LAMBDA double f, p; // FREQUENCY, PHASE xform T; // TRANSFORMATIONpublic: virtual void out(ostream& o) {} pigment() {t=vector(0.,0.,0.); o=6; m=.5; l=2.; f=1.; p=0.;} virtual ~pigment() {} void operator|=(pigment& p) { t=p.t; o=p.o; m=p.m; l=p.l; f=p.f; this->p=p.p; T=p.T; } void setq(color& q) {this->q=q;} void sett(vector& t) {this->t=t;} void seto(int o) {this->o=o;} void setm(double m) {this->m=m;} void setl(double l) {this->l=l;} void setf(double f) {this->f=f;} void setp(double p) {this->p=p;} void traT(vector& v) {T+=v;} void rotT(vector& v) {T<<=v;} void scaT(vector& v) {T*=v;} virtual pigment* copy() {pigment *p=new pigment; *p=*this; return p;} virtual color paint(vector& p) {return q;} color surfcolor(vector& p) {return paint(T/p);}};class solid : public pigment { color c;public: solid() {c=color(1.,1.,1.); setq(c);} solid(color& c) {this->c=c; setq(c);} void out(ostream& o) {o<<"color "<<c<<"\n";} pigment* copy() {solid *p=new solid; *p=*this; return p;} color paint(vector& p) {return c;}};class checker : public pigment { color c1, c2;public: checker() {c1=color(0.,0.,1.,0.); c2=color(0.,1.,0.,0.);} checker(color& c1) {this->c1=c1; c2=color(0.,1.,0.,0.);} checker(color& c1, color& c2) {this->c1=c1; this->c2=c2;} void out(ostream& o) {o<<"checker color "<<c1<<" color "<<c2<<"\n";} pigment* copy() {checker *p=new checker; *p=*this; return p;} color paint(vector& p) {return (((int)p[0]+(int)p[1]+(int)p[2])%2)?c2:c1;}};class hexagon : public pigment { color c1, c2, c3;public: hexagon() { c1=color(0.,0.,1.,0.); c2=color(0.,1.,0.,0.); c3=color(1.,0.,0.,0.); } hexagon(color& c1) {this->c1=c1; c2=color(0.,1.,0.,0.); c3=color(1.,0.,0.,0.);} hexagon(color& c1, color& c2) {this->c1=c1; this->c2=c2; c3=color(1.,0.,0.,0.);} hexagon(color& c1, color& c2, color& c3) {this->c1=c1; this->c2=c2; this->c3=c3;} pigment* copy() {hexagon *p=new hexagon; *p=*this; return p;} color paint(vector& p) {return c1;}};struct colormapitem { double b, e; // BEGIN, END VALUES color cb, ce; // BEGIN, END COLORS colormapitem() {b=0.; e=1.; cb=color(0.,0.,0.); ce=color(1.,1.,1.);} colormapitem(double b, double e, color& cb, color& ce) {this->b=b; this->e=e; this->cb=cb; this->ce=ce;}};class colormap { friend ostream& operator<<(ostream& o, colormap& m); friend class colormapped; colormapitem *I; int nI;public: colormap() {I=new colormapitem; nI=1;} virtual ~colormap() {delete I;} colormap& operator=(colormap& m) { delete I; I=new colormapitem[m.nI]; for(register int i=0; i<m.nI; i++) I[i]=m.I[i]; nI=m.nI; return *this; } void operator+=(colormapitem& J) { colormapitem *K=new colormapitem[nI+1]; for(register int i=0; i<nI; i++) K[i]=I[i]; K[nI]=J; delete I; I=K; nI=nI+1; } colormap* copy() {colormap*p=new colormap; *p=*this; return p;}};class colormapped : public pigment { friend ostream& operator<<(ostream& o, colormapped& m);public: colormap cm; colormapped() {} virtual ~colormapped() {} pigment* copy() {colormapped*p=new colormapped; *p=*this; return p;}};class gradient : public colormapped {};class marble : public colormapped {};class wood : public colormapped {};class onion : public colormapped {};class leopard : public colormapped {};class granite : public colormapped {};class bozo : public colormapped {};class spotted : public colormapped {};class agate : public colormapped {};class mandel : public colormapped {};class radial : public colormapped {};// TEXTURES - II. NORMALclass normal { friend ostream& operator<<(ostream& o, normal& n); vector t; // TURBULENCE double f, p; // FREQUENCY, PHASE xform T; // TRANSFORMATIONpublic: virtual void out(ostream& o) {} normal() {t=vector(0.,0.,0.); f=1.; p=0.;} virtual ~normal() {} void operator|=(normal& n) { t=n.t; f=n.f; p=n.p; T=n.T; } void sett(vector& t) {this->t=t;} void setf(double f) {this->f=f;} void setp(double p) {this->p=p;} void traT(vector& v) {T+=v;} void rotT(vector& v) {T<<=v;} void scaT(vector& v) {T*=v;} virtual normal* copy() {normal *n=new normal; *n=*this; return n;} virtual vector perturbate(vector& n,vector& p) {return n;} vector surfnormal(vector& n,vector& p) { return norm(T<<perturbate(norm(T>>n),T*p)); }};class bumps : public normal { double p; // PERTURBATIONpublic: void out(ostream& o) {o<<"bumps "<<p<<"\n";} bumps() {p=.4;} bumps(double d) {p=d;} normal* copy() {bumps *n=new bumps; *n=*this; return n;} vector perturbate(vector& n,vector& p) { double theta,phi,nx,ny,nz; theta=acos(n.get_z())+RAD((double)rand()*this->p); phi=atan(n.get_y()/n.get_x())+RAD((double)rand()*this->p); /*double k=RAD(p%p); theta=acos(n.get_z())+RAD(sin(k)*this->p); phi=atan(n.get_y()/n.get_x())+RAD(cos(k)*this->p);*/ nz=cos(theta); nx=sqrt((1-nz*nz)/(1+tan(phi)*tan(phi))); ny=nx*tan(phi); n=vector(nx,ny,nz); return n; }};class dents : public normal { double d; // DENTINGpublic: void out(ostream& o) {o<<"dents "<<d<<"\n";} dents() {d=.4;} dents(double d) {this->d=d;} normal* copy() {dents *n=new dents; *n=*this; return n;} vector perturbate(vector& n,vector& p) {return n;}};class ripples : public normal {};class waves : public normal {};class wrinkles : public normal {};class bumpmap : public normal {};// TEXTURES - III. FINISHclass finish { friend ostream& operator<<(ostream& o, finish& f); double kd, kb, kc; // DIFFUSE, BRILLIANCE, CRAND double ka; // AMBIENT double kr; // REFLECTION double ks, kp, kh, kg; // PHONG, SPECULAR HIGHLIGHTS int km; // METALLIC double kt, ki; // REFRACTION, INDEX OF REFR.public: finish() { kd=.6; kb=0.; kc=0.; ka=.1; kr=0.; ks=0.; kp=40.; kh=0.; kg=.05; km=0; kt=0.; ki=1.; } void setkd(double d) {kd=d;} void setkb(double d) {kb=d;} void setkc(double d) {kc=d;} void setka(double d) {ka=d;} void setkr(double d) {kr=d;} void setks(double d) {ks=d;} void setkp(double d) {kp=d;} void setkh(double d) {kh=d;} void setkg(double d) {kg=d;} void setkm(int i) {km=i;} void setkt(double d) {kt=d;} void setki(double d) {ki=d;} finish* copy() {finish *f=new finish; *f=*this; return f;} intensity surfoptics(color& c, vector& n, ray& r, intersect& i);};// TEXTURES - IV. TOP LEVELclass texture { friend ostream& operator<<(ostream& o, texture& t); pigment *p; normal *n; finish *f;protected: list<texture*> *l; xform T;public: texture() {p=new solid;n=new normal;f=new finish;l=new list<texture*>;} virtual ~texture() { delete p; delete n; delete f; for(texture* t=l->first(); t; t=l->next()) delete t; delete l; } texture& operator=(texture& t) { delete p; p=t.p->copy(); delete n; n=t.n->copy(); delete f; f=t.f->copy(); for(texture* x=l->first(); x; x=l->next()) delete x; delete l; l=new list<texture*>; for(texture* p=t.l->first(); p; p=t.l->next()) *l+=p->copy(); return *this; } void operator+=(texture* t) {*l+=t;} virtual void out(ostream& o) { o<<"texture {\n"; o<<*p; o<<*n; o<<*f; o<<T<<"}\n"; for(texture* x=l->first(); x; x=l->next()) o<<*x; } void setp(pigment& p) {delete this->p; this->p=p.copy();} void setn(normal& n) {delete this->n; this->n=n.copy();} void setf(finish& f) {delete this->f; this->f=f.copy();} void traT(vector& v) {T+=v;} void rotT(vector& v) {T<<=v;} void scaT(vector& v) {T*=v;} pigment* copyp() {return p->copy();} normal* copyn() {return n->copy();} finish* copyf() {return f->copy();} virtual texture* copy() {texture* t=new texture; *t=*this; return t;} virtual intensity shade(ray& r, intersect& i) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -