Ejemplo n.º 1
0
// ***************************************************************************
void					CMaterial::decompUserTexMat(uint stage, float &uTrans, float &vTrans, float &wRot, float &uScale, float &vScale)
{
	nlassert(stage < IDRV_MAT_MAXTEXTURES);
	nlassert(isUserTexMatEnabled(stage)); // must activate animated texture matrix for this stage
	CMatrix convMat; // exported v are already inverted (todo: optim this...)
	convMat.setRot(CVector::I, -CVector::J, CVector::K);
	convMat.setPos(CVector::J);

	const NLMISC::CMatrix texMat = convMat * _TexUserMat->TexMat[stage] * convMat;
	/// find the rotation around w
	NLMISC::CVector i = texMat.getI();
	NLMISC::CVector j = texMat.getJ();
	uScale = sqrtf(i.x * i.x + j.x * j.x);
	vScale = sqrtf(i.y * i.y + j.y * j.y);
	//
	i.normalize();
	//
	float angle = acosf(i.x / i.norm());
	if (i.y < 0)
	{
		angle = 2.f * (float) NLMISC::Pi - angle;
	}
	wRot = angle;

	// compute position
	CMatrix InvSR;
	InvSR.setRot(texMat.getI(), texMat.getJ(), texMat.getK());
	InvSR.invert();
	CVector half(0.5f, 0.5f, 0.f);
	CVector offset = half + InvSR * (texMat.getPos() -half);
	uTrans = - offset.x;
	vTrans = - offset.y;
}
Ejemplo n.º 2
0
void CDirectionEdit::selectNewVect(const CPoint &point)
{
	const float epsilon = 10E-3f;
	NLMISC::CVector v = _Wrapper->get();
	if (point.x > CornerDist && point.y > CornerDist && point.x < (CornerDist + BasisSize) && point.y < (CornerDist + BasisSize))
	{		
		ScreenToVect(v.x, v.z, point.x, point.y, CornerDist, CornerDist, BasisSize);	
		float d = v.x * v.x + v.z * v.z;
		float f; 
		if (fabsf(d > epsilon))
		{
			f = sqrtf((1.f - v.y * v.y) / d);
		}
		else
		{
			f = 1;
		}

		v.x *= f;
		v.z *= f;
	}

	if (point.x > CornerDist && point.y > (BasisGap + BasisSize + CornerDist) && point.x < (CornerDist + BasisSize) && point.y < (CornerDist + BasisGap + 2 * BasisSize))
	{		
		ScreenToVect(v.y, v.z, point.x, point.y, CornerDist, CornerDist + BasisGap + BasisSize, BasisSize);	
		float d = v.y * v.y + v.z * v.z;
		float f; 
		if (fabsf(d > epsilon))
		{
			f = sqrtf((1.f - v.x * v.x) / d);
		}
		else
		{
			f = 1;
		}

		v.y *= f;
		v.z *= f;
	}

	v.normalize();
	_Wrapper->setAndUpdateModifiedFlag(v);

	Invalidate();

}
Ejemplo n.º 3
0
void CDirectionWidget::setNewVecYZ(float x, float y)
{
	const float epsilon = 10E-3f;
	NLMISC::CVector v = _value;

	v.y = x;
	v.z = y;

	float d = v.y * v.y + v.z * v.z;
	float f;
	if (fabs(d) > epsilon)
		f = sqrt((1.f - v.x * v.x) / d);
	else
		f = 1;

	v.y *= f;
	v.z *= f;

	v.normalize();

	setValue(v);
}
void CDirectionWidget::setNewVecYZ(float x, float y)
{
	const float epsilon = 10E-3f;
	NLMISC::CVector v = _Wrapper->get();
	
	v.y = x;
	v.z = y;
	
	float d = v.y * v.y + v.z * v.z;
	float f; 
	if (fabs(d) > epsilon)
		f = sqrt((1.f - v.x * v.x) / d);
	else
		f = 1;
	
	v.y *= f;
	v.z *= f;
	
	v.normalize();

	_Wrapper->setAndUpdateModifiedFlag(v);
	_ui.xzWidget->setVector(_Wrapper->get().x, _Wrapper->get().z);
	_ui.yzWidget->setVector(_Wrapper->get().y, _Wrapper->get().z);
}