Files
CodeChickenCore/codechicken/lib/lighting/LC.java
T

89 lines
2.1 KiB
Java
Raw Normal View History

2013-07-16 17:58:02 +10:00
package codechicken.lib.lighting;
import codechicken.lib.render.CCModel;
2014-04-07 14:02:47 +10:00
import codechicken.lib.util.Copyable;
2013-07-16 17:58:02 +10:00
import codechicken.lib.vec.Rotation;
import codechicken.lib.vec.Vector3;
2014-04-07 14:02:47 +10:00
public class LC implements Copyable<LC>
2013-07-16 17:58:02 +10:00
{
public int side;
public float fa;
public float fb;
public float fc;
public float fd;
2014-04-07 14:02:47 +10:00
public LC() {
this(0, 0, 0, 0, 0);
}
public LC(int s, float a, float b, float c, float d) {
side = s;
fa = a;
fb = b;
fc = c;
fd = d;
}
public LC set(int s, float a, float b, float c, float d) {
side = s;
fa = a;
fb = b;
fc = c;
fd = d;
return this;
}
public LC set(LC lc) {
return set(lc.side, lc.fa, lc.fb, lc.fc, lc.fd);
}
public LC compute(Vector3 vec, Vector3 normal) {
2013-07-16 17:58:02 +10:00
int side = CCModel.findSide(normal);
2014-04-07 14:02:47 +10:00
if (side < 0)
return set(12, 1, 0, 0, 0);
2013-07-16 17:58:02 +10:00
return compute(vec, side);
}
2014-04-07 14:02:47 +10:00
public LC compute(Vector3 vec, int side) {
2013-07-16 17:58:02 +10:00
boolean offset = false;
2014-04-07 14:02:47 +10:00
switch (side) {
case 0:
offset = vec.y <= 0;
break;
case 1:
offset = vec.y >= 1;
break;
case 2:
offset = vec.z <= 0;
break;
case 3:
offset = vec.z >= 1;
break;
case 4:
offset = vec.x <= 0;
break;
case 5:
offset = vec.x >= 1;
break;
2013-07-16 17:58:02 +10:00
}
2014-04-07 14:02:47 +10:00
if (!offset)
side += 6;
2013-07-16 17:58:02 +10:00
return computeO(vec, side);
}
2014-04-07 14:02:47 +10:00
public LC computeO(Vector3 vec, int side) {
Vector3 v1 = Rotation.axes[((side & 0xE) + 3) % 6];
Vector3 v2 = Rotation.axes[((side & 0xE) + 5) % 6];
2013-07-16 17:58:02 +10:00
float d1 = (float) vec.scalarProject(v1);
2014-04-07 14:02:47 +10:00
float d2 = 1 - d1;
2013-07-16 17:58:02 +10:00
float d3 = (float) vec.scalarProject(v2);
2014-04-07 14:02:47 +10:00
float d4 = 1 - d3;
return set(side, d2 * d4, d2 * d3, d1 * d4, d1 * d3);
}
@Override
public LC copy() {
return new LC(side, fa, fb, fc, fd);
2013-07-16 17:58:02 +10:00
}
}