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


Java Vector.normalize方法代码示例

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


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

示例1: applyImpulses

import org.bukkit.util.Vector; //导入方法依赖的package包/类
private void applyImpulses(LivingEntity attacker) {
    final KnockbackSettings knockback = this.knockback.get();

    final Vector normal = victim.getLocation().subtract(attacker.getLocation()).toVector();
    if(normal.isZero()) return;
    normal.normalize();

    final Vector victimNormal = knockback.pitchedNormal(normal);
    final Vector attackerNormal = normal.times(-1);

    if(victimNormal.isZero() || attackerNormal.isZero()) return;

    final boolean ground = attacker.isOnGround();
    final double attackSpeed = Math.max(0, attacker.getPredictedVelocity().dot(normal));
    final boolean sprint = ground && attackSpeed > knockback.sprintThreshold;

    victim.applyImpulse(victimNormal.multiply(knockback.power(sprint)), true);
    attacker.applyImpulse(attackerNormal.multiply(knockback.recoil(ground) * attackSpeed), true);

    final MatchPlayer matchAttacker = match.getPlayer(attacker);
    if(matchAttacker != null) {
        matchAttacker.facet(DamageDisplayPlayerFacet.class).showKnockback(victim, sprint);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:KnockbackPlayerFacet.java

示例2: repellExpOrb

import org.bukkit.util.Vector; //导入方法依赖的package包/类
final void repellExpOrb(final Player player, final ExperienceOrb orb) {
	final Location pLoc = player.getLocation();
	final Location oLoc = orb.getLocation();
	final Vector dir = oLoc.toVector().subtract(pLoc.toVector());
	final double dx = Math.abs(dir.getX());
	final double dz = Math.abs(dir.getZ());
	if ( (dx == 0.0) && (dz == 0.0)){
		// Special case probably never happens
		dir.setX(0.001);
	}
	if ((dx < 3.0) && (dz < 3.0)){
		final Vector nDir = dir.normalize();
		final Vector newV = nDir.clone().multiply(0.3);
		newV.setY(0);
		orb.setVelocity(newV);
		if ((dx < 1.0) && (dz < 1.0)){
			// maybe oLoc
			orb.teleport(oLoc.clone().add(nDir.multiply(1.0)), TeleportCause.PLUGIN);
		} 
		if ((dx < 0.5) && (dz < 0.5)){
			orb.remove();
		} 
	} 
}
 
开发者ID:smessie,项目名称:SkyWarsReloaded,代码行数:25,代码来源:SpectatorListener.java

示例3: pitchedNormal

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public Vector pitchedNormal(Vector delta) {
    delta = delta.clone();
    delta.setY(0);
    if(delta.isZero()) return Vectors.ZERO;
    delta.normalize();
    final double theta = Math.toRadians(pitch);
    final double cos = Math.cos(theta);
    delta.set(cos * delta.getX(),
               Math.sin(theta),
               cos * delta.getZ());
    return delta;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:KnockbackSettings.java

示例4: calculateVectorPath

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public static ArrayList<Location> calculateVectorPath(Location start, Vector direction, int length, int spacing, boolean ignoreBlock) {
    ArrayList<Location> locs = new ArrayList<Location>();
    Location loc = start;
    direction = direction.normalize();
    length *= spacing;
    direction = direction.multiply(1.0 / spacing);
    for (int k = 0; k < length; k++) {
        loc = loc.add(direction);
        if (!ignoreBlock && !RParticles.isAirlike(loc.getBlock()))
            break;
        locs.add(loc.clone());
    }
    return locs;
}
 
开发者ID:edasaki,项目名称:ZentrelaCore,代码行数:15,代码来源:RMath.java

示例5: getDirection

import org.bukkit.util.Vector; //导入方法依赖的package包/类
public static Vector getDirection(double x1, double y1, double x2, double y2) {
    Vector vec = new Vector(x2 - x1, 0, y2 - y1);
    if (vec.length() < 0.001)
        return vec;
    return vec.normalize();
}
 
开发者ID:SamaGames,项目名称:AgarMC,代码行数:7,代码来源:Utils.java


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