Пример #1
0
A3DLine A3DPlane::Reflection(const A3DLine& line) const
{
	/*
	 * 	 [x]   [a1]    2.(d1.(a1 - c1) + d2.(a2 - c2) + d3.(a3 - c3))  [d1]
	 * 	 [y] = [a2] - ------------------------------------------------.[d2]
	 * 	 [z]   [a3]              d1.d1 + d2.d2 + d3.d3                 [d3]
	 */

	return A3DLine(Reflection(line.Start), Reflection(line.Vector + Point) - Point);
}
Пример #2
0
A3DPlane A3DPlane::Reflection(const A3DPlane& plane) const
{
	/*
	 * 	 [x]   [a1]    2.(d1.(a1 - c1) + d2.(a2 - c2) + d3.(a3 - c3))  [d1]
	 * 	 [y] = [a2] - ------------------------------------------------.[d2]
	 * 	 [z]   [a3]              d1.d1 + d2.d2 + d3.d3                 [d3]
	 */

	return A3DPlane(Reflection(plane.Point), Reflection(plane.Normal + Point) - Point);
}
Пример #3
0
Color Ray::IntersectColor(Scene& sc, Ratio weight)
{
	Inter inter=Intersection(sc);
	if(inter.second>=0)
	{
		Color cl=LocalShading(sc,inter);
		//Color cl=Ambient(sc,inter);
		//cl=cl+LocalShading(sc,inter);
		Ratio reflect=sc.obj[inter.second].prop.specular_reflection;
		Ratio refract=sc.obj[inter.second].prop.refraction;
		if(weight.b>=1./256.||weight.g>=1./256||weight.r>=1./256)
		{
			Vector inter_node=end+inter.first*direction;
			if(reflect.b+reflect.g+reflect.r>=1./256)
			{
				Ray rfray=Reflection(sc.obj[inter.second],inter_node);
				cl=cl+rfray.IntersectColor(sc,weight*reflect)*reflect;
			}
			if(refract.b+refract.g+refract.r>=1./256)
			{
				Ray rfray=Refraction(sc.obj[inter.second],inter_node);
				cl=cl+rfray.IntersectColor(sc,weight*refract)*refract;
			}
		}
		//cout << cl << endl ;
		return cl;
	}
	else
	{
		//cout << "(0,0,0)" << endl ;
		return Color();
	}
}
Пример #4
0
void CHC_GameSystem::RefreshBackTrace(int x, int y, int d, CHC_Color & col)
{
	mark[x][y][d] = true;
	now_map[x][y].col[d/2].add(col);
	x += dx[d/2], y += dy[d/2];
	if (!InMap(x, y) || mark[x][y][d]) return;
	now_map[x][y].col[(d / 2 + 2) % 4].add(col);
	
	int d_1, d_2;
	if (now_map[x][y].isMirror()) {
		if (now_map[x][y].mirror_s == 0) {
			d_1 = Reflection(d, now_map[x][y].dir, 0);
			if (d_1 < 0) return;
			RefreshBackTrace(x, y, d_1, col);
		} else 
		if (now_map[x][y].mirror_s == 2) {
			d_1 = Reflection(d, now_map[x][y].dir, 0);
			d_2 = Reflection(d, (now_map[x][y].dir + 4) % NUM_MIRROR_STATE, 0);
			if (d_1 >= 0) RefreshBackTrace(x, y, d_1, col);
			else if (d_2 >= 0) RefreshBackTrace(x, y, d_2, col);
		} else 
		if (now_map[x][y].mirror_s == 4) {
			d_1 = Reflection(d, now_map[x][y].dir, 0);
			d_2 = Reflection(d, (now_map[x][y].dir + 4) % NUM_MIRROR_STATE, 0);
			if (d_1 >= 0) RefreshBackTrace(x, y, d_1, col);
			else if (d_2 >= 0) RefreshBackTrace(x, y, d_2, col);
			if (d / 2 % 2 == 1) {
				// -
				if (now_map[x][y].dir != 0 && now_map[x][y].dir != 4) RefreshBackTrace(x, y, d, col);
			} else {
				// |
				if (now_map[x][y].dir != 2 && now_map[x][y].dir != 6) RefreshBackTrace(x, y, d, col); 
			}
		}
	} else
	if (now_map[x][y].isSender()) {
		return;
	} else {
		RefreshBackTrace(x, y, d, col);
	}
}
Пример #5
0
namespace CGAL {

const Translation             TRANSLATION = Translation();
const Rotation                ROTATION = Rotation();
const Scaling                 SCALING = Scaling();
const Reflection              REFLECTION = Reflection();
const Identity_transformation IDENTITY = Identity_transformation();

const Origin      ORIGIN = Origin();
const Null_vector NULL_VECTOR = Null_vector();

} //namespace CGAL
Пример #6
0
// Returns a sample into the specular lobe. This is a type of importance sampling
Sample Raytracer::SampleSpecularLobe(const Vec3 &R, float phong_exp) {
	double s, t;
	Sample sample;

	double r = 1.0;
	s = rand(0.0, 1.0);
	t = rand(0.0, 1.0);

	//Punt aleatori a la semiesfera.
	double x = sqrt(1 - pow(t, 2 / (phong_exp + 1)))* cos(2 * Pi*s);
	double y = sqrt(1 - pow(t, 2 / (phong_exp + 1)))* sin(2 * Pi*s);
	double z = sqrt(1 - x*x - y*y);

	//Obtenim un punt aleatori de la nostra esfera.
	Vec3 reflected_sample = Vec3(x, y, z);
	sample.P = (Reflection(-reflected_sample , Unit(R + Vec3(0,0,1))));

	// Assigns the weight
	sample.w = Pi;

	return sample;
}
Пример #7
0
// Returns a sample into the project hemishpere. This is a type of importance sampling.
Sample Raytracer::SampleProjectedHemisphere(const Vec3 &N) {

	double s, t;
	Sample sample;

	double r = 1.0;
	s = rand(0.0, 1.0);
	t = rand(0.0, 1.0);

	//Punt aleatori a la semiesfera.
	double x = sqrt(t)*cos(2 * Pi*s);
	double y = sqrt(t)*sin(2 * Pi*s);
	double z = sqrt(1 - x*x - y*y);

	//Obtenim un punt aleatori de la nostra esfera.
	Vec3 reflected_sample = Vec3(x, y, z);
	sample.P = (Reflection(-reflected_sample, Unit( N + Vec3(0, 0, 1))));

	// Assigns the weight
	sample.w = Pi;

	return sample;
}
namespace corecvs {
template<>
Reflection BaseReflection<DistortionApplicationParameters>::reflection = Reflection();
template<>
int BaseReflection<DistortionApplicationParameters>::dummy = DistortionApplicationParameters::staticInit();
} // namespace corecvs 
Пример #9
0
namespace corecvs {
template<>
Reflection BaseReflection<Draw3dParameters>::reflection = Reflection();
template<>
int BaseReflection<Draw3dParameters>::dummy = Draw3dParameters::staticInit();
} // namespace corecvs 
namespace corecvs {
template<>
Reflection BaseReflection<OmnidirectionalBaseParameters>::reflection = Reflection();
template<>
int BaseReflection<OmnidirectionalBaseParameters>::dummy = OmnidirectionalBaseParameters::staticInit();
} // namespace corecvs 
namespace corecvs {
template<>
Reflection BaseReflection<ExtrinsicsPlacerParameters>::reflection = Reflection();
template<>
int BaseReflection<ExtrinsicsPlacerParameters>::dummy = ExtrinsicsPlacerParameters::staticInit();
} // namespace corecvs 
namespace corecvs {
template<>
Reflection BaseReflection<InputFilterParameters>::reflection = Reflection();
template<>
int BaseReflection<InputFilterParameters>::dummy = InputFilterParameters::staticInit();
} // namespace corecvs 
namespace corecvs {
template<>
Reflection BaseReflection<ThickeningParameters>::reflection = Reflection();
template<>
int BaseReflection<ThickeningParameters>::dummy = ThickeningParameters::staticInit();
} // namespace corecvs 
Пример #14
0
// Shade assigns a color to a point on a surface, as it is seen
// from another point.  The coordinates of these points, the normal
// of the surface, and the surface material are all recorded in the
// HitInfo structure.  The shader will typically make calls to Trace
// to handle shadows and reflections.
Color Raytracer::Shade(const HitInfo &hit, const Scene &scene, int max_tree_depth)
{
	Color color = { 0.0f, 0.0f, 0.0f };
	Vec3 point = hit.geom.point + hit.geom.normal*Epsilon;
	HitInfo hitObstacle = hit;
	Ray ray, ray2;
	Color diffuse = Color(0,0,0), specular = Color(0,0,0);
	Color direct = Color(0,0,0), indirect = Color(0,0,0);
	Sample lightPoint;

	Vec3 V;
	Color irradiant = Color(0,0,0);
	int espec = 0;
	Color indirect_hemisphere = Color(0, 0, 0), indirect_lobe = Color(0, 0, 0);

	//if (max_tree_depth >= 0) {

		if (hit.material.Emitter()) {
			return hit.material.m_Diffuse;
		}else{
			for (Object *object = scene.first; object != NULL; object = object->next)
			{

				if (object->material.Emitter() == true)
				{
					lightPoint = object->GetSample(hit.geom.point, hit.geom.normal);
					ray.origin = hit.geom.point;

					//lightPoint.P = lightPoint.P + hit.geom.normal*Epsilon;
					ray.direction = Unit(lightPoint.P - hit.geom.point);
					hitObstacle.geom.distance = Length(lightPoint.P - point);

					V = Unit(hit.geom.origin - hit.geom.point);
						Vec3 N = (hit.geom.normal);
						Vec3 H = Unit(V + ray.direction);
						//V = Unit(hit.geom.origin - hit.geom.point);
						Vec3 L = (-ray.direction);// Unit(point - lightPoint.P);
						Vec3 R = Unit(Reflection(-L, N));//Unit((2*N*(N*L))-L);

					espec = hit.material.m_Phong_exp;

					double c = (L*H);
					double g = sqrt((pow(1.4 / 1, 2.0))+ pow(c,2)-1);
					Color f0 = hit.material.m_Specular;


					double F = (f0.red + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.green + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.blue+(1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)));
					//double F = (1 / 2)*((pow(g - c, 2))/(pow(g + c, 2)))*(1+pow((c*(g+c)-1),2)/ (1 + pow((c*(g - c) + 1), 2)));
					double D = ((espec + 2) / (2 * Pi))*(pow((H*N), espec));
					//double D = 1/(sqrt(2*Pi))
					double G = min(min(1.0, (2 * (N*H)*(N*V)) / (V*H)), (2 * (N*H)*(N*L)) / (L*H));
					if (G < 0) G = 0;
					if (D < 0) D = 0;
					if (F < 0) F = 0;

					if (!Cast(ray, scene, hitObstacle)) {
						

						if (N * L > 0) {
							diffuse = (N*L)*hit.material.m_Diffuse/Pi;
						}
						else {
							diffuse = Color(0.0, 0.0, 0.0);
						}

						irradiant = object->material.m_Emission*(lightPoint.w);
						
						if ((R*V) > 0 && hit.material.m_Phong_exp > 0) {
							specular = /*(espec + 2)/(2*Pi) * pow((R*V), espec)*/(F*D*G / (4 * (N*L)*(N*V)))*hit.material.m_Specular;
						}
						else {
							specular = Color(0.0, 0.0, 0.0);
						}
						direct += (diffuse + specular)*irradiant;
					}
				}
			}
			if (hit.material.m_Phong_exp > 0) {
				Vec3 N = (hit.geom.normal);
				Vec3 L = Unit(-ray.direction);
				V = -Unit(hit.geom.point - hit.geom.origin);
				Vec3 R = Unit(Reflection(-V, N));
				Vec3 H = Unit(V + ray.direction);
				double c = (L*H);
				double g = sqrt((pow(1.4 / 1, 2.0)) + pow(c, 2) - 1);
				Color f0 = hit.material.m_Specular;

				double F = (f0.red + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.green + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)), f0.blue + (1.0 - f0.red, 1.0 - f0.green, 1.0 - f0.blue)*(pow((1 - (N*V)), 5)));
				//double F = (1 / 2)*((pow(g - c, 2))/(pow(g + c, 2)))*(1+pow((c*(g+c)-1),2)/ (1 + pow((c*(g - c) + 1), 2)));
				double D = ((espec + 2) / (2 * Pi))*(pow((H*N), espec));
				double G = min(min(1.0, (2 * (N*H)*(N*V)) / (V*H)), (2 * (N*H)*(N*L)) / (L*H));
				if (G < 0) G = 0;
				if (D < 0) D = 0;
				if (F < 0) F = 0;


				float phong_exp = hit.material.m_Phong_exp;
				ray2.origin = point;

				Sample sample_hemisphere = SampleProjectedHemisphere(N);
				ray2.direction = Unit(sample_hemisphere.P);
				//ray2.no_emitters = true;
				indirect_hemisphere = Trace(ray2, scene, max_tree_depth-1)*  hit.material.m_Diffuse;

				Sample specular_sample = SampleSpecularLobe(R, phong_exp);
				ray2.direction = Unit(specular_sample.P);
				indirect_lobe = Trace(ray2, scene, max_tree_depth - 1)*F*D*G / (4 * (N*L)*(N*V));// *hit.material.m_Specular;

				indirect = indirect_hemisphere + indirect_lobe;// *(F*D*G / (4 * (N*L)*(N*V)));
			}
			
			return (direct) + indirect;
		}
	//}
}
// public GeneratedApplication() [instance] :240
void GeneratedApplication::ctor_4()
{
    ctor_3(uArray::Init< ::g::Uno::Net::IPEndPoint*>(::TYPES[0/*Uno.Net.IPEndPoint[]*/], 2, (::g::Uno::Net::IPEndPoint*)::g::Uno::Net::IPEndPoint::New1(::g::Uno::Net::IPAddress::Parse(::STRINGS[0/*"127.0.0.1"*/]), 12124), (::g::Uno::Net::IPEndPoint*)::g::Uno::Net::IPEndPoint::New1(::g::Uno::Net::IPAddress::Parse(::STRINGS[1/*"192.168.1.37"*/]), 12124)), ::STRINGS[2/*"C:\\Users\\...*/]);
    Reflection((uObject*)::g::Outracks::Simulator::Reflection::Native::NativeReflection::New1((uObject*)::g::Outracks::Simulator::Reflection::Native::SimpleTypeMap::New1()));
}
void Simplex::OneCall()
{
    // calcola l,h e centroide
    Initialize();

    Reflection();

    double ystar = EvalFunction(m_Pstar);
    double y_l = EvalFunction(m_P[m_l]);
    double y_h = EvalFunction(m_P[m_h]);

    // il punto riflesso sta sotto y_l
    if (ystar < y_l)
    {
        Expansion();

        // espansione riuscita
        if (EvalFunction(m_Pstarstar) < y_l)
        {
            m_P[m_h]->SetPoint(m_Pstarstar);
            return;
        }

        // espansione fallita
        else
        {
            m_P[m_h]->SetPoint(m_Pstar);
            return;
        }
     }

    // il punto riflesso non sta sotto y_l
    else
    {
        // calcola se il punto riflesso è maggiore di tutti gli altri
        int counter = 0;
        for (int i = 0; i < 3; i++)
        {
            if ( ystar > EvalFunction(m_P[i]) )
            {counter++;}
        }

        // il punto non è maggiore di tutti gli i != h
        if (counter < 2)
        {
            m_P[m_h]->SetPoint(m_Pstar);
            return;
        }

        // il punto è maggiore di tutti gli i (!)= h
        else
        {
            // se non è maggiore di h, sostituisco h
            if (counter < 3)
            {
                m_P[m_h]->SetPoint(m_Pstar);
                y_h = EvalFunction(m_P[m_h]);
            }

            Contraction();

            // il punto contratto non è maggiore di y_h
            if (EvalFunction(m_Pstarstar) <= y_h)
            {
                m_P[m_h]->SetPoint(m_Pstarstar);
                return;
            }
            // il punto contratto è maggiore di y_h
            else
            {
                double x_point_l = m_P[m_l]->GetX();
                double y_point_l = m_P[m_l]->GetY();
                for (int i = 0; i < 3; i++)
                {
                    m_P[i]->SetX(0.5*(m_P[i]->GetX() + x_point_l));
                    m_P[i]->SetY(0.5*(m_P[i]->GetY() + y_point_l));
                }
                return;
            }
        }
   }

}
Пример #17
0
mat3x3 S(const vec3& axis)
{
    return Rotation(axis, 360.0/n)*Reflection(axis);
}