Skip to content

Commit

Permalink
WIP #12: Further refactor of Internals
Browse files Browse the repository at this point in the history
- I still haven't tested DAMCON selectability.  I'll try adding it to
  the FakeEngineeringConsoleManager if I have a chance.
- The DAMCON team rendering currently shares a Sphere with the internal
  nodes, but they should probably be a box or something.
- See TODOs for many other WIP/unimplemented features
  • Loading branch information
jacobmaxfrank committed Jan 18, 2016
1 parent 5bf7764 commit dde81cc
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 145 deletions.
20 changes: 12 additions & 8 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class Damcon implements MouseListener, MouseMotionListener, MouseWheelLis
private Map<GridCoord, InternalNode> internalNodes = new HashMap<>();
private Set<InternalConnection> internalConnections = new HashSet<>();
private Map<Integer, InternalTeam> internalTeams = new HashMap<>();
private Map<Node, Internal> nodesToInternals = new HashMap<>();
private Map<Node, InternalSelectable> nodesToSelectabls = new HashMap<>();
private static final float PICK_TOLERANCE = 0.1f;

public Damcon(EngineeringConsoleManager engineeringConsoleManager) {
Expand All @@ -91,7 +91,7 @@ public Damcon(EngineeringConsoleManager engineeringConsoleManager) {
createUniverseAndScene();
}

loadInternalNodes();
loadInternalNodesAndDamconTeams();
loadCorridors();

addMouseListeners();
Expand Down Expand Up @@ -120,20 +120,24 @@ private void loadAndWireframeifyModel() {
}
}

private void loadInternalNodes() {
BranchGroup node_branchgroup = new BranchGroup(), damcon_branchgroup = new BranchGroup();
private void loadInternalNodesAndDamconTeams() {
BranchGroup node_branchgroup = new BranchGroup();
node_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
node_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);

for (VesselNode vn : this.engineeringConsoleManager.getGrid()) {
InternalNode in = new InternalNode(vn);
internalNodes.put(vn.getGridCoord(), in);
nodesToInternals.put(in.getShape(), in);
nodesToSelectabls.put(in.getShape(), in);
node_branchgroup.addChild(in.getBranchGroup());
}

this.universe.addBranchGraph(node_branchgroup);

BranchGroup damcon_branchgroup = new BranchGroup();
damcon_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
damcon_branchgroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);

