コード例 #1
0
	virtual bool apply(LLViewerObject* object, S32 te)
	{
		LLFace* facep = object->mDrawable->getFace(te);
		if (!facep)
		{
			return false;
		}
		if (facep == mCenterFace)
		{
			return true;
		}
		
		LLVector2 aligned_st_offset, aligned_st_scale;
		F32 aligned_st_rot;
		if ( facep->calcAlignedPlanarTE(mCenterFace, &aligned_st_offset, &aligned_st_scale, &aligned_st_rot) )
		{
			const LLTextureEntry* tep = facep->getTextureEntry();
			LLVector2 st_offset, st_scale;
			tep->getOffset(&st_offset.mV[VX], &st_offset.mV[VY]);
			tep->getScale(&st_scale.mV[VX], &st_scale.mV[VY]);
			F32 st_rot = tep->getRotation();
			// needs a fuzzy comparison, because of fp errors
			if (is_approx_equal_fraction(st_offset.mV[VX], aligned_st_offset.mV[VX], 16) && 
				is_approx_equal_fraction(st_offset.mV[VY], aligned_st_offset.mV[VY], 16) && 
				is_approx_equal_fraction(st_scale.mV[VX], aligned_st_scale.mV[VX], 16) &&
				is_approx_equal_fraction(st_scale.mV[VY], aligned_st_scale.mV[VY], 16) &&
				is_approx_equal_fraction(st_rot, aligned_st_rot, 14))
			{
				return true;
			}
		}
		return false;
	}
コード例 #2
0
	void llquat_test_object_t::test<21>()
	{
		//void LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) const fn
		F32 angle_value = 90.0f;
		LLVector3 vect(12.0f, 4.0f, 1.0f);
		LLQuaternion llquat(angle_value, vect);
		llquat.getAngleAxis(&angle_value, vect); 
		ensure(
			"LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) failed", 
			is_approx_equal_fraction(2.035406f, angle_value, 16) &&
			is_approx_equal_fraction(0.315244f, vect.mV[1], 16) &&
			is_approx_equal_fraction(0.078811f, vect.mV[2], 16) &&
			is_approx_equal_fraction(0.945733f, vect.mV[0], 16));
	}
コード例 #3
0
	void llquat_test_object_t::test<12>()
	{
		LLVector3d vect(-2.0f, 5.0f, -6.0f);
		LLQuaternion quat(-3.5f, 4.5f, 3.5f, 6.5f);
		LLVector3d result = vect * quat;
		ensure(
			"1. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed ", 
			(-633.0f == result.mdV[0]) &&
			(-300.0f == result.mdV[1]) &&
			(-36.0f == result.mdV[2]));

		LLVector3d vect1(5.0f, -4.5f, 8.21f);
		LLQuaternion quat1(2.0f, 4.5f, -7.2f, 9.5f);
		result = vect1 * quat1;
		ensure(
			"2. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", 
			is_approx_equal_fraction(-120.29f, (F32) result.mdV[0], 8) &&
			is_approx_equal_fraction(-1683.958f, (F32) result.mdV[1], 8) &&
			is_approx_equal_fraction(516.56f, (F32) result.mdV[2], 8));

		LLVector3d vect2(2.0f, 3.5f, 1.1f);
		LLQuaternion quat2(1.0f, 4.0f, 2.0f, 5.0f);
		result = vect2 * quat2;
		ensure(
			"3. LLVector3d operator*(const LLVector3d &a, const LLQuaternion &rot) failed", 
			is_approx_equal_fraction(18.400001f, (F32) result.mdV[0], 8) &&
			is_approx_equal_fraction(188.6f, (F32) result.mdV[1], 8) &&
			is_approx_equal_fraction(32.20f, (F32) result.mdV[2], 8));
	}
