void ImageBox::OnAnySizeChanged(){
	if (!mAtlasRegion && mAtlasRegions.empty())
	{
		auto texture = mUIObject->GetMaterial()->GetTexture(BINDING_SHADER_PS, 0);
		if (texture)
			CalcUV(texture->GetSize());
	}
	else{
		if (mAtlasRegion)
		{
			const auto& imagesize = mAtlasRegion->GetSize();
			/*if (imagesize.x > mSize.x * 2 || imagesize.y > mSize.y * 2){
				Vec2 start((float)mAtlasRegion->mStart.x, (float)mAtlasRegion->mStart.y);
				auto xsize = imagesize.x > mSize.x * 2 ? mSize.x : imagesize.x;
				auto ysize = imagesize.y > mSize.y * 2 ? mSize.y : imagesize.y;
				Vec2 end(start.x + xsize, start.y + ysize);
				auto uvEnd = end / mTextureAtlas->mTexture->GetSize();
				Vec2 texcoords[4];
				texcoords[0] = Vec2(mAtlasRegion->mUVStart.x, uvEnd.y);
				texcoords[1] = mAtlasRegion->mUVStart;
				texcoords[2] = uvEnd;
				texcoords[3] = Vec2(uvEnd.x, mAtlasRegion->mUVStart.y);
				mUIObject->SetTexCoord(texcoords, 4);
			}
			else{*/
				Vec2 texcoords[4];
				mAtlasRegion->GetQuadUV(texcoords);
				mUIObject->SetTexCoord(texcoords, 4);
			//}

		}
	}
}
Example #2
0
void ViewableSphere::CalcUV( const VectorR3& posVec, VectorR2* returnedUV ) const
{
	double z = posVec^AxisA;
	double y = posVec^AxisC;
	double x = posVec^AxisB;

	CalcUV( x, y, z, uvProjectionType, returnedUV );
}
void ImageBox::SetKeepImageRatio(bool keep)
{
	mKeepImageRatio = keep;
	if (!mAtlasRegion)
	{
		auto texture = mUIObject->GetMaterial()->GetTexture(BINDING_SHADER_PS, 0);
		if (texture)
			CalcUV(texture->GetSize());
	}
}
void ImageBox::SetTexture(TexturePtr pTexture)
{
	//mImageFile.clear();
	if (!pTexture || strlen(pTexture->GetFilePath())==0){
		mImageFile.clear();
	}
	mTexture = pTexture;
	SAMPLER_DESC sd;
	sd.AddressU = TEXTURE_ADDRESS_BORDER;
	sd.AddressV = TEXTURE_ADDRESS_BORDER;
	sd.AddressW = TEXTURE_ADDRESS_BORDER;
	mUIObject->GetMaterial()->SetTexture(pTexture, BINDING_SHADER_PS, 0, sd);
	if (pTexture)
		CalcUV(pTexture->GetSize());
}
Example #5
0
void Lemon::UVCoord(Vector2d& Result, const Intersection *Inter, TraceThreadData *Thread) const
{
    CalcUV(Inter->IPoint, Result);
}
Example #6
0
// Returns an intersection if found with distance maxDistance
// viewDir must be a unit vector.
// intersectDistance and visPoint are returned values.
bool ViewableSphere::FindIntersectionNT ( 
		const VectorR3& viewPos, const VectorR3& viewDir, double maxDist,
		double *intersectDistance, VisiblePoint& returnedPoint ) const 
{
	VectorR3 tocenter(Center);
	tocenter -= viewPos;		// Vector view position to the center

	// D = Distance to pt on view line closest to sphere
	// v = vector from sphere center to the closest pt on view line
	// ASq = the distance from v to sphere center squared
	double D = (viewDir^tocenter);
	VectorR3 v(viewDir);
	v *= D;
	v -= tocenter;
	double ASq = v.NormSq();

	// Ray-line completely misses sphere, or just grazes it.
	if ( ASq >= RadiusSq ) {
		return false;
	}

	double BSq = RadiusSq-ASq;
	if ( D>0.0 && D*D>BSq && 
		(D<maxDist || BSq>Square(D-maxDist) ) ) {
		
		// Return the point where view intersects with the outside of
		//		the sphere.
		*intersectDistance = D-sqrt(BSq);
		v = viewDir;
		v *= *intersectDistance;
		v += viewPos;					//  Position of intersection
		returnedPoint.SetPosition( v );
		v -= Center;					
		v /= Radius;	// Normalize: normal out from intersection pt
		v.ReNormalize();
		returnedPoint.SetNormal( v );
		returnedPoint.SetMaterial ( *OuterMaterial );
		returnedPoint.SetFrontFace();	// Front face direction
		CalcUV( v, &(returnedPoint.GetUV()) );
		returnedPoint.SetFaceNumber( 0 );
		return true;
	}

	else if ( (D>0.0 || D*D<BSq) && D<maxDist && BSq<Square(D-maxDist) ) {

		// return the point where view exits the sphere
		*intersectDistance = D+sqrt(BSq);
		v = viewDir;
		v *= *intersectDistance;
		v += viewPos;
		returnedPoint.SetPosition( v );
		v -= Center;
		v /= Radius;	// Normalize, but still points outward
		v.ReNormalize(); // Just in case
		returnedPoint.SetNormal( v );
		returnedPoint.SetMaterial ( *InnerMaterial );
		returnedPoint.SetBackFace();
		CalcUV( v, &(returnedPoint.GetUV()) );
		return true;
	}

	else {
		return false;
	}
}
Example #7
0
void Torus::UVCoord(UV_VECT Result, const Intersection *Inter, TraceThreadData *Thread) const
{
	CalcUV(Inter->IPoint, Result);
}