+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-package eu.svjatoslav.sixth.e3d.geometry;
-
-import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
-
-public class GeometryCoordinate {
-
- public Point3D coordinate;
- public Point3D transformedCoordinate;
- public Point2D onScreenCoordinate;
-
- int lastTransformedFrame;
-
- public GeometryCoordinate() {
- coordinate = new Point3D();
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- public GeometryCoordinate(final Point3D location) {
- coordinate = location;
- transformedCoordinate = new Point3D();
- onScreenCoordinate = new Point2D();
- }
-
- public void transform(final TransformPipe transforms,
- final RenderingContext renderContext) {
-
- if (lastTransformedFrame == renderContext.frameNumber)
- return;
-
- lastTransformedFrame = renderContext.frameNumber;
-
- transforms.transform(coordinate, transformedCoordinate);
-
- onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.xCenter;
- onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
- + renderContext.yCenter;
- }
-}
+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-
-package eu.svjatoslav.sixth.e3d.geometry;
-
-public class Orientation implements Cloneable {
-
- private double s1, c1, s2, c2;
-
- private double angleXZ = 0;
- private double angleYZ = 0;
-
- public Orientation() {
- computeMultipliers();
- }
-
- public Orientation(final double angleXZ, final double angleYZ) {
- this.angleXZ = angleXZ;
- this.angleYZ = angleYZ;
- computeMultipliers();
- }
-
- @Override
- public Orientation clone() {
- return new Orientation(angleXZ, angleYZ);
- }
-
- private void computeMultipliers() {
- s1 = Math.sin(angleXZ);
- c1 = Math.cos(angleXZ);
-
- s2 = Math.sin(angleYZ);
- c2 = Math.cos(angleYZ);
- }
-
- public void rotate(final Point3D point3d) {
- final double z1 = (point3d.z * c1) - (point3d.x * s1);
- point3d.x = (point3d.z * s1) + (point3d.x * c1);
-
- point3d.z = (z1 * c2) - (point3d.y * s2);
- point3d.y = (z1 * s2) + (point3d.y * c2);
- }
-
- public void rotate(final double angleXZ, final double angleYZ) {
- this.angleXZ += angleXZ;
- this.angleYZ += angleYZ;
- computeMultipliers();
- }
-
-}
package eu.svjatoslav.sixth.e3d.geometry;
+import static java.lang.Math.sqrt;
+
public class Point2D implements Cloneable {
public double x, y;
return this;
}
+ public boolean isZero(){
+ return (x == 0) && (y == 0);
+ }
+
@Override
public Point2D clone() {
return new Point2D(this);
y = source.y;
}
- public Point2D computeMiddlePoint(final Point2D p1, final Point2D p2) {
+ public Point2D getMiddle(final Point2D p1, final Point2D p2) {
x = (p1.x + p2.x) / 2d;
y = (p1.y + p2.y) / 2d;
return this;
return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
}
+ /**
+ * Compute distance to another point.
+ */
public double getDistanceTo(final Point2D anotherPoint) {
final double xDiff = x - anotherPoint.x;
final double yDiff = y - anotherPoint.y;
- return Math.sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+ return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
+ }
+
+ public double getVectorLength() {
+ return sqrt(((x * x) + (y * y)));
}
public Point2D invert() {
y = (int) y;
}
- public Point2D subtract(final Point2D direction) {
- x -= direction.x;
- y -= direction.y;
+ public Point2D subtract(final Point2D point) {
+ x -= point.x;
+ y -= point.y;
return this;
}
package eu.svjatoslav.sixth.e3d.geometry;
+import static java.lang.Math.cos;
+import static java.lang.Math.sin;
+import static java.lang.Math.sqrt;
+
/**
- * Used to represent point in a 3D space, vector or speed.
+ * Used to represent point in a 3D space or vector.
*/
public class Point3D extends Point2D implements Cloneable {
- public static final Point3D ZERO = new Point3D();
public double z;
public Point3D() {
return this;
}
+ @Override
+ public boolean isZero(){
+ return (x == 0) && (y == 0) && (z == 0);
+ }
+
public double getAngleXZ(final Point3D anotherPoint) {
return Math.atan2(x - anotherPoint.x, z - anotherPoint.z);
}
final double yDelta = y - anotherPoint.y;
final double zDelta = z - anotherPoint.z;
- return Math
- .sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
+ return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta)));
+ }
+
+ @Override
+ public double getVectorLength() {
+ return sqrt(((x * x) + (y * y) + (z * z)));
}
@Override
public void rotate(final Point3D center, final double angleXZ,
final double angleYZ) {
- final double s1 = Math.sin(angleXZ);
- final double c1 = Math.cos(angleXZ);
+ final double s1 = sin(angleXZ);
+ final double c1 = cos(angleXZ);
- final double s2 = Math.sin(angleYZ);
- final double c2 = Math.cos(angleYZ);
+ final double s2 = sin(angleYZ);
+ final double c2 = cos(angleYZ);
x -= center.x;
y -= center.y;
return this;
}
- public boolean withinDrawingLimits() {
+ public boolean isVisible() {
if (z > 0)
return true;
+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-package eu.svjatoslav.sixth.e3d.geometry;
-
-public class Transform implements Cloneable {
-
- private final Point3D translation;
- private final Orientation orientation;
-
- public Transform() {
- translation = new Point3D();
- orientation = new Orientation();
- }
-
- public Transform(final Point3D translation) {
- this.translation = translation;
- orientation = new Orientation();
- }
-
- public Transform(final Point3D translation, final double angleXZ,
- final double angleYZ) {
-
- this.translation = translation;
- orientation = new Orientation(angleXZ, angleYZ);
- }
-
- public Transform(final Point3D translation, final Orientation orientation) {
- this.translation = translation;
- this.orientation = orientation;
- }
-
- @Override
- public Transform clone() {
- return new Transform(translation, orientation);
- }
-
- public Orientation getOrientation() {
- return orientation;
- }
-
- public Point3D getTranslation() {
- return translation;
- }
-
- public void transform(final Point3D point) {
- orientation.rotate(point);
- point.add(translation);
- }
-
-}
+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-package eu.svjatoslav.sixth.e3d.geometry;
-
-public class TransformPipe {
-
- private Transform[] transforms = new Transform[100];
-
- private int transformsCount = 0;
-
- public void addTransform(final Transform transform) {
- transforms[transformsCount] = transform;
- transformsCount++;
- }
-
- public void clear() {
- transformsCount = 0;
- }
-
- public void dropTransform() {
- transformsCount--;
- }
-
- public void transform(final Point3D source, final Point3D destination) {
-
- destination.clone(source);
-
- for (int i = transformsCount - 1; i >= 0; i--)
- transforms[i].transform(destination);
- }
-}
import static java.lang.Math.cos;
import static java.lang.Math.sin;
-public class Avatar implements ViewUpdateListener {
+public class Avatar implements ViewRenderListener {
public static final double SPEED_LIMIT = 30;
/**
}
@Override
- public boolean beforeViewUpdate(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
final Point3D locationBeforeUpdate = new Point3D(location);
translateAvatarLocation(millisecondsSinceLastFrame);
}
public void enforceSpeedLimit() {
- final double currentSpeed = movementVector
- .getDistanceTo(Point3D.ZERO);
+ final double currentSpeed = movementVector.getVectorLength();
if (currentSpeed <= SPEED_LIMIT)
return;
}
public double getMovementSpeed() {
- return movementVector.getDistanceTo(Point3D.ZERO);
+ return movementVector.getVectorLength();
}
private void applyFrictionToUserMovement(int millisecondsPassedSinceLastFrame) {
import eu.svjatoslav.sixth.e3d.geometry.Box;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
import eu.svjatoslav.sixth.e3d.gui.humaninput.UserInputHandler;
import eu.svjatoslav.sixth.e3d.gui.textEditorComponent.KeyboardHelper;
}
@Override
- public boolean beforeViewUpdate(final ViewContext viewContext,
- final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewContext viewContext,
+ final int millisecondsSinceLastFrame) {
return false;
}
package eu.svjatoslav.sixth.e3d.gui;
-import eu.svjatoslav.sixth.e3d.geometry.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
public class UserRelativityTracker {
- public final static int minimalSliceFactor = 5;
+ private final static int minimalSliceFactor = 5;
public GeometryCoordinate center = new GeometryCoordinate();
public GeometryCoordinate right;
public GeometryCoordinate down;
}
public double getDistanceToUser() {
- return center.transformedCoordinate
- .getDistanceTo(Point3D.ZERO);
+ return center.transformedCoordinate.getVectorLength();
}
public double proposeSliceFactor() {
private static final long serialVersionUID = 1683277888885045387L;
private final List<ViewListener> viewListeners = new ArrayList<>();
- private final List<ViewUpdateListener> viewUpdateListeners = new ArrayList<>();
+ private final List<ViewRenderListener> viewRenderListeners = new ArrayList<>();
private final ViewContext context = new ViewContext(this);
/**
* Last time this view was updated
private boolean repaintDuringNextViewUpdate = true;
public View() {
- viewUpdateListeners.add(context.getAvatar());
+ viewRenderListeners.add(context.getAvatar());
// initialize input tracker
context.getUserInputTracker().bind(this);
- viewUpdateListeners.add(context.getUserInputTracker());
+ viewRenderListeners.add(context.getUserInputTracker());
initializePanelLayout();
getViewListeners().add(listener);
}
- public void addViewUpdateListener(final ViewUpdateListener listener) {
- viewUpdateListeners.add(listener);
+ public void addViewUpdateListener(final ViewRenderListener listener) {
+ viewRenderListeners.add(listener);
}
@Override
// notify update listeners
boolean reRenderFrame = false;
- for (final ViewUpdateListener listener : viewUpdateListeners)
- if (listener.beforeViewUpdate(context,
+ for (final ViewRenderListener listener : viewRenderListeners)
+ if (listener.beforeRender(context,
millisecondsPassedSinceLastUpdate))
reRenderFrame = true;
--- /dev/null
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ *
+ */
+
+package eu.svjatoslav.sixth.e3d.gui;
+
+public interface ViewRenderListener {
+
+ /**
+ * Notifies that it is about time to render next frame and
+ * allows listener to do any related processing that it needs to.
+ *
+ * Each {@link ViewRenderListener} will be notified exactly once before every frame is rendered.
+ *
+ * {@link ViewRenderListener} can determine if frame repaint is actually
+ * needed from its perspective. Frame will be rendered only if at least one listener says yes.
+ *
+ * @return <code>true</code> if underlying view shall be re-rendered. If at least one of the view update listeners
+ * returns <code>true</code>, view is re-rendered.
+ */
+ boolean beforeRender(ViewContext viewContext, final int millisecondsSinceLastFrame);
+}
+++ /dev/null
-/*
- * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
- *
- */
-
-package eu.svjatoslav.sixth.e3d.gui;
-
-public interface ViewUpdateListener {
-
- /**
- * Notifies that it is about time to render next frame. Update listener can determine if frame repaint is actually
- * needed from its perspective. Frame will be rendered if at least one listener says yes.
- *
- * @return <code>true</code> if underlying view shall be re-rendered. If at least one of the view update listeners
- * returns <code>true</code>, view is re-rendered.
- */
- boolean beforeViewUpdate(ViewContext viewContext, final int millisecondsSinceLastFrame);
-}
package eu.svjatoslav.sixth.e3d.gui.humaninput;
import eu.svjatoslav.sixth.e3d.gui.ViewContext;
-import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
+import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
import java.awt.event.KeyEvent;
-public interface UserInputHandler extends ViewUpdateListener {
+public interface UserInputHandler extends ViewRenderListener {
void focusLost(ViewContext viewContext);
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.gui.View;
import eu.svjatoslav.sixth.e3d.gui.ViewContext;
-import eu.svjatoslav.sixth.e3d.gui.ViewUpdateListener;
+import eu.svjatoslav.sixth.e3d.gui.ViewRenderListener;
import javax.swing.*;
import java.awt.event.*;
import java.util.Map;
public class UserInputTracker
- implements MouseMotionListener, KeyListener, MouseListener, MouseWheelListener, ViewUpdateListener {
+ implements MouseMotionListener, KeyListener, MouseListener, MouseWheelListener, ViewRenderListener {
/**
* <pre>
private final Map<Integer, Long> pressedKeysToPressedTimeMap = new HashMap<>();
private final List<MouseClick> detectedMouseClicks = new ArrayList<>();
private final List<KeyEvent> detectedKeyEvents = new ArrayList<>();
- public int wheelMovedDirection = 0;
- Point2D mouseDraggedDirection = new Point2D();
- Point2D oldMouseCoordinatesWhenDragging;
- ViewContext viewContext;
- Point2D currentMouseLocation;
- boolean mouseMoved;
+ private int wheelMovedDirection = 0;
+ private Point2D mouseDraggedDirection = new Point2D();
+ private Point2D oldMouseCoordinatesWhenDragging;
+ private ViewContext viewContext;
+ private Point2D currentMouseLocation;
+ private boolean mouseMoved;
private boolean mouseWithinWindow = false;
public UserInputTracker(final ViewContext viewContext) {
* {@inheritDoc}
*/
@Override
- public boolean beforeViewUpdate(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewContext viewContext, final int millisecondsSinceLastFrame) {
boolean viewUpdateNeeded = handleDetectedMouseClicks(viewContext.getView());
viewUpdateNeeded |= handleDetectedKeyEvents();
- viewContext.getKeyboardFocusTracker().getCurrentFocusOwner().beforeViewUpdate(viewContext,
+ viewContext.getKeyboardFocusTracker().getCurrentFocusOwner().beforeRender(viewContext,
millisecondsSinceLastFrame);
+
viewUpdateNeeded |= trackMouse();
return viewUpdateNeeded;
panel.addMouseWheelListener(this);
}
- public boolean handleDetectedKeyEvents() {
+ private boolean handleDetectedKeyEvents() {
boolean keyEventsHandled = false;
final UserInputHandler currentFocusOwner = viewContext.getKeyboardFocusTracker().getCurrentFocusOwner();
}
/**
- * Returns <code>true</code> if mouse events are detected and view needs to
- * be repainted.
+ * @return <code>true</code> if view needs to be repainted.
*/
- public synchronized boolean handleDetectedMouseClicks(final View view) {
+ private synchronized boolean handleDetectedMouseClicks(final View view) {
if (detectedMouseClicks.isEmpty()) {
if (currentMouseLocation != null)
return true;
}
- public boolean isKeyPressed(final int keyCode) {
+ boolean isKeyPressed(final int keyCode) {
return pressedKeysToPressedTimeMap.containsKey(keyCode);
}
/**
* Interpret mouse movement
*/
- public boolean trackMouse() {
+ private boolean trackMouse() {
final Avatar avatar = viewContext.getAvatar();
+ trackDragging(avatar);
+ trackVerticalScrolling(avatar);
+
+ boolean repaintNeeded = !mouseDraggedDirection.isZero() || (wheelMovedDirection != 0);
- // track mouse dragging
+ // reset movement counters
+ wheelMovedDirection = 0;
+ mouseDraggedDirection.zero();
+
+ return repaintNeeded;
+ }
+
+ private void trackVerticalScrolling(Avatar avatar) {
+ final double actualAcceleration = 50 * avatar.avatarAcceleration * (1 + (avatar.getMovementSpeed() / 10));
+ avatar.getMovementVector().y += (wheelMovedDirection * actualAcceleration);
+ avatar.enforceSpeedLimit();
+ }
+ private void trackDragging(Avatar avatar) {
// TODO: need to detect whether user moved mouse or touch screen
// for mouse
// mouseDraggedDirection.x / 50));
// avatar.setAngleYZ(avatar.getAngleYZ() + ((float)
// mouseDraggedDirection.y / 50));
-
- // track mouse wheel movements
- final double actualAcceleration = 50 * avatar.avatarAcceleration * (1 + (avatar.getMovementSpeed() / 10));
-
- avatar.getMovementVector().y += (wheelMovedDirection * actualAcceleration);
- avatar.enforceSpeedLimit();
-
- // check if view shall be repainted
- boolean repaintNeeded;
- repaintNeeded = (mouseDraggedDirection.x != 0) || (mouseDraggedDirection.y != 0) || (wheelMovedDirection != 0);
-
- // reset movement counters
- wheelMovedDirection = 0;
- mouseDraggedDirection.zero();
-
- return repaintNeeded;
}
}
public class WorldNavigationTracker implements UserInputHandler {
@Override
- public boolean beforeViewUpdate(final ViewContext viewContext,
- final int millisecondsSinceLastFrame) {
+ public boolean beforeRender(final ViewContext viewContext,
+ final int millisecondsSinceLastFrame) {
trackKeys(millisecondsSinceLastFrame, viewContext);
return false;
package eu.svjatoslav.sixth.e3d.gui.textEditorComponent;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.gui.GuiComponent;
import eu.svjatoslav.sixth.e3d.gui.TextPointer;
import eu.svjatoslav.sixth.e3d.gui.ViewContext;
--- /dev/null
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ *
+ */
+
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point2D;
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
+
+public class GeometryCoordinate {
+
+ public Point3D coordinate;
+ public Point3D transformedCoordinate;
+ public Point2D onScreenCoordinate;
+
+ private int lastTransformedFrame;
+
+ public GeometryCoordinate() {
+ coordinate = new Point3D();
+ transformedCoordinate = new Point3D();
+ onScreenCoordinate = new Point2D();
+ }
+
+ public GeometryCoordinate(final Point3D location) {
+ coordinate = location;
+ transformedCoordinate = new Point3D();
+ onScreenCoordinate = new Point2D();
+ }
+
+ public void transform(final TransformPipe transforms,
+ final RenderingContext renderContext) {
+
+ if (lastTransformedFrame == renderContext.frameNumber)
+ return;
+
+ lastTransformedFrame = renderContext.frameNumber;
+
+ transforms.transform(coordinate, transformedCoordinate);
+
+ onScreenCoordinate.x = ((transformedCoordinate.x / transformedCoordinate.z) * renderContext.zoom)
+ + renderContext.xCenter;
+ onScreenCoordinate.y = ((transformedCoordinate.y / transformedCoordinate.z) * renderContext.zoom)
+ + renderContext.yCenter;
+ }
+}
--- /dev/null
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ *
+ */
+
+
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class Orientation implements Cloneable {
+
+ private double s1, c1, s2, c2;
+
+ private double angleXZ = 0;
+ private double angleYZ = 0;
+
+ public Orientation() {
+ computeMultipliers();
+ }
+
+ public Orientation(final double angleXZ, final double angleYZ) {
+ this.angleXZ = angleXZ;
+ this.angleYZ = angleYZ;
+ computeMultipliers();
+ }
+
+ @Override
+ public Orientation clone() {
+ return new Orientation(angleXZ, angleYZ);
+ }
+
+ private void computeMultipliers() {
+ s1 = Math.sin(angleXZ);
+ c1 = Math.cos(angleXZ);
+
+ s2 = Math.sin(angleYZ);
+ c2 = Math.cos(angleYZ);
+ }
+
+ public void rotate(final Point3D point3d) {
+ final double z1 = (point3d.z * c1) - (point3d.x * s1);
+ point3d.x = (point3d.z * s1) + (point3d.x * c1);
+
+ point3d.z = (z1 * c2) - (point3d.y * s2);
+ point3d.y = (z1 * s2) + (point3d.y * c2);
+ }
+
+ public void rotate(final double angleXZ, final double angleYZ) {
+ this.angleXZ += angleXZ;
+ this.angleYZ += angleYZ;
+ computeMultipliers();
+ }
+
+}
--- /dev/null
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ *
+ */
+
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class Transform implements Cloneable {
+
+ private final Point3D translation;
+ private final Orientation orientation;
+
+ public Transform() {
+ translation = new Point3D();
+ orientation = new Orientation();
+ }
+
+ public Transform(final Point3D translation) {
+ this.translation = translation;
+ orientation = new Orientation();
+ }
+
+ public Transform(final Point3D translation, final double angleXZ,
+ final double angleYZ) {
+
+ this.translation = translation;
+ orientation = new Orientation(angleXZ, angleYZ);
+ }
+
+ public Transform(final Point3D translation, final Orientation orientation) {
+ this.translation = translation;
+ this.orientation = orientation;
+ }
+
+ @Override
+ public Transform clone() {
+ return new Transform(translation, orientation);
+ }
+
+ public Orientation getOrientation() {
+ return orientation;
+ }
+
+ public Point3D getTranslation() {
+ return translation;
+ }
+
+ public void transform(final Point3D point) {
+ orientation.rotate(point);
+ point.add(translation);
+ }
+
+}
--- /dev/null
+/*
+ * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ *
+ */
+
+package eu.svjatoslav.sixth.e3d.math;
+
+import eu.svjatoslav.sixth.e3d.geometry.Point3D;
+
+public class TransformPipe {
+
+ private Transform[] transforms = new Transform[100];
+
+ private int transformsCount = 0;
+
+ public void addTransform(final Transform transform) {
+ transforms[transformsCount] = transform;
+ transformsCount++;
+ }
+
+ public void clear() {
+ transformsCount = 0;
+ }
+
+ public void dropTransform() {
+ transformsCount--;
+ }
+
+ public void transform(final Point3D source, final Point3D destination) {
+
+ destination.clone(source);
+
+ for (int i = transformsCount - 1; i >= 0; i--)
+ transforms[i].transform(destination);
+ }
+}
package eu.svjatoslav.sixth.e3d.renderer.octree.raytracer;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
private void computeCameraCoordinates(final Avatar avatar) {
initialize(CAMERA_SIZE, CAMERA_SIZE, IMAGE_SIZE, IMAGE_SIZE, 3);
- camCenter = Point3D.ZERO.clone();
+ camCenter = new Point3D();
topLeft.setValues(camCenter.x, camCenter.y, camCenter.z + CAMERA_SIZE);
topLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
topRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomLeft
- .rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
- bottomRight.rotate(camCenter, -avatar.getAngleXZ(),
- -avatar.getAngleYZ());
+ bottomLeft.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
+ bottomRight.rotate(camCenter, -avatar.getAngleXZ(), -avatar.getAngleYZ());
final Color cameraColor = new Color(255, 255, 0, 255);
final LineAppearance appearance = new LineAppearance(2, cameraColor);
package eu.svjatoslav.sixth.e3d.renderer.raster;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.Avatar;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.ViewContext;
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
-import eu.svjatoslav.sixth.e3d.geometry.GeometryCoordinate;
+import eu.svjatoslav.sixth.e3d.math.GeometryCoordinate;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
accumulatedZ += geometryPoint.transformedCoordinate.z;
- if (!geometryPoint.transformedCoordinate.withinDrawingLimits())
+ if (!geometryPoint.transformedCoordinate.isVisible())
paint = false;
}
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
import eu.svjatoslav.sixth.e3d.renderer.raster.RenderAggregator;
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.GlowingPoint;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.Line;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
import eu.svjatoslav.sixth.e3d.geometry.Point2D;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.texturedpolygon.TexturedPolygon;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.UserRelativityTracker;
import eu.svjatoslav.sixth.e3d.gui.humaninput.MouseInteractionController;
package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
-import eu.svjatoslav.sixth.e3d.geometry.TransformPipe;
+import eu.svjatoslav.sixth.e3d.math.Transform;
+import eu.svjatoslav.sixth.e3d.math.TransformPipe;
import eu.svjatoslav.sixth.e3d.gui.RenderingContext;
import eu.svjatoslav.sixth.e3d.gui.TextPointer;
import eu.svjatoslav.sixth.e3d.renderer.raster.Color;
import eu.svjatoslav.sixth.e3d.geometry.Point3D;
import eu.svjatoslav.sixth.e3d.geometry.Rectangle;
-import eu.svjatoslav.sixth.e3d.geometry.Transform;
+import eu.svjatoslav.sixth.e3d.math.Transform;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.line.LineAppearance;
import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape;
public PolygonCoordinate getMiddlePoint() {
return new PolygonCoordinate(new Point3D().computeMiddlePoint(c1.space,
- c2.space), new Point2D().computeMiddlePoint(c1.texture,
+ c2.space), new Point2D().getMiddle(c1.texture,
c2.texture));
}
}