1package com.fs.starfarer.api.util;
5import org.lwjgl.opengl.GL11;
7import com.fs.starfarer.api.graphics.SpriteAPI;
11 public static class MutatingValue {
13 protected float value;
19 protected float rateSign;
21 protected float sign = 0;
23 public MutatingValue() {
26 public MutatingValue(
float min,
float max,
float rate) {
29 this.rate =
Math.abs(rate);
31 value = min + (
float)
Math.random() * (max - min);
32 rateSign =
Math.signum(rate);
35 public void set(
float min,
float max) {
38 value = min + (
float)
Math.random() * (max - min);
41 public void advance(
float amount) {
43 value +=
amount * rate * rateSign;
50 }
else if (value < min) {
56 public float getValue() {
57 if (sign != 0)
return value * sign;
61 public void setValue(
float value) {
65 public float getMin() {
69 public void setMin(
float min) {
73 public float getMax() {
77 public void setMax(
float max) {
81 public float getRate() {
85 public void setRate(
float rate) {
87 this.rate =
Math.abs(rate);
91 public float getSign() {
95 public void setSign(
float sign) {
96 this.sign =
Math.signum(sign);
99 public void setRandomSign() {
101 if (sign == 0) sign = 1;
103 public void setRandomRateSign() {
105 if (rateSign == 0) rateSign = 1;
108 public float getRateSign() {
112 public void setRateSign(
float rateSign) {
113 this.rateSign = rateSign;
119 public static class WSVertex {
120 public MutatingValue theta;
121 public MutatingValue radius;
125 theta =
new MutatingValue(-360f * ((
float)
Math.random() * 30f + 1f), 360f * ((
float)
Math.random() * 30f + 1f), 30f + 70f * (
float)
Math.random());
126 radius =
new MutatingValue(0, 10f + 15f * (
float)
Math.random(), 3f + 7f * (
float)
Math.random());
129 public void advance(
float amount) {
135 theta.setMax((
int)theta.getMax());
136 theta.setMin((
int)theta.getMin());
137 theta.setRate((
int)theta.getRate());
138 theta.setValue((
int)theta.getValue());
140 radius.setMax((
int)radius.getMax());
141 radius.setMin((
int)radius.getMin());
142 radius.setRate((
int)radius.getRate());
143 radius.setValue((
int)radius.getValue());
148 private int verticesWide, verticesTall;
149 private WSVertex [] [] vertices;
153 this.verticesWide = verticesWide;
154 this.verticesTall = verticesTall;
156 vertices =
new WSVertex[verticesWide][verticesTall];
157 for (
int i = 0; i < verticesWide; i++) {
158 for (
int j = 0; j < verticesTall; j++) {
159 vertices[i][j] =
new WSVertex();
176 for (
int i = 0; i < verticesWide; i++) {
177 for (
int j = 0; j < verticesTall; j++) {
178 vertices[i][j].advance(
amount);
189 sprite.bindTexture();
192 Color color = sprite.getColor();
193 GL11.glColor4ub((
byte) color.getRed(), (
byte) color.getGreen(),
194 (
byte) color.getBlue(), (
byte)(color.getAlpha() * sprite.getAlphaMult()));
204 float w = sprite.getWidth();
205 float h = sprite.getHeight();
206 float tw = sprite.getTextureWidth() - 0.001f;
207 float th = sprite.getTextureHeight() - 0.001f;
209 float cw = w / (
float) (verticesWide - 1);
210 float ch = h / (
float) (verticesTall- 1);
211 float ctw = tw / (
float) (verticesWide - 1);
212 float cth = th / (
float) (verticesTall- 1);
214 for (
float i = 0; i < verticesWide - 1; i++) {
218 for (
float j = 0; j < verticesTall; j++) {
221 float x2 =
cw * (i + 1f);
226 float tx2 =
ctw * (i + 1f);
229 if (i != 0 && i != verticesWide - 1 && j != 0 && j != verticesTall - 1) {
230 float theta = (
float)
Math.toRadians(vertices[(
int)i][(
int)j].theta.getValue());
231 float radius = vertices[(
int)i][(
int)j].radius.getValue();
240 if (i + 1 != 0 && i + 1 != verticesWide - 1 && j != 0 && j != verticesTall - 1) {
241 float theta = (
float)
Math.toRadians(vertices[(
int)i + 1][(
int)j].theta.getValue());
242 float radius = vertices[(
int)i + 1][(
int)j].radius.getValue();
void advance(float amount)
void renderNoBlendOrRotate(SpriteAPI sprite, float xOff, float yOff, boolean disableBlend)
void renderNoBlendOrRotate(SpriteAPI sprite, float x, float y)
WarpingSpriteRendererUtil(int verticesWide, int verticesTall, float minWarpRadius, float maxWarpRadius, float warpRateMult)