Exemple #1
0
float GetPlaneCapsuleOffset(const Vect &dir, float capsuleHalfHeight, float capsuleRadius)
{
    Vect2 dir2(sqrtf(1.0f-(dir.y*dir.y)), fabs(dir.y));
    Vect2 centerOffset(capsuleRadius, capsuleHalfHeight);

    return centerOffset.Dot(dir2)-(1.0f-MAX(dir2.x, dir2.y));
}
Exemple #2
0
float GetPlaneCylinderOffset(const Vect &dir, float cylHalfHeight, float cylRadius)
{
    Vect2 dir2(sqrtf(1.0f-(dir.y*dir.y)), fabs(dir.y));
    Vect2 centerOffset(cylRadius, cylHalfHeight);

    return centerOffset.Dot(dir2);
}
Exemple #3
0
void test_filter_sweep() {		
	WhiteNoise wnoise;
	Sine centerSin;
	centerSin.set_frequency(0.5);
	MulOp centerMod(centerSin, 500.0);
	StaticVariable centerOffset(1000);
	AddOp centerSweep(centerMod, 1000.0);
	Sine BWSin;
	BWSin.set_frequency(5);
	MulOp BWMod(BWSin, 50.0);
	AddOp BWSweep(BWMod, 100.0);
	Butter lpfilter(wnoise, wnoise.sample_rate(), Butter::BW_BAND_PASS, centerSweep, BWSweep);
	logMsg("playing filter_sweep...");
	run_test(lpfilter);
	logMsg("filter_sweep done.");
}
void ButtonComponent::render(const Eigen::Affine3f& parentTrans)
{
	Eigen::Affine3f trans = roundMatrix(parentTrans * getTransform());
	
	mBox.render(trans);

	if(mTextCache)
	{
		Eigen::Vector3f centerOffset((mSize.x() - mTextCache->metrics.size.x()) / 2, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0);
		centerOffset = roundVector(centerOffset);
		trans = trans.translate(centerOffset);

		Renderer::setMatrix(trans);
		mTextCache->setColor(getCurTextColor());
		mFont->renderTextCache(mTextCache.get());
		trans = trans.translate(-centerOffset);
	}

	renderChildren(trans);
}
Exemple #5
0
 void Scale9Sprite::updatePositions()
 {
     Size size = this->_contentSize;
     
     float sizableWidth = size.width - _topLeftSize.width - _bottomRightSize.width;
     float sizableHeight = size.height - _topLeftSize.height - _bottomRightSize.height;
     
     float horizontalScale = sizableWidth/_centerSize.width;
     float verticalScale = sizableHeight/_centerSize.height;
     
     if(_centre)
     {
         _centre->setScaleX(horizontalScale);
         _centre->setScaleY(verticalScale);
     }
     
     float rescaledWidth = _centerSize.width * horizontalScale;
     float rescaledHeight = _centerSize.height * verticalScale;
     
     float leftWidth = _topLeftSize.width;
     float bottomHeight = _bottomRightSize.height;
     
     Vec2 centerOffset(_centerOffset.x * horizontalScale, _centerOffset.y * verticalScale);
     
     // Position corners
     if(_bottomLeft)
     {
         _bottomLeft->setAnchorPoint(Vec2(1,1));
         _bottomLeft->setPosition(leftWidth,bottomHeight);
     }
     if(_bottomRight)
     {
         _bottomRight->setAnchorPoint(Vec2(0,1));
         _bottomRight->setPosition(leftWidth+rescaledWidth,bottomHeight);
     }
     if(_topLeft)
     {
         _topLeft->setAnchorPoint(Vec2(1,0));
         _topLeft->setPosition(leftWidth, bottomHeight+rescaledHeight);
     }
     if(_topRight)
     {
         _topRight->setAnchorPoint(Vec2(0,0));
         _topRight->setPosition(leftWidth+rescaledWidth, bottomHeight+rescaledHeight);
     }
     
     // Scale and position borders
     if(_left)
     {
         _left->setAnchorPoint(Vec2(1,0.5));
         _left->setPosition(leftWidth, bottomHeight+rescaledHeight/2 + centerOffset.y);
         _left->setScaleY(verticalScale);
     }
     if(_right)
     {
         _right->setAnchorPoint(Vec2(0,0.5));
         _right->setPosition(leftWidth+rescaledWidth,bottomHeight+rescaledHeight/2 + centerOffset.y);
         _right->setScaleY(verticalScale);
     }
     if(_top)
     {
         _top->setAnchorPoint(Vec2(0.5,0));
         _top->setPosition(leftWidth+rescaledWidth/2 + centerOffset.x,bottomHeight+rescaledHeight);
         _top->setScaleX(horizontalScale);
     }
     if(_bottom)
     {
         _bottom->setAnchorPoint(Vec2(0.5,1));
         _bottom->setPosition(leftWidth+rescaledWidth/2 + centerOffset.x,bottomHeight);
         _bottom->setScaleX(horizontalScale);
     }
     // Position centre
     if(_centre)
     {
         _centre->setAnchorPoint(Vec2(0.5,0.5));
         _centre->setPosition(leftWidth+rescaledWidth/2 + centerOffset.x, bottomHeight+rescaledHeight/2 + centerOffset.y);
         _centre->setScaleX(horizontalScale);
         _centre->setScaleY(verticalScale);
     }
 }
