コード例 #1
0
ファイル: light.c プロジェクト: SleepyFanjo/RT
void			calc_light(t_param *param, t_info *info, t_list *spot)
{
	t_info	*light;
	t_spot	*o_spot;
	t_lum	lum;
	int		*s_color;

	if (info->distance < 0)
		return ;
	s_color = init_color();
	while (spot)
	{
		o_spot = (t_spot *)spot->content;
		light = init_light(info, o_spot);
		calc_intersection(param, light);
		if (point_cmp(info->r_pos, light->r_pos) == 1)
		{
			lum.fading = ft_abs(calc_fading(light->r_line.vec, info->vec_n));
			lum.shining = ft_abs(calc_shining(info->vec_n, light->r_line.vec));
			info->light += o_spot->value * lum.fading;
			info->light += o_spot->value * lum.shining * lum.fading;
			calc_color(&s_color, o_spot->color, o_spot->value, lum.fading);
		}
		spot = spot->next;
	}
	info->color = retrieve_col(s_color, damer(param, info, info->s_pos),
		get_shine(info));
}
コード例 #2
0
void GTerm::screen_align()
{
    int y, yp, x, c;

    c = calc_color(7, 0, 0);

    for (y = 0; y<height; y++)
    {
        yp = linenumbers[y] * MAXWIDTH;
		int altY = m_nextLineCounter * MAXWIDTH;

        changed_line(y, 0, width - 1);

        for (x = 0; x<width; x++)
        {
            //text[yp + x] = 'E';

			tm[y][x] = 'E';

            //color[yp + x] = c;

			tm.SetColorAdjusted(y, x, c);
        }
    }
}
コード例 #3
0
t_color			get_ambiant_light(t_scene scene, t_vector ray,
									t_obj object, t_point inter)
{
	t_llst		*tmp;
	t_point		light_inter;
	double		norm;

	tmp = scene.lst_light;
	scene.color = new_color(0, 0, 0);
	while (tmp)
	{
		light_inter = new_point(inter.x - tmp->light->body.center.x, inter.y -
			tmp->light->body.center.y, inter.z - tmp->light->body.center.z);
		norm = sqrt(pow(light_inter.x, 2) + pow(light_inter.y, 2) +
				pow(light_inter.z, 2));
		scene.normal = object.normal(object, inter, ray);
		light_inter = new_point((double)light_inter.x / norm,
						light_inter.y / norm, light_inter.z / norm);
		scene.scal = scalar_prod(light_inter, scene.normal);
		scene.ray = ray.dir;
		if (norm_is_shit(scene, *(tmp->light), inter, norm) &&
				scene.scal >= 0.000000000000000000001)
			scene.color = calc_color(get_spec(scene, *(tmp->light),
			light_inter, object), object.texturing(object, inter, ray),
			*(tmp->light), scene.scal);
		tmp = tmp->next;
	}
	return (scene.color);
}
コード例 #4
0
ファイル: color-wheel.c プロジェクト: kbob/hw-samples
int main()
{
    init_timer();
    init_SPI();
    init_ATX_power();
    sei();

    enable_ATX_power();
    repeat_LEDs_off();

    uint32_t d = ROTATION_SECONDS * 1000L / (6 * 127);
    wait_for_it(d);
    
#if 0
    while (true) {
        for (uint8_t i = 0; i < 6; i++) {
            for (uint8_t j = 0; j < 127; j++) {
                wait_for_it(0);
                uint8_t r, g, b;
                calc_color(i, j, &r, &g, &b);
                set_LEDs_color(r, g, b);
            }
        }
    }
#else
    while (true) {
        for (uint8_t i = 0; i < 6; i++) {
            for (uint8_t j = 0; j < 127; j++) {
                wait_for_it(0);
                begin_LEDs_refresh();
                for (uint8_t p = 0; p < PIXEL_COUNT; p++) {
                    uint8_t r=0, g=0, b=0;
                    uint8_t ii = i, jj = j + 4 * p;
                    if (jj >= 127) {
                        jj -= 127;
                        if (++ii == 6) ii = 0;
                    }
                    calc_color(ii, jj, &r, &g, &b);
                    set_pixel_color(r, g, b);
                }                
                end_LEDs_refresh();
            }
        }
    }
#endif
}
コード例 #5
0
ファイル: tile.cpp プロジェクト: BackupTheBerlios/flexlay-svn
CL_Color
Tile::get_color()
{
  if (impl->has_color)
  {
    return impl->color;
  }
  else
  {
    impl->color = calc_color();
    impl->has_color = true;
    return impl->color;
  }
}
コード例 #6
0
ファイル: calc_detail.c プロジェクト: Frozenhorns/project
int
calc_detail(t_detail *detail, t_color *color, t_camera *camera, double *vector)
{
  if (detail == NULL || color == NULL || camera == NULL || vector == NULL)
    return (EXIT_FAILURE);
  calc_point(camera->position, vector, detail->position, detail->k);
  calc_color(color, detail);
  calc_normal(camera, detail, vector, detail->normal);
  calc_perturbation(detail->object, detail->position, detail->normal);
  if ((detail->object->image_bump != NULL && detail->object->image_bump->type == B_BUMP) ||
      (detail->object->perlin != NULL && (detail->object->perlin->apply == APP_BUMP ||
					  detail->object->perlin->apply == APP_BUMP_TEXT)))
    texture_bump_mapping(detail, detail->normal);
  else if (detail->object->image_bump != NULL && detail->object->image_bump->type == B_NORMAL)
    texture_normal_mapping(detail, detail->normal);
  return (EXIT_SUCCESS);
}
コード例 #7
0
ファイル: rend.cpp プロジェクト: Changtx/3dRendering
//------------------------------------------------------------------------------
int GzPutTriangle(GzRender *render, int numParts, GzToken *nameList, GzPointer *valueList) {
    /* numParts : how many names and values */

    // Do some sanity checking    
    if(NULL == render || NULL == nameList || NULL == valueList || numParts != 3)
    {
        return GZ_FAILURE;
    } 
    
        
    Matrix *Xsm = render->xStack.leftMulMatricesOnStack();
    if (Xsm == NULL)
    {
        fprintf(stderr, "Got NULL from stack in GzPutTriangle.\n");
    } 
    
    
    
    
    GzCoord *c_old;
    GzCoord *n;
    GzColor triEdgeColors[3];
    GzTextureIndex *triTextures;
    
    for (int i = 0; i < numParts; i++)
    {
        int name = nameList[i];
        switch(name)
        {
            case GZ_POSITION:
            {
                // Get ready to read coordinates
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                c_old = static_cast<GzCoord *> (l2[i]);
                
                break;
            }
            
            case GZ_NORMAL:
            {
                void *l1 = valueList;
                GzCoord **l2 = static_cast<GzCoord **> (l1);
                
                n = static_cast<GzCoord *> (l2[i]);
                
                
                if (render->interp_mode == GZ_COLOR) 
                {
                    for (int k = 0; k < 3; k++)
                        calc_color(render, n[k], triEdgeColors[k], (render->tex_fun == false));

                }

                break;
            }
            
            case GZ_TEXTURE_INDEX:
            {
                void *l1 = valueList;
                GzTextureIndex **l2 = static_cast<GzTextureIndex**> (l1);
                triTextures = l2[i];             
                
                break;
            }
            
            default:
                return GZ_FAILURE;            
        }// end of switch statement
    }//end of for loop
    
    
    
   

    GzCoord c[3];
    // Transform triangle coordinates into screen coordinates
    for(int i = 0; i < 3 ; i++)
    {
        float array[4] = {c_old[i][0], c_old[i][1], c_old[i][2], 1};
        float rMulResult[4] ={0, 0, 0, 0};
        Xsm->rightMultiply(array, 4, rMulResult);
        c[i][X] = rMulResult[0] + render->aa_delta_x;
        c[i][Y] = rMulResult[1] + render->aa_delta_y;
        c[i][Z] = rMulResult[2];           
    }

    // Lets see if all 3 triangle coordinates are viewable or not.
    if(isBehindViewPlane(render, c) || isClipped(render, c))
        return GZ_FAILURE;   

    // Find bounding box
    int x_min = floor(findMin(c, 0, 3));
    int x_max = ceil (findMax(c, 0, 3));
    int y_min = floor(findMin(c, 1, 3));
    int y_max = ceil (findMax(c, 1, 3));


    // Iterate over every pixel in the bounding box
    for(int j = y_min; j <= y_max; j++)        
        for(int i = x_min; i <= x_max; i++)
        {
            // Calculate Barycentric coordinates
            GzCoord p = {float(i), float(j), 0};
            float alpha = f(c[1], c[2], p) / f(c[1], c[2], c[0]);
            float beta  = f(c[2], c[0], p) / f(c[2], c[0], c[1]);
            float gamma = f(c[0], c[1], p) / f(c[0], c[1], c[2]);

            // Litmus Test: Is pixel (i,j) inside triangle?
            if ( alpha > 0 && beta > 0 && gamma > 0)                
            {
                //interpolate z value
                float newZ = alpha*(c[0][2]) + beta*(c[1][2]) + gamma*(c[2][2]);


                // Get current Z value for this specific pixel (i,j)
                GzIntensity dummy;
                GzDepth oldZ;
                GzGetDisplay(render->display, i, j, &dummy, &dummy, &dummy, &dummy, &oldZ);


                // Check will this pixel be displayed or not
                if(newZ < oldZ)
                {

                    GzColor interpColor = {0, 0, 0};                    
                    GzColor color = {1.0f, 1.0f, 1.0f}; // color coming from texture
                    if(render->tex_fun != false)
                        calcTexture(render, triTextures, c, newZ, alpha, beta, gamma, color);


                    
                    
                    
                    if(render->interp_mode == GZ_NORMALS) // Phong Shading
                    {
                        GzCoord interpN = {0,0,0};
                        for (int k = 0; k < 3; k++)
                            interpN[k] = alpha*n[0][k] + beta*n[1][k] + gamma*n[2][k];
                        
                        if(render->tex_fun != false)
                        {
                                memcpy(render->Ka, color, sizeof (GzColor));
                                memcpy(render->Kd, color, sizeof (GzColor));
                        }
                
                        

                          
                        calc_color(render, interpN, interpColor, true);
                        
                        GzPutDisplay(render->display, i, j, ctoi(interpColor[X]), ctoi(interpColor[Y]), ctoi(interpColor[Z]), 1, newZ);
                        
                    }
                    else if(render->interp_mode == GZ_COLOR) // Gouraud Shading
                    {
                        float r = alpha * triEdgeColors[0][X] + beta * triEdgeColors[1][X] + gamma * triEdgeColors[2][X];
                        float g = alpha * triEdgeColors[0][Y] + beta * triEdgeColors[1][Y] + gamma * triEdgeColors[2][Y];
                        float b = alpha * triEdgeColors[0][Z] + beta * triEdgeColors[1][Z] + gamma * triEdgeColors[2][Z];
                        
                        // Multiply by Kt which is in color due to earlier texture calculation
                        r *= color[RED];
                        g *= color[GREEN];
                        b *= color[BLUE];



                        GzPutDisplay(render->display, i, j, ctoi(r), ctoi(g), ctoi(b), 1, newZ);
                        
                    }
                    
                    
                    // FLAT Shading 
                                            
                        //GzPutDisplay(render->display, i, j, ctoi(render->flatcolor[0]), 
                        //ctoi(render->flatcolor[1]), ctoi(render->flatcolor[2]), 1, newZ);                   

                }


            }// end of litmus test if
        }   
    
    return GZ_SUCCESS;
}
コード例 #8
0
void CUIProgressShape::Draw()
{
	if(m_bText)
		DrawText		();

	UIRender->SetShader				(*GetShader());
	Fvector2						tsize;
	UIRender->GetActiveTextureResolution(tsize);

	
	UIRender->StartPrimitive		(m_sectorCount*3,IUIRender::ptTriList, UI().m_currentPointType);

	Frect pos_rect;
	GetAbsoluteRect					(pos_rect);
	UI().ClientToScreenScaled		(pos_rect.lt, pos_rect.x1, pos_rect.y1);
	UI().ClientToScreenScaled		(pos_rect.rb, pos_rect.x2, pos_rect.y2);

	Fvector2						center_pos;
	pos_rect.getcenter				(center_pos);

	Frect tex_rect					= GetUIStaticItem().GetTextureRect();
	
	tex_rect.lt.x					/= tsize.x;
	tex_rect.lt.y					/= tsize.y;
	tex_rect.rb.x					/= tsize.x;
	tex_rect.rb.y					/= tsize.y;

	Fvector2						center_tex;
	tex_rect.getcenter				(center_tex);

	float		radius_pos			= pos_rect.width()/2.0f;

	float		radius_tex			= tex_rect.width()/2.0f;

	float		curr_angle			=  m_angle_begin;
	float		sin_a				= _sin(curr_angle);
	float		cos_a				= _cos(curr_angle);
	Fvector2	start_pos_pt,	prev_pos_pt;
	Fvector2	start_tex_pt,	prev_tex_pt;
	
	start_pos_pt.set				(0.0f, -radius_pos);
	prev_pos_pt						= start_pos_pt;

	start_tex_pt.set				(0.0f, -radius_tex);
	prev_tex_pt						= start_tex_pt;

	_make_rot_tex(prev_pos_pt, start_pos_pt.y, sin_a, cos_a);
	_make_rot_tex(prev_tex_pt, start_tex_pt.y, sin_a, cos_a);

	float angle_range = PI_MUL_2;
	if ( m_bClockwise )
	{
		angle_range = -abs( m_angle_end - m_angle_begin );
	}
	else
	{
		angle_range = abs( m_angle_end - m_angle_begin );
	}
	
	for ( u32 i = 0; i < m_sectorCount; ++i )
	{
		float ffff					= calc_color		(i+1, m_sectorCount, m_stage, 1.0f, m_blend);
		u32 color					= color_argb_f		(ffff,1.0f,1.0f,1.0f); 

		UIRender->PushPoint(center_pos.x, center_pos.y, 0, color, center_tex.x, center_tex.y);

		Fvector2	tp;
		tp.set						(prev_pos_pt);
		tp.add						(center_pos);

		Fvector2	tx;
		tx.set						(prev_tex_pt);
		tx.add						(center_tex);

		Fvector2	tp1;
		Fvector2	tx1;
		tp1.set(tp);
		tx1.set(tx);

		curr_angle					+= angle_range/float(m_sectorCount);

		sin_a						= _sin(curr_angle);
		cos_a						= _cos(curr_angle);

		_make_rot_tex(prev_pos_pt, start_pos_pt.y, sin_a, cos_a);
		_make_rot_tex(prev_tex_pt, start_tex_pt.y, sin_a, cos_a);

		tp.set						(prev_pos_pt);
		tp.add						(center_pos);

		tx.set						(prev_tex_pt);
		tx.add						(center_tex);

		if (m_bClockwise)
		{
			UIRender->PushPoint(tp1.x,	tp1.y,	0,	color, tx1.x,	tx1.y);
			UIRender->PushPoint(tp.x,	tp.y,	0,	color, tx.x,	tx.y);
		}
		else
		{
			UIRender->PushPoint(tp.x,	tp.y,	0, color, tx.x,		tx.y);
			UIRender->PushPoint(tp1.x,	tp1.y,	0, color, tx1.x,	tx1.y);
		}
	}


	UIRender->FlushPrimitive();
}
コード例 #9
0
//////////////////////////////////////////////////////////////////////////////
///  private normal_input
///  Handles most of the input stuff for GTerm
///
///  @return void
///
///  @author Timothy Miller @date 04-22-2004
//////////////////////////////////////////////////////////////////////////////
void GTerm::normal_input()
{
    int n, n_taken, i, c, y;

#if 0

    char str[100];

#endif

    if (* input_data<32)
        return;

    if (cursor_x>=width)
    {
        if (mode_flags & NOEOLWRAP)
        {
            cursor_x = width - 1;
        }
        else
        {
            next_line();
        }
    }

    n = 0;

    if (mode_flags & NOEOLWRAP)
    {
        while (input_data[n]>31 && n<data_len)
            n++;

        n_taken = n;

        if (cursor_x + n>=width)
            n = width - cursor_x;
    }
    else
    {
        while (input_data[n]>31 && n<data_len && cursor_x + n<width)
            n++;

        n_taken = n;
    }

#if 0

    memcpy(str, input_data, n);
    str[n] = 0;
    //printf("Processing %d characters (%d): %s\n", n, str[0], str);

#endif

    if (mode_flags & INSERT)
    {
        changed_line(cursor_y, cursor_x, width - 1);
    }
    else
    {
        changed_line(cursor_y, cursor_x, cursor_x + n - 1);
    }

	// IMPORTANT Here's where the text pointer gets assigned.
    y = linenumbers[cursor_y] * MAXWIDTH;

	int altY = m_nextLineCounter * MAXWIDTH;

	// MPE: moves the text after the cursor to the right N spaces (inserting)
    if (mode_flags & INSERT)
        for (i = width - 1; i>=cursor_x + n; i--)
        {
            //text[y + i] = text[y + i - n];

			char c = tm.GetCharAdjusted(cursor_y, i - n);
			tm.SetCharAdjusted(cursor_y, i, c);

            //color[y + i] = color[y + i - n];

			unsigned short tempcolor = tm.GetColorAdjusted(cursor_y, i - n);
			tm.SetColorAdjusted(cursor_y, i, tempcolor);
        }

    c = calc_color(fg_color, bg_color, mode_flags);

	// MPE: inserts the new received text, overwriting what was there already
    for (i = 0; i<n; i++)
    {
        //text[y + cursor_x] = input_data[i];
		tm.SetCharAdjusted(cursor_y, cursor_x, input_data[i]);

        //color[y + cursor_x] = c;
		tm.SetColorAdjusted(cursor_y, cursor_x, c);
        cursor_x++;
    }

    input_data += n_taken - 1;
    data_len -= n_taken - 1;
}