List of commits:
Subject Hash Author Date (UTC)
first simple form of rotating a cube implemented all the matrix multiplication 8a7e7a890b639dd426bd5ec337ea23869fd46fb1 sven 2019-04-05 18:01:50
zwischenspeichern 4ccbb91007a83a77db702422936d7a05b6d15237 sven 2019-03-27 07:59:54
class Vector 5e896e7f5614d9b2d219ec835367d9f0e9cb4a01 ani 2019-03-01 18:37:08
initial Commit e69430bfab98d7aa5f068b4324fd27f86c996fc8 sven 2019-03-01 17:42:02
Commit 8a7e7a890b639dd426bd5ec337ea23869fd46fb1 - first simple form of rotating a cube implemented all the matrix multiplication
Author: sven
Author date (UTC): 2019-04-05 18:01
Committer name: sven
Committer date (UTC): 2019-04-05 18:01
Parent(s): 4ccbb91007a83a77db702422936d7a05b6d15237
Signing key:
Tree: 77d27751d0a06e10aa5c5cc31a08ef6f215b9bd6
File Lines added Lines deleted
src/data/OwnMath.java 5 5
src/data/Vector.java 31 20
src/ui/Controller.java 38 8
File src/data/OwnMath.java changed (mode: 100644) (index 8dd48a4..608293d)
... ... package data;
3 3
4 4
5 5 public class OwnMath { public class OwnMath {
6 public float[][] getRotationMatrix(float angle, int axis){
7 float[][] mat= new float[3][3];
8 for(int i =0; i< 4;i++){
9 for (int j = 0; j < 4; j++) {
6 public static double[][] getRotationMatrix(double angle, int axis){
7 double[][] mat= new double[3][3];
8 for(int i =0; i< mat.length;i++){
9 for (int j = 0; j < mat[0].length; j++) {
10 10 mat[i][j] =0; mat[i][j] =0;
11 11 } }
12 12 } }
 
... ... public class OwnMath {
35 35 default: default:
36 36 mat = null; mat = null;
37 37 } }
38 return new float[0][0];
38 return mat;
39 39 } }
40 40 } }
File src/data/Vector.java changed (mode: 100644) (index c9845d2..ef90de1)
1 1 package data; package data;
2 2
3 import java.util.List;
3 public class Vector {
4 4
5 public class Vector{
5 private double[] vector;
6 6
7 private int[] vector;
8
9 public Vector(int[] vector){
10 this.vector = vector;
7 public Vector(double... val){
8 vector=val;
11 9 } }
12 10
13 public void multi(int a){
14 for(int i=0; i<vector.length; i++){
15 vector[i]= vector[i]*a;
11 public Vector multi(int a) {
12 double[] newVal = new double[vector.length];
13 for (int i = 0; i < vector.length; i++) {
14 newVal[i] = vector[i] * a;
16 15 } }
16 return new Vector(newVal);
17 17 } }
18 18
19 public void add(Vector point){
20 int[] pointVal=point.getValues();
21 for(int i=0; i<pointVal.length; i++){
22 vector[i]= vector[i]+pointVal[i];
19 public Vector add(Vector point) {
20 double[] newVal = new double[vector.length];
21 double[] pointVal = point.getValues();
22 for (int i = 0; i < pointVal.length; i++) {
23 newVal[i] = vector[i] + pointVal[i];
23 24 } }
25 return new Vector(newVal);
24 26 } }
25 27
26 public void matrixMulti(float[][] matrix){
27
28
29
28 public Vector matrixMulti(double[][] matrix) {
29 if (matrix[0].length == vector.length) {
30 double[] newVal = new double[matrix[0].length];
31 for (int i = 0; i < matrix.length; i++) {
32 for (int j = 0; j < vector.length; j++) {
33 newVal[i] += vector[j] * matrix[i][j];
34 }
35 }
36 return new Vector(newVal);
37 }else{
38 throw new IllegalArgumentException("Number of columns of the matrix must match the number of coordinates of the Vector.");
39 }
30 40 } }
31 public int[] getValues(){
41
42 private double[] getValues() {
32 43 return vector; return vector;
33 44 } }
34 45
35 private List<Vector> splitMatrix(float[][] matrix){
36
46 public double get(int index){
47 return vector[index];
37 48 } }
38 49 } }
File src/ui/Controller.java changed (mode: 100644) (index f1b0869..ff94bbe)
1 1 package ui; package ui;
2 2
3 import data.OwnMath;
4 import data.Vector;
3 5 import javafx.fxml.FXML; import javafx.fxml.FXML;
4 6 import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
5 7 import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
6
7 import data.Vector;
8 8 import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
9 9 import javafx.scene.control.Slider; import javafx.scene.control.Slider;
10 10 import javafx.scene.paint.Color; import javafx.scene.paint.Color;
11 import javafx.scene.paint.Paint;
11
12 import java.util.ArrayList;
13 import java.util.List;
12 14
13 15 public class Controller { public class Controller {
14 private int WIDTH,HEIGHT;
16 private int WIDTH,HEIGHT,POINTSIZE =10;
17
18 private List<Vector> points=new ArrayList<>();
19 private Vector origin;
20
15 21 private GraphicsContext gc; private GraphicsContext gc;
22 private double angle=0;
23
16 24 @FXML @FXML
17 25 private Canvas canvasDraw; private Canvas canvasDraw;
18 26 @FXML @FXML
 
... ... public class Controller {
25 33 gc = canvasDraw.getGraphicsContext2D(); gc = canvasDraw.getGraphicsContext2D();
26 34 WIDTH=(int)Math.round(canvasDraw.getWidth()); WIDTH=(int)Math.round(canvasDraw.getWidth());
27 35 HEIGHT=(int)Math.round(canvasDraw.getHeight()); HEIGHT=(int)Math.round(canvasDraw.getHeight());
36
37 points.add(new Vector(-50,-50,-50));
38 points.add(new Vector(-50,50,-50));
39 points.add(new Vector(50,-50,-50));
40 points.add(new Vector(50,50,-50));
41 points.add(new Vector(-50,-50,50));
42 points.add(new Vector(-50,50,50));
43 points.add(new Vector(50,-50,50));
44 points.add(new Vector(50,50,50));
45
46 this.origin=new Vector(WIDTH/2,HEIGHT/2,0.0);
28 47 } }
29 48
30 49 public void simulate(){ public void simulate(){
50 //draw background
31 51 gc.setFill(Color.GRAY); gc.setFill(Color.GRAY);
32 gc.fillRect(0, 0, 600, 600);
52 gc.fillRect(0, 0, WIDTH, HEIGHT);
53 gc.strokeOval(WIDTH/2,HEIGHT/2,POINTSIZE,POINTSIZE);
33 54 gc.setFill(Color.WHITE); gc.setFill(Color.WHITE);
34 gc.fillOval(WIDTH / 2, HEIGHT / 2, 10, 10);
35
55 //draw object
56 angle+=0.01;
57 if(angle>(2*Math.PI))
58 angle=0;
59 if(!points.isEmpty()){
60 for (Vector v :
61 points) {
62 v = v.matrixMulti(OwnMath.getRotationMatrix(angle,1));
63 drawPoint(v.add(origin));
64 }
65 }
36 66 } }
37 67
38 68 private void drawPoint( Vector v){ private void drawPoint( Vector v){
39 gc.fillOval(v.get(0),v.get(1),5,5);
69 gc.fillOval(v.get(0),v.get(1),POINTSIZE,POINTSIZE);
40 70 } }
41 71 private void connect( Vector v1 , Vector v2){ private void connect( Vector v1 , Vector v2){
42 72 gc.strokeLine(v1.get(0),v1.get(1),v2.get(0),v2.get(1)); gc.strokeLine(v1.get(0),v1.get(1),v2.get(0),v2.get(1));
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/SF2311/Rotation

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/SF2311/Rotation

Clone this repository using git:
git clone git://git.rocketgit.com/user/SF2311/Rotation

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main