-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
50 lines (40 loc) · 1.54 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.ideog.myapplication;
/**
* Created by ideog on 20.11.2017.
*/
public class Main {
public static void main(String[] args) {
test_vec3_to_quat();
}
public static void test_rotation() {
Vector3 v = new Vector3(0, 0, 9.85f);
Quaternion q = new Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
q = q.conjugate();
Vector3 rot_v = q.rotateVector(v);
System.out.println("Euler angles\n" + q.eulerAngles().mul1d(180f/3.14f).toString());
System.out.println();
System.out.println("Before\n" + v.toString());
System.out.println();
System.out.println("After\n" + rot_v.toString());
}
public static void test_projection() {
Vector3 v = new Vector3(2, 1, 1);
Vector3 direction = new Vector3(1, 0, 0);
System.out.println("Proj\n" + v.proj(direction).toString());
}
public static void test_twist() {
Quaternion q = new Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
Vector3 direction = new Vector3(0, 0, 1);
System.out.println("Twist\n" + q.calculateTwist(direction).toString());
}
public static void test_vec3_to_quat() {
Vector3 v = new Vector3((float) (Math.PI/2), 0, 0);
Quaternion q0 = new Quaternion(0.707f,0, 0, 0.707f);
Quaternion q1 = new Quaternion(v);
Quaternion q = q0.cross(q1);
Vector3 rotate = new Vector3();
System.out.println("Q0\n" + q0.toString());
System.out.println();
System.out.println("Cross product\n" + q.toString());
}
}