Slightly better alignment
The mode for alignment is more concise
This commit is contained in:
parent
576cfed99f
commit
c1a57f7d7a
@ -12,27 +12,23 @@ import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
|
||||
public class CubeComponent extends Component {
|
||||
|
||||
private Mat4 transforms[];
|
||||
private Vec4[] normals;
|
||||
private final Mat4[] transforms;
|
||||
private final Vec4[] normals;
|
||||
private final long startTime;
|
||||
|
||||
private final double pi2 = Math.PI/2;
|
||||
private final double r3 = Math.sqrt(3);
|
||||
private final double r3 = Math.sqrt(3+.01);
|
||||
|
||||
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
private final int size;
|
||||
|
||||
private int size = 400;
|
||||
|
||||
public CubeComponent(String name)
|
||||
{
|
||||
this(name, 400);
|
||||
}
|
||||
public CubeComponent(String name, int size) {
|
||||
super(name);
|
||||
this.size = size;
|
||||
transforms = new Mat4[6];
|
||||
normals = new Vec4[6];
|
||||
setPreferredSize((int) Math.ceil(r3*size),(int) Math.ceil(r3*size));
|
||||
executor.scheduleAtFixedRate(() -> requestReassembly(), 1, 60, TimeUnit.MILLISECONDS);
|
||||
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
executor.scheduleAtFixedRate(this::requestReassembly, 1, 60, TimeUnit.MILLISECONDS);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// Notes to me
|
||||
@ -43,6 +39,7 @@ public class CubeComponent extends Component {
|
||||
|
||||
private void computeTransforms()
|
||||
{
|
||||
//Creates all of the sides
|
||||
transforms[0] = new Mat4(1);
|
||||
transforms[1] = new Mat4(1);
|
||||
transforms[2] = new Mat4(1);
|
||||
@ -50,8 +47,10 @@ public class CubeComponent extends Component {
|
||||
transforms[4] = new Mat4(1);
|
||||
transforms[5] = new Mat4(1);
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
//Gets time since creation(for rotation amount)
|
||||
long time = System.currentTimeMillis()-startTime;
|
||||
|
||||
//Initializes the way each face is facing
|
||||
normals[0] = new Vec4(0,0,-1,0);
|
||||
normals[1] = new Vec4(0,1,0,0);
|
||||
normals[2] = new Vec4(1,0,0,0);
|
||||
@ -61,15 +60,25 @@ public class CubeComponent extends Component {
|
||||
|
||||
for (int i=0;i<6;i++)
|
||||
{
|
||||
//Rotates given side with the time one first, then ot get it on its off axis, then gets the image of each axis under the given rotation
|
||||
//The rotate functions do change the transforms, but the multiplication does not
|
||||
normals[i] = transforms[i].rotate((float) (time%(6000*6.28) )/ 6000, new Vec3(0,1,0)).rotate((float) 24, new Vec3(1,.5,0)).mul_(normals[i]);
|
||||
}
|
||||
double pi2 = Math.PI / 2;
|
||||
|
||||
//Move and rotate the sides from the middle of the cube to the appropriate edges
|
||||
transforms[0].translate(new Vec3(-size/2f,-size/2f,size/2f));
|
||||
transforms[1].translate(new Vec3(-size/2f,-size/2f,-size/2f)).rotate((float) pi2, new Vec3(1,0,0));
|
||||
transforms[2].translate(new Vec3(-size/2f,-size/2f,size/2f)).rotate((float) pi2, new Vec3(0,1,0));
|
||||
transforms[3].translate(new Vec3(-size/2f,-size/2f,-size/2f));
|
||||
transforms[4].translate(new Vec3(-size/2f,size/2f,-size/2f)).rotate((float) pi2, new Vec3(1,0,0));
|
||||
transforms[5].translate(new Vec3(size/2f,-size/2f,size/2f)).rotate((float) pi2, new Vec3(0,1,0));
|
||||
|
||||
for (int i=0;i<6;i++) // I have no clue why this is necessary, without it the sides of the cube mess up; may need to be changed if the title screen changes position.
|
||||
{
|
||||
transforms[i] = transforms[i].translate(new Vec3(0,0,17.5-3*(i<2 ? 1 : 0)));
|
||||
}
|
||||
|
||||
transforms[0].translate(new Vec3(-size/2,-size/2,size/2+11));
|
||||
transforms[1].translate(new Vec3(-size/2,-size/2-12,-size/2)).rotate((float) pi2, new Vec3(1,0,0));
|
||||
transforms[2].translate(new Vec3(-size/2+13,-size/2,size/2)).rotate((float) pi2, new Vec3(0,1,0));
|
||||
transforms[3].translate(new Vec3(-size/2,-size/2,-size/2+14));
|
||||
transforms[4].translate(new Vec3(-size/2,size/2-15.5,-size/2)).rotate((float) pi2, new Vec3(1,0,0));
|
||||
transforms[5].translate(new Vec3(size/2+15.5,-size/2,size/2)).rotate((float) pi2, new Vec3(0,1,0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,8 +94,9 @@ public class CubeComponent extends Component {
|
||||
{
|
||||
target.pushTransform(transforms[b]);
|
||||
|
||||
float dot = normals[b].dot(new Vec4(-1,0,0,0));
|
||||
Vec4 color = new Vec4(.4+.3*dot, .4+.3*dot, .6+.4*dot,1.0);
|
||||
float dot = normals[b].dot(new Vec4(-1,0,0,0)); //Gets the "amount" the given side is pointing in the -x direction
|
||||
|
||||
Vec4 color = new Vec4(.4+.3*dot, .4+.3*dot, .6+.4*dot,1.0); //More aligned means brighter color
|
||||
|
||||
target.fill(0,0, size, size, color);
|
||||
|
||||
|
Reference in New Issue
Block a user