use of javax.vecmath.Vector3f in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method applyUVLock.
public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, EnumFacing originalSide, ITransformation rotation) {
TRSRTransformation global = new TRSRTransformation(rotation.getMatrix());
Matrix4f uv = global.getUVLockTransform(originalSide).getMatrix();
Vector4f vec = new Vector4f(0, 0, 0, 1);
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0)) / 16;
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0)) / 16;
uv.transform(vec);
// / vec.w;
float uMin = 16 * vec.x;
// / vec.w;
float vMin = 16 * vec.y;
vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2)) / 16;
vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2)) / 16;
vec.z = 0;
vec.w = 1;
uv.transform(vec);
// / vec.w;
float uMax = 16 * vec.x;
// / vec.w;
float vMax = 16 * vec.y;
if (uMin > uMax) {
float t = uMin;
uMin = uMax;
uMax = t;
}
if (vMin > vMax) {
float t = vMin;
vMin = vMax;
vMax = t;
}
float a = (float) Math.toRadians(blockFaceUV.rotation);
Vector3f rv = new Vector3f(MathHelper.cos(a), MathHelper.sin(a), 0);
Matrix3f rot = new Matrix3f();
uv.getRotationScale(rot);
rot.transform(rv);
int angle = MathHelper.normalizeAngle(-(int) Math.round(Math.toDegrees(Math.atan2(rv.y, rv.x)) / 90) * 90, 360);
return new BlockFaceUV(new float[] { uMin, vMin, uMax, vMax }, angle);
}
use of javax.vecmath.Vector3f in project MinecraftForge by MinecraftForge.
the class VertexLighterFlat method processQuad.
@Override
protected void processQuad() {
float[][] position = quadData[posIndex];
float[][] normal = null;
float[][] lightmap = quadData[lightmapIndex];
float[][] color = quadData[colorIndex];
if (normalIndex != -1 && (quadData[normalIndex][0][0] != -1 || quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][2] != -1)) {
normal = quadData[normalIndex];
} else {
normal = new float[4][4];
Vector3f v1 = new Vector3f(position[3]);
Vector3f t = new Vector3f(position[1]);
Vector3f v2 = new Vector3f(position[2]);
v1.sub(t);
t.set(position[0]);
v2.sub(t);
v1.cross(v2, v1);
v1.normalize();
for (int v = 0; v < 4; v++) {
normal[v][0] = v1.x;
normal[v][1] = v1.y;
normal[v][2] = v1.z;
normal[v][3] = 0;
}
}
int multiplier = -1;
if (tint != -1) {
multiplier = blockInfo.getColorMultiplier(tint);
}
VertexFormat format = parent.getVertexFormat();
int count = format.getElementCount();
for (int v = 0; v < 4; v++) {
position[v][0] += blockInfo.getShx();
position[v][1] += blockInfo.getShy();
position[v][2] += blockInfo.getShz();
float x = position[v][0] - .5f;
float y = position[v][1] - .5f;
float z = position[v][2] - .5f;
//if(blockInfo.getBlock().isFullCube())
{
x += normal[v][0] * .5f;
y += normal[v][1] * .5f;
z += normal[v][2] * .5f;
}
float blockLight = lightmap[v][0], skyLight = lightmap[v][1];
updateLightmap(normal[v], lightmap[v], x, y, z);
if (dataLength[lightmapIndex] > 1) {
if (blockLight > lightmap[v][0])
lightmap[v][0] = blockLight;
if (skyLight > lightmap[v][1])
lightmap[v][1] = skyLight;
}
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
if (diffuse) {
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
for (int i = 0; i < 3; i++) {
color[v][i] *= d;
}
}
if (EntityRenderer.anaglyphEnable) {
applyAnaglyph(color[v]);
}
// no need for remapping cause all we could've done is add 1 element to the end
for (int e = 0; e < count; e++) {
VertexFormatElement element = format.getElement(e);
switch(element.getUsage()) {
case POSITION:
// position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
/*float[] pos = new float[4];
System.arraycopy(position[v], 0, pos, 0, position[v].length);
pos[0] += blockInfo.getBlockPos().getX();
pos[1] += blockInfo.getBlockPos().getY();
pos[2] += blockInfo.getBlockPos().getZ();*/
parent.put(e, position[v]);
break;
case NORMAL:
if (normalIndex != -1) {
parent.put(e, normal[v]);
break;
}
case COLOR:
parent.put(e, color[v]);
break;
case UV:
if (element.getIndex() == 1) {
parent.put(e, lightmap[v]);
break;
}
default:
parent.put(e, quadData[e][v]);
}
}
}
tint = -1;
}
use of javax.vecmath.Vector3f in project jmonkeyengine by jMonkeyEngine.
the class BufferedTriangleCallback method processTriangle.
@Override
public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) {
// Three sets of individual lines
// The new Vector is needed as the given triangle reference is from a pool
vertices.add(new Vector3f(triangle[0]));
vertices.add(new Vector3f(triangle[1]));
vertices.add(new Vector3f(triangle[2]));
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class Dbvt method update.
public boolean update(Node leaf, DbvtAabbMm volume, float margin) {
if (leaf.volume.Contain(volume)) {
return false;
}
Stack stack = Stack.enter();
Vector3f tmp = stack.allocVector3f();
tmp.set(margin, margin, margin);
volume.Expand(tmp);
update(leaf, volume);
stack.leave();
return true;
}
use of javax.vecmath.Vector3f in project bdx by GoranM.
the class Dbvt method topdown.
private static Node topdown(Dbvt pdbvt, ObjectArrayList<Node> leaves, int bu_treshold) {
if (leaves.size() > 1) {
if (leaves.size() > bu_treshold) {
Stack stack = Stack.enter();
DbvtAabbMm vol = bounds(leaves);
Vector3f org = vol.Center(stack.allocVector3f());
ObjectArrayList[] sets = new ObjectArrayList[2];
for (int i = 0; i < sets.length; i++) {
sets[i] = new ObjectArrayList();
}
int bestaxis = -1;
int bestmidp = leaves.size();
int[][] splitcount = new int[][] { { 0, 0 }, { 0, 0 }, { 0, 0 } };
Vector3f x = stack.allocVector3f();
for (int i = 0; i < leaves.size(); i++) {
leaves.getQuick(i).volume.Center(x);
x.sub(org);
for (int j = 0; j < 3; j++) {
splitcount[j][x.dot(axis[j]) > 0f ? 1 : 0]++;
}
}
for (int i = 0; i < 3; i++) {
if ((splitcount[i][0] > 0) && (splitcount[i][1] > 0)) {
int midp = Math.abs(splitcount[i][0] - splitcount[i][1]);
if (midp < bestmidp) {
bestaxis = i;
bestmidp = midp;
}
}
}
if (bestaxis >= 0) {
//sets[0].reserve(splitcount[bestaxis][0]);
//sets[1].reserve(splitcount[bestaxis][1]);
split(leaves, sets[0], sets[1], org, axis[bestaxis]);
} else {
//sets[1].reserve(leaves.size()/2);
for (int i = 0, ni = leaves.size(); i < ni; i++) {
sets[i & 1].add(leaves.getQuick(i));
}
}
Node node = createnode(pdbvt, null, vol, null);
node.childs[0] = topdown(pdbvt, sets[0], bu_treshold);
node.childs[1] = topdown(pdbvt, sets[1], bu_treshold);
node.childs[0].parent = node;
node.childs[1].parent = node;
stack.leave();
return node;
} else {
bottomup(pdbvt, leaves);
return leaves.getQuick(0);
}
}
return leaves.getQuick(0);
}
Aggregations