protected static Transform toBulletTransform(org.terasology.math.Transform transform) { return new Transform( new javax.vecmath.Matrix4f(VecMath.to(transform.rotation), VecMath.to(transform.origin), transform.scale) ); } }
@Nonnull @Override @SideOnly(Side.CLIENT) public Pair<IBakedModel, Matrix4f> getModel(@Nonnull IVehicleAccess access) { Pair<IBakedModel, Matrix4f> model = handler.getModel(0); Matrix4f transform = new Matrix4f(); transform.setIdentity(); // Center the view (-0.5) and then move half a pixel back out. transform.setTranslation(new Vector3f(0, 0, -0.5f + (1 / 32.0f))); transform.mul(transform, model.getRight()); return Pair.of(model.getLeft(), transform); }
Matrix4f temp = new Matrix4f(); Matrix4f trans = new Matrix4f(); trans.setIdentity(); temp.setIdentity(); temp.setTranslation(new Vector3f((float) x + ox, (float) y + 0.375f + oy, (float) z + oz)); trans.mul(temp); temp.setIdentity(); temp.rotY((float) Math.toRadians(180 - yaw)); trans.mul(temp); temp.setIdentity(); temp.rotZ((float) Math.toRadians(-pitch)); trans.mul(temp); temp.setIdentity(); temp.rotX((float) Math.toRadians(MathHelper.sin(amplitude) * amplitude * roll / 10.0F * (float) getRollingDirection())); trans.mul(temp); trans.setScale(0.75F); temp.setIdentity(); temp.setTranslation(new Vector3f(-0.5F, (float) (offset - 8) / 16.0F, 0.5F)); trans.mul(temp);
Matrix4f rotMat = new Matrix4f(); rotMat.setIdentity(); rotMat.rotX((float) Math.toRadians(30F)); GlStateManager.translate(-offX, 0, -offZ); GlStateManager.rotate(time, 0F, 1F, 0F); rotMat.rotY((float) Math.toRadians(-time)); GlStateManager.rotate(45F, 0F, 1F, 0F); rotMat.rotY((float) Math.toRadians(-45F)); GlStateManager.translate(offX, 0, offZ); rotMat.transform(eye); renderElements(multiblockObj, BlockPos.getAllInBoxMutable(BlockPos.ORIGIN, new BlockPos(multiblockObj.sizeX - 1, multiblockObj.sizeY - 1, multiblockObj.sizeZ - 1)), eye);
Matrix4f transform = new Matrix4f(); transform.setIdentity(); float yOffset = -row * 3 / 16.0f; transform.setTranslation( new Vector3f( xOffset, yOffset, 0 ) );
protected static Matrix4f getCombinedRotation(float x, float y, float z) { Matrix4f xMat = new Matrix4f(); xMat.rotX((float) Math.toRadians(x)); Matrix4f yMat = new Matrix4f(); yMat.rotY((float) Math.toRadians(y)); Matrix4f zMat = new Matrix4f(); zMat.rotZ((float) Math.toRadians(z)); xMat.mul(yMat); xMat.mul(zMat); return xMat; }
Matrix4f matrix = new Matrix4f(); matrix.setIdentity(); matrix.setRotation( new AxisAngle4f( 0, 1, 0, rotation ) );
private static Matrix4f blockCenterToCorner(Matrix4f transform) { Matrix4f ret = new Matrix4f(transform); Matrix4f tmp = new Matrix4f(); tmp.setIdentity(); tmp.m03 = tmp.m13 = tmp.m23 = +0.5f; ret.mul(tmp, ret); tmp.m03 = tmp.m13 = tmp.m23 = -0.5f; ret.mul(tmp); return ret; }
private static int getIntersectSlot(Vec3d fromVec, Vec3d toVec, Matrix4f transform) { Matrix4f inv = new Matrix4f(); inv.invert(transform); // Convert the vectors into "minecart" space Vector4f to = new Vector4f((float) toVec.x, (float) toVec.y, (float) toVec.z, 1); inv.transform(to); Vector4f from = new Vector4f((float) fromVec.x, (float) fromVec.y, (float) fromVec.z, 1); inv.transform(from); Vector4f step = new Vector4f(); step.sub(to, from); step.scale(1 / 100.0f); // Now ray-trace to find where they intersect with the bounding box. for (int offset = 0; offset <= 100; offset++) { for (int i = 0; i < BOUNDS.length; i++) { AxisAlignedBB bb = BOUNDS[i]; if (bb.contains(new Vec3d(from.getX(), from.getY(), from.getZ()))) { // If we got the actual block itself then pretend nothing happened. return i - 1; } } from.add(step); } return -1; }
effectStack.clear(); currMat.set(projMat); currEffectMat = new javax.vecmath.Matrix4f(); currEffectMat.setIdentity(); effectStack.push(new EffectStackItem(currEffectMat, projMat, 1.0f, null)); for (int r = 0; r < 4; r++) for (int c = 0; c < 4; c++) currCoords[r + c*4] = currMat.getElement(r, c); // TRANSPOSED renderStartTime = Sage.eventTime(); effectAnimationsWereActive = effectAnimationsActive;
protected javax.vecmath.Matrix4f generateProjectionMatrix(float cameraOffsetX, float cameraOffsetY) { int viewportWidth = master.getWidth(); int viewportHeight = master.getHeight(); int cameraX = Math.round(cameraOffsetX);//viewportWidth/2; int cameraY = Math.round(cameraOffsetY);//viewportHeight/2; javax.vecmath.Matrix4f viewMat = MathUtils.createScaleMatrix(1.0f, -1.0f); viewMat.m03 = -(viewportWidth*0.5f + cameraX); viewMat.m13 = viewportHeight*0.5f + cameraY; viewMat.m23 = viewportWidth; float xmin = (viewportWidth*0.5f + cameraX)/-2; float xmax = (viewportWidth*0.5f - cameraX)/2; float ymin = (viewportHeight*0.5f - cameraY)/-2; float ymax = (viewportHeight*0.5f + cameraY)/2; float zmin = viewportWidth*0.5f; float zmax = viewportWidth*50; javax.vecmath.Matrix4f projMat =new javax.vecmath.Matrix4f( 2*zmin/(xmax - xmin), 0, 0, 0, 0, 2*zmin/(ymax-ymin), 0, 0, (xmin+xmax)/(xmin-xmax), (ymin+ymax)/(ymin-ymax), zmax/(zmax-zmin), 1, 0, 0, zmax*zmin/(zmin-zmax), 0); projMat.transpose(); // This is the view-projection matrix currently projMat.mul(projMat, viewMat); return projMat; }
stackItem.xform = currEffectMat; projMat = generateProjectionMatrix(op.effectTracker.getCameraOffsetX(), op.effectTracker.getCameraOffsetY()); currEffectMat = new javax.vecmath.Matrix4f(tempMat); currEffectMat.mul(stackItem.xform, tempMat); currMat.mul(projMat, currEffectMat); currEffectMat = new javax.vecmath.Matrix4f(tempMat); currEffectMat.mul(stackItem.xform, tempMat); tempMat.mul(currMat, tempMat); currMat = new javax.vecmath.Matrix4f(tempMat); currCoords[r + c*4] = currMat.getElement(r, c); // TRANSPOSED if (stackItem.projxform != null) projMat = stackItem.projxform; currMat.mul(projMat, currEffectMat); for (int r = 0; r < 4; r++) for (int c = 0; c < 4; c++) currCoords[r + c*4] = currMat.getElement(r, c); // TRANSPOSED
private Orientation(HalfAxis x, HalfAxis y) { this.x = x; this.y = y; this.z = x.cross(y); addDirectionMappings(EnumFacing.EAST, x.dir); addDirectionMappings(EnumFacing.UP, y.dir); addDirectionMappings(EnumFacing.SOUTH, z.dir); this.name = x.shortName + "_" + y.shortName + "_" + z.shortName; this.lowercaseName = name().toLowerCase(Locale.ROOT); this.blockCenterToWorld = new Matrix3f( x.x, y.x, z.x, x.y, y.y, z.y, x.z, y.z, z.z); final Matrix4f tmp = new Matrix4f(); tmp.set(this.blockCenterToWorld); this.blockCornerToWorld = blockCenterToCorner(tmp); }
public Transformer(TRSRTransformation transformation, VertexFormat format) { super(new UnpackedBakedQuad.Builder(format)); // position transform this.transformation = transformation.getMatrix(); // normal transform this.normalTransformation = new Matrix3f(); this.transformation.getRotationScale(this.normalTransformation); this.normalTransformation.invert(); this.normalTransformation.transpose(); }