Java Code Examples for android.util.FloatMath#sin()

The following examples show how to use android.util.FloatMath#sin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Transformation.java    From 30-android-libraries-in-30-days with Apache License 2.0 6 votes vote down vote up
public final void preRotate(final float pAngle) {
	final float angleRad = MathConstants.DEG_TO_RAD * pAngle;

	final float sin = FloatMath.sin(angleRad);
	final float cos = FloatMath.cos(angleRad);

	final float a = this.a;
	final float b = this.b;
	final float c = this.c;
	final float d = this.d;

	this.a = cos * a + sin * c;
	this.b = cos * b + sin * d;
	this.c = cos * c - sin * a;
	this.d = cos * d - sin * b;
}
 
Example 2
Source File: PLHotspot.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
protected List<PLPosition> calculatePoints(GL10 gl)
{
	List<PLPosition> result = new ArrayList<PLPosition>(4);
	//1
	PLPosition pos = this.convertPitchAndYawToPosition(mAtv, mAth), pos1 = this.convertPitchAndYawToPosition(mAtv + 0.0001f, mAth);
	//2 and 3
	PLVector3 p1 = new PLVector3(pos.x, pos.y, pos.z),
			  p2p1 = new PLVector3(0.0f, 0.0f, 0.0f).sub(p1),
			  r = p2p1.crossProduct(new PLVector3(pos1.x, pos1.y, pos1.z).sub(p1)),
			  s = p2p1.crossProduct(r);
	//4
	r.normalize();
	s.normalize();
	//5.1
	float w = mWidth * PLConstants.kPanoramaRadius, h = mHeight * PLConstants.kPanoramaRadius;
	float radius = FloatMath.sqrt((w * w) + (h * h));
	//5.2
	float angle = (float)Math.asin(h / radius);
	//5.3
	PLVector3 n = new PLVector3(0.0f, 0.0f, 0.0f);
	for(float theta : new float[]{ PLConstants.kPI - angle, angle, PLConstants.kPI + angle, 2 * PLConstants.kPI - angle})
	{
		n.x = p1.x + (radius * FloatMath.cos(theta) * r.x) + (radius * FloatMath.sin(theta) * s.x);
		n.y = p1.y + (radius * FloatMath.cos(theta) * r.y) + (radius * FloatMath.sin(theta) * s.y);
		n.z = p1.z + (radius * FloatMath.cos(theta) * r.z) + (radius * FloatMath.sin(theta) * s.z);
		n.normalize();
		result.add(PLPosition.PLPositionMake(n.x, n.y, n.z));
	}
	return result;
}
 
Example 3
Source File: EaseElasticIn.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public static float getValue(final float pSecondsElapsed, final float pDuration, final float pPercentage) {
	if(pSecondsElapsed == 0) {
		return 0;
	}
	if(pSecondsElapsed == pDuration) {
		return 1;
	}

	final float p = pDuration * 0.3f;
	final float s = p / 4;

	final float t = pPercentage - 1;
	return -(float)Math.pow(2, 10 * t) * FloatMath.sin((t * pDuration - s) * MathConstants.PI_TWICE / p);
}
 
Example 4
Source File: EaseElasticOut.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public static float getValue(final float pSecondsElapsed, final float pDuration, final float pPercentageDone) {
	if(pSecondsElapsed == 0) {
		return 0;
	}
	if(pSecondsElapsed == pDuration) {
		return 1;
	}

	final float p = pDuration * 0.3f;
	final float s = p / 4;

	return 1 + (float)Math.pow(2, -10 * pPercentageDone) * FloatMath.sin((pPercentageDone * pDuration - s) * MathConstants.PI_TWICE / p);
}
 
Example 5
Source File: MathUtils.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public static float[] rotateAroundCenter(final float[] pVertices, final float pRotation, final float pRotationCenterX, final float pRotationCenterY) {
	if(pRotation != 0) {
		final float rotationRad = MathUtils.degToRad(pRotation);
		final float sinRotationRad = FloatMath.sin(rotationRad);
		final float cosRotationInRad = FloatMath.cos(rotationRad);

		for(int i = pVertices.length - 2; i >= 0; i -= 2) {
			final float pX = pVertices[i];
			final float pY = pVertices[i + 1];
			pVertices[i] = pRotationCenterX + (cosRotationInRad * (pX - pRotationCenterX) - sinRotationRad * (pY - pRotationCenterY));
			pVertices[i + 1] = pRotationCenterY + (sinRotationRad * (pX - pRotationCenterX) + cosRotationInRad * (pY - pRotationCenterY));
		}
	}
	return pVertices;
}
 
