use of codechicken.lib.vec.Vector3 in project CodeChickenLib by Chicken-Bones.
the class LC method computeO.
public LC computeO(Vector3 vec, int side) {
Vector3 v1 = Rotation.axes[((side & 0xE) + 3) % 6];
Vector3 v2 = Rotation.axes[((side & 0xE) + 5) % 6];
float d1 = (float) vec.scalarProject(v1);
float d2 = 1 - d1;
float d3 = (float) vec.scalarProject(v2);
float d4 = 1 - d3;
return set(side, d2 * d4, d2 * d3, d1 * d4, d1 * d3);
}
use of codechicken.lib.vec.Vector3 in project CodeChickenLib by Chicken-Bones.
the class LightModel method apply.
/**
* @param colour The pre-lighting vertex colour. RGBA format
* @param normal The normal at the vertex
* @return The lighting applied colour
*/
public int apply(int colour, Vector3 normal) {
Vector3 n_colour = ambient.copy();
for (int l = 0; l < lightCount; l++) {
Light light = lights[l];
double n_l = light.position.dotProduct(normal);
double f = n_l > 0 ? 1 : 0;
n_colour.x += light.ambient.x + f * light.diffuse.x * n_l;
n_colour.y += light.ambient.y + f * light.diffuse.y * n_l;
n_colour.z += light.ambient.z + f * light.diffuse.z * n_l;
}
if (n_colour.x > 1)
n_colour.x = 1;
if (n_colour.y > 1)
n_colour.y = 1;
if (n_colour.z > 1)
n_colour.z = 1;
n_colour.multiply((colour >>> 24) / 255D, (colour >> 16 & 0xFF) / 255D, (colour >> 8 & 0xFF) / 255D);
return (int) (n_colour.x * 255) << 24 | (int) (n_colour.y * 255) << 16 | (int) (n_colour.z * 255) << 8 | colour & 0xFF;
}
use of codechicken.lib.vec.Vector3 in project CodeChickenLib by Chicken-Bones.
the class RenderUtils method renderFluidQuad.
/**
* Draws a tessellated quadrilateral bottom to top, left to right
*
* @param base The bottom left corner of the quad
* @param wide The bottom of the quad
* @param high The left side of the quad
* @param res Units per icon
*/
public static void renderFluidQuad(Vector3 base, Vector3 wide, Vector3 high, TextureAtlasSprite icon, double res) {
WorldRenderer r = Tessellator.getInstance().getWorldRenderer();
double u1 = icon.getMinU();
double du = icon.getMaxU() - icon.getMinU();
double v2 = icon.getMaxV();
double dv = icon.getMaxV() - icon.getMinV();
double wlen = wide.mag();
double hlen = high.mag();
double x = 0;
while (x < wlen) {
double rx = wlen - x;
if (rx > res)
rx = res;
double y = 0;
while (y < hlen) {
double ry = hlen - y;
if (ry > res)
ry = res;
Vector3 dx1 = vectors[2].set(wide).multiply(x / wlen);
Vector3 dx2 = vectors[3].set(wide).multiply((x + rx) / wlen);
Vector3 dy1 = vectors[4].set(high).multiply(y / hlen);
Vector3 dy2 = vectors[5].set(high).multiply((y + ry) / hlen);
r.pos(base.x + dx1.x + dy2.x, base.y + dx1.y + dy2.y, base.z + dx1.z + dy2.z).tex(u1, v2 - ry / res * dv).endVertex();
r.pos(base.x + dx1.x + dy1.x, base.y + dx1.y + dy1.y, base.z + dx1.z + dy1.z).tex(u1, v2).endVertex();
r.pos(base.x + dx2.x + dy1.x, base.y + dx2.y + dy1.y, base.z + dx2.z + dy1.z).tex(u1 + rx / res * du, v2).endVertex();
r.pos(base.x + dx2.x + dy2.x, base.y + dx2.y + dy2.y, base.z + dx2.z + dy2.z).tex(u1 + rx / res * du, v2 - ry / res * dv).endVertex();
y += ry;
}
x += rx;
}
}
use of codechicken.lib.vec.Vector3 in project PneumaticCraft by MineMaarten.
the class FMPPlacementListener method place.
public static boolean place(EntityPlayer player, World world) {
MovingObjectPosition hit = RayTracer.reTrace(world, player);
if (hit == null)
return false;
BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
ItemStack held = player.getHeldItem();
PartPressureTube part = null;
if (held == null)
return false;
Block heldBlock = Block.getBlockFromItem(held.getItem());
if (heldBlock == Blockss.pressureTube) {
part = new PartPressureTube();
} else if (heldBlock == Blockss.advancedPressureTube) {
part = new PartAdvancedPressureTube();
}
if (part == null)
return false;
if (//attempt to use block activated like normal and tell the server the right stuff
world.isRemote && !player.isSneaking()) {
Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
if (!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z)) {
player.swingItem();
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
return true;
}
}
TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part)) {
pos = pos.offset(hit.sideHit);
tile = TileMultipart.getOrConvertTile(world, pos);
if (tile == null || !tile.canAddPart(part))
return false;
}
if (!world.isRemote) {
TileMultipart.addPart(world, pos, part);
world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F);
if (!player.capabilities.isCreativeMode) {
held.stackSize--;
if (held.stackSize == 0) {
player.inventory.mainInventory[player.inventory.currentItem] = null;
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
}
}
} else {
player.swingItem();
NetworkHandler.sendToServer(new PacketFMPPlacePart());
}
return true;
}
use of codechicken.lib.vec.Vector3 in project CodeChickenLib by Chicken-Bones.
the class RayTracer method traceSide.
private void traceSide(int side, Vector3 start, Vector3 end, Cuboid6 cuboid) {
vec.set(start);
Vector3 hit = null;
switch(side) {
case 0:
hit = vec.XZintercept(end, cuboid.min.y);
break;
case 1:
hit = vec.XZintercept(end, cuboid.max.y);
break;
case 2:
hit = vec.XYintercept(end, cuboid.min.z);
break;
case 3:
hit = vec.XYintercept(end, cuboid.max.z);
break;
case 4:
hit = vec.YZintercept(end, cuboid.min.x);
break;
case 5:
hit = vec.YZintercept(end, cuboid.max.x);
break;
}
if (hit == null)
return;
switch(side) {
case 0:
case 1:
if (!MathHelper.between(cuboid.min.x, hit.x, cuboid.max.x) || !MathHelper.between(cuboid.min.z, hit.z, cuboid.max.z))
return;
break;
case 2:
case 3:
if (!MathHelper.between(cuboid.min.x, hit.x, cuboid.max.x) || !MathHelper.between(cuboid.min.y, hit.y, cuboid.max.y))
return;
break;
case 4:
case 5:
if (!MathHelper.between(cuboid.min.y, hit.y, cuboid.max.y) || !MathHelper.between(cuboid.min.z, hit.z, cuboid.max.z))
return;
break;
}
double dist = vec2.set(hit).subtract(start).magSquared();
if (dist < s_dist) {
s_side = side;
s_dist = dist;
s_vec.set(vec);
}
}
Aggregations