示例#1
0
T3DObject3DText::T3DObject3DText(T3DScene *iscene) : T3DGeoObject(iscene)
{
	content=addparam(_qstr("Content"),SC_valname_string)->content.G_content_string();
	depth=addparam(_qstr("Depth"),SC_valname_scalar)->content.G_content_scalar();
	unitdirx=G_valuecontent<Tvector>(&addparam(_qstr("UnitX"),SC_valname_vector)->content);
	unitdiry=G_valuecontent<Tvector>(&addparam(_qstr("UnitY"),SC_valname_vector)->content);
	*unitdirx=Tvector(1,0,0);
	*unitdiry=Tvector(0,1,0);
	cancache->copyfrom(false);
}
示例#2
0
void T3DControl_Text::render_impl(Trendercontext *rc, const TObjectRenderStatus *status)
{
	double x0=G_controlposx();
	double y0=G_controlposy();
	double z0=G_offset();
	double sy=G_sizeunit();


	QString str;
	content->tostring(str,0);
	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	rc->rendertext(DEFAULT_FONT,&Tvertex(x0,y0+sy/4,z0),
		&Tvector(G_textsize(),0,0),
		&Tvector(0,G_textsize(),0),str,0);
}
示例#3
0
Tvector Tvector::crossProduct(const Tvector &v1, const Tvector &v2)
{
    float x = (v1.y ()* v2.z ()) - (v1.z ()* v2.y ());
    float y = (v1.z ()* v2.x ()) - (v1.x ()* v2.z ());
    float z = (v1.x ()* v2.y ()) - (v1.y ()* v2.x ());
    return Tvector(x, y, z);
}
示例#4
0
void T3DControl_Scalar::render_impl(Trendercontext *rc, const TObjectRenderStatus *status)
{
	double x0=G_controlposx();
	double y0=G_controlposy();
	double z0=G_offset();
	double sx=sizex->G_val();
	double sy=G_sizeunit();

	double vl=value->G_val();
	int digitcount=decimalcount->G_intval();

	RenderGenericBackGround(rc);

	TCHAR formatstr[100];
	CString str;
	_stprintf_s(formatstr,99,_qstr("%%0.%dlf"),digitcount);
	str.Format(formatstr,vl);

	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	rc->rendertext(DEFAULT_FONT,&Tvertex(x0+sy/10,y0+sy/4,z0),
		&Tvector(G_textsize(),0,0),
		&Tvector(0,G_textsize(),0),str,0);

	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	render_frame(rc,x0,y0,sx,sy,z0+G_offset());

	//draw range
	x0=G_controlposx()+sizex->G_val()+G_sizeunit()/5;
	y0=y0+sy/2;
	sx=rangesizex->G_val()-G_sizeunit()/5;
	if (sx>0)
	{
		double x1=sx*(value->G_val()-vmin->G_val())/(vmax->G_val()-vmin->G_val());
		if (x1<0) x1=0;if (x1>sx) x1=sx;
		x1+=x0;
		glLineWidth(2.0f);
		glBegin(GL_LINES);
		glVertex3d(x0,y0,z0);
		glVertex3d(x0+sx,y0,z0);
		glVertex3d(x1,y0-sy/4,z0);
		glVertex3d(x1,y0+sy/4,z0);
		glEnd();
	}

}
示例#5
0
void T3DControl_List::render_impl(Trendercontext *rc, const TObjectRenderStatus *status)
{
	QString str;

	double x0=G_controlposx();
	double y0=G_controlposy();
	double z0=G_offset();
	double sx=sizex->G_val();

	TSC_color *backcol=G_scene()->G_backcolor();

	TQXColor col_foreground(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	TQXColor col_background(backcol->G_R(),backcol->G_G(),backcol->G_B(),backcol->G_A());
	TQXColor selcl1=3*col_background+col_foreground;
	TQXColor selcl2=selcl1.IntensIncr(0.25)+0.2*TQXColor(0.0,1.0,0.0);

	int linecount=county->G_intval();
	double unity=G_sizeunit();

	RenderGenericBackGround(rc);

	for (int i=0; i<list->G_size(); i++)
		if ((i-offset>=0)&&(i-offset<linecount))
		{
			double yps=y0+unity/10+unity*(linecount-1-(i-offset));
			if (i==selectidx->G_intval())
			{
				rc->set_color((rendercolor.G_R()+backcol->G_R())/2,(rendercolor.G_G()+backcol->G_G())/2,(rendercolor.G_B()+backcol->G_B())/2,(rendercolor.G_A()+backcol->G_A())/2);
				render_rect2(rc,x0,yps,sx,unity,z0,selcl1,selcl2);
			}
			list->get(i)->tostring(str);
			rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
			rc->rendertext(DEFAULT_FONT,&Tvertex(x0+unity/10,yps+unity/4,z0+G_offset()),
				&Tvector(G_textsize(),0,0),
				&Tvector(0,G_textsize(),0),str,0);
		}

	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	render_frame(rc,x0,y0,sx,unity*linecount,z0+G_offset());
}
示例#6
0
void T3DControl_Edit::render_impl(Trendercontext *rc, const TObjectRenderStatus *status)
{
	double x0=G_controlposx();
	double y0=G_controlposy();
	double z0=G_offset();
	double sx=sizex->G_val();
	double sy=G_sizeunit();

	RenderGenericBackGround(rc);

	QString str;
	str=content->G_string();
	if (G_isactive())
		str+=_qstr("|");
	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	rc->rendertext(DEFAULT_FONT,&Tvertex(x0+sy/10,y0+sy/4,z0),
		&Tvector(G_textsize(),0,0),
		&Tvector(0,G_textsize(),0),str,0);

	rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	render_frame(rc,x0,y0,sx,sy,z0+G_offset());
}
示例#7
0
void T3DControl_Button::render_impl(Trendercontext *rc, const TObjectRenderStatus *status)
{
	double x0=G_controlposx();
	double y0=G_controlposy();
	double z0=G_offset();
	double sx=sizex->G_val();
	double sy=G_sizeunit();



	QString str;
	content->tostring(str,0);

	//rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());
	rc->set_color(0.2,0.8,0.2,rendercolor.G_A());
	rc->rendertext(DEFAULT_FONT,&Tvertex(x0+sy/5,y0+sy/4,z0),
		&Tvector(G_textsize(),0,0),
		&Tvector(0,G_textsize(),0),str,0);

	//rc->set_color(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());

	double lx=sx;double ly=sy;
	double oo=sy/4;
	glLineWidth(3.0f);
	glBegin(GL_LINE_LOOP);
	glVertex3d(x0+oo,y0,z0);
	glVertex3d(x0+lx-oo,y0,z0);
	glVertex3d(x0+lx,y0+oo,z0);
	glVertex3d(x0+lx,y0+ly-oo,z0);
	glVertex3d(x0+lx-oo,y0+ly,z0);
	glVertex3d(x0+oo,y0+ly,z0);
	glVertex3d(x0,y0+ly-oo,z0);
	glVertex3d(x0,y0+oo,z0);
	glEnd();

	//render_frame(x0,y0,sx,sy,z0+G_offset());
}
示例#8
0
void T2DContourset::generate(TSC_functor *functor, double minv, double maxv, int count)
{
	if (count<2) throw QError(_qstr("Generate contour: invalid number of points"));

	try{
		double vl,vl1,vl2,dff;
		Tvertex pt,pt1,pt2;
		Tvector tangent,norm;
		TSC_funcarglist arglist(NULL);
		TSC_value retval0,arg;
		arg.createtype(GetTSCenv().G_datatype(SC_valname_scalar));
		arglist.add(&arg);
		dff=(maxv-minv)/count/50;
		for (int i=0; i<count; i++)
		{
			vl=minv+(maxv-minv)*i/(count-1.0);
			vl1=vl-dff/2;
			vl2=vl+dff/2;
			arg.copyfrom(vl);functor->eval(&arglist,&retval0);pt=*G_valuecontent<Tvertex>(&retval0);
			arg.copyfrom(vl1);functor->eval(&arglist,&retval0);pt1=*G_valuecontent<Tvertex>(&retval0);
			arg.copyfrom(vl2);functor->eval(&arglist,&retval0);pt2=*G_valuecontent<Tvertex>(&retval0);
			tangent.subtr(&pt2,&pt1);
			norm.vecprod(&tangent,&Tvector(0,0,1));norm.normfrom(&norm);
			addpoint(&pt,&norm);
		}
	}
	catch(TSC_runerror err)
	{
		QString errstring;
		FormatString(errstring,_text("Generate contour: ^1"),err.G_content());
		throw QError(errstring);
	}
	catch(QError err)
	{
		QString errstring;
		FormatString(errstring,_text("Generate contour: ^1"),err.G_content());
		throw QError(errstring);
	}
}
示例#9
0
const Tvector Tvector::negatived()
{
    return Tvector(-x(),-y(),-z());
}
示例#10
0
const Tvector Tvector::operator -() const
{
    return Tvector(-x(),-y(),-z());
}
示例#11
0
const Tvector Tvector::operator +(const Tvector v) const
{
    return Tvector(x() + v.x (),y() + v.y (), z() + v.z ());
}
示例#12
0
const Tvector Tvector::operator /(float f)
{
    return Tvector(x()/f,y()/f,z()/f);
}
示例#13
0
const Tvector Tvector::operator *(float f) const
{
    return Tvector(x()*f, y()*f,z()*f);
}
示例#14
0
const Tvector Tvector::operator -(Tvector v)
{
    return Tvector(x() - v.x (), y() - v.y () , z() - v.z ());
}
示例#15
0
void T3DControl_Menu::rendermenu(T3DControl_Menu_Item *parentitem, Trendercontext *rc, double x0, double y0)
{
	StrPtr texturename=G_texturename();
	T3DTexture *texture=NULL;
	if (qstrlen(texturename)>0)
	{
		texture=parentframe->G_texture(texturename);
		if (texture==NULL)
		{
			QString errstr;FormatString(errstr,_text("Could not find texture '^1'"),texturename);
			throw QError(errstr);
		}
	}

	TQXColor col_foreground(rendercolor.G_R(),rendercolor.G_G(),rendercolor.G_B(),rendercolor.G_A());

	TSC_color *backcol=G_scene()->G_backcolor();
	TQXColor col_background(backcol->G_R(),backcol->G_G(),backcol->G_B(),backcol->G_A());

	TQXColor col_menuback=6*col_background+col_foreground;


	TQXColor col_sel=TQXColor(0,0.7,0);

	TQXColor col_menubacksel=1.5*col_background+col_foreground;

	TQXColor col_menubackactivesel=col_menubacksel+1.5*col_sel;

	if (texture!=NULL)
	{
		col_menuback=col_foreground;
		col_menubacksel=col_foreground;
		col_menubackactivesel=col_sel;
	}


	double z0=G_offset();
	double sx=sizex->G_val();
	double yp=y0;
	for (int i=0; i<parentitem->subitems.G_count(); i++)
	{
		T3DControl_Menu_Item *item=parentitem->subitems[i];
		double lineh=GetItemH(*item);

		TQXColor cl1=col_menuback;
		if (i==parentitem->cursubsel)
		{
			cl1=col_menubacksel;
			if (G_isactive())
				cl1=col_menubackactivesel;
		}

		TQXColor cl2=cl1;
		if (texture==NULL)
			cl2=cl1.IntensIncr(0.10)+0.05*TQXColor(0.0,1.0,0.0);
		cl1.set(cl1.G_r(),cl1.G_g(),cl1.G_b(),col_foreground.G_a());
		cl2.set(cl2.G_r(),cl2.G_g(),cl2.G_b(),col_foreground.G_a());

		if (texture!=NULL) texture->select(rc);
		render_rect2(rc,x0,yp-lineh,sx,lineh,z0,cl1,cl2);
		if (texture!=NULL) texture->unselect(rc);

		if (!item->IsSeparator())
		{
			rc->set_color(0,0,0,col_foreground.G_a());
			rc->rendertext(DEFAULT_FONT,&Tvertex(x0+0.7*lineh+G_textsize()/15,yp-lineh+lineh/4-G_textsize()/15,z0+G_offset()/2),
				&Tvector(G_textsize(),0,0),
				&Tvector(0,G_textsize(),0),item->name,0);

			rc->set_color(col_foreground.G_r(),col_foreground.G_g(),col_foreground.G_b(),col_foreground.G_a());
			rc->rendertext(DEFAULT_FONT,&Tvertex(x0+0.7*lineh,yp-lineh+lineh/4,z0+G_offset()),
				&Tvector(G_textsize(),0,0),
				&Tvector(0,G_textsize(),0),item->name,0);
		}
		else
		{
			rc->set_color(col_foreground.G_r(),col_foreground.G_g(),col_foreground.G_b(),col_foreground.G_a());
			//render_rect(rc,x0,yp,sx,lineh/3,z0+G_offset());
			render_rect2(rc,x0,yp-lineh/2-lineh/6,sx,lineh/3,z0+G_offset(),3*col_foreground+col_menuback,6*col_foreground+col_menuback);
		}

		if (item->checked)
		{
			double oo=lineh/8;
			glLineWidth(2.0f);
			glBegin(GL_LINE_STRIP);
			glVertex3d(x0+lineh/4-oo,yp-lineh+0.4*lineh+oo,z0+G_offset());
			glVertex3d(x0+lineh/4,yp-lineh+0.4*lineh,z0+G_offset());
			glVertex3d(x0+lineh/4+2*oo,yp-lineh+0.4*lineh+2*oo,z0+G_offset());
			glEnd();
		}

		if (item->subitems.G_count()>0)
		{
			double oo=lineh/4;
//			glLineWidth(2.0f);
			glBegin(GL_TRIANGLES);
			glVertex3d(x0+sx-oo/2-oo,yp-lineh+lineh/2-oo,z0+G_offset());
			glVertex3d(x0+sx-oo/2,yp-lineh+lineh/2,z0+G_offset());
			glVertex3d(x0+sx-oo/2-oo,yp-lineh+lineh/2+oo,z0+G_offset());
			glEnd();
		}

		if (i==parentitem->cursubsel) rendermenu(item,rc,x0+sx+lineh/10,yp);

		yp-=lineh;
	}
}
示例#16
0
Tcolor TrayTracer::radiancePathTracer(Tray ray, int reflectLevel)
{
    if(reflectLevel <=0) return Tcolor(0,0,0);
    auto result = scene()->intersect(ray);
    if (result.geometry()) {
        auto material = result.geometry ()->material ();
        auto emissionColor = material->sampleSelfColor () * material->emission ();
        auto reflectColor = Tcolor(0,0,0);
        switch(material->getType ())
        {
        case Tmaterial::MaterialType::Mirror://ideal specular object.
        {
            auto reflectVec = reflect(ray.direction (),result.normal ());
            auto reflectRay = Tray(result.pos (),reflectVec);
            auto idealSpecularRadiance = radiancePathTracer(reflectRay,reflectLevel - 1);
            reflectColor +=idealSpecularRadiance * material->BRDF (-ray.direction (),reflectVec,result.normal ());
        }
            break;
        case Tmaterial::MaterialType::Light://ideal emission object.
        {
            reflectColor = Tcolor(0,0,0);
        }
            break;
        case Tmaterial::MaterialType::BlinnPhong:
        {

        }
            break;
        case Tmaterial::MaterialType::Diffuse:
        {
            Tvector nl;
            if(Tvector::dotProduct (result.normal (),ray.direction ())<0)
            {
                nl = result.normal ();
            }else
            {
                nl = result.normal ().negatived();
            }

            double r1=2*TbaseMath::PI*TbaseMath::randF ();
            double r2=TbaseMath::randF ();
            double r2s=sqrt(r2);
            Tvector w=nl;
            Tvector u;
            if(fabs(w.x())>0.1)
            {
                u = Tvector(0,1,0);
            }else
            {
                u = Tvector(1,0,0);
            }
            u = Tvector::crossProduct (u,w);
            u.normalize ();
            Tvector v=Tvector::crossProduct (w,u);
            Tvector dir = (u*cos(r1)*r2s + v*sin(r1)*r2s + w*sqrt(1-r2)).normalized();
            reflectColor = radiancePathTracer(Tray(result.pos (),dir),reflectLevel - 1);
        }
            break;
        }
        return emissionColor + material->selfColor () * reflectColor * material->reflectiveness ();
    }
    return Tcolor(0,0,0);
}