Example 6
Source File: AnalogOnScreenControl.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
protected void onUpdateControlKnob(final float pRelativeX, final float pRelativeY) {
	if(pRelativeX * pRelativeX + pRelativeY * pRelativeY <= 0.25f) {
		super.onUpdateControlKnob(pRelativeX, pRelativeY);
	} else {
		final float angleRad = MathUtils.atan2(pRelativeY, pRelativeX);
		super.onUpdateControlKnob(FloatMath.cos(angleRad) * 0.5f, FloatMath.sin(angleRad) * 0.5f);
	}
}
 
Example 7
Source File: TriangleFeature.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
@Override
	public void onCreateInGLESThread() {
		
		final int numOfVertices = (numBorderPoints+2) * 3;
		final int numOfColors = (numBorderPoints+2) * 4;
//		final int numOfTexCoords = (numBorderPoints+2) * 2;
		
		final float[] vertices = new float[numOfVertices];
		final float[] colors = new float[numOfColors];
		final float[] normals = new float[numOfVertices];
//		final float[] texCoords = new float[numOfTexCoords];
		
		for (int i = 3, point = 0; i < numOfVertices; i += 3, point++) {
			float radians = (float) Math.toRadians(360.f - point * 360.f / numBorderPoints);
			vertices[i] 	= FloatMath.cos(radians);
			vertices[i + 2] = FloatMath.sin(radians);

			normals[i + 1] = 1.0f;
		}
		
		/** set color coordinates - first point is in the middle */
		colors[0] = 1.0f;
		colors[3] = 1.0f;
		for (int i = 4; i < numOfColors; i += 4) {
			colors[i] = 1.0f;
			colors[i + 3] = 0.1f;
		}
		
		setRenderObjectives(vertices, colors, normals, null);
	}
 
Example 8
Source File: MathUtils.java    From umeng_community_android with MIT License 5 votes vote down vote up
/**
 * Rotates p1 around p2 by angle degrees.
 * @param p1
 * @param p2
 * @param angle
 */
public void rotate(PointF p1, PointF p2, float angle) {
	float px = p1.x;
	float py = p1.y;
	float ox = p2.x;
	float oy = p2.y;
	p1.x = (FloatMath.cos(angle) * (px-ox) - FloatMath.sin(angle) * (py-oy) + ox);
	p1.y = (FloatMath.sin(angle) * (px-ox) + FloatMath.cos(angle) * (py-oy) + oy);
}
 
Example 9
Source File: Transformation.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
public final Transformation setToRotate(final float pAngle) {
	final float angleRad = MathConstants.DEG_TO_RAD * pAngle;

	final float sin = FloatMath.sin(angleRad);
	final float cos = FloatMath.cos(angleRad);

	this.a = cos;
	this.b = sin;
	this.c = -sin;
	this.d = cos;
	this.tx = 0.0f;
	this.ty = 0.0f;

	return this;
}
 
Example 10
Source File: MathUtils.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
/**
 * Rotates p1 around p2 by angle degrees.
 * @param p1
 * @param p2
 * @param angle
 */
public void rotate(PointF p1, PointF p2, float angle) {
	float px = p1.x;
	float py = p1.y;
	float ox = p2.x;
	float oy = p2.y;
	p1.x = (FloatMath.cos(angle) * (px-ox) - FloatMath.sin(angle) * (py-oy) + ox);
	p1.y = (FloatMath.sin(angle) * (px-ox) + FloatMath.cos(angle) * (py-oy) + oy);
}
 
Example 11
Source File: PLHotspot.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**calculate methods*/

protected PLPosition convertPitchAndYawToPosition(float pitch, float yaw)
{
	float r = this.getZ(), pr = (90.0f - pitch) * PLConstants.kToRadians, yr = -yaw * PLConstants.kToRadians;
	float x = r * FloatMath.sin(pr) * FloatMath.cos(yr);
	float y = r * FloatMath.sin(pr) * FloatMath.sin(yr);
	float z = r * FloatMath.cos(pr);
	return PLPosition.PLPositionMake(y, z, x);
}
 
