-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement sensors * Fix memory leak in accel
- Loading branch information
1 parent
cdc61ea
commit 8cf0fbe
Showing
7 changed files
with
169 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Quaternion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.panda3ds.pandroid.math; | ||
|
||
public class Quaternion { | ||
public float x, y, z, w; | ||
public Quaternion(float x, float y, float z, float w) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
this.w = w; | ||
} | ||
|
||
public Quaternion fromEuler(Vector3 euler) { | ||
float x = euler.x; | ||
float y = euler.y; | ||
float z = euler.z; | ||
|
||
double c1 = Math.cos(x / 2.0); | ||
double c2 = Math.cos(y / 2.0); | ||
double c3 = Math.cos(z / 2.0); | ||
|
||
double s1 = Math.sin(x / 2.0); | ||
double s2 = Math.sin(y / 2.0); | ||
double s3 = Math.sin(z / 2.0); | ||
|
||
this.x = (float) (s1 * c2 * c3 + c1 * s2 * s3); | ||
this.y = (float) (c1 * s2 * c3 - s1 * c2 * s3); | ||
this.z = (float) (c1 * c2 * s3 + s1 * s2 * c3); | ||
this.w = (float) (c1 * c2 * c3 - s1 * s2 * s3); | ||
return this; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/pandroid/app/src/main/java/com/panda3ds/pandroid/math/Vector3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.panda3ds.pandroid.math; | ||
|
||
public class Vector3 { | ||
private final Quaternion quaternion = new Quaternion(0, 0, 0, 0); | ||
public float x, y, z; | ||
|
||
public Vector3(float x, float y, float z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public Vector3 rotateByEuler(Vector3 euler) { | ||
this.quaternion.fromEuler(euler); | ||
|
||
float x = this.x, y = this.y, z = this.z; | ||
float qx = this.quaternion.x; | ||
float qy = this.quaternion.y; | ||
float qz = this.quaternion.z; | ||
float qw = this.quaternion.w; | ||
|
||
float ix = qw * x + qy * z - qz * y; | ||
float iy = qw * y + qz * x - qx * z; | ||
float iz = qw * z + qx * y - qy * x; | ||
float iw = -qx * x - qy * qz * z; | ||
|
||
this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy; | ||
this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz; | ||
this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; | ||
return this; | ||
} | ||
} |