//--------------------------------------------------------------------------------------------------
// Name: ExtractUVCoords
// Desc: Extracts the uv coord basis from the render mesh
//--------------------------------------------------------------------------------------------------
void CBreakableGlassSystem::ExtractUVCoords(IStatObj* const pStatObj, const primitives::box& bbox, const int thinAxis, SBreakableGlassPhysData& data)
{
	IIndexedMesh* pIndexedMesh = pStatObj ? pStatObj->GetIndexedMesh(true) : NULL;
	CMesh* pMesh = pIndexedMesh ? pIndexedMesh->GetMesh() : NULL;

	if (pMesh)
	{
		CRY_ASSERT(pMesh->m_pPositionsF16 == 0);
		const SMeshTexCoord* pUV = pMesh->m_pTexCoord;
		const SMeshTangents* pTangents = pMesh->m_pTangents;
		const Vec3* pPositions = pMesh->m_pPositions;

		if (pTangents && pUV)
		{	
			// Determine thinnest axis
			Vec3 thinRow = bbox.Basis.GetRow(idxmin3((float*)&bbox.size));

			// Attempt UV coord extraction
			const int numVerts = pMesh->GetVertexCount();
			CRY_ASSERT(numVerts == pMesh->GetTexCoordCount());

			// Initialise our surface points with invalid data
			uint pts[6] =
			{
				numVerts, numVerts, numVerts, // Front faces
				numVerts, numVerts, numVerts	// Back faces
			};

			for (int i = 0; i < numVerts; ++i)
			{
				// Unpack surface data
				Vec3 tangent, binormal;
				tPackB2F(pTangents[i].Tangent, tangent);
				tPackB2F(pTangents[i].Binormal, binormal);
				Vec3 normal = tangent.Cross(binormal);

				// Validate vertex is part of our surface
				const float flatThreshold = 0.95f;
				const float dot = thinRow.Dot(normal);

				if (dot >= flatThreshold)
				{
					// Store unique points to determine UV axes
					if (pts[0] == numVerts)
					{
						pts[0] = i;
					}
					else if (pts[1] == numVerts && pUV[pts[0]].s != pUV[i].s)
					{
						pts[1] = i;
					}
					else if (pts[2] == numVerts && pUV[pts[0]].t != pUV[i].t)
					{
						pts[2] = i;
					}

					if (pts[1] < numVerts && pts[2] < numVerts)
					{
						break;
					}
				}
				else if (dot <= -flatThreshold)
				{
					// Same as above, but for back-faces
					if (pts[3] == numVerts)
					{
						pts[3] = i;
					}
					else if (pts[4] == numVerts && pUV[pts[3]].s != pUV[i].s)
					{
						pts[4] = i;
					}
					else if (pts[5] == numVerts && pUV[pts[3]].t != pUV[i].t)
					{
						pts[5] = i;
					}

					if (pts[4] < numVerts && pts[5] < numVerts)
					{
						break;
					}
				}
			}

			// If we failed to get data from the front faces, swap with back
			if (pts[1] == numVerts || pts[2] == numVerts)
			{
				pts[0] = pts[3];
				pts[1] = pts[4];
				pts[2] = pts[5];
			}

			if (pts[1] < numVerts && pts[2] < numVerts)
			{
				// Calculate vertex transformation constants
				int xAxis = thinAxis == 0 ? 2 : (thinAxis == 1 ? 0 : 0);
				int yAxis = thinAxis == 0 ? 1 : (thinAxis == 1 ? 2 : 1);

				const Vec3& vx = bbox.Basis.GetRow(xAxis);
				const Vec3& vy = bbox.Basis.GetRow(yAxis);

				const Vec3 centerAxis = bbox.Basis.TransformVector(bbox.center);
				Vec2 centerOffset(centerAxis[xAxis], centerAxis[yAxis]);

				// Transform and store best 3 points
				data.uvBasis[0].x = vx.Dot(pPositions[pts[0]]) - centerOffset.x;
				data.uvBasis[0].y = vy.Dot(pPositions[pts[0]]) - centerOffset.y;

				data.uvBasis[1].x = vx.Dot(pPositions[pts[1]]) - centerOffset.x;
				data.uvBasis[1].y = vy.Dot(pPositions[pts[1]]) - centerOffset.y;

				data.uvBasis[2].x = vx.Dot(pPositions[pts[2]]) - centerOffset.x;
				data.uvBasis[2].y = vy.Dot(pPositions[pts[2]]) - centerOffset.y;

				// Store associated UV coords
				data.uvBasis[0].z = pUV[pts[0]].s;
				data.uvBasis[0].w = pUV[pts[0]].t;

				data.uvBasis[1].z = pUV[pts[1]].s;
				data.uvBasis[1].w = pUV[pts[1]].t;

				data.uvBasis[2].z = pUV[pts[2]].s;
				data.uvBasis[2].w = pUV[pts[2]].t;
			}
			else
			{
				LOG_GLASS_ERROR("Failed to extract UV coordinates from mesh.");
			}
		}
	}
}//-------------------------------------------------------------------------------------------------