本文整理了Java中net.minecraft.util.math.MathHelper.atan2()
方法的一些代码示例,展示了MathHelper.atan2()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MathHelper.atan2()
方法的具体详情如下:
包路径:net.minecraft.util.math.MathHelper
类名称:MathHelper
方法名:atan2
暂无
代码示例来源:origin: Vazkii/Botania
/**
* Updates the entity motion clientside, called by packets from the server
*/
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z)
{
this.motionX = x;
this.motionY = y;
this.motionZ = z;
if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
{
float f = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
}
}
代码示例来源:origin: Vazkii/Botania
/**
* Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
*/
public void shoot(double x, double y, double z, float velocity, float inaccuracy)
{
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double)f;
y = y / (double)f;
z = z / (double)f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
x = x * (double)velocity;
y = y * (double)velocity;
z = z * (double)velocity;
this.motionX = x;
this.motionY = y;
this.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
this.prevRotationYaw = this.rotationYaw;
this.prevRotationPitch = this.rotationPitch;
this.ticksInGround = 0;
}
代码示例来源:origin: vadis365/TheErebus
private void calculateRotationYaw(double x, double z) {
rotationYaw = (float) (MathHelper.atan2(z - posZ, x - posX) * (180D / Math.PI)) - 90.0F;
}
代码示例来源:origin: Vazkii/Botania
this.posZ += this.motionZ;
float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
代码示例来源:origin: Alex-the-666/Ice_and_Fire
public void setThrowableHeading(Entity fireball, double x, double y, double z, float velocity, float inaccuracy) {
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
x = x * (double) velocity;
y = y * (double) velocity;
z = z * (double) velocity;
fireball.motionX = x;
fireball.motionY = y;
fireball.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
fireball.rotationYaw = (float) (MathHelper.atan2(x, z) * (180D / Math.PI));
fireball.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * (180D / Math.PI));
fireball.prevRotationYaw = fireball.rotationYaw;
fireball.prevRotationPitch = fireball.rotationPitch;
}
代码示例来源:origin: Alex-the-666/Ice_and_Fire
public void setThrowableHeading(Entity fireball, double x, double y, double z, float velocity, float inaccuracy) {
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
x = x * (double) velocity;
y = y * (double) velocity;
z = z * (double) velocity;
fireball.motionX = x;
fireball.motionY = y;
fireball.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
fireball.rotationYaw = (float) (MathHelper.atan2(x, z) * (180D / Math.PI));
fireball.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * (180D / Math.PI));
fireball.prevRotationYaw = fireball.rotationYaw;
fireball.prevRotationPitch = fireball.rotationPitch;
}
代码示例来源:origin: SquidDev-CC/plethora
@Override
@SideOnly(Side.CLIENT)
public void setVelocity(double x, double y, double z) {
motionX = x;
motionY = y;
motionZ = z;
if (prevRotationPitch == 0.0f && prevRotationYaw == 0.0f) {
float magnitude = MathHelper.sqrt(x * x + z * z);
prevRotationYaw = rotationYaw = (float) (MathHelper.atan2(x, z) * 180 / Math.PI);
prevRotationPitch = rotationPitch = (float) (MathHelper.atan2(y, magnitude) * 180 / Math.PI);
}
}
代码示例来源:origin: TeamWizardry/Wizardry
public static float[] vecToRotations(Vec3d vec) {
float yaw = (float) MathHelper.atan2(vec.z, vec.x);
float pitch = (float) Math.asin(vec.y / vec.length());
return new float[]{(float) Math.toDegrees(pitch), (float) Math.toDegrees(yaw) + 90};
}
代码示例来源:origin: Vazkii/Botania
posZ += motionZ;
float f = MathHelper.sqrt(motionX * motionX + motionZ * motionZ);
rotationYaw = (float)(MathHelper.atan2(motionX, motionZ) * (180D / Math.PI));
for (rotationPitch = (float)(MathHelper.atan2(motionY, f) * (180D / Math.PI)); rotationPitch - prevRotationPitch < -180.0F; prevRotationPitch -= 360.0F)
代码示例来源:origin: Alex-the-666/Ice_and_Fire
public void setThrowableHeading(Entity fireball, double x, double y, double z, float velocity, float inaccuracy) {
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double) f;
y = y / (double) f;
z = z / (double) f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
x = x * (double) velocity;
y = y * (double) velocity;
z = z * (double) velocity;
fireball.motionX = x;
fireball.motionY = y;
fireball.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
fireball.rotationYaw = (float) (MathHelper.atan2(x, z) * (180D / Math.PI));
fireball.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * (180D / Math.PI));
fireball.prevRotationYaw = fireball.rotationYaw;
fireball.prevRotationPitch = fireball.rotationPitch;
}
代码示例来源:origin: Alex-the-666/Ice_and_Fire
public void setThrowableHeading(Entity fireball, double x, double y, double z, float velocity, float inaccuracy) {
float f = MathHelper.sqrt(x * x + y * y + z * z);
x = x / (double) f;
y = y / (double) f;
z = z / (double) f;
x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
x = x * (double) velocity;
y = y * (double) velocity;
z = z * (double) velocity;
fireball.motionX = x;
fireball.motionY = y;
fireball.motionZ = z;
float f1 = MathHelper.sqrt(x * x + z * z);
fireball.rotationYaw = (float) (MathHelper.atan2(x, z) * (180D / Math.PI));
fireball.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * (180D / Math.PI));
fireball.prevRotationYaw = fireball.rotationYaw;
fireball.prevRotationPitch = fireball.rotationPitch;
}
代码示例来源:origin: SquidDev-CC/plethora
@Override
public void shoot(double vx, double vy, double vz, float velocity, float inaccuracy) {
// Normalise magnitude
float magnitude = MathHelper.sqrt(vx * vx + vy * vy + vz * vz);
vx /= magnitude;
vy /= magnitude;
vz /= magnitude;
// Tiny offset
vx += rand.nextGaussian() * 0.007499999832361937D * inaccuracy;
vy += rand.nextGaussian() * 0.007499999832361937D * inaccuracy;
vz += rand.nextGaussian() * 0.007499999832361937D * inaccuracy;
// Reset velocity
vx *= velocity;
vy *= velocity;
vz *= velocity;
motionX = vx;
motionY = vy;
motionZ = vz;
float newMagnitude = MathHelper.sqrt(vx * vx + vz * vz);
prevRotationYaw = rotationYaw = (float) (MathHelper.atan2(vx, vz) * 180 / Math.PI);
prevRotationPitch = rotationPitch = (float) (MathHelper.atan2(vy, newMagnitude) * 180 / Math.PI);
}
代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition
public void onUpdateMoveHelper() {
if (this.action == Action.MOVE_TO) {
int i = MathHelper.floor(this.entity.getEntityBoundingBox().minY + 0.5D);
double d0 = this.posX - this.parentEntity.posX;
double d1 = this.posY - (double) i;
double d2 = this.posZ - this.parentEntity.posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
float f = MathHelper.sqrt(posX * posX + posY * posY);
this.parentEntity.prevRotationYaw = this.parentEntity.rotationYaw = (float) (MathHelper.atan2(posX, posZ) * 180.0D / Math.PI);
this.parentEntity.prevRotationPitch = this.parentEntity.rotationPitch = (float) (MathHelper.atan2(posY, (double) f) * 180.0D / Math.PI);
d3 = (double) MathHelper.sqrt(d3);
this.parentEntity.motionX = d0 / d3 * this.speed;
this.parentEntity.motionY = d1 / d3 * this.speed;
this.parentEntity.motionZ = d2 / d3 * this.speed;
this.action = Action.WAIT;
}
}
}
代码示例来源:origin: TeamWizardry/Wizardry
public static float signAngle(Vec3d a, Vec3d b, Vec3d n) {
Vec3d cross = a.crossProduct(b);
double s = cross.length();
double c = a.dotProduct(b);
double angle = MathHelper.atan2(s, c);
if (n != null) {
if (n.dotProduct(cross) < 0) {
angle = -angle;
}
}
return (float) Math.toDegrees(angle);
}
代码示例来源:origin: JurassiCraftTeam/JurassiCraft2
@Override
public void onUpdateLook() {
this.dinosaur.rotationPitch = 0.0F;
if (this.isLooking) {
this.isLooking = false;
double deltaX = this.posX - this.dinosaur.posX;
double deltaY = this.posY - (this.dinosaur.posY + (double) this.dinosaur.getEyeHeight());
double deltaZ = this.posZ - this.dinosaur.posZ;
double delta = (double) MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ);
float desiredYaw = (float) (MathHelper.atan2(deltaZ, deltaX) * (10D / Math.PI)) - 90.0F;
float desiredPitch = (float) (-(MathHelper.atan2(deltaY, delta) * (180.0D / Math.PI)));
this.dinosaur.rotationPitch = this.updateRotation(this.dinosaur.rotationPitch, desiredPitch, this.deltaLookPitch);
this.dinosaur.rotationYawHead = this.updateRotation(this.dinosaur.rotationYawHead, desiredYaw, this.deltaLookYaw);
} else {
this.dinosaur.rotationYawHead = this.updateRotation(this.dinosaur.rotationYawHead, this.dinosaur.renderYawOffset, 10.0F);
}
}
代码示例来源:origin: vadis365/TheErebus
@Override
protected void updateAITasks() {
super.updateAITasks();
BlockPos blockpos = new BlockPos(this);
if (spawnPosition != null && (!world.isAirBlock(spawnPosition) || spawnPosition.getY() < 1))
spawnPosition = null;
if (spawnPosition == null || rand.nextInt(30) == 0 || spawnPosition.distanceSq((double) ((int) posX), (double) ((int) posY), (double) ((int) posZ)) < 4.0D)
spawnPosition = new BlockPos((int) posX + rand.nextInt(7) - rand.nextInt(7), (int) posY + rand.nextInt(6) - 2, (int) posZ + rand.nextInt(7) - rand.nextInt(7));
double d0 = (double) spawnPosition.getX() + 0.5D - posX;
double d1 = (double) spawnPosition.getY() + 0.1D - posY;
double d2 = (double) spawnPosition.getZ() + 0.5D - posZ;
motionX += (Math.signum(d0) * 0.5D - motionX) * 0.10000000149011612D;
motionY += (Math.signum(d1) * 0.699999988079071D - motionY) * 0.10000000149011612D;
motionZ += (Math.signum(d2) * 0.5D - motionZ) * 0.10000000149011612D;
float f = (float) (MathHelper.atan2(motionZ, motionX) * (180D / Math.PI)) - 90.0F;
float f1 = MathHelper.wrapDegrees(f - rotationYaw);
moveForward = 0.5F;
rotationYaw += f1;
}
代码示例来源:origin: SleepyTrousers/EnderIO
public void faceEntity(Entity entityIn) {
double d0 = entityIn.posX - this.posX;
double d2 = entityIn.posZ - this.posZ;
double d1;
if (entityIn instanceof EntityLivingBase) {
EntityLivingBase entitylivingbase = (EntityLivingBase) entityIn;
d1 = entitylivingbase.posY + entitylivingbase.getEyeHeight() - (this.posY + this.getEyeHeight());
} else {
d1 = (entityIn.getEntityBoundingBox().minY + entityIn.getEntityBoundingBox().maxY) / 2.0D - (this.posY + this.getEyeHeight());
}
double d3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
rotationPitch = MathHelper.wrapDegrees((float) (-(MathHelper.atan2(d1, d3) * (180D / Math.PI))));
rotationYaw = MathHelper.wrapDegrees((float) (MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F);
}
代码示例来源:origin: PrinceOfAmber/Cyclic
/**
* Summon a ray of fangs in the direction of these coordinates away from the caster
*
* @param caster
* @param posX
* @param posY
* @param posZ
*/
private void summonFangRay(EntityPlayer caster, double posX, double posY, double posZ) {
double minY = Math.min(posY, caster.posY);
//double d1 = Math.max(posY,caster.posY) ;
float arctan = (float) MathHelper.atan2(posZ - caster.posZ, posX - caster.posX);
for (int i = 0; i < MAX_RANGE; ++i) {
double fract = 1.25D * (i + 1);
this.summonFangSingle(caster,
caster.posX + MathHelper.cos(arctan) * fract,
minY,
caster.posZ + MathHelper.sin(arctan) * fract,
arctan, i);
}
onCastSuccess(caster);
}
代码示例来源:origin: Alex-the-666/Ice_and_Fire
public void onUpdateMoveHelper() {
if (this.action == EntityMoveHelper.Action.MOVE_TO) {
double d0 = this.posX - EntityMyrmexRoyal.this.posX;
double d1 = this.posY - EntityMyrmexRoyal.this.posY;
double d2 = this.posZ - EntityMyrmexRoyal.this.posZ;
double d3 = d0 * d0 + d1 * d1 + d2 * d2;
d3 = (double) MathHelper.sqrt(d3);
if (d3 < EntityMyrmexRoyal.this.getEntityBoundingBox().getAverageEdgeLength()) {
this.action = EntityMoveHelper.Action.WAIT;
EntityMyrmexRoyal.this.motionX *= 0.5D;
EntityMyrmexRoyal.this.motionY *= 0.5D;
EntityMyrmexRoyal.this.motionZ *= 0.5D;
} else {
EntityMyrmexRoyal.this.motionX += d0 / d3 * 0.15D * this.speed;
EntityMyrmexRoyal.this.motionY += d1 / d3 * 0.15D * this.speed;
EntityMyrmexRoyal.this.motionZ += d2 / d3 * 0.15D * this.speed;
if (EntityMyrmexRoyal.this.getAttackTarget() == null) {
EntityMyrmexRoyal.this.rotationYaw = -((float) MathHelper.atan2(EntityMyrmexRoyal.this.motionX, EntityMyrmexRoyal.this.motionZ)) * (180F / (float) Math.PI);
EntityMyrmexRoyal.this.renderYawOffset = EntityMyrmexRoyal.this.rotationYaw;
} else {
double d4 = EntityMyrmexRoyal.this.getAttackTarget().posX - EntityMyrmexRoyal.this.posX;
double d5 = EntityMyrmexRoyal.this.getAttackTarget().posZ - EntityMyrmexRoyal.this.posZ;
EntityMyrmexRoyal.this.rotationYaw = -((float) MathHelper.atan2(d4, d5)) * (180F / (float) Math.PI);
EntityMyrmexRoyal.this.renderYawOffset = EntityMyrmexRoyal.this.rotationYaw;
}
}
}
}
}
代码示例来源:origin: Alex-the-666/Ice_and_Fire
private static float getStymphalianFlockDirection(EntityStymphalianBird bird){
EntityStymphalianBird leader = bird.flock.getLeader();
if(bird.getDistanceSq(leader) > 2){
double d0 = leader.posX - bird.posX;
double d2 = leader.posZ - bird.posZ;
double d1 = leader.posY + (double)leader.getEyeHeight() - (bird.posY + (double)bird.getEyeHeight());
double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
float degrees = MathHelper.wrapDegrees(f - bird.rotationYaw);
return bird.rotationYaw + degrees;
}else{
return leader.renderYawOffset;
}
}
内容来源于网络,如有侵权,请联系作者删除!