Skip to content

Commit

Permalink
WIP #12, etc.: Refactor of shared coloring and Internal code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmaxfrank committed Jan 18, 2016
1 parent 24659a4 commit ee612bd
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SystemHealthSlider extends SystemStatusSlider {
private static BufferedImage statusImageWithColor = null, statusImageWhite = null;

public SystemHealthSlider(ShipSystem system, EngineeringConsoleManager engineeringConsoleManager) {
super(system, engineeringConsoleManager);
super(system, engineeringConsoleManager, true);
}

@Override
Expand Down Expand Up @@ -46,14 +46,4 @@ protected BufferedImage getStatusImageWithColor() {
protected BufferedImage getStatusImageWhite() {
return statusImageWhite;
}

@Override
protected float getFullHue() {
return 120f / 360f;
}

@Override
protected float getEmptyHue() {
return 0f;
}
}
12 changes: 1 addition & 11 deletions src/com/brindyblitz/artemis/engconsole/ui/SystemHeatSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SystemHeatSlider extends SystemStatusSlider {
private static BufferedImage statusImageWithColor = null, statusImageWhite = null;

public SystemHeatSlider(ShipSystem system, EngineeringConsoleManager engineeringConsoleManager) {
super(system, engineeringConsoleManager);
super(system, engineeringConsoleManager, false);
}

@Override
Expand Down Expand Up @@ -46,14 +46,4 @@ protected BufferedImage getStatusImageWithColor() {
protected BufferedImage getStatusImageWhite() {
return statusImageWhite;
}

@Override
protected float getFullHue() {
return 0f;
}

@Override
protected float getEmptyHue() {
return 60f / 360f;
}
}
26 changes: 22 additions & 4 deletions src/com/brindyblitz/artemis/engconsole/ui/SystemStatusSlider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
public abstract class SystemStatusSlider extends JPanel {
private static final long serialVersionUID = 1L;

protected boolean isHealth;

protected static final int
WIDGET_HEIGHT = 20,
WIDGET_WIDTH = 100,
Expand All @@ -30,9 +32,10 @@ public abstract class SystemStatusSlider extends JPanel {

protected ShipSystem system;

public SystemStatusSlider(ShipSystem system, EngineeringConsoleManager engineeringConsoleManager) {
public SystemStatusSlider(ShipSystem system, EngineeringConsoleManager engineeringConsoleManager, boolean is_health) {
this.system = system;
this.engineeringConsoleManager = engineeringConsoleManager;
this.isHealth = is_health;

this.setSize(WIDGET_WIDTH, WIDGET_HEIGHT);
this.setBackground(new Color(0, 0, 0, 0));
Expand Down Expand Up @@ -117,13 +120,28 @@ private float getStatusScaleFactor() {

private Color getStatusColor() {
float factor = getStatusScaleFactor();
return factor == 0f ? Color.GRAY : Color.getHSBColor(getEmptyHue() - (getEmptyHue() - getFullHue()) * getStatusScaleFactor(), 1, 1);
return factor == 0f ? Color.GRAY :
Color.getHSBColor(getEmptyHue(isHealth) - (getEmptyHue(isHealth) - getFullHue(isHealth)) * getStatusScaleFactor(), 1, 1);
}

protected abstract int getStatusPctInt();
protected abstract void loadIcons();
protected abstract BufferedImage getStatusImageWithColor();
protected abstract BufferedImage getStatusImageWhite();
protected abstract float getFullHue();
protected abstract float getEmptyHue();

public static float getFullHue(boolean health) {
if (health) {
return 120f / 360f;
} else {
return 0f;
}
}

public static float getEmptyHue(boolean health) {
if (health) {
return 0f;
} else {
return 60f / 360f;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class UserInterfaceFrame extends JFrame implements KeyListener {

private ArrayList<SystemSlider> sliders = new ArrayList<>();
private Damcon damcon;

// TODO: constant cleanup!

private static final int
WINDOW_WIDTH = 1024,
WINDOW_HEIGHT = 768,
Expand Down
5 changes: 3 additions & 2 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Damcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public class Damcon implements MouseListener, MouseMotionListener, MouseWheelListener {
private static final int WIDTH = 400, HEIGHT = 300;

private static final Color WIREFRAME_COLOR = Color.GREEN; // TODO: vary this color with total ship health if available?
private static final Color WIREFRAME_COLOR = Color.BLUE;
private static final float ALPHA = 0.9f;

private static final Transform3D DEFAULT_CAMERA_VIEW = new Transform3D(new double[] {
0.6954015757171349d, 0.4658852009660681d, -0.5471449789689495d, -2.0244364221851137d,
Expand Down Expand Up @@ -213,7 +214,7 @@ private static Appearance getWireframeAppearance(int line_attributes_pattern) {
Appearance appearance = new Appearance();

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

// Enable automatic anti-aliasing
Expand Down
35 changes: 35 additions & 0 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/Internal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.brindyblitz.artemis.engconsole.ui.damcon;


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

import javax.media.j3d.Appearance;
import javax.media.j3d.Node;
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 static Point3f vesselNodePosition(VesselNode vn) {
Point3f p = new Point3f(-vn.getX(), vn.getY(), vn.getZ());
p.scale(SCALE);
return p;
}

protected abstract Appearance appearanceFromHealthPercentage(float pct);
public abstract void updateHealth(float 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);
}

}
Original file line number Diff line number Diff line change
@@ -1,54 +1,42 @@
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

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

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

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);
this.vesselNodeConnection = vessel_node_connection;

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

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

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

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

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

// Enable automatic anti-aliasing
Expand All @@ -58,27 +46,13 @@ private static Appearance appearanceFromHealthPercentage(float pct) {
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);
coloring_attributes.setColor(getColorFromHealth(pct));
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;
}
Expand Down
43 changes: 12 additions & 31 deletions src/com/brindyblitz/artemis/engconsole/ui/damcon/InternalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

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

public class InternalNode {
private static final float RADIUS = 0.05f, SCALE = 0.0034f;
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;
private VesselNode vesselNode;
private Sphere sphere;

public InternalNode(VesselNode vessel_node) {
alpha = 0.3f;

this.vesselNode = vessel_node;

this.branchGroup = new BranchGroup();
Expand All @@ -25,19 +27,14 @@ 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, Shape3D.ALLOW_APPEARANCE_WRITE | Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE, appearanceFromHealthPercentage(1f));
/*sphere.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
sphere.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_READ);
sphere.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
sphere.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);*/
Sphere sphere = new Sphere(RADIUS, appearanceFromHealthPercentage(1f));
sphere.getShape(Sphere.BODY).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

sphere.setCapability(Shape3D.ENABLE_PICK_REPORTING);
sphere.setPickable(true);

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

TransformGroup tg = new TransformGroup();
tg.setTransform(transform);
Expand All @@ -47,38 +44,22 @@ public InternalNode(VesselNode vessel_node) {
}
}

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

private static Appearance appearanceFromHealthPercentage(float pct) {
Color color = Color.getHSBColor(getEmptyHue() - (getEmptyHue() - getFullHue()) * pct, 1, 1);

// TODO: cleanup!

Color3f ambientColour = new Color3f(0f, 0f, 0f);
Color3f emissiveColour = new Color3f(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f);
Color3f specularColour = new Color3f(0f, 0f, 0f);
Color3f diffuseColour = new Color3f(0f, 0f, 0f);
float shininess = 0.0f;
@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(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, .5f); // TODO: when hovering, make opaque
app.setMaterial(new Material(BLACK, getColorFromHealth(pct), BLACK, BLACK, SHININESS));
TransparencyAttributes transparency = new TransparencyAttributes(TransparencyAttributes.NICEST, alpha); // TODO: when hovering, make opaque
app.setTransparencyAttributes(transparency);
return app;
}

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

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

private InternalNode(Vector3d position, int IDONTWORKYET) {
if (true) {
throw new NotImplementedException();
Expand Down

0 comments on commit ee612bd

Please sign in to comment.