Beispiel #1
0
ZRange GlyphGadget::calcZRange(void) const
	{
	ZRange result=ZRange(glyphBox.origin[2],glyphBox.origin[2]);
	if(depth==IN)
		result.first-=bevelSize;
	else
		result.second+=bevelSize;
	return result;
	}
Beispiel #2
0
ZRange Button::calcZRange(void) const
	{
	/* Calculate the parent class widget's z range: */
	ZRange myZRange=Label::calcZRange();
	
	/* Adjust for the popping in/out when arming/disarming: */
	myZRange+=ZRange(getExterior().origin[2]-getBorderWidth(),getExterior().origin[2]+getBorderWidth());
	
	return myZRange;
	}
Beispiel #3
0
	int Ardb::Sort(const DBID& db, const Slice& key, const StringArray& args,
	        ValueArray& values)
	{
		SortOptions options;
		if (parse_sort_options(options, args) < 0)
		{
			DEBUG_LOG("Failed to parse sort options.");
			return ERR_INVALID_ARGS;
		}
		int type = Type(db, key);
		ValueArray sortvals;
		switch (type)
		{
			case LIST_META:
			{
				LRange(db, key, 0, -1, sortvals);
				break;
			}
			case SET_ELEMENT:
			{
				SMembers(db, key, sortvals);
				break;
			}
			case ZSET_ELEMENT_SCORE:
			{
				QueryOptions tmp;
				ZRange(db, key, 0, -1, sortvals, tmp);
				if(NULL == options.by)
				{
					options.nosort = true;
				}
				break;
			}
			default:
			{
				return ERR_INVALID_TYPE;
			}
		}

		if (sortvals.empty())
		{
			return 0;
		}
		if (options.with_limit)
		{
			if (options.limit_offset < 0)
			{
				options.limit_offset = 0;
			}
			if ((uint32) options.limit_offset > sortvals.size())
			{
				values.clear();
				return 0;
			}
			if (options.limit_count < 0)
			{
				options.limit_count = sortvals.size();
			}
		}

		std::vector<SortValue> sortvec;
		if (!options.nosort)
		{
			if (NULL != options.by)
			{
				sortvec.reserve(sortvals.size());
			}
			for (uint32 i = 0; i < sortvals.size(); i++)
			{
				if (NULL != options.by)
				{
					sortvec.push_back(SortValue(&sortvals[i]));
					if (GetValueByPattern(db, options.by, sortvals[i],
					        sortvec[i].cmp) < 0)
					{
						DEBUG_LOG("Failed to get value by pattern:%s", options.by);
						sortvec[i].cmp.Clear();
						continue;
					}
				}
				if (options.with_alpha)
				{
					if (NULL != options.by)
					{
						value_convert_to_raw(sortvec[i].cmp);
					}
					else
					{
						value_convert_to_raw(sortvals[i]);
					}
				}
				else
				{
					if (NULL != options.by)
					{
						value_convert_to_number(sortvec[i].cmp);
					}
					else
					{
						value_convert_to_number(sortvals[i]);
					}
				}
			}
			if (NULL != options.by)
			{
				if (!options.is_desc)
				{
					std::sort(sortvec.begin(), sortvec.end(),
					        less_value<SortValue>);
				}
				else
				{
					std::sort(sortvec.begin(), sortvec.end(),
					        greater_value<SortValue>);
				}

			}
			else
			{
				if (!options.is_desc)
				{
					std::sort(sortvals.begin(), sortvals.end(),
					        less_value<ValueObject>);
				}
				else
				{
					std::sort(sortvals.begin(), sortvals.end(),
					        greater_value<ValueObject>);
				}
			}
		}

		if (!options.with_limit)
		{
			options.limit_offset = 0;
			options.limit_count = sortvals.size();
		}

		uint32 count = 0;
		for (uint32 i = options.limit_offset;
		        i < sortvals.size() && count < (uint32) options.limit_count;
		        i++, count++)
		{
			ValueObject* patternObj = NULL;
			if (NULL != options.by)
			{
				patternObj = sortvec[i].value;
			}
			else
			{
				patternObj = &(sortvals[i]);
			}
			if (options.get_patterns.empty())
			{
				values.push_back(*patternObj);
			}
			else
			{
				for (uint32 j = 0; j < options.get_patterns.size(); j++)
				{
					ValueObject vo;
					if (GetValueByPattern(db, options.get_patterns[j],
					        *patternObj, vo) < 0)
					{
						DEBUG_LOG("Failed to get value by pattern for:%s", options.get_patterns[j]);
						vo.Clear();
					}
					values.push_back(vo);
				}
			}
		}

		if (options.store_dst != NULL && !values.empty())
		{
			BatchWriteGuard guard(GetEngine());
			LClear(db, options.store_dst);
			ValueArray::iterator it = values.begin();
			uint64 score = 0;

			while (it != values.end())
			{
				if (it->type != EMPTY)
				{
					ListKeyObject lk(options.store_dst, score, db);
					SetValue(lk, *it);
					score++;
				}
				it++;
			}
			ListMetaValue meta;
			meta.min_score = 0;
			meta.max_score = (score - 1);
			meta.size = score;
			SetListMetaValue(db, options.store_dst, meta);
		}
		return 0;
	}
		void GLBasicShadowMapRenderer::BuildMatrix(float near, float far){
			// TODO: variable light direction?
			Vector3 lightDir = MakeVector3(0, -1, -1).Normalize();
			// set better up dir?
			Vector3 up = MakeVector3(0, 0, 1);
			Vector3 side = Vector3::Cross(up, lightDir).Normalize();
			up = Vector3::Cross(lightDir, side).Normalize();
			
			// build frustrum
			client::SceneDefinition def = GetRenderer()->GetSceneDef();
			Vector3 frustrum[8];
			float tanX = tanf(def.fovX * .5f);
			float tanY = tanf(def.fovY * .5f);
			
			frustrum[0] = FrustrumCoord(def, tanX, tanY, near);
			frustrum[1] = FrustrumCoord(def, tanX, -tanY, near);
			frustrum[2] = FrustrumCoord(def, -tanX, tanY, near);
			frustrum[3] = FrustrumCoord(def, -tanX, -tanY, near);
			frustrum[4] = FrustrumCoord(def, tanX, tanY, far);
			frustrum[5] = FrustrumCoord(def, tanX, -tanY, far);
			frustrum[6] = FrustrumCoord(def, -tanX, tanY, far);
			frustrum[7] = FrustrumCoord(def, -tanX, -tanY, far);
			
			// compute frustrum's x,y boundary
			float minX, maxX, minY, maxY;
			minX = maxX = Vector3::Dot(frustrum[0], side);
			minY = maxY = Vector3::Dot(frustrum[0], up);
			for(int i = 1; i < 8; i++){
				float x = Vector3::Dot(frustrum[i], side);
				float y = Vector3::Dot(frustrum[i], up);
				if(x < minX) minX = x;
				if(x > maxX) maxX = x;
				if(y < minY) minY = y;
				if(y > maxY) maxY = y;
			}
			
			// compute frustrum's z boundary
			Segment seg;
			Plane3 plane1(0,0,1,-4.f);
			Plane3 plane2(0,0,1,64.f);
			seg += ZRange(side * minX + up * minY,
						  lightDir, plane1, plane2);
			seg += ZRange(side * minX + up * maxY,
						  lightDir, plane1, plane2);
			seg += ZRange(side * maxX + up * minY,
						  lightDir, plane1, plane2);
			seg += ZRange(side * maxX + up * maxY,
						  lightDir, plane1, plane2);
			
			
			for(int i = 1; i < 8; i++){
				seg += Vector3::Dot(frustrum[i], lightDir);
			}
			
			
			// build frustrum obb
			Vector3 origin = side * minX + up * minY + lightDir * seg.low;
			Vector3 axis1 = side * (maxX - minX);
			Vector3 axis2 = up * (maxY - minY);
			Vector3 axis3 = lightDir * (seg.high - seg.low);
			
			obb = OBB3(Matrix4::FromAxis(axis1, axis2, axis3,
										 origin));
			vpWidth = 2.f / axis1.GetLength();
			vpHeight = 2.f / axis2.GetLength();
		
			// convert to projectionview matrix
			matrix = obb.m.InversedFast();
			
			matrix = Matrix4::Scale(2.f) * matrix;
			matrix = Matrix4::Translate(-1, -1, -1) * matrix;
			
			// scale a little big for padding
			matrix = Matrix4::Scale(.98f) * matrix;
			//
			matrix = Matrix4::Scale(1,1,-1) * matrix;
			
			// make sure frustrums in range
#ifndef NDEBUG
			for(int i = 0; i < 8; i++){
				Vector4 v = matrix * frustrum[i];
				SPAssert(v.x >= -1.f);
				SPAssert(v.y >= -1.f);
				//SPAssert(v.z >= -1.f);
				SPAssert(v.x < 1.f);
				SPAssert(v.y < 1.f);
				//SPAssert(v.z < 1.f);
			}
#endif
		}