Example 12
Source File: VectorF.java    From umeng_community_android with MIT License 4 votes vote down vote up
public void calculateEndPoint() {
	end.x = FloatMath.cos(angle) * length + start.x;
	end.y = FloatMath.sin(angle) * length + start.y;
}
 
Example 13
Source File: CustomViewAbove.java    From BigApp_WordPress_Android with Apache License 2.0 4 votes vote down vote up
float distanceInfluenceForSnapDuration(float f) {
	f -= 0.5f; // center the values about 0.
	f *= 0.3f * Math.PI / 2.0f;
	return (float) FloatMath.sin(f);
}
 
Example 14
Source File: CustomViewAbove.java    From quickmark with MIT License 4 votes vote down vote up
float distanceInfluenceForSnapDuration(float f) {
	f -= 0.5f; // center the values about 0.
	f *= 0.3f * Math.PI / 2.0f;
	return (float) FloatMath.sin(f);
}
 
Example 15
Source File: Flare.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("FloatMath")
public Flare( int nRays, float radius ) {
	
	super( 0, 0, 0, 0 );
	
	int gradient[] = {0xFFFFFFFF, 0x00FFFFFF};
	texture = new Gradient( gradient );
	
	this.nRays = nRays;
	
	angle = 45;
	angularSpeed = 180;
	
	vertices = ByteBuffer.
		allocateDirect( (nRays * 2 + 1) * 4 * (Float.SIZE / 8) ).
		order( ByteOrder.nativeOrder() ).
		asFloatBuffer();
	
	indices = ByteBuffer.
		allocateDirect( nRays * 3 * Short.SIZE / 8 ).
		order( ByteOrder.nativeOrder() ).
		asShortBuffer();
	
	float v[] = new float[4];
	
	v[0] = 0;
	v[1] = 0;
	v[2] = 0.25f;
	v[3] = 0;
	vertices.put( v );
	
	v[2] = 0.75f;
	v[3] = 0;
	
	for (int i=0; i < nRays; i++) {
		
		float a = i * 3.1415926f * 2 / nRays;
		v[0] = FloatMath.cos( a ) * radius;
		v[1] = FloatMath.sin( a ) * radius;
		vertices.put( v );
		
		a += 3.1415926f * 2 / nRays / 2;
		v[0] = FloatMath.cos( a ) * radius;
		v[1] = FloatMath.sin( a ) * radius;
		vertices.put( v );
		
		indices.put( (short)0 );
		indices.put( (short)(1 + i * 2) );
		indices.put( (short)(2 + i * 2) );
	}
	
	indices.position( 0 );
}
 
Example 16
Source File: CircleParticleEmitter.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public void getPositionOffset(final float[] pOffset) {
	final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
	pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX * MathUtils.RANDOM.nextFloat();
	pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY * MathUtils.RANDOM.nextFloat();
}
 
Example 17
Source File: CircleOutlineParticleEmitter.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public void getPositionOffset(final float[] pOffset) {
	final float random = MathUtils.RANDOM.nextFloat() * MathConstants.PI * 2;
	pOffset[VERTEX_INDEX_X] = this.mCenterX + FloatMath.cos(random) * this.mRadiusX;
	pOffset[VERTEX_INDEX_Y] = this.mCenterY + FloatMath.sin(random) * this.mRadiusY;
}
 
Example 18
Source File: VectorF.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
public void calculateEndPoint() {
	end.x = FloatMath.cos(angle) * length + start.x;
	end.y = FloatMath.sin(angle) * length + start.y;
}
 
Example 19
Source File: CustomViewAbove.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
float distanceInfluenceForSnapDuration(float f) {
	f -= 0.5f; // center the values about 0.
	f *= 0.3f * Math.PI / 2.0f;
	return (float) FloatMath.sin(f);
}
 
Example 20
Source File: EaseSineOut.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public static float getValue(final float pPercentage) {
	return FloatMath.sin(pPercentage * MathConstants.PI_HALF);
}