当前位置: 首页>>代码示例>>Java>>正文


Java Vec3d.subtract方法代码示例

本文整理汇总了Java中net.minecraft.util.math.Vec3d.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java Vec3d.subtract方法的具体用法?Java Vec3d.subtract怎么用?Java Vec3d.subtract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.util.math.Vec3d的用法示例。


在下文中一共展示了Vec3d.subtract方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: pointWithinTriangle

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * Check if a point is within a triangle.
 * Point is assumed to on same plane as triangle.
 */
private static boolean pointWithinTriangle(Vec3d p, Vec3d v0, Vec3d v1, Vec3d v2)
{
	Vec3d u = v0.subtract(v1);
	Vec3d v = v0.subtract(v2);
	Vec3d w = v0.subtract(p);
	//System.out.println(u + " " + v + " " + w);
	double dn = u.dotProduct(v)*u.dotProduct(v)-u.dotProduct(u)*v.dotProduct(v);
	double s = (u.dotProduct(v)*w.dotProduct(v)-v.dotProduct(v)*w.dotProduct(u))/dn;
	double t = (u.dotProduct(v)*w.dotProduct(u)-u.dotProduct(u)*w.dotProduct(v))/dn;
	if(s>=0 && t>=0 && s+t<=1 && s != -0.0F && t != -0.0F)
		return true;
	return false;
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:18,代码来源:MathHelper.java

示例2: getDirectionVector

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * Get the direction vector from p to q.
 */
private Vec3d getDirectionVector(Vertex p, Vertex q)
{
    Vec3d pVec = new Vec3d(p.x, p.y, p.z);
    Vec3d qVec = new Vec3d(q.x, q.y, q.z);
    return pVec.subtract(qVec);
}
 
开发者ID:ObsidianSuite,项目名称:ObsidianSuite,代码行数:10,代码来源:BezierCurve.java

示例3: drawLine

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
public static void drawLine(Vec3d startPos, Vec3d endPos, int color, boolean smooth, float width) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder BufferBuilder = tessellator.getBuffer();

    Vec3d endVecPos = endPos.subtract(startPos);

    float r = (float)(color >> 16 & 255) / 255.0F;
    float g = (float)(color >> 8 & 255) / 255.0F;
    float b = (float)(color & 255) / 255.0F;
    float a = (float)(color >> 24 & 255) / 255.0F;

    if(smooth)
        GL11.glEnable(GL11.GL_LINE_SMOOTH);

    GL11.glLineWidth(width);

    GlStateManager.pushMatrix();
    GlStateManager.translate(startPos.x, startPos.y, startPos.z);
    GlStateManager.disableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
    GlStateManager.shadeModel(GL11.GL_SMOOTH);

    BufferBuilder.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
    BufferBuilder.pos(0, 0, 0).color(r, g, b, a).endVertex();
    BufferBuilder.pos(endVecPos.x, endVecPos.y, endVecPos.z).color(r, g, b, a).endVertex();
    tessellator.draw();

    if(smooth)
        GL11.glDisable(GL11.GL_LINE_SMOOTH);

    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.disableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.enableTexture2D();
    GlStateManager.enableDepth();
    GlStateManager.enableCull();
    GlStateManager.popMatrix();
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:41,代码来源:RenderUtils.java

示例4: rayTraceAABB

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
@Nullable
public static RayTraceResult rayTraceAABB(AxisAlignedBB box, BlockPos pos, Vec3d start, Vec3d end) {
	double x = pos.getX();
	double y = pos.getY();
	double z = pos.getZ();
	Vec3d a = start.subtract(x, y, z);
	Vec3d b = end.subtract(x, y, z);
	RayTraceResult result = box.calculateIntercept(a, b);
	if(result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
		return result;
	}
	return null;
}
 
开发者ID:ArekkuusuJerii,项目名称:Solar,代码行数:14,代码来源:RayTraceHelper.java

示例5: findRandomTargetBlockTowards

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
@Nullable

    /**
     * finds a random target within par1(x,z) and par2 (y) blocks in the direction of the point par3
     */
    public static Vec3d findRandomTargetBlockTowards(EntityCreature entitycreatureIn, int xz, int y, Vec3d targetVec3)
    {
        staticVector = targetVec3.subtract(entitycreatureIn.posX, entitycreatureIn.posY, entitycreatureIn.posZ);
        return findRandomTargetBlock(entitycreatureIn, xz, y, staticVector);
    }
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:11,代码来源:RandomPositionGenerator.java

示例6: rayTrace

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
@Nullable
protected RayTraceResult rayTrace(BlockPos pos, Vec3d start, Vec3d end, AxisAlignedBB boundingBox)
{
    Vec3d vec3d = start.subtract((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
    Vec3d vec3d1 = end.subtract((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
    RayTraceResult raytraceresult = boundingBox.calculateIntercept(vec3d, vec3d1);
    return raytraceresult == null ? null : new RayTraceResult(raytraceresult.hitVec.addVector((double)pos.getX(), (double)pos.getY(), (double)pos.getZ()), raytraceresult.sideHit, pos);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:9,代码来源:Block.java

示例7: onUpdateNavigation

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
public void onUpdateNavigation()
{
    ++this.totalTicks;

    if (this.tryUpdatePath)
    {
        this.updatePath();
    }

    if (!this.noPath())
    {
        if (this.canNavigate())
        {
            this.pathFollow();
        }
        else if (this.currentPath != null && this.currentPath.getCurrentPathIndex() < this.currentPath.getCurrentPathLength())
        {
            Vec3d vec3d = this.getEntityPosition();
            Vec3d vec3d1 = this.currentPath.getVectorFromIndex(this.theEntity, this.currentPath.getCurrentPathIndex());

            if (vec3d.yCoord > vec3d1.yCoord && !this.theEntity.onGround && MathHelper.floor(vec3d.xCoord) == MathHelper.floor(vec3d1.xCoord) && MathHelper.floor(vec3d.zCoord) == MathHelper.floor(vec3d1.zCoord))
            {
                this.currentPath.setCurrentPathIndex(this.currentPath.getCurrentPathIndex() + 1);
            }
        }

        if (!this.noPath())
        {
            Vec3d vec3d2 = this.currentPath.getPosition(this.theEntity);

            if (vec3d2 != null)
            {
                BlockPos blockpos = (new BlockPos(vec3d2)).down();
                AxisAlignedBB axisalignedbb = this.worldObj.getBlockState(blockpos).getBoundingBox(this.worldObj, blockpos);
                vec3d2 = vec3d2.subtract(0.0D, 1.0D - axisalignedbb.maxY, 0.0D);
                this.theEntity.getMoveHelper().setMoveTo(vec3d2.xCoord, vec3d2.yCoord, vec3d2.zCoord, this.speed);
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:41,代码来源:PathNavigate.java

示例8: isLyingInCone

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * @param x coordinates of point to be tested 
 * @param t coordinates of apex point of cone
 * @param b coordinates of center of basement circle
 * @param aperture in radians
 */
static public boolean isLyingInCone(Vec3d x, Vec3d start, Vec3d end, 
                                    float aperture){

    // This is for our convenience
    float halfAperture = aperture/2.f;

    // Vector pointing to X point from apex
    Vec3d apexToXVect = start.subtract(x);

    // Vector pointing from apex to circle-center point.
    Vec3d axisVect = start.subtract(end);

    // X is lying in cone only if it's lying in 
    // infinite version of its cone -- that is, 
    // not limited by "round basement".
    // We'll use dotProd() to 
    // determine angle between apexToXVect and axis.
    boolean isInInfiniteCone = apexToXVect.dotProduct(axisVect)
                               /apexToXVect.lengthVector()/axisVect.lengthVector()
                                 >
                               // We can safely compare cos() of angles 
                               // between vectors instead of bare angles.
                               MathHelper.cos(halfAperture);


    return isInInfiniteCone;

    // X is contained in cone only if projection of apexToXVect to axis
    // is shorter than axis. 
    // We'll use dotProd() to figure projection length.
   /* boolean isUnderRoundCap = dotProd(apexToXVect,axisVect)
                              /magn(axisVect)
                                <
                              magn(axisVect);
    return isUnderRoundCap;*/
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:43,代码来源:TF2Util.java

示例9: findRandomTargetBlockTowards

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * finds a random target within par1(x,z) and par2 (y) blocks in the direction of the point par3
 */
@Nullable
public static Vec3d findRandomTargetBlockTowards(EntityCreature entitycreatureIn, int xz, int y, Vec3d targetVec3)
{
    staticVector = targetVec3.subtract(entitycreatureIn.posX, entitycreatureIn.posY, entitycreatureIn.posZ);
    /**
     * searches 10 blocks at random in a within par1(x,z) and par2 (y) distance, ignores those not in the direction
     * of par3Vec3, then points to the tile for which creature.getBlockPathWeight returns the highest number
     */
    return findRandomTargetBlock(entitycreatureIn, xz, y, staticVector);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:14,代码来源:RandomPositionGenerator.java

示例10: onUpdateNavigation

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
public void onUpdateNavigation()
{
    ++this.totalTicks;

    if (this.tryUpdatePath)
    {
        this.updatePath();
    }

    if (!this.noPath())
    {
        if (this.canNavigate())
        {
            this.pathFollow();
        }
        else if (this.currentPath != null && this.currentPath.getCurrentPathIndex() < this.currentPath.getCurrentPathLength())
        {
            Vec3d vec3d = this.getEntityPosition();
            Vec3d vec3d1 = this.currentPath.getVectorFromIndex(this.theEntity, this.currentPath.getCurrentPathIndex());

            if (vec3d.yCoord > vec3d1.yCoord && !this.theEntity.onGround && MathHelper.floor_double(vec3d.xCoord) == MathHelper.floor_double(vec3d1.xCoord) && MathHelper.floor_double(vec3d.zCoord) == MathHelper.floor_double(vec3d1.zCoord))
            {
                this.currentPath.setCurrentPathIndex(this.currentPath.getCurrentPathIndex() + 1);
            }
        }

        if (!this.noPath())
        {
            Vec3d vec3d2 = this.currentPath.getPosition(this.theEntity);

            if (vec3d2 != null)
            {
                BlockPos blockpos = (new BlockPos(vec3d2)).down();
                AxisAlignedBB axisalignedbb = this.worldObj.getBlockState(blockpos).getBoundingBox(this.worldObj, blockpos);
                vec3d2 = vec3d2.subtract(0.0D, 1.0D - axisalignedbb.maxY, 0.0D);
                this.theEntity.getMoveHelper().setMoveTo(vec3d2.xCoord, vec3d2.yCoord, vec3d2.zCoord, this.speed);
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:41,代码来源:PathNavigate.java

示例11: getImpactPos

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * Find the position the arrows trajectory will hit
 */
public static Vec3d getImpactPos(ItemStack itemStack, Vec3d initPos, Vec3d hitPos, Angle angle) {
    double force = getForce(itemStack);

    Angle initAngle = new Angle(-angle.getPitch(), angle.getYaw() + 90.D, 0);

    double fixX = Math.cos(initAngle.getYaw(true) - Math.PI / 2.0) * 0.16;
    double fixY = PROJECTILE_SHOOTPOS_OFFSET;
    double fixZ = Math.sin(initAngle.getYaw(true) - Math.PI / 2.0) * 0.16;

    initPos = initPos.subtract(fixX, fixY, fixZ);

    Vec3d velocity = initAngle.getCartesianCoords().normalize().scale(force);

    Vec3d acceleration = getGravity(itemStack);
    Vec3d airResistance = getAirResistance(itemStack);

    double bestDistance = -1;
    Vec3d startPos = VectorUtils.copy(initPos);
    Vec3d endPos = VectorUtils.copy(startPos);
    for(int i = 1; i < SIMULATION_ITERATIONS; i++) {
        // add velocity
        startPos = startPos.add(velocity);
        // add air resistance
        velocity = VectorUtils.multiplyBy(velocity, airResistance);
        // add gravity (acceleration)
        velocity = velocity.add(acceleration);

        double x = startPos.x - hitPos.x;
        double z = startPos.z - hitPos.z;

        double distance = x*x + z*z;
        if(distance == -1 || distance < bestDistance)
            bestDistance = distance;
        else
            break;
        endPos = VectorUtils.copy(startPos);
    }

    RayTraceResult trace = MC.world.rayTraceBlocks(startPos, endPos);
    if(trace != null &&
            trace.typeOfHit.equals(RayTraceResult.Type.BLOCK))
        return trace.hitVec;
    else
        return initPos;
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:49,代码来源:ProjectileUtils.java

示例12: getShootAngle

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
/**
 * Find the angle required to hit the targets position
 */
public static Angle getShootAngle(ItemStack itemStack, Vec3d startPos, Vec3d targetPos, double force) {
    Angle angle = new Angle();

    // start at targets position
    Vec3d initPos = startPos.subtract(0, PROJECTILE_SHOOTPOS_OFFSET, 0);
    // subtract starting position and PROJECTILE_SHOOTPOS_OFFSET
    initPos = initPos.subtract(targetPos);

    // yaw is simply just aiming at the target position, so we can reuse
    // math from getLookAtAngles(targetPos)
    angle.setYaw(Utils.getLookAtAngles(targetPos).getYaw(false));

    Vec3d acceleration = getGravity(itemStack);
    Vec3d airResistance = getAirResistance(itemStack);

    // to find the pitch we use this equation
    //https://en.wikipedia.org/wiki/Trajectory_of_a_projectile#Angle_.7F.27.22.60UNIQ--postMath-00000010-QINU.60.22.27.7F_required_to_hit_coordinate_.28x.2Cy.29

    // calculate air resistance in the acceleration
    force *= airResistance.y;

    // magnitude of a 2d vector
    double x = Math.sqrt(initPos.x*initPos.x + initPos.z*initPos.z);
    double g = acceleration.y;

    double root = Math.pow(force, 4) - g * (g * Math.pow(x, 2) + 2 * initPos.y * Math.pow(force, 2));

    // if the root is negative then we will get a non-real result
    if(root < 0)
        return null;

    // there are two possible solutions
    // +root and -root
    double A = (Math.pow(force, 2) + Math.sqrt(root)) / (g * x);
    double B = (Math.pow(force, 2) - Math.sqrt(root)) / (g * x);

    // use the lowest pitch
    angle.setPitch(Math.toDegrees(Math.atan(Math.max(A, B))));

    return angle.normalize();
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:45,代码来源:ProjectileUtils.java

示例13: drawBox

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
public static void drawBox(Vec3d startPos, Vec3d endPos, int color, float width, boolean ignoreZ) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();

    Vec3d renderPos = EntityUtils.getInterpolatedPos(getLocalPlayer(), MC.getRenderPartialTicks());

    Vec3d min = startPos.subtract(renderPos);
    Vec3d max = endPos.subtract(renderPos);

    double minX = min.x, minY = min.y, minZ = min.z;
    double maxX = max.x, maxY = max.y, maxZ = max.z;

    float r = (float)(color >> 16 & 255) / 255.0F;
    float g = (float)(color >> 8 & 255) / 255.0F;
    float b = (float)(color & 255) / 255.0F;
    float a = (float)(color >> 24 & 255) / 255.0F;

    GlStateManager.pushMatrix();
    GlStateManager.disableTexture2D();
    GlStateManager.enableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
    GlStateManager.shadeModel(GL11.GL_SMOOTH);
    GlStateManager.glLineWidth(width);

    if(ignoreZ)
        GlStateManager.disableDepth();

    GlStateManager.color(r, g, b, a);

    //GlStateManager.translate(startPos.xCoord, startPos.yCoord, startPos.zCoord);

    buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION);
    buffer.pos(minX, minY, minZ).endVertex();
    buffer.pos(maxX, minY, minZ).endVertex();
    buffer.pos(maxX, minY, maxZ).endVertex();
    buffer.pos(minX, minY, maxZ).endVertex();
    buffer.pos(minX, minY, minZ).endVertex();
    tessellator.draw();
    buffer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION);
    buffer.pos(minX, maxY, minZ).endVertex();
    buffer.pos(maxX, maxY, minZ).endVertex();
    buffer.pos(maxX, maxY, maxZ).endVertex();
    buffer.pos(minX, maxY, maxZ).endVertex();
    buffer.pos(minX, maxY, minZ).endVertex();
    tessellator.draw();
    buffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
    buffer.pos(minX, minY, minZ).endVertex();
    buffer.pos(minX, maxY, minZ).endVertex();
    buffer.pos(maxX, minY, minZ).endVertex();
    buffer.pos(maxX, maxY, minZ).endVertex();
    buffer.pos(maxX, minY, maxZ).endVertex();
    buffer.pos(maxX, maxY, maxZ).endVertex();
    buffer.pos(minX, minY, maxZ).endVertex();
    buffer.pos(minX, maxY, maxZ).endVertex();
    tessellator.draw();

    GlStateManager.shadeModel(GL11.GL_FLAT);
    GlStateManager.disableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.enableTexture2D();
    GlStateManager.enableDepth();
    GlStateManager.enableCull();
    GlStateManager.popMatrix();
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:66,代码来源:RenderUtils.java

示例14: emulateHandleMotion

import net.minecraft.util.math.Vec3d; //导入方法依赖的package包/类
private static void emulateHandleMotion(EntityPlayer player, Vec3d newPosition, boolean packetOnGround) {
    // emulate server handling of C03PacketPlayer
    Vec3d oldPosition = serverPosition;
    if (newPosition == null) newPosition = oldPosition;
    if (player.isRiding()) {
        // needs improvement
        serverPosition = serverNextPosition = newPosition;
        serverMotion   = serverNextMotion;
        return;
    }
    if (isSleeping(player)) {
        // needs improvement
        serverPosition = serverNextPosition = oldPosition;
        serverMotion   = serverNextMotion;
        return;
    }
    // server update part
    if (!anticipated) {
        setPosition(serverDummy, serverPosition);
        setMotion(serverDummy,   serverMotion);
        serverDummy.onUpdate();
        serverNextPosition = getPosition(serverDummy);
        serverNextMotion   = getMotion(serverDummy);
    }
    serverPosition = serverNextPosition;
    serverMotion   = serverNextMotion;
    anticipated = false;
    // moved too quickly check
    if (isMultiplayer() && isMoveTooQuick(newPosition)) {
        serverNextPosition = serverPosition = oldPosition;
        // note: motion is kept as is and a position packet is sent
        return;
    }
    // server movement attempt
    setPosition(serverDummy, oldPosition);
    double spacing = 0.0625;
    boolean wasFree = getWorld(player).getCollisionBoxes(player, getAABB(serverDummy).contract(spacing)).isEmpty();
    if (getOnGround(serverDummy) && !packetOnGround
     && getX(player) > getX(oldPosition)) {
        serverDummy.jump();
    }
    Vec3d move = newPosition.subtract(oldPosition);
    serverDummy.moveEntity(MoverType.SELF, getX(move), getY(move), getZ(move));
    setOnGround(serverDummy, packetOnGround);
    // moved wrongly check
    boolean moveWrong = false;
    if (!isSleeping(player) && !isCreative(player)
     && wasMoveWrong(serverDummy, newPosition)) {
        moveWrong = true;
    }
    setPosition(serverDummy, newPosition);
    if (!getNoclip(player)) {
        boolean isFree = getWorld(player).getCollisionBoxes(player, getAABB(serverDummy).contract(spacing)).isEmpty();
        if (wasFree && (moveWrong || !isFree) && !isSleeping(player)) {
            serverNextPosition = serverPosition = oldPosition;
            // note: motion is kept as is and a position packet is sent
            return;
        }
    }
    setOnGround(serverDummy, packetOnGround);
    // serverUpdateMountedMovingPlayer(serverDummy)
    // serverDummy.handleFalling(getY(serverDummy) - getY(oldPosition), packetOnGround);
    serverNextPosition = serverPosition = getPosition(serverDummy);
    serverNextMotion   = serverMotion   = getMotion(serverDummy);
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:66,代码来源:Motion.java


注:本文中的net.minecraft.util.math.Vec3d.subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。