Skip to content

Commit

Permalink
jse3d v1.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Emery Ferrari committed Jun 4, 2020
1 parent 3a97167 commit f690f32
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
60 changes: 42 additions & 18 deletions src/com/emeryferrari/jse3d/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Display(Scene scene, String frameTitle, boolean visible, boolean renderPo
fpsLimit = true;
fpsLogging = false;
lineRender = true;
faceRender = true;
faceRender = false;
targetFps = 60;
optimalTime = 1000000000/targetFps;
invertColors = false;
Expand Down Expand Up @@ -111,6 +111,7 @@ public JFrame getFrame() {
}
@Override
public void paintComponent(Graphics graphics) {
ArrayList<Point[]> pointArrays = new ArrayList<Point[]>();
if (invertColors) {
graphics.setColor(Display.invertColor(backgroundColor));
} else {
Expand Down Expand Up @@ -173,6 +174,12 @@ public void paintComponent(Graphics graphics) {
}
}
if (faceRender) {
double objDist = 0.0;
for (int x = 0; x < distance.get(a).size(); x++) {
objDist += distance.get(a).get(x).distance;
}
objDist /= distance.get(a).size();
scene.object[a].camDist = objDist;
for (int x = 0; x < scene.object[a].faces.length; x++) {
int[] pointIDs = scene.object[a].faces[x].getPointIDs();
double[] distances = new double[pointIDs.length];
Expand All @@ -199,13 +206,31 @@ public void paintComponent(Graphics graphics) {
}
}
}
pointArrays.add(points);
}
}
if (camPosPrint) {
Point3D cameraPos = getCameraPositionActual();
graphics.setColor(invertColor(backgroundColor));
graphics.drawString("x: " + cameraPos.x + " // y: " + cameraPos.y + " // z: " + cameraPos.z, 0, 11);
}
if (faceRender) {
for (int a = 0; a < scene.object.length; a++) {
for (int x = a+1; x < scene.object.length; x++) {
if (scene.object[a].camDist < scene.object[x].camDist) {
Point[] temp = pointArrays.get(a);
pointArrays.set(a, pointArrays.get(x));
pointArrays.set(x, temp);
}
}
for (int x = 0; x < scene.object[a].faces.length; x++) {
for (int y = 0; y < scene.object[a].faces[x].triangles.length; y++) {
int[] xs = {0, 0, 0};
int[] ys = {0, 0, 0};
try {
int[] xs2 = {points[scene.object[a].faces[x].triangles[y].pointID1].x, points[scene.object[a].faces[x].triangles[y].pointID2].x, points[scene.object[a].faces[x].triangles[y].pointID3].x};
int[] ys2 = {points[scene.object[a].faces[x].triangles[y].pointID1].y, points[scene.object[a].faces[x].triangles[y].pointID2].y, points[scene.object[a].faces[x].triangles[y].pointID3].y};
// SORT POINTARRAYS BY ENTIRE OBJECT3D'S CAMDIST
int[] xs2 = {pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID1].x, pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID2].x, pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID3].x};
int[] ys2 = {pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID1].y, pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID2].y, pointArrays.get(a)[scene.object[a].faces[x].triangles[y].pointID3].y};
xs = xs2;
ys = ys2;
} catch (NullPointerException ex) {}
Expand All @@ -218,24 +243,23 @@ public void paintComponent(Graphics graphics) {
}
}
}
if (lineRender) {
if (invertColors) {
graphics.setColor(Display.invertColor(lineColor));
} else {
graphics.setColor(lineColor);
}
for (int i = 0; i < scene.object[a].edges.length; i++) {
int point1 = scene.object[a].edges[i].pointID1;
int point2 = scene.object[a].edges[i].pointID2;
graphics.drawLine(points[point1].x, points[point1].y, points[point2].x, points[point2].y);
}
if (lineRender) {
for (int a = 0; a < scene.object.length; a++) {
if (lineRender) {
if (invertColors) {
graphics.setColor(Display.invertColor(lineColor));
} else {
graphics.setColor(lineColor);
}
for (int i = 0; i < scene.object[a].edges.length; i++) {
int point1 = scene.object[a].edges[i].pointID1;
int point2 = scene.object[a].edges[i].pointID2;
graphics.drawLine(pointArrays.get(a)[point1].x, pointArrays.get(a)[point1].y, pointArrays.get(a)[point2].x, pointArrays.get(a)[point2].y);
}
}
}
}
if (camPosPrint) {
Point3D cameraPos = getCameraPositionActual();
graphics.setColor(invertColor(backgroundColor));
graphics.drawString("x: " + cameraPos.x + " // y: " + cameraPos.y + " // z: " + cameraPos.z, 0, 11);
}
fps++;
this.revalidate();
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/emeryferrari/jse3d/JSE3DConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
public class JSE3DConst {
private JSE3DConst() {}
public static final String NAME = "jse3d";
public static final String VERSION = "v1.5.6";
public static final String VERSION = "v1.5.7";
public static final String FULL_NAME = JSE3DConst.NAME + " " + JSE3DConst.VERSION;
}
1 change: 1 addition & 0 deletions src/com/emeryferrari/jse3d/Object3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Object3D implements Serializable {
public Point3D[] points;
public Line[] edges = {};
public Face[] faces = {};
double camDist = 0;
public Object3D(Point3D[] points, Face[] faces, Line[] edges) {
this(points, faces);
this.edges = edges;
Expand Down
7 changes: 4 additions & 3 deletions src/com/emeryferrari/jse3d/example/JSE3DExample.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.emeryferrari.jse3d.example;
import com.emeryferrari.jse3d.*;
public class JSE3DExample {
public static void main(String[] args) throws InterruptedException {
Object3D[] objects = {ObjectTemplate.getCube()};
public static void main(String[] args) {
Object3D[] objects = {ObjectTemplate.getCube(), ObjectTemplate.getCube()};
Scene scene = new Scene(objects, 5.0);
Display display = new Display(scene, "jse3d demo", true, false);
display.enableFPSLogging();
display.enableCameraPositionPrinting();
display.disableLineRendering();
display.enableFaceRendering();
display.startRender();
display.getScene().getObjects()[1].transitionPosRel(1, 1, 1, 5000, display);
}
}

0 comments on commit f690f32

Please sign in to comment.