Starsector API
Loading...
Searching...
No Matches
NeuralTransferVisual.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.awt.Color;
4
5import org.lwjgl.opengl.GL11;
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin;
10import com.fs.starfarer.api.combat.CombatEngineLayers;
11import com.fs.starfarer.api.combat.ShipAPI;
12import com.fs.starfarer.api.combat.ViewportAPI;
13import com.fs.starfarer.api.graphics.SpriteAPI;
14import com.fs.starfarer.api.util.FaderUtil;
15import com.fs.starfarer.api.util.Misc;
16
17public class NeuralTransferVisual extends BaseCombatLayeredRenderingPlugin {
18
19 public static float TEX_SCROLL_SPEED = 1f;
20
21 protected ShipAPI from;
22 protected ShipAPI to;
23 protected float duration;
24
25 protected FaderUtil fader = new FaderUtil(0f, 0.5f, 0.5f);
26
27 protected SpriteAPI sprite;
28 protected float texProgress = 0f;
29
30 public NeuralTransferVisual(ShipAPI from, ShipAPI to, float duration) {
31 this.from = from;
32 this.to = to;
33 this.duration = duration;
34
35 sprite = Global.getSettings().getSprite("misc", "neural_transfer_beam");
36 fader.fadeIn();
37 }
38
39 @Override
40 public void advance(float amount) {
41 super.advance(amount);
42
43 if (Global.getCombatEngine().isPaused()) return;
44
45 entity.getLocation().set(to.getShieldCenterEvenIfNoShield());
46 fader.advance(amount);
47 duration -= amount;
48 if (!fader.isFadingOut() && duration <= 0f) {
49 fader.fadeOut();
50 }
51
52 texProgress -= TEX_SCROLL_SPEED * amount * 2f;
53 }
54
55 @Override
56 public float getRenderRadius() {
57 return to.getShieldRadiusEvenIfNoShield() * 3f + 200f;
58 }
59
60 @Override
61 public void render(CombatEngineLayers layer, ViewportAPI viewport) {
62 super.render(layer, viewport);
63
64
65 //float length = to.getShieldRadiusEvenIfNoShield() * 3f + 100f;
66 float length1 = 500f;
67 length1 = Math.min(length1, Misc.getDistance(from.getLocation(), to.getLocation()));
68 float length2 = to.getShieldRadiusEvenIfNoShield();
69 if (length1 < length2) length1 = length2;
70 length1 += length2;
71 float w1 = to.getShieldRadiusEvenIfNoShield() * 0.3f;
72 float w2 = to.getShieldRadiusEvenIfNoShield() * 1.5f;
73 float w3 = to.getShieldRadiusEvenIfNoShield() * 2.5f;
74 float wMult = 0.33f;
75 w1 *= wMult;
76 w2 *= wMult;
77 w3 *= wMult;
78 //w1 = w2 = 400;
79
80 float angle = Misc.getAngleInDegrees(from.getLocation(), to.getLocation());
81
82 Vector2f dest = new Vector2f(to.getShieldCenterEvenIfNoShield());
83 Vector2f src = Misc.getUnitVectorAtDegreeAngle(angle + 180f);
84 src.scale(length1 - length2/2f);
85 Vector2f.add(src, dest, src);
86
87 Vector2f dir = Misc.getUnitVectorAtDegreeAngle(angle);
88 Vector2f dest2 = new Vector2f(dir);
89 dest2.scale(length2/3f * 1f);
90 Vector2f.add(dest2, dest, dest2);
91 Vector2f dest1 = new Vector2f(dir);
92 dest1.scale(-length2/3f * 2f);
93 Vector2f.add(dest1, dest, dest1);
94
95
96 Vector2f perp = Misc.getUnitVectorAtDegreeAngle(angle + 90);
97
98 GL11.glEnable(GL11.GL_TEXTURE_2D);
99 //GL11.glDisable(GL11.GL_TEXTURE_2D);
100 sprite.bindTexture();
101 GL11.glEnable(GL11.GL_BLEND);
102 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
103
104 Color color = new Color(0,121,216,255);
105
106 boolean wireframe = false;
107 //wireframe = true;
108 if (wireframe) {
109 GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
110 GL11.glDisable(GL11.GL_TEXTURE_2D);
111 //GL11.glDisable(GL11.GL_BLEND);
112 }
113
114 float alpha = (float) (viewport.getAlphaMult() * Math.sqrt(fader.getBrightness()));
115 alpha *= 0.5f;
116 alpha *= (0.5f + Math.min(0.5f, 0.5f * w2 / 360f));
117 GL11.glBegin(GL11.GL_TRIANGLE_FAN);
118 Misc.setColor(color, alpha * 1f);
119 GL11.glTexCoord2f(0.5f + texProgress, 0.5f);
120 GL11.glVertex2f((src.x + dest1.x)/2f, (src.y + dest1.y)/2f);
121
122 Misc.setColor(color, alpha * 0f);
123 GL11.glTexCoord2f(0f + texProgress, 0f);
124 GL11.glVertex2f(src.x + perp.x * w1/2f, src.y + perp.y * w1/2f);
125 GL11.glTexCoord2f(0f + texProgress, 1f);
126 GL11.glVertex2f(src.x - perp.x * w1/2f, src.y - perp.y * w1/2f);
127
128 Misc.setColor(color, alpha * 1f);
129 GL11.glTexCoord2f(1f + texProgress, 1f);
130 GL11.glVertex2f(dest1.x - perp.x * w2/2f, dest1.y - perp.y * w2/2f);
131 GL11.glTexCoord2f(1f + texProgress, 0f);
132 GL11.glVertex2f(dest1.x + perp.x * w2/2f, dest1.y + perp.y * w2/2f);
133
134 Misc.setColor(color, alpha * 0f);
135 GL11.glTexCoord2f(0f + texProgress, 0f);
136 GL11.glVertex2f(src.x + perp.x * w1/2f, src.y + perp.y * w1/2f);
137 GL11.glEnd();
138
139 float th = length2 / length1;
140
141 GL11.glBegin(GL11.GL_TRIANGLE_FAN);
142 Misc.setColor(color, alpha * 1f);
143 GL11.glTexCoord2f(0.5f + texProgress + th, 0.5f);
144 GL11.glVertex2f((dest1.x + dest2.x)/2f, (dest1.y + dest2.y)/2f);
145
146 Misc.setColor(color, alpha * 1f);
147 GL11.glTexCoord2f(0f + texProgress, 0f);
148 GL11.glVertex2f(dest1.x + perp.x * w2/2f, dest1.y + perp.y * w2/2f);
149 GL11.glTexCoord2f(0f + texProgress, 1f);
150 GL11.glVertex2f(dest1.x - perp.x * w2/2f, dest1.y - perp.y * w2/2f);
151
152 Misc.setColor(color, alpha * 0f);
153 GL11.glTexCoord2f(1f + texProgress + th, 1f);
154 GL11.glVertex2f(dest2.x - perp.x * w3/2f, dest2.y - perp.y * w3/2f);
155 GL11.glTexCoord2f(1f + texProgress + th, 0f);
156 GL11.glVertex2f(dest2.x + perp.x * w3/2f, dest2.y + perp.y * w3/2f);
157
158 Misc.setColor(color, alpha * 1f);
159 GL11.glTexCoord2f(0f + texProgress + th, 0f);
160 GL11.glVertex2f(dest1.x + perp.x * w2/2f, dest1.y + perp.y * w2/2f);
161 GL11.glEnd();
162
163 if (wireframe) GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
164
165 }
166
167 @Override
168 public boolean isExpired() {
169 return fader.isFadedOut() && duration <= 0f;
170 }
171
172
173
174
175
176}
static SettingsAPI getSettings()
Definition Global.java:51
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
void render(CombatEngineLayers layer, ViewportAPI viewport)
NeuralTransferVisual(ShipAPI from, ShipAPI to, float duration)
SpriteAPI getSprite(String filename)