this.engineeringConsoleManager.addChangeListener(new EngineeringConsoleManager.EngineeringConsoleChangeListener() {
@Override
public void onChange() {
Expand All @@ -147,6 +151,7 @@ public void onChange() {
if (it == null) {
it = new InternalTeam(damconStatus.getX(), damconStatus.getY(), damconStatus.getZ());
internalTeams.put(damconStatus.getTeamNumber(), it);
nodesToSelectabls.put(it.getBranchGroup(), it);
damcon_branchgroup.addChild(it.getBranchGroup());
}
it.updatePos(damconStatus.getX(), damconStatus.getY(), damconStatus.getZ());
Expand All @@ -164,7 +169,6 @@ private void loadCorridors() {
InternalConnection ih = new InternalConnection(vnc);
internalConnections.add(ih);
Node node = ih.getShape();
nodesToInternals.put(node, ih);
corridor_bg.addChild(node);
}

Expand Down Expand Up @@ -274,7 +278,7 @@ public void mouseClicked(MouseEvent e) {
// TODO: DAMCON > Use pickAll(). Prioritize as follows:
// DAMCON teams, system nodes, non-system nodes, hallways

for (Internal i : nodesToInternals.values()) {
for (InternalSelectable i : nodesToSelectabls.values()) {
i.setSelected(false);
}

Expand All @@ -283,7 +287,7 @@ public void mouseClicked(MouseEvent e) {
}

Node scene_node = pi.getNode();
Internal internal = nodesToInternals.get(scene_node);
InternalSelectable internal = nodesToSelectabls.get(scene_node);
internal.setSelected(true);
System.out.println("Selecting " + internal);
}
Expand Down
35 changes: 6 additions & 29 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Internal.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,22 @@
package com.brindyblitz.artemis.engconsole.ui.damcon;


import com.brindyblitz.artemis.engconsole.ui.SystemStatusSlider;
import net.dhleong.acl.vesseldata.VesselNode;

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

public abstract class Internal {
protected static final float SCALE = 0.0034f;
protected static final float SHININESS = 0f;

protected float alpha;
protected boolean selected = false;
protected float healthPct = 1f;

protected static Point3f vesselNodePosition(VesselNode vn) {
Point3f p = new Point3f(-vn.getX(), vn.getY(), vn.getZ());
protected static Point3f internalPositionToWorldSpace(float x, float y, float z) {
Point3f p = new Point3f(-x, y, z);
p.scale(SCALE);
return p;
}

protected abstract Appearance appearanceFromHealthPercentage(float pct);

public void updateHealth(float pct) {
this.healthPct = pct;
}

protected void updateSelection() {

}

protected Color3f getColorFromHealth(float pct) {
Color color = Color.getHSBColor(
SystemStatusSlider.getEmptyHue(true) - (SystemStatusSlider.getEmptyHue(true) - SystemStatusSlider.getFullHue(true)) * pct, 1, 1);
return new Color3f(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f);
}

public void setSelected(boolean selected) {
this.selected = selected;
updateSelection();
protected static Point3f internalPositionToWorldSpace(VesselNode vn) {
return internalPositionToWorldSpace(vn.getX(), vn.getY(), vn.getZ());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
package com.brindyblitz.artemis.engconsole.ui.damcon;

import com.sun.j3d.utils.picking.PickTool;
import net.dhleong.acl.vesseldata.VesselNodeConnection;

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

public class InternalConnection extends Internal {
private VesselNodeConnection vesselNodeConnection;
private LineArray lineArray;
private Shape3D shape;

private static final Color3f LINE_COLOR = new Color3f(0f, 1f, 0f);

public InternalConnection(VesselNodeConnection vessel_node_connection) {
alpha = 0.1f;

this.vesselNodeConnection = vessel_node_connection;

lineArray = new LineArray(2, LineArray.COORDINATES);
lineArray.setCoordinate(0, Internal.vesselNodePosition(this.vesselNodeConnection.getNode1()));
lineArray.setCoordinate(1, Internal.vesselNodePosition(this.vesselNodeConnection.getNode2()));
lineArray.setCoordinate(0, Internal.internalPositionToWorldSpace(this.vesselNodeConnection.getNode1()));
lineArray.setCoordinate(1, Internal.internalPositionToWorldSpace(this.vesselNodeConnection.getNode2()));
lineArray.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

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

@Override
public void updateHealth(float pct) {
super.updateHealth(pct);
shape.setAppearance(appearanceFromHealthPercentage(pct));
}

@Override
protected Appearance appearanceFromHealthPercentage(float pct) {
Appearance appearance = new Appearance();

// Set transparency
Expand All @@ -49,10 +36,11 @@ protected Appearance appearanceFromHealthPercentage(float pct) {

// Set color
ColoringAttributes coloring_attributes = new ColoringAttributes();
coloring_attributes.setColor(getColorFromHealth(pct));
coloring_attributes.setColor(LINE_COLOR);
appearance.setColoringAttributes(coloring_attributes);

return appearance;
this.shape = new Shape3D(lineArray, appearance);
this.shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}

public Shape3D getShape() {
Expand Down
72 changes: 22 additions & 50 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
import javax.media.j3d.*;
import javax.vecmath.*;

public class InternalNode extends Internal {
private static final float RADIUS = 0.05f;
private static final Color3f BLACK = new Color3f(0f, 0f, 0f);

private BranchGroup branchGroup;
public class InternalNode extends InternalSelectable {
private VesselNode vesselNode;
private Sphere sphere;

public InternalNode(VesselNode vessel_node) {
alpha = 0.3f;
Expand All @@ -26,31 +21,27 @@ public InternalNode(VesselNode vessel_node) {
Vector3f pos = new Vector3f(-vessel_node.getX(), vessel_node.getY(), vessel_node.getZ());
pos.scale(SCALE);

sphere = new Sphere(RADIUS, appearanceFromHealthPercentage(1f));
sphere = new Sphere(RADIUS, appearanceFromHealthPercentage(1f, !isSystemNode()));
sphere.getShape(Sphere.BODY).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

Transform3D transform = new Transform3D();
transform.setTranslation(new Vector3f(Internal.vesselNodePosition(vessel_node)));
transform.setTranslation(new Vector3f(Internal.internalPositionToWorldSpace(vessel_node)));

TransformGroup tg = new TransformGroup();
tg.setTransform(transform);
tg.addChild(this.sphere);

this.branchGroup.addChild(tg);

// TODO: this one works, remove unneeded calls to appearance caps elsewhere (except for internalhallway)
// be careful not to break anything!
Shape3D shape = this.sphere.getShape(Sphere.BODY);
shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

shape.setCapability(Shape3D.ENABLE_PICK_REPORTING);
shape.setPickable(true);
setPickable(shape);
}

@Override
public void updateHealth(float pct) {
super.updateHealth(pct);
sphere.setAppearance(appearanceFromHealthPercentage(pct));
sphere.setAppearance(appearanceFromHealthPercentage(pct, !isSystemNode()));
}

@Override
Expand All @@ -59,31 +50,29 @@ protected void updateSelection() {
return;
}

// TODO: > bug here. Transparency of something is jumping on first node selection after launch. Investigate.
if (selected) {
Appearance app = appearanceFromHealthPercentage(healthPct);
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, 0f);
app.setTransparencyAttributes(ta);
sphere.setAppearance(app);
} else {
updateHealth(healthPct);
}
super.updateSelection();
}

// TODO: can I pull this up to Internal? Node vs. shape vs. group issue, same as elsewhere, worth cleaning up
// TODO: > can I pull these 2 methods up to Internal? Node vs. shape vs. group issue, same as elsewhere, worth cleaning up


public Shape3D getShape() {
return this.sphere.getShape(Sphere.BODY);
}

private boolean isSystemNode() {
return this.vesselNode.getSystem() != null;
}

@Override
protected Appearance appearanceFromHealthPercentage(float pct) {
Appearance app = new Appearance();
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
app.setMaterial(new Material(BLACK, getColorFromHealth(pct), BLACK, BLACK, SHININESS));
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST,
isSystemNode() ? alpha : 1f); // TODO: FILE ISSUE > when hovering, make opaque or circle or something
app.setTransparencyAttributes(transparency);
return app;
public String toString() {
return "Node: " + this.vesselNode;
}


//////////////////////
// WIP: Billboards? //
//////////////////////
private InternalNode(Vector3d position, int IDONTWORKYET) {
if (true) {
throw new NotImplementedException();
Expand Down Expand Up @@ -128,21 +117,4 @@ private InternalNode(Vector3d position, int IDONTWORKYET) {
branchGroup = new BranchGroup();
branchGroup.addChild(billboard);
}

public BranchGroup getBranchGroup() {
return branchGroup;
}

public Shape3D getShape() {
return this.sphere.getShape(Sphere.BODY);
}

private boolean isSystemNode() {
return this.vesselNode.getSystem() != null;
}

@Override
public String toString() {
return "Node: " + this.vesselNode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.brindyblitz.artemis.engconsole.ui.damcon;

import com.brindyblitz.artemis.engconsole.ui.SystemStatusSlider;
import com.sun.j3d.utils.geometry.Sphere;

import javax.media.j3d.*;
import javax.vecmath.Color3f;
import java.awt.*;

public abstract class InternalSelectable extends Internal {
protected static final float RADIUS = 0.05f;
protected static final float SHININESS = 0f;
protected static final Color3f BLACK = new Color3f(0f, 0f, 0f);

protected boolean selected = false;
protected float healthPct = 1f;

protected Sphere sphere;
protected BranchGroup branchGroup;

protected Appearance appearanceFromHealthPercentage(float pct, boolean invisible) {
Appearance app = new Appearance();
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
app.setMaterial(new Material(BLACK, getColorFromHealth(pct), BLACK, BLACK, SHININESS));
// TODO: FILE ISSUE > when hovering, make opaque or circle or something
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, invisible ? 1f : alpha);
app.setTransparencyAttributes(transparency);
return app;
}

protected void setPickable(Shape3D shape) {
shape.setCapability(Shape3D.ENABLE_PICK_REPORTING);
shape.setPickable(true);
}

public void updateHealth(float pct) {
this.healthPct = pct;
}

protected Color3f getColorFromHealth(float pct) {
Color color = Color.getHSBColor(
SystemStatusSlider.getEmptyHue(true) - (SystemStatusSlider.getEmptyHue(true) - SystemStatusSlider.getFullHue(true)) * pct, 1, 1);
return new Color3f(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f);
}

public void setSelected(boolean selected) {
this.selected = selected;
updateSelection();
}

protected void updateSelection() {
// TODO: > bug here. Transparency of something is jumping on first node selection after launch. Investigate.
// It actually looks like the depth of the nodes is being put behind the model for some reason
if (selected) {
Appearance app = appearanceFromHealthPercentage(healthPct, false);
TransparencyAttributes ta = new TransparencyAttributes(TransparencyAttributes.NICEST, 0f);
app.setTransparencyAttributes(ta);
sphere.setAppearance(app);
} else {
updateHealth(healthPct);
}
}

public BranchGroup getBranchGroup() {
return branchGroup;
}
}
Loading

0 comments on commit dde81cc

Please sign in to comment.