示例#1
0
void WindowTree::onRenderItem( RenderContext & context, const RectInt & window, PointInt & pos, Item * pItem )
{
	WindowStyle * pStyle = windowStyle();
	ASSERT( pStyle );
	Font * pFont = windowStyle()->font();
	ASSERT( pFont );

	// get the depth of this item
	int depth = itemDepth( pItem );
	// determine the X position based on it's depth
	pos.x = window.left + (depth * m_Indent);
	// get the size of the label text
	SizeInt labelSize( pFont->size( pItem->sLabel ) );
	// determine the height of this item
	int height = (int)(labelSize.height + TREE_ITEM_BUFFER);
	RectInt itemRect( window.left, pos.y, window.right, pos.y + height );

	// check if this item is highlighted or not
	if ( m_CursorInWindow && itemRect.inRect( m_LastCursorPosition ) )
		onHighlight( pItem );

	PrimitiveMaterial::push( context.display(), WHITE, PrimitiveMaterial::ALPHA );

	if ( pItem->dwFlags & BUTTON )
	{
		bool expanded = (pItem->dwFlags & EXPANDED) != 0;
		Color backColor( expanded ? pStyle->backColor() * TREE_SHADE_COLOR : pStyle->backColor() );
		Color shadeColor( expanded ? pStyle->borderColor() * TREE_LIGHT_COLOR : pStyle->borderColor() * TREE_SHADE_COLOR );
		Color lightColor( expanded ? pStyle->borderColor() * TREE_SHADE_COLOR : pStyle->borderColor() * TREE_LIGHT_COLOR );

		// render the button
		pushBackground( context, itemRect, backColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );
		pushBorder( context, itemRect, lightColor, shadeColor, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );

		// draw glow around this object if the mouse is currently over this button
		if ( m_pCursorOver == pItem )
			pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, TREE_BUTTON_STYLE, TREE_BUTTON_BORDER );

		// place the label in the center of the button
		PointInt labelPos( itemRect.center() - PointInt( labelSize.width / 2, labelSize.height / 2 ) );
		// draw the label
		Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor );
	}
	else
	{
		if ( m_pSelected == pItem )
			pushBackground( context, itemRect, pStyle->highColor(), 0, 0 );
		if ( m_pCursorOver == pItem )
			pushGlow( context, itemRect, TREE_GLOW_SIZE, TREE_GLOW_INNER, TREE_GLOW_OUTER, 0, 0 );

		PointInt labelPos( pos.x, (int)(pos.y + (TREE_ITEM_BUFFER / 2)) );
		// render the label text`
		Font::push( context.display(), pFont, labelPos, pItem->sLabel, pItem->cColor );

	}


	// move y down
	pos.y += (int)(height + WINDOW_TREE_SPACING);
}
示例#2
0
void RayTracer::run()
{
	int index;
	float viewPlaneX;
	float viewPlaneY;
	Ray ray;

	ray.origin = viewPoint;

	for(int i=0; i<winWidth; i++)
	{
		viewPlaneX = ((float)i)/((float)winWidth) * simWidth;

		for(int j=0; j<winHeight; j++)
		{
			Vec3f shadeColor(0.0f, 0.0f, 0.0f);
			viewPlaneY = ((float)j)/((float)winHeight) * simHeight;
			index = j*winWidth+i;
			ray.direction = Vec3f(viewPlaneX, viewPlaneY, viewPlaneZ) - viewPoint;

			rayTracing(ray, shadeColor, 0);

			pixel[index*4+0] = (unsigned char)(shadeColor.x*255.0f);
			pixel[index*4+1] = (unsigned char)(shadeColor.y*255.0f);
			pixel[index*4+2] = (unsigned char)(shadeColor.z*255.0f);
			pixel[index*4+3] = 255;
		}
	}
}
示例#3
0
    Color LambertianShader::shade(const geometry::DifferentialGeometry &dg, int bounce) {
      // initialize the return color for the shader to black
      Color shadeColor(0,0,0,1);

      /************************************************************************/

      // no light falloff based on distance (defaulted to no falloff)
      float distanceVal_no_falloff = 1.0f;

      // linear light falloff based on distance
//     float distanceVal_linear = (light_vec.length());

      // quadratic light falloff based on distance
//      float distanceVal_quadratic = (light_vec.length() * light_vec.length());

      // ambient lighting - faking global illumination with constant
      // low color value
      shadeColor.red = mImpl->color.red * 0.1f;
      shadeColor.green = mImpl->color.green * 0.1f;
      shadeColor.blue = mImpl->color.blue * 0.1f;

      std::vector<std::shared_ptr<Light > > lights;
      lights = Scene::getInstance().lights();
      /************************************************************************/
      for (int i=0; i<lights.size(); i++) {
	      float intensity = lights[i]->intensity();
	      math::Vector light_vec = lights[i]->getLightVector(dg);
	      Ray light_ray(dg.p, light_vec.normalized());

	      // This implementation uses the singleton of the scene to see if we
	      // hit any objects.  Note that we do not need to pass in the Scene as
	      // an argument since a singleton is in the global namespace,
	      // essentially, a global class where there is only one instance)
	      if (!Scene::getInstance().hit(light_ray)) { // if no objects in the way, do lighting
		// this computes the cosine of the angle between the light vector
		// and the geometry normal

      		float shadeAngle = light_vec.normalized().dot(dg.nn);
		  // if the angle is greater than 0, do the lambertian shading
		      if (shadeAngle > 0) {
		    // add the diffuse (matte) lighting to the ambient lighting based on
		    // the intensity and the falloff factor based on the distance
		        float factor = shadeAngle*intensity/distanceVal_no_falloff;
		        shadeColor.red += mImpl->color.red*factor;
	          shadeColor.green += mImpl->color.green*factor;
            shadeColor.blue += mImpl->color.blue*factor;
		      }
         }
    }

    if (dg.shape->reflectivity() > 0 && bounce < mImpl->max_num_reflects) {
      math::Vector normal = math::Vector(dg.nn.x(), dg.nn.y(), dg.nn.z());
      float cl = -dg.V.dir().dot(normal);
      Ray reflect_ray = Ray(dg.p, dg.V.dir()+(2*normal* cl));
      std::shared_ptr<DifferentialGeometry> dg1;
      std::shared_ptr<Primitive> prim;
      float rHit;
      if (Scene::getInstance().hit(reflect_ray, rHit, dg1, prim)) {
        Color temp = prim->shade(dg1, bounce+1);
        shadeColor.red+=(temp.red*dg.shape->reflectivity());
        shadeColor.green+=(temp.green*dg.shape->reflectivity());
        shadeColor.blue+=(temp.blue*dg.shape->reflectivity());
      }
    }
    return shadeColor;
  }