package detectiongame.proto;
import engine.Vec3f;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
import static org.lwjgl.opengl.GL11.*;
public class StarField {
private Vector<Vec3f> stars;
private Vector<Integer> stars_colours;
private Vector<Float> stars_lum;
private Vector<Vec3f> colour_list;
public StarField(){
stars = new Vector<>();
stars_colours = new Vector<>();
stars_lum = new Vector<>();
colour_list = new Vector<>();
colour_list.add(new Vec3f(0f,0.4f,1f));
colour_list.add(new Vec3f(0.2f,0.6f,1f));
colour_list.add(new Vec3f(0.8f,1f,1f));
colour_list.add(new Vec3f(1f,0.85f,0.6f));
colour_list.add(new Vec3f(1f,0.8f,0.2f));
colour_list.add(new Vec3f(1f,0.2f,0f));
colour_list.add(new Vec3f(1f,0f,0f));
Vector<String> list;
list = readFile("starlist.txt");
String[] temp;
for(int i=0; i<list.size(); i++){
temp = list.get(i).split("\\s+");
if(Float.parseFloat(temp[1]) < 200f)
continue;
stars.add(new Vec3f(Float.parseFloat(temp[0])*10,Float.parseFloat(temp[1]),Float.parseFloat(temp[2])*10));
stars_colours.add(Integer.parseInt(temp[4]));
stars_lum.add(Float.parseFloat(temp[3])/60f);
}
}
public void exist(){
glEnable(GL_BLEND);
glPointSize(1.0f);
glPushMatrix();
glBegin(GL_POINTS);
for(int i=0; i<this.stars.size(); i++){
//glColor4f(this.colour_list.get(stars_colours.get(i)-1).x, this.colour_list.get(stars_colours.get(i)-1).y, this.colour_list.get(stars_colours.get(i)-1).z, stars_lum.get(i));
glVertex3f(this.stars.get(i).x, this.stars.get(i).y, this.stars.get(i).z);
}
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
}
private Vector<String> readFile(String path) {
Vector<String> file = new Vector<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(path));
//temporary string to store a line from file
String s;
while((s = reader.readLine()) != null) {
file.addElement(s.trim());
}
reader.close();
} catch(IOException e) {
//TODO error handling
}
return file;
}
}