コード例 #4
0
	void llquat_test_object_t::test<7>()
	{
		F32 radian = 60.0f;
		LLQuaternion quat(3.0f, 2.0f, 6.0f, 0.0f);
		LLQuaternion quat1;
		quat1 = quat.constrain(radian);
		ensure("1. LLQuaternion::constrain(F32 radians) failed", 
									is_approx_equal_fraction(-0.423442f, quat1.mQ[0], 8) &&
									is_approx_equal_fraction(-0.282295f, quat1.mQ[1], 8) &&
									is_approx_equal_fraction(-0.846884f, quat1.mQ[2], 8) &&				
									is_approx_equal_fraction(0.154251f, quat1.mQ[3], 8));				
											

		radian = 30.0f;
		LLQuaternion quat0(37.50f, 12.0f, 86.023f, 40.32f);
		quat1 = quat0.constrain(radian);
	
		ensure("2. LLQuaternion::constrain(F32 radians) failed", 
									is_approx_equal_fraction(37.500000f, quat1.mQ[0], 8) &&
									is_approx_equal_fraction(12.0000f, quat1.mQ[1], 8) &&
									is_approx_equal_fraction(86.0230f, quat1.mQ[2], 8) &&				
									is_approx_equal_fraction(40.320000f, quat1.mQ[3], 8));				
	}
