Skip to content

Commit

Permalink
WIP #12: track and render internal hallways/connections
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmaxfrank committed Jan 18, 2016
1 parent d9ec33e commit 24659a4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.sun.j3d.utils.universe.ViewingPlatform;
import net.dhleong.acl.util.GridCoord;
import net.dhleong.acl.vesseldata.VesselNode;
import net.dhleong.acl.vesseldata.VesselNodeConnection;

import javax.media.j3d.*;
import javax.swing.*;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis
private static final Random random = new Random();

private Map<GridCoord, InternalNode> internalNodes = new HashMap<>();
private Set<InternalHallway> internalHallways = new HashSet<>();

public Damcon(EngineeringConsoleManager engineeringConsoleManager) {
this.engineeringConsoleManager = engineeringConsoleManager;
Expand All @@ -78,6 +80,7 @@ public Damcon(EngineeringConsoleManager engineeringConsoleManager) {
}

loadInternalNodes();
loadCorridors();

addMouseListeners();
setCameraPresets();
Expand Down Expand Up @@ -132,6 +135,18 @@ public void onChange() {
});
}

private void loadCorridors() {
BranchGroup corridor_bg = new BranchGroup();

for (VesselNodeConnection vnc : this.engineeringConsoleManager.getGridConnections()) {
InternalHallway ih = new InternalHallway(vnc);
internalHallways.add(ih);
corridor_bg.addChild(ih.getShape());
}

this.universe.addBranchGraph(corridor_bg);
}

private void createUniverseAndScene() {
// This is an attempt to give the Viewer a canvas so it doesn't create its own window (it doesn't render properly)
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.brindyblitz.artemis.engconsole.ui.damcon;

import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Sphere;
import net.dhleong.acl.vesseldata.VesselNode;
import net.dhleong.acl.vesseldata.VesselNodeConnection;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import javax.media.j3d.*;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;
import java.awt.*;

public class InternalHallway {
private static final float RADIUS = 0.05f, SCALE = 0.0034f; // TODO: unify scale in Damcon.java or make these subclasses with access to that

private VesselNodeConnection vesselNodeConnection;
private LineArray lineArray;
private Shape3D shape;

public InternalHallway(VesselNodeConnection vessel_node_connection) {
this.vesselNodeConnection = vessel_node_connection;

VesselNode vn1 = this.vesselNodeConnection.getNode1(),
vn2 = this.vesselNodeConnection.getNode2();

Point3f p1 = new Point3f(-vn1.getX(), vn1.getY(), vn1.getZ());
Point3f p2 = new Point3f(-vn2.getX(), vn2.getY(), vn2.getZ());
p1.scale(SCALE);
p2.scale(SCALE);

lineArray = new LineArray(2, LineArray.COORDINATES);
lineArray.setCoordinate(0, p1);
lineArray.setCoordinate(1, p2);
lineArray.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

this.shape = new Shape3D(lineArray, appearanceFromHealthPercentage(1f));
}

public void updateHealth(float pct) {
// lineArray.setAppearance(appearanceFromHealthPercentage(pct));
// TODO: implement
}

private static Appearance appearanceFromHealthPercentage(float pct) {
Appearance appearance = new Appearance();

// Set transparency
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, .1f);
appearance.setTransparencyAttributes(transparency);

// Enable automatic anti-aliasing
LineAttributes line_attributes = new LineAttributes();
line_attributes.setLineAntialiasingEnable(true);
line_attributes.setLinePattern(LineAttributes.PATTERN_SOLID);
appearance.setLineAttributes(line_attributes);

// Set color
Color awtColor = Color.getHSBColor(getEmptyHue() - (getEmptyHue() - getFullHue()) * pct, 1, 1);
Color3f color = new Color3f(awtColor);
ColoringAttributes coloring_attributes = new ColoringAttributes();
coloring_attributes.setColor(color);
appearance.setColoringAttributes(coloring_attributes);

LineArray la = new LineArray(2, LineArray.COORDINATES);
la.setCoordinate(0, new Point3f(0f, 0f, 0f));
la.setCoordinate(1, new Point3f(1f, 0f, 0f));
return appearance;
}

private static float getFullHue() {
return 120f / 360f;
}

private static float getEmptyHue() {
return 0f;
}
// TODO: this color stuff is duplicated in SystemHealthSlider.java, fix it!

public Shape3D getShape() {
return this.shape;
}
}

0 comments on commit 24659a4

Please sign in to comment.