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

The following examples show how to use android.util.FloatMath#cos() . 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 postRotate(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;
	final float tx = this.tx;
	final float ty = this.ty;

	this.a = a * cos - b * sin;
	this.b = a * sin + b * cos;
	this.c = c * cos - d * sin;
	this.d = c * sin + d * cos;
	this.tx = tx * cos - ty * sin;
	this.ty = tx * sin + ty * cos;
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: PointF.java    From PD-classes with GNU General Public License v3.0 4 votes vote down vote up
public PointF polar( float a, float l ) {
	this.x = l * FloatMath.cos( a );
	this.y = l * FloatMath.sin( a );
	return this;
}
 
Example 12
Source File: EaseSineInOut.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public float getPercentage(final float pSecondsElapsed, final float pDuration) {
	final float percentage = pSecondsElapsed / pDuration;

	return -0.5f * (FloatMath.cos(percentage * PI) - 1);
}
 
Example 13
Source File: EaseSineIn.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.cos(pPercentage * MathConstants.PI_HALF) + 1;
}
 
Example 14
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 15
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 16
Source File: FlatCircleFeature.java    From geoar-app with Apache License 2.0 4 votes vote down vote up
@Override
	public void onCreateInGLESThread() {
		final int numOfVertices = (numCirclePoints+1)*3*3;
		final int numOfColorCoords = (numCirclePoints+1)*4*3;
		final int numOfTexCoords = (numCirclePoints+1)*2*3;
		
		final float[] vertices = new float[numOfVertices];
		final float[] colors = new float[numOfColorCoords];
		final float[] normals = new float[numOfVertices];
		final float[] texCoords = new float[numOfTexCoords];
		
		float radians = 0;
		for(int i = 0, point = 0; i < numOfVertices; i+=9, point++){
			vertices[i] = 0.0f;
			vertices[i+1] = 0.0f;
			vertices[i+2] = 0.0f;
			
			radians = (float) Math.toRadians(point*360/numCirclePoints);
			vertices[i+3] = FloatMath.cos(radians);
			vertices[i+5] = FloatMath.cos(radians);
			
			radians = (float) Math.toRadians((point+1)*360/numCirclePoints);
			vertices[i+6] = FloatMath.cos(radians);
			vertices[i+8] = FloatMath.cos(radians);
			
			normals[i+1] = 1.0f;
			normals[i+4] = 1.0f;
			normals[i+7] = 1.0f;
		}
		
		for (int i = 0; i < numOfColorCoords; i += 4) {
			colors[i] = 1.0f;
			colors[i + 1] = 0.0f;
			colors[i + 2] = 0.0f;
			colors[i + 3] = 0.1f;
		}
		
//		// circle center, we want no triangulation from the border
//		vertices[0] = 0.0f;
//		vertices[1] = 0.0f;
//		vertices[2] = 0.0f;
//		
//		normals[1] = 1.0f;
//		
//		for(int i = 3; i < numOfVertices; i+=3){
//			float radians = (float) Math.toRadians(i*360/numCirclePoints);
//			vertices[i] = FloatMath.cos(radians);
//			vertices[i+1] = 0.0f;
//			vertices[i+2] = FloatMath.sin(radians);
//			
//			normals[i] = 0.0f;
//			normals[i+1] = 1.0f;
//			normals[i+2] = 0.0f;
//		}
//		
//		for(int i = 0; i < numOfColorCoords; i+=4){
//			colors[i] = 1.0f;
//			colors[i+1] = 0.0f;
//			colors[i+2] = 0.0f;
//			colors[i+3] = 0.5f;
//		}
		
//		for(int i = 0; i < numOfTexCoords; i+=2){
//			texCoords[i] = 0.0f;
//			texCoords[i] = 0.0
//		}
		
		setRenderObjectives(vertices, colors, normals, null);
	}
 
Example 17
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 18
Source File: Flare.java    From unleashed-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 19
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 20
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;
}