コード例 #5
0
bool llsd_equals(const LLSD& lhs, const LLSD& rhs, unsigned bits)
{
    // We're comparing strict equality of LLSD representation rather than
    // performing any conversions. So if the types aren't equal, the LLSD
    // values aren't equal.
    if (lhs.type() != rhs.type())
    {
        return false;
    }

    // Here we know both types are equal. Now compare values.
    switch (lhs.type())
    {
    case LLSD::TypeUndefined:
        // Both are TypeUndefined. There's nothing more to know.
        return true;

    case LLSD::TypeReal:
        // This is where the 'bits' argument comes in handy. If passed
        // explicitly, it means to use is_approx_equal_fraction() to compare.
        if (bits >= 0)
        {
            return is_approx_equal_fraction(lhs.asReal(), rhs.asReal(), bits);
        }
        // Otherwise we compare bit representations, and the usual caveats
        // about comparing floating-point numbers apply. Omitting 'bits' when
        // comparing Real values is only useful when we expect identical bit
        // representation for a given Real value, e.g. for integer-valued
        // Reals.
        return (lhs.asReal() == rhs.asReal());

#define COMPARE_SCALAR(type)                                    \
    case LLSD::Type##type:                                      \
        /* LLSD::URI has operator!=() but not operator==() */   \
        /* rely on the optimizer for all others */              \
        return (! (lhs.as##type() != rhs.as##type()))

    COMPARE_SCALAR(Boolean);
    COMPARE_SCALAR(Integer);
    COMPARE_SCALAR(String);
    COMPARE_SCALAR(UUID);
    COMPARE_SCALAR(Date);
    COMPARE_SCALAR(URI);
    COMPARE_SCALAR(Binary);

#undef COMPARE_SCALAR

    case LLSD::TypeArray:
    {
        LLSD::array_const_iterator
            lai(lhs.beginArray()), laend(lhs.endArray()),
            rai(rhs.beginArray()), raend(rhs.endArray());
        // Compare array elements, walking the two arrays in parallel.
        for ( ; lai != laend && rai != raend; ++lai, ++rai)
        {
            // If any one array element is unequal, the arrays are unequal.
            if (! llsd_equals(*lai, *rai, bits))
                return false;
        }
        // Here we've reached the end of one or the other array. They're equal
        // only if they're BOTH at end: that is, if they have equal length too.
        return (lai == laend && rai == raend);
    }

    case LLSD::TypeMap:
    {
        // Build a set of all rhs keys.
        std::set<LLSD::String> rhskeys;
        for (LLSD::map_const_iterator rmi(rhs.beginMap()), rmend(rhs.endMap());
             rmi != rmend; ++rmi)
        {
            rhskeys.insert(rmi->first);
        }
        // Now walk all the lhs keys.
        for (LLSD::map_const_iterator lmi(lhs.beginMap()), lmend(lhs.endMap());
             lmi != lmend; ++lmi)
        {
            // Try to erase this lhs key from the set of rhs keys. If rhs has
            // no such key, the maps are unequal. erase(key) returns count of
            // items erased.
            if (rhskeys.erase(lmi->first) != 1)
                return false;
            // Both maps have the current key. Compare values.
            if (! llsd_equals(lmi->second, rhs[lmi->first], bits))
                return false;
        }
        // We've now established that all the lhs keys have equal values in
        // both maps. The maps are equal unless rhs contains a superset of
        // those keys.
        return rhskeys.empty();
    }

    default:
        // We expect that every possible type() value is specifically handled
        // above. Failing to extend this switch to support a new LLSD type is
        // an error that must be brought to the coder's attention.
        LL_ERRS("llsd_equals") << "llsd_equals(" << lhs << ", " << rhs << ", " << bits << "): "
            "unknown type " << lhs.type() << LL_ENDL;
        return false;               // pacify the compiler
    }
}
コード例 #6
0
	void llquat_test_object_t::test<17>()
	{
		//test case for LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order)
		F32 x = 2.0f;
		F32 y = 1.0f;
		F32 z = 3.0f;
		
		LLQuaternion result = mayaQ(x, y, z, LLQuaternion::XYZ);
		ensure(
			"1. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
			is_approx_equal_fraction(0.0172174f, result.mQ[0], 16) &&
			is_approx_equal_fraction(0.009179f, result.mQ[1], 16) &&
			is_approx_equal_fraction(0.026020f, result.mQ[2], 16) &&
			is_approx_equal_fraction(0.999471f, result.mQ[3], 16));

		LLQuaternion result1 = mayaQ(x, y, z, LLQuaternion::YZX);
		ensure(
			"2. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XYZ",
			is_approx_equal_fraction(0.017217f, result1.mQ[0], 16) &&
			is_approx_equal_fraction(0.008265f, result1.mQ[1], 16) &&
			is_approx_equal_fraction(0.026324f, result1.mQ[2], 16) &&
			is_approx_equal_fraction(0.999471f, result1.mQ[3], 16));
		
		LLQuaternion result2 = mayaQ(x, y, z, LLQuaternion::ZXY);
		ensure(
			"3. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZXY", 
			is_approx_equal_fraction(0.017674f, result2.mQ[0], 16) &&
			is_approx_equal_fraction(0.008265f, result2.mQ[1], 16) &&
			is_approx_equal_fraction(0.026020f, result2.mQ[2], 16) &&
			is_approx_equal_fraction(0.999471f, result2.mQ[3], 16));
											
		LLQuaternion result3 = mayaQ(x, y, z, LLQuaternion::XZY);
		ensure(
			"4. TLLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for XZY", 
			is_approx_equal_fraction(0.017674f, result3.mQ[0], 16) &&
			is_approx_equal_fraction(0.009179f, result3.mQ[1], 16) &&
			is_approx_equal_fraction(0.026020f, result3.mQ[2], 16) &&
			is_approx_equal_fraction(0.999463f, result3.mQ[3], 16));
											
		LLQuaternion result4 = mayaQ(x, y, z, LLQuaternion::YXZ);
		ensure(
			"5. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for YXZ", 
			is_approx_equal_fraction(0.017217f, result4.mQ[0], 16) &&
			is_approx_equal_fraction(0.009179f, result4.mQ[1], 16) &&
			is_approx_equal_fraction(0.026324f, result4.mQ[2], 16) &&
			is_approx_equal_fraction(0.999463f, result4.mQ[3], 16));
											
		LLQuaternion result5 = mayaQ(x, y, z, LLQuaternion::ZYX);
		ensure(
			"6. LLQuaternion mayaQ(F32 xRot, F32 yRot, F32 zRot, LLQuaternion::Order order) failed for ZYX", 
			is_approx_equal_fraction(0.017674f, result5.mQ[0], 16) &&
			is_approx_equal_fraction(0.008265f, result5.mQ[1], 16) &&
			is_approx_equal_fraction(0.026324f, result5.mQ[2], 16) &&
			is_approx_equal_fraction(0.999463f, result5.mQ[3], 16));
	}
コード例 #7
0
	void llquat_test_object_t::test<8>()
	{
		F32 value1 = 15.0f;
		LLQuaternion quat1(1.0f, 2.0f, 4.0f, 1.0f);
		LLQuaternion quat2(4.0f, 3.0f, 6.5f, 9.7f);
		LLQuaternion res_lerp, res_slerp, res_nlerp;
		
		//test case for lerp(F32 t, const LLQuaternion &q) fn. 
		res_lerp = lerp(value1, quat1);
		ensure("1. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", 
										is_approx_equal_fraction(0.181355f, res_lerp.mQ[0], 16) &&
										is_approx_equal_fraction(0.362711f, res_lerp.mQ[1], 16) &&
										is_approx_equal_fraction(0.725423f, res_lerp.mQ[2], 16) &&				
										is_approx_equal_fraction(0.556158f, res_lerp.mQ[3], 16));				

		//test case for lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) fn.
		res_lerp = lerp(value1, quat1, quat2);
		ensure("2. LLQuaternion lerp(F32 t, const LLQuaternion &p, const LLQuaternion &q) failed",
										is_approx_equal_fraction(0.314306f, res_lerp.mQ[0], 16) &&
										is_approx_equal_fraction(0.116156f, res_lerp.mQ[1], 16) &&
										is_approx_equal_fraction(0.283559f, res_lerp.mQ[2], 16) &&				
										is_approx_equal_fraction(0.898506f, res_lerp.mQ[3], 16));				

		//test case for slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b ) fn.
		res_slerp = slerp(value1, quat1, quat2);
		ensure("3. LLQuaternion slerp( F32 u, const LLQuaternion &a, const LLQuaternion &b) failed", 
										is_approx_equal_fraction(46.000f, res_slerp.mQ[0], 16) &&
										is_approx_equal_fraction(17.00f, res_slerp.mQ[1], 16) &&
										is_approx_equal_fraction(41.5f, res_slerp.mQ[2], 16) &&				
										is_approx_equal_fraction(131.5f, res_slerp.mQ[3], 16));				

		//test case for nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) fn.
		res_nlerp = nlerp(value1, quat1, quat2);
		ensure("4. LLQuaternion nlerp(F32 t, const LLQuaternion &a, const LLQuaternion &b) failed",  
										is_approx_equal_fraction(0.314306f, res_nlerp.mQ[0], 16) &&
										is_approx_equal_fraction(0.116157f, res_nlerp.mQ[1], 16) &&
										is_approx_equal_fraction(0.283559f, res_nlerp.mQ[2], 16) &&				
										is_approx_equal_fraction(0.898506f, res_nlerp.mQ[3], 16));				

		//test case for nlerp(F32 t, const LLQuaternion &q) fn.
		res_slerp = slerp(value1, quat1);
		ensure("5. LLQuaternion slerp(F32 t, const LLQuaternion &q) failed", 
										is_approx_equal_fraction(1.0f, res_slerp.mQ[0], 16) &&
										is_approx_equal_fraction(2.0f, res_slerp.mQ[1], 16) &&
										is_approx_equal_fraction(4.0000f, res_slerp.mQ[2], 16) &&				
										is_approx_equal_fraction(1.000f, res_slerp.mQ[3], 16));				
										
		LLQuaternion quat3(2.0f, 1.0f, 5.5f, 10.5f);
		LLQuaternion res_nlerp1;
		value1 = 100.0f;
		res_nlerp1 = nlerp(value1, quat3);
		ensure("6. LLQuaternion nlerp(F32 t, const LLQuaternion &q)  failed", 
										is_approx_equal_fraction(0.268245f, res_nlerp1.mQ[0], 16) &&										is_approx_equal_fraction(0.134122f, res_nlerp1.mQ[1], 2) &&
										is_approx_equal_fraction(0.737673f, res_nlerp1.mQ[2], 16) &&				
										is_approx_equal_fraction(0.604892f, res_nlerp1.mQ[3], 16));				

		//test case for lerp(F32 t, const LLQuaternion &q) fn. 
		res_lerp = lerp(value1, quat2);
		ensure("7. LLQuaternion lerp(F32 t, const LLQuaternion &q) failed", 
										is_approx_equal_fraction(0.404867f, res_lerp.mQ[0], 16) &&
										is_approx_equal_fraction(0.303650f, res_lerp.mQ[1], 16) &&
										is_approx_equal_fraction(0.657909f, res_lerp.mQ[2], 16) &&				
										is_approx_equal_fraction(0.557704f, res_lerp.mQ[3], 16));				
		
	}