Initial commit
This commit is contained in:
21
Java/3DEngine/src/de/craftix/engine/Calculator.java
Normal file
21
Java/3DEngine/src/de/craftix/engine/Calculator.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
public class Calculator {
|
||||
|
||||
static double CalculatePositionX(double[] viewFrom, double[] viewTo, double x, double y, double z) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double CalculatePositionY(double[] viewFrom, double[] viewTo, double x, double y, double z) {
|
||||
setStuff(viewFrom, viewTo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setStuff(double[] viewFrom, double[] viewTo) {
|
||||
Vector viewVector = new Vector(viewTo[0] - viewFrom[0], viewTo[1] - viewFrom[1], viewTo[1] - viewFrom[1]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
17
Java/3DEngine/src/de/craftix/engine/Engine.java
Normal file
17
Java/3DEngine/src/de/craftix/engine/Engine.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Engine extends JFrame {
|
||||
private Screen screen = new Screen();
|
||||
|
||||
public Engine() {
|
||||
setUndecorated(true);
|
||||
setSize(Toolkit.getDefaultToolkit().getScreenSize());
|
||||
add(screen);
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
27
Java/3DEngine/src/de/craftix/engine/Polygon3D.java
Normal file
27
Java/3DEngine/src/de/craftix/engine/Polygon3D.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Polygon3D {
|
||||
private Color c;
|
||||
private double[] x, y, z;
|
||||
|
||||
public Polygon3D(double[] x, double[] y, double[] z, Color c) {
|
||||
this.c = c;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
createPolygon();
|
||||
}
|
||||
|
||||
void createPolygon() {
|
||||
double[] newX = new double[x.length];
|
||||
double[] newY = new double[y.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
newX[i] = Calculator.CalculatePositionX(Screen.viewFrom, Screen.viewTo, x[i], y[i], z[i]);
|
||||
newY[i] = Calculator.CalculatePositionY(Screen.viewFrom, Screen.viewTo, x[i], y[i], z[i]);
|
||||
}
|
||||
Screen.polygons[Screen.numberOfPolygons] = new PolygonObject(newX, newY, c);
|
||||
}
|
||||
|
||||
}
|
||||
21
Java/3DEngine/src/de/craftix/engine/PolygonObject.java
Normal file
21
Java/3DEngine/src/de/craftix/engine/PolygonObject.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class PolygonObject {
|
||||
private Polygon p;
|
||||
private Color c;
|
||||
|
||||
public PolygonObject(double[] x, double[] y, Color c) {
|
||||
Screen.numberOfPolygons++;
|
||||
this.c = c;
|
||||
p = new Polygon();
|
||||
for (int i = 0; i < x.length; i++) p.addPoint((int) x[i], (int) y[i]);
|
||||
}
|
||||
|
||||
void drawPolygon(Graphics g) {
|
||||
g.setColor(c);
|
||||
g.drawPolygon(p);
|
||||
}
|
||||
|
||||
}
|
||||
25
Java/3DEngine/src/de/craftix/engine/Screen.java
Normal file
25
Java/3DEngine/src/de/craftix/engine/Screen.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Screen extends JPanel {
|
||||
static double[] viewFrom = new double[]{ 10, 10, 10 };
|
||||
static double[] viewTo = new double[]{ 0, 0, 0 };
|
||||
|
||||
public static int numberOfPolygons = 0;
|
||||
public static PolygonObject[] polygons = new PolygonObject[100];
|
||||
|
||||
Polygon3D poly3D;
|
||||
|
||||
public Screen() {
|
||||
poly3D = new Polygon3D(new double[]{2, 4, 2}, new double[]{2, 4, 6}, new double[]{5, 5, 5}, Color.BLACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
|
||||
for (int i = 0; i < numberOfPolygons; i++) polygons[i].drawPolygon(g);
|
||||
}
|
||||
}
|
||||
21
Java/3DEngine/src/de/craftix/engine/Vector.java
Normal file
21
Java/3DEngine/src/de/craftix/engine/Vector.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package de.craftix.engine;
|
||||
|
||||
public class Vector {
|
||||
double x, y, z;
|
||||
|
||||
public Vector(double x, double y, double z) {
|
||||
double length = Math.sqrt(x*x + y*y + z*z);
|
||||
this.x = x / length;
|
||||
this.y = y / length;
|
||||
this.z = z / length;
|
||||
}
|
||||
|
||||
Vector crossProduct(Vector v) {
|
||||
return new Vector(
|
||||
y * v.z - z * v.y,
|
||||
z * v.x - x * v.z,
|
||||
x * v.y - y * v.x
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
11
Java/3DEngine/src/test/Main.java
Normal file
11
Java/3DEngine/src/test/Main.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package test;
|
||||
|
||||
import de.craftix.engine.Engine;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Engine();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user