Esempio 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;
}
Esempio n. 2
0
/*
 * Get the orientation vectors
 */
void					CListenerAL::getOrientation( NLMISC::CVector& front, NLMISC::CVector& up ) const
{
	// Forward then up
	ALfloat v[6];
	alGetListenerfv( AL_ORIENTATION, v );
	alTestError();
	// Coordsys conversion
	front.set( v[0], -v[2], v[1] );
	up.set( v[3], -v[5], v[4] );
}
/*
 * Set the direction vector (3D mode only, ignored in stereo mode) (default: (0,0,0) as non-directional)
 */
void CStreamSource::setDirection(const NLMISC::CVector& dir)
{
	CAutoMutex<CMutex> autoMutex(m_BufferMutex);

	CSourceCommon::setDirection(dir);

	// Set the direction
	if (hasPhysicalSource())
	{
		if (!m_Buffers[0]->isStereo())
		{
			static bool coneset = false;
			if (dir.isNull()) // workaround // For what?
			{
				getPhysicalSource()->setCone(float(Pi * 2), float(Pi * 2), 1.0f); // because the direction with 0 is not enough for a non-directional source!
				getPhysicalSource()->setDirection(CVector::I);  // Don't send a 0 vector, DSound will complain. Send (1,0,0), it's omnidirectional anyway.
				coneset = false;
			}
			else
			{
//				if (!coneset)
				{
					getPhysicalSource()->setCone(m_StreamSound->getConeInnerAngle(), m_StreamSound->getConeOuterAngle(), m_StreamSound->getConeOuterGain());
					coneset = true;
				}
				getPhysicalSource()->setDirection(dir);
			}
		}
	}
}
Esempio n. 4
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();

}
Esempio n. 5
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);
}
Esempio n. 6
0
/*
 * Get the velocity vector
 */
void				 	CListenerAL::getVelocity( NLMISC::CVector& vel ) const
{
#ifdef NL_OS_WINDOWS
	// Coordsys conversion
	float glposz;
	alGetListener3f( AL_VELOCITY, &vel.x, &vel.z, &glposz );
	vel.y = - glposz;
#else
	float velarray [3];
	alGetListenerfv( AL_VELOCITY, velarray );
	// Coordsys conversion
	vel.set( velarray[0], -velarray[2], velarray[1] );
#endif
	alTestError();
}
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);
}
Esempio n. 8
0
// ***************************************************************************
void CExportNel::getNELBoneLocalScale(INode &node, TimeValue time, NLMISC::CVector &nelScale)
{
	// To get the correct local Scale, we use an other bone as reference (if present)
	INode	*referenceNode= getNELScaleReferenceNode(node);

	// get the Max local pos.
	Matrix3 localTM (TRUE);
	getLocalMatrix (localTM, node, time);
	NLMISC::CVector		maxScale;
	NLMISC::CQuat		maxRot;
	NLMISC::CVector		maxPos;
	decompMatrix (maxScale, maxRot, maxPos, localTM);


	// Biped node case, take the scale from ratio with the reference node.
	if(isBipedNode(node))
	{
		// Replace scale with ratio from reference value, if possible
		if (referenceNode)
		{
			ScaleValue	scaleValue;
			// get my Offset scale.
			CVector		myScale;
			scaleValue = node.GetObjOffsetScale();
			myScale.x= scaleValue.s.x;
			myScale.y= scaleValue.s.y;
			myScale.z= scaleValue.s.z;

			// get its Offset scale.
			CVector		refScale;
			scaleValue = referenceNode->GetObjOffsetScale();
			refScale.x= scaleValue.s.x;
			refScale.y= scaleValue.s.y;
			refScale.z= scaleValue.s.z;

			// Get The ratio as the result
			nelScale.x= myScale.x / refScale.x;
			nelScale.y= myScale.y / refScale.y;
			nelScale.z= myScale.z / refScale.z;
		}
		else
		{
			// Not present, suppose no scale.
			nelScale.set(1,1,1);
		}

	}
	// get the scale from std way.
	else
	{
		// We are a normal node here, not biped.

		/* If this node do not inherit scale (ie must unherit), then we must not take the localScale computed 
			with getLocalMatrix. In this case, the local Scale is simply the NodeTM scale.
		*/
		if( getNELUnHeritFatherScale(node) )
		{
			Matrix3	nodeTM;
			nodeTM = node.GetNodeTM (time);
			decompMatrix (maxScale, maxRot, maxPos, nodeTM);
			// Get the scale from worldMatrix.
			nelScale= maxScale;
		}
		else
		{
			// Get the scale from localMatrix.
			nelScale= maxScale;
		}
	}

}