Skip to content

Commit

Permalink
jse3d v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Emery Ferrari committed Jul 20, 2020
1 parent ba3d740 commit 77d2785
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alyxferrari</groupId>
<artifactId>jse3d</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<name>jse3d</name>
<packaging>jar</packaging>
<url>https://github.com/alyxferrari/jse3d</url>
Expand Down
2 changes: 1 addition & 1 deletion src/com/alyxferrari/jse3d/JSE3DConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private JSE3DConst() {}
public static final String NAME = "jse3d";
/** Represents the version number of this build of the library.
*/
public static final String VERSION = "v3.0.1";
public static final String VERSION = "v3.0.2";
/** Represents the name of this library and the version of the current build concatenated with a space between.
*/
public static final String FULL_NAME = JSE3DConst.NAME + " " + JSE3DConst.VERSION;
Expand Down
2 changes: 2 additions & 0 deletions src/com/alyxferrari/jse3d/example/ObjModelDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static void main(String[] args) throws Exception {
Display display = new Display(scene, "jse3d obj model demo", Math.toRadians(60), objects[0].points.length, objects[0].points.length, 1);
display.setPointSize(new Dimension(2000, 2000));
display.disableFPSLimit();
display.setBackgroundColor(Color.CYAN);
display.setScrollWheelMultiplier(1.2);
display.enableFPSLogging();
display.setRenderTarget(RenderTarget.CPU_SINGLETHREADED);
display.setRenderQuality(RenderMode.PERFORMANCE);
Expand Down
43 changes: 26 additions & 17 deletions src/com/alyxferrari/jse3d/gfx/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void render() {
protected void renderFrame() {
fields.localCamPos = new Vector3(0, 0, 0);
try {fields.localCamPos = getCameraPositionActual();} catch (NullPointerException ex) {}
try {fields.graphics.setRenderingHints(fields.hints);} catch (ConcurrentModificationException ex) {} // sets rendering hints
try {fields.graphics.setRenderingHints(fields.hints);} catch (ConcurrentModificationException ex) {} catch (NullPointerException ex) {} // sets rendering hints
renderBackground();
fields.script.preRender(fields.graphics);
calculateMouse();
Expand All @@ -441,21 +441,21 @@ protected Point calculateParticle(int particleID) {
// the following if statement checks if this particle is in front of the camera, not behind, and hence, if it should be rendered or not
if (fields.scene.particles.get(particleID).getPosition().getZ()*fields.sphere.cosViewAngleX*fields.sphere.cosViewAngleY + fields.scene.particles.get(particleID).getPosition().getX()*fields.sphere.sinViewAngleX*fields.sphere.cosViewAngleY - fields.scene.particles.get(particleID).getPosition().getY()*fields.sphere.sinViewAngleY < fields.scene.camDist) {
// 3D to 2D particle conversion
double zAngle = Math.atan(fields.scene.particles.get(particleID).getPosition().getZ()/fields.scene.particles.get(particleID).getPosition().getX());
double zAngle = StrictMath.atan(fields.scene.particles.get(particleID).getPosition().getZ()/fields.scene.particles.get(particleID).getPosition().getX());
if (fields.scene.particles.get(particleID).getPosition().getX() == 0 && fields.scene.particles.get(particleID).getPosition().getZ() == 0) {
zAngle = 0;
}
double mag = Math.hypot(fields.scene.particles.get(particleID).getPosition().getX(), fields.scene.particles.get(particleID).getPosition().getZ());
double mag = StrictMath.hypot(fields.scene.particles.get(particleID).getPosition().getX(), fields.scene.particles.get(particleID).getPosition().getZ());
if (fields.scene.particles.get(particleID).getPosition().getX() < 0) {
fields.xTransform = -mag*DisplaySettings.SCALE*Math.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = -mag*DisplaySettings.SCALE*Math.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.particles.get(particleID).getPosition().getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
fields.xTransform = -mag*DisplaySettings.SCALE*StrictMath.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = -mag*DisplaySettings.SCALE*StrictMath.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.particles.get(particleID).getPosition().getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
} else {
fields.xTransform = mag*DisplaySettings.SCALE*Math.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = mag*DisplaySettings.SCALE*Math.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.particles.get(particleID).getPosition().getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
fields.xTransform = mag*DisplaySettings.SCALE*StrictMath.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = mag*DisplaySettings.SCALE*StrictMath.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.particles.get(particleID).getPosition().getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
}
double distance = Math3D.hypot3(fields.localCamPos.getX()-fields.scene.particles.get(particleID).getPosition().getX(), fields.localCamPos.getY()-fields.scene.particles.get(particleID).getPosition().getY(), fields.localCamPos.getZ()-fields.scene.particles.get(particleID).getPosition().getZ());
double theta = Math.asin((Math.hypot(fields.xTransform, fields.yTransform)/DisplaySettings.SCALE)/distance);
double camScale = distance*Math.cos(theta)*Math.sin(fields.settings.viewAngle/2);
double theta = StrictMath.asin((Math.hypot(fields.xTransform, fields.yTransform)/DisplaySettings.SCALE)/distance);
double camScale = distance*StrictMath.cos(theta)*StrictMath.sin(fields.settings.viewAngle/2);
return new Point((int)((fields.renderer.size.width+fields.renderer.location.x)/2+fields.xTransform/camScale), (int)((fields.renderer.size.height+fields.renderer.location.y)/2-fields.yTransform/camScale));
}
return null;
Expand All @@ -464,21 +464,21 @@ protected Point calculatePoint(int a, int i) {
// the following if statement checks if this point is in front of the camera, not behind, and hence, if it should be rendered or not
if (fields.scene.object[a].points[i].getZ()*fields.sphere.cosViewAngleX*fields.sphere.cosViewAngleY + fields.scene.object[a].points[i].getX()*fields.sphere.sinViewAngleX*fields.sphere.cosViewAngleY - fields.scene.object[a].points[i].getY()*fields.sphere.sinViewAngleY < fields.scene.camDist) {
// 3D to 2D point conversion
double zAngle = Math.atan((fields.scene.object[a].points[i].getZ())/(fields.scene.object[a].points[i].getX()));
double zAngle = StrictMath.atan((fields.scene.object[a].points[i].getZ())/(fields.scene.object[a].points[i].getX()));
if (fields.scene.object[a].points[i].getX() == 0 && fields.scene.object[a].points[i].getZ() == 0) {
zAngle = 0;
}
double mag = Math.hypot(fields.scene.object[a].points[i].getX(), fields.scene.object[a].points[i].getZ());
double mag = StrictMath.hypot(fields.scene.object[a].points[i].getX(), fields.scene.object[a].points[i].getZ());
if (fields.scene.object[a].points[i].getX() < 0) {
fields.xTransform = -mag*DisplaySettings.SCALE*Math.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = -mag*DisplaySettings.SCALE*Math.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.object[a].points[i].getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
fields.xTransform = -mag*DisplaySettings.SCALE*StrictMath.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = -mag*DisplaySettings.SCALE*StrictMath.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.object[a].points[i].getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
} else {
fields.xTransform = mag*DisplaySettings.SCALE*Math.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = mag*DisplaySettings.SCALE*Math.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.object[a].points[i].getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
fields.xTransform = mag*DisplaySettings.SCALE*StrictMath.cos(fields.sphere.viewAngleX+zAngle);
fields.yTransform = mag*DisplaySettings.SCALE*StrictMath.sin(fields.sphere.viewAngleX+zAngle)*fields.sphere.sinViewAngleY+(fields.scene.object[a].points[i].getY())*DisplaySettings.SCALE*fields.sphere.cosViewAngleY;
}
fields.distance[a][i] = new Distance(Math3D.hypot3(fields.localCamPos.getX()-fields.scene.object[a].points[i].getX(), fields.localCamPos.getY()-fields.scene.object[a].points[i].getY(), fields.localCamPos.getZ()-fields.scene.object[a].points[i].getZ()), i);
double theta = Math.asin((Math.hypot(fields.xTransform, fields.yTransform)/DisplaySettings.SCALE)/fields.distance[a][i].distance);
fields.camScale[a][i] = fields.distance[a][i].distance*Math.cos(theta)*Math.sin(fields.settings.viewAngle/2);
double theta = StrictMath.asin((StrictMath.hypot(fields.xTransform, fields.yTransform)/DisplaySettings.SCALE)/fields.distance[a][i].distance);
fields.camScale[a][i] = fields.distance[a][i].distance*StrictMath.cos(theta)*StrictMath.sin(fields.settings.viewAngle/2);
return new Point((int)((fields.renderer.size.width+fields.renderer.location.x)/2+fields.xTransform/fields.camScale[a][i]), (int)((fields.renderer.size.height+fields.renderer.location.y)/2-fields.yTransform/fields.camScale[a][i]));
}
return null;
Expand Down Expand Up @@ -1522,4 +1522,13 @@ public void run() {
fields.mouse = new Point(MouseInfo.getPointerInfo().getLocation().x-fields.frame.getLocationOnScreen().x, MouseInfo.getPointerInfo().getLocation().y-fields.frame.getLocationOnScreen().y);
}
}
/** Sets the rendering hints directly. This has no effect on the output of any specific rendering hint getters.
* @param hints The new rendering hints.
* @return The Display object on which this method was called.
* @since 3.0.2
*/
public Display setRenderingHints(RenderingHints hints) {
fields.hints = hints;
return this;
}
}
8 changes: 4 additions & 4 deletions src/com/alyxferrari/jse3d/gfx/ViewAngle.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class ViewAngle {
public ViewAngle(double viewAngleX, double viewAngleY) {
this.viewAngleX = viewAngleX;
this.viewAngleY = viewAngleY;
sinViewAngleX = Math.sin(viewAngleX);
cosViewAngleX = Math.cos(viewAngleX);
sinViewAngleY = Math.sin(viewAngleY);
cosViewAngleY = Math.cos(viewAngleY);
sinViewAngleX = StrictMath.sin(viewAngleX);
cosViewAngleX = StrictMath.cos(viewAngleX);
sinViewAngleY = StrictMath.sin(viewAngleY);
cosViewAngleY = StrictMath.cos(viewAngleY);
}
}
2 changes: 1 addition & 1 deletion src/com/alyxferrari/jse3d/network/JSE3DClientConst.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.alyxferrari.jse3d.network;
class JSE3DClientConst {
private JSE3DClientConst() {}
public static final String API_VERSION = "v1.1.301";
public static final String API_VERSION = "v1.1.302";
}
2 changes: 1 addition & 1 deletion src/com/alyxferrari/jse3d/obj/Vector3.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected Vector3(double x, double y, double z, Object object) {
this.y = y;
this.z = z;
magnitude = Math3D.hypot3(x, y, z);
sqrMagnitude = Math.pow(magnitude, 2);
sqrMagnitude = StrictMath.pow(magnitude, 2);
normal = this;
}
/** Moves this vector relative to (0,0,0).
Expand Down

0 comments on commit 77d2785

Please sign in to comment.