Пример #1
0
	colorRGB BRDF_reflection::reflect_f(hitInfo *info_ptr, const vector3D &win) const {
		hitInfo info = *info_ptr;
		light_point reflect = light_point(info_ptr->hit_point, rho);

		reflect.inherit_light(info_ptr->light_ptr);
		reflect.set_shadow(false);
		info.ray_tracing_depth = info_ptr->ray_tracing_depth - 1;
		return rho * info_ptr->camera_ptr->render_scene(info_ptr->hit_point, 2 * info_ptr->normal - win, &info, &reflect);
	}
Пример #2
0
void	lighting(t_intersect *sct, t_env *env, float *reflect)
{
	float	refl_ray;
	t_vec	tmp;
//	t_ray	r;

//	reset_ray(r, &env->r);
	sct->norm_check = 1.0f / sqrtf(sct->norm_check);
	sct->normal = vector_scale(sct->norm_check, &sct->normal);
	light_point(sct, env);
	env->coef *= *reflect;
	refl_ray = 2.0f * vector_dot(&env->r.dir, &sct->normal);
	tmp = vector_scale(refl_ray, &sct->normal);
	env->r.dir = vector_sub(&env->r.dir, &tmp);
}
Пример #3
0
Файл: widget.cpp Проект: 4b4b/CG
void Widget::paintEvent(QPaintEvent *)
{
    int i, nSteps, count;
    double t, tt, scale = ( width()/4 + height()/4 )/6, sum, k;
    double x, y, z, delta = 0.005, dxdt = 1, dydt = 1, tempDelta;

    my_vector4 xyz(0.0, 0.0, 0.0), xyz0(width()/2, height()/2, scale*5.0), xxyyzz(0.0, 0.0, 0.0),
            light_point(0.0, 0.0, scale*13.0), xyz_s(0.0,0.0,0.0), xxyyzz_s(0.0, 0.0, 0.0);

    QPainter p(this);

    if (!dF){
        delta = inpDelta;
        nSteps =  (2*pi) / delta  + 1;
    }
    else{
        delta = 0.05;
        count = 0;
        sum = 0;
        t = 0;
        tt = 0;
        k = 1;
        while (sum < 2*pi){
            dxdt = -inpA * sin( t ) + inpB * inpC * sin ( inpC * t );
            dydt = inpA * cos( t ) - inpB * inpC * cos ( inpC * t );
            tempDelta = delta/maxAbs(dxdt, dydt);
            t += tempDelta;
            sum+=tempDelta;
            count++;
        }
        nSteps = count + 1;
    }

    k = 1;
    t = 0;
    tt = 0;
    dxdt = 1;
    dydt = 1;

    for (i = 0; i < nSteps; i++){

        if(dF){
            dxdt = -inpA * sin( t ) + inpB * inpC * sin ( inpC * t );
            dydt = inpA * cos( t ) - inpB * inpC * cos ( inpC * t );
            k = 1/maxAbs(dxdt, dydt);
        }

        tempDelta = delta * k;
        tt = t + tempDelta;

        x = inpA * cos( t ) - inpB * cos ( inpC * t );
        y = inpA * sin( t ) - inpB * sin ( inpC * t );
        z = cos ( sqrt( x * x + y * y ) );
        t = t + tempDelta;

        xyz.setElem(0, x );
        xyz.setElem(1, y );
        xyz.setElem(2, z );

        x = inpA * cos( tt ) - inpB * cos ( inpC * tt );
        y = inpA * sin( tt ) - inpB * sin ( inpC * tt );
        z = cos ( sqrt( x * x + y * y ) );

        xxyyzz.setElem(0, x );
        xxyyzz.setElem(1, y );
        xxyyzz.setElem(2, z );


        if (flag) {
            rotateX ( xyz , beta);
            rotateX ( xxyyzz, beta );

            rotateY ( xyz, alpha );
            rotateY ( xxyyzz, alpha );
        }

        if (!flag){
            rotateY ( xyz , alpha);
            rotateY ( xxyyzz, alpha );

            rotateX ( xyz, beta );
            rotateX ( xxyyzz, beta );
        }

        xyz.numMul(scale);
        xxyyzz.numMul(scale);

        vecSum(xyz, xyz0);
        vecSum(xxyyzz, xyz0);

        getShadowXY(light_point, xyz, xyz_s);
        getShadowXY(light_point, xxyyzz, xxyyzz_s);

        p.setPen(Qt::darkMagenta);
        p.drawLine( xyz.getElem(0), xyz.getElem(1), xxyyzz.getElem(0), xxyyzz.getElem(1) );

        p.setPen(Qt::darkGray);
        p.drawLine( xyz_s.getElem(0), xyz_s.getElem(1), xxyyzz_s.getElem(0), xxyyzz_s.getElem(1) );

    }
}