Navigation Menu

Skip to content

Commit

Permalink
Add new Math types
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanl committed Feb 5, 2012
1 parent e11f39c commit ba061dd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/com/osesm/randy/framework/math/Matrix4.java
@@ -1,5 +1,7 @@
package com.osesm.randy.framework.math;

import java.nio.FloatBuffer;

import android.opengl.Matrix;

public class Matrix4 {
Expand Down Expand Up @@ -57,12 +59,17 @@ public Matrix4 rotate(float angle, float scaleX, float scaleY, float scaleZ) {
}

public Matrix4 multiplyByMatrix(Matrix4 otherMatrix) {
Matrix.multiplyMM(tmp, 0, values, 0, otherMatrix.getValues(), 0);
Matrix.multiplyMM(tmp, 0, values, 0, otherMatrix.values(), 0);
return new Matrix4(tmp);
}

public float[] getValues() {
public float[] values() {
return values;
}

public FloatBuffer toFloatBuffer() {
// TODO Auto-generated method stub
return null;
}

}
5 changes: 5 additions & 0 deletions src/com/osesm/randy/framework/math/Quaternion.java
Expand Up @@ -119,4 +119,9 @@ public Quaternion add(Quaternion quaternion) {
public Quaternion normalize() {
return scaled(1 / FloatMath.sqrt(dot(this)));
}

public Matrix4 toMatrix4() {
// TODO Auto-generated method stub
return null;
}
}
13 changes: 8 additions & 5 deletions src/com/osesm/randy/framework/math/Vector3.java
Expand Up @@ -4,9 +4,13 @@

public class Vector3 {

private float z;
private float y;
private float x;
public float z;
public float y;
public float x;

public static int size() {
return 3 * 4;
}

public Vector3() {
}
Expand All @@ -21,7 +25,7 @@ public Vector3(Vector3 other) {
this(other.x, other.y, other.z);
}

public Vector3 cpy() {
public Vector3 copy() {
return new Vector3(x, y, z);
}

Expand Down Expand Up @@ -93,5 +97,4 @@ private float distanceSquared(float x2, float y2, float z2) {
float distanceZ = this.z - z;
return distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ;
}

}
66 changes: 66 additions & 0 deletions src/com/osesm/randy/framework/math/Vector4.java
@@ -0,0 +1,66 @@
package com.osesm.randy.framework.math;

import java.nio.FloatBuffer;

public class Vector4 {
public float x;
public float y;
public float z;
public float w;

public Vector4() {
}

public Vector4(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = 1.0f;
}

public Vector4(Vector4 other) {
this(other.x, other.y, other.z, other.w);
}

public Vector4 copy() {
return new Vector4(x, y, z, w);
}

public Vector4 add(float x, float y, float z, float w) {
this.x += x;
this.y += y;
this.z += z;
this.w += w;
return this;
}

public Vector4 add(Vector4 other) {
return add(other.x, other.y, other.z, other.w);
}

public Vector4 sub(float x, float y, float z, float w) {
this.x -= x;
this.y -= y;
this.z -= z;
this.w -= w;
return this;
}

public Vector4 sub(Vector4 other) {
return sub(other.x, other.y, other.z, other.w);
}

public Vector4 mul(float scalar) {
this.x *= scalar;
this.y *= scalar;
this.z *= scalar;
return this;
}

public FloatBuffer toFloatBuffer() {
// TODO Auto-generated method stub
return null;
}


}

0 comments on commit ba061dd

Please sign in to comment.