当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.length方法代码示例

本文整理汇总了Java中org.andengine.util.math.MathUtils.length方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.length方法的具体用法?Java MathUtils.length怎么用?Java MathUtils.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.andengine.util.math.MathUtils的用法示例。


在下文中一共展示了MathUtils.length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onUpdateColor

import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdateColor(final Gradient pGradient) {
	final float[] bufferData = this.mBufferData;

	final float gradientVectorX = pGradient.getGradientVectorX();
	final float gradientVectorY = pGradient.getGradientVectorY();

	final float length = MathUtils.length(gradientVectorX, gradientVectorY);
	if (length == 0) {
		return;
	}

	float dX = gradientVectorX / length;
	float dY = gradientVectorY / length;

	final float c = MathConstants.SQRT_2;
	final float c2 = 2 * c;

	if (pGradient.isGradientFitToBounds()) {
		final float tmp = 1 / (Math.abs(dX) + Math.abs(dY));
		dX *= tmp * c;
		dY *= tmp * c;
	}

	final float fromRed = pGradient.getFromRed();
	final float fromGreen = pGradient.getFromGreen();
	final float fromBlue = pGradient.getFromBlue();
	final float fromAlpha = pGradient.getFromAlpha(); // TODO * 'this.mOverallOpactity'

	final float toRed = pGradient.getToRed();
	final float toGreen = pGradient.getToGreen();
	final float toBlue = pGradient.getToBlue();
	final float toAlpha = pGradient.getToAlpha(); // TODO * 'this.mOverallOpactity'

	/* Pre-fetch some calculations. */
	final float dRed = fromRed - toRed;
	final float dGreen = fromGreen - toGreen;
	final float dBlue = fromBlue - toBlue;
	final float dAlpha = fromAlpha - toAlpha;


	final float v0 = (c + dX + dY) / c2;
	bufferData[(0 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v0), toGreen + (dGreen * v0), toBlue + (dBlue * v0), toAlpha + (dAlpha * v0));

	final float v1 = (c + dX - dY) / c2;
	bufferData[(1 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v1), toGreen + (dGreen * v1), toBlue + (dBlue * v1), toAlpha + (dAlpha * v1));

	final float v2 = (c - dX + dY) / c2;
	bufferData[(2 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v2), toGreen + (dGreen * v2), toBlue + (dBlue * v2), toAlpha + (dAlpha * v2));

	final float v3 = (c - dX - dY) / c2;
	bufferData[(3 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX] = ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v3), toGreen + (dGreen * v3), toBlue + (dBlue * v3), toAlpha + (dAlpha * v3));


	this.setDirtyOnHardware();
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:57,代码来源:HighPerformanceGradientVertexBufferObject.java

示例2: onUpdateColor

import org.andengine.util.math.MathUtils; //导入方法依赖的package包/类
@Override
public void onUpdateColor(final Gradient pGradient) {
	final FloatBuffer bufferData = this.mFloatBuffer;

	final float gradientVectorX = pGradient.getGradientVectorX();
	final float gradientVectorY = pGradient.getGradientVectorY();

	final float length = MathUtils.length(gradientVectorX, gradientVectorY);
	if (length == 0) {
		return;
	}

	float dX = gradientVectorX / length;
	float dY = gradientVectorY / length;

	final float c = MathConstants.SQRT_2;
	final float c2 = 2 * c;

	if (pGradient.isGradientFitToBounds()) {
		final float tmp = 1 / (Math.abs(dX) + Math.abs(dY));
		dX *= tmp * c;
		dY *= tmp * c;
	}

	final float fromRed = pGradient.getFromRed();
	final float fromGreen = pGradient.getFromGreen();
	final float fromBlue = pGradient.getFromBlue();
	final float fromAlpha = pGradient.getFromAlpha(); // TODO * 'this.mOverallOpactity'

	final float toRed = pGradient.getToRed();
	final float toGreen = pGradient.getToGreen();
	final float toBlue = pGradient.getToBlue();
	final float toAlpha = pGradient.getToAlpha(); // TODO * 'this.mOverallOpactity'

	/* Pre-fetch some calculations. */
	final float dRed = fromRed - toRed;
	final float dGreen = fromGreen - toGreen;
	final float dBlue = fromBlue - toBlue;
	final float dAlpha = fromAlpha - toAlpha;


	final float v0 = (c + dX + dY) / c2;
	bufferData.put((0 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v0), toGreen + (dGreen * v0), toBlue + (dBlue * v0), toAlpha + (dAlpha * v0)));

	final float v1 = (c + dX - dY) / c2;
	bufferData.put((1 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v1), toGreen + (dGreen * v1), toBlue + (dBlue * v1), toAlpha + (dAlpha * v1)));

	final float v2 = (c - dX + dY) / c2;
	bufferData.put((2 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v2), toGreen + (dGreen * v2), toBlue + (dBlue * v2), toAlpha + (dAlpha * v2)));

	final float v3 = (c - dX - dY) / c2;
	bufferData.put((3 * Gradient.VERTEX_SIZE) + Gradient.COLOR_INDEX, ColorUtils.convertRGBAToABGRPackedFloat(toRed + (dRed * v3), toGreen + (dGreen * v3), toBlue + (dBlue * v3), toAlpha + (dAlpha * v3)));


	this.setDirtyOnHardware();
}
 
开发者ID:ArturVasilov,项目名称:AndroidCourses,代码行数:57,代码来源:LowMemoryGradientVertexBufferObject.java


注:本文中的org.andengine.util.math.MathUtils.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。