本文整理匯總了Java中net.minecraft.util.math.Vec3d.dotProduct方法的典型用法代碼示例。如果您正苦於以下問題:Java Vec3d.dotProduct方法的具體用法?Java Vec3d.dotProduct怎麽用?Java Vec3d.dotProduct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.minecraft.util.math.Vec3d
的用法示例。
在下文中一共展示了Vec3d.dotProduct方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onClientUpdate
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private static void onClientUpdate(EntityPlayer player) {
checkDummy(player);
// if position was changed between two updates,
if (clientPosition != null
&& (getX(clientPosition) != getPrevX(player)
|| getY(clientPosition) != getPrevY(player)
|| getZ(clientPosition) != getPrevZ(player))) {
// then emulate the handling of S08PacketPlayerPosLook
serverMotion = clientMotion = getMotion(player);
serverPosition = getPosition(player);
emulateHandleMotion(player, getPosition(player), false);
}
clientPosition = getPosition(player);
// if motion was changed between two updates, use it
Vec3d gain = getMotion(player).subtract(clientMotion);
//serverMotion = serverMotion.add(gain);
if (gain.dotProduct(gain) > 0) serverMotion = getMotion(player);
// anticipated new position and motion
setPosition(serverDummy, serverPosition);
setMotion(serverDummy, serverMotion);
serverDummy.onUpdate();
serverNextPosition = getPosition(serverDummy);
serverNextMotion = getMotion(serverDummy);
anticipated = true;
}
示例2: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Checks to see if this enderman should be attacking this player
*/
private boolean shouldAttackPlayer(EntityPlayer player)
{
ItemStack itemstack = (ItemStack)player.inventory.armorInventory.get(3);
if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
{
return false;
}
else
{
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例3: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Checks to see if this enderman should be attacking this player
*/
private boolean shouldAttackPlayer(EntityPlayer player)
{
ItemStack itemstack = player.inventory.armorInventory[3];
if (itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
{
return false;
}
else
{
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(this.posX - player.posX, this.getEntityBoundingBox().minY + (double)this.getEyeHeight() - (player.posY + (double)player.getEyeHeight()), this.posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例4: isEntityWithinPlayerFOV
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isEntityWithinPlayerFOV(EntityPlayer player, Entity entity) {
// code used from the Enderman player looking code.
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(entity.posX - player.posX, entity.getEntityBoundingBox().minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 2.5D / d0;
// return d1 > 1.0D - 0.025D / d0;
}
示例5: isPlayerLookingAtTarget
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isPlayerLookingAtTarget() {
// code used from the Enderman player looking code.
EntityPlayer player = FMLClientHandler.instance().getClient().player;
World world = FMLClientHandler.instance().getClient().world;
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(entity.posX - player.posX, entity.getEntityBoundingBox().minY + entity.height / 2.0F - (player.posY + player.getEyeHeight()), entity.posZ - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 0.050D / d0;
}
示例6: isPlayerLookingAtTarget
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean isPlayerLookingAtTarget() {
Vec3d vec3 = player.getLook(1.0F).normalize();
Vec3d vec31 = new Vec3d(pos.getX() + 0.5D - player.posX, pos.getY() + 0.5D - player.posY - player.getEyeHeight(), pos.getZ() + 0.5D - player.posZ);
double d0 = vec31.lengthVector();
vec31 = vec31.normalize();
double d1 = vec3.dotProduct(vec31);
return d1 > 1.0D - 0.025D / d0;
}
示例7: 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;
}
示例8: getRayPlaneIntersection
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Calculate the point of intersection between a ray and a plane.
* @param ray - Ray to test.
* @param p - Point on plane.
* @param n - Normal to plane.
* @return - Point on plane where ray intersects, null if no intersection.
*/
public static Vec3d getRayPlaneIntersection(RayTrace ray, Vec3d p, Vec3d n)
{
//Vector in direction of line
Vec3d l = ray.p1.subtract(ray.p0);
double rd = n.dotProduct(l);
if(rd == 0)
return p;
double r = n.dotProduct(p.subtract(ray.p1))/rd;
return addVector(ray.p1, scale(l,r));
}
示例9: getAngleBetweenVectors
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
public static double getAngleBetweenVectors(Vec3d v, Vec3d w, Vec3d n)
{
double angleDot = Math.acos(v.dotProduct(w)/(v.lengthVector()*w.lengthVector()));
Vec3d crossProduct = v.crossProduct(w);
if(n.dotProduct(crossProduct) < 0)
angleDot *= -1;
return angleDot;
}
示例10: shouldAttackPlayer
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private boolean shouldAttackPlayer(EntityPlayer player) {
ItemStack itemstack = player.inventory.armorInventory.get(3);
if (itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN) || itemstack.getItem() instanceof ItemSkullBase) {
return false;
}
else {
Vec3d vec3d = player.getLook(1.0F).normalize();
Vec3d vec3d1 = new Vec3d(posX - player.posX, getEntityBoundingBox().minY + getEyeHeight() - (player.posY + player.getEyeHeight()), posZ - player.posZ);
double d0 = vec3d1.lengthVector();
vec3d1 = vec3d1.normalize();
double d1 = vec3d.dotProduct(vec3d1);
return d1 > 1.0D - 0.025D / d0 ? player.canEntityBeSeen(this) : false;
}
}
示例11: reflect
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
private static Vec3d reflect(Vec3d dir, Vec3d normal)
{
//dir - 2.0 * dot(normal, dir) * normal
double dot = dir.dotProduct(normal);
double x = dir.xCoord - 2.0 * dot * normal.xCoord;
double y = dir.yCoord - 2.0 * dot * normal.yCoord;
double z = dir.zCoord - 2.0 * dot * normal.zCoord;
return new Vec3d(x, y, z);
}
示例12: 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;*/
}
示例13: doLocalUpdate
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Gives the phase a chance to update its status.
* Called by dragon's onLivingUpdate. Only used when !worldObj.isRemote.
*/
public void doLocalUpdate()
{
++this.scanningTime;
EntityLivingBase entitylivingbase = this.dragon.world.getNearestAttackablePlayer(this.dragon, 20.0D, 10.0D);
if (entitylivingbase != null)
{
if (this.scanningTime > 25)
{
this.dragon.getPhaseManager().setPhase(PhaseList.SITTING_ATTACKING);
}
else
{
Vec3d vec3d = (new Vec3d(entitylivingbase.posX - this.dragon.posX, 0.0D, entitylivingbase.posZ - this.dragon.posZ)).normalize();
Vec3d vec3d1 = (new Vec3d((double)MathHelper.sin(this.dragon.rotationYaw * 0.017453292F), 0.0D, (double)(-MathHelper.cos(this.dragon.rotationYaw * 0.017453292F)))).normalize();
float f = (float)vec3d1.dotProduct(vec3d);
float f1 = (float)(Math.acos((double)f) * (180D / Math.PI)) + 0.5F;
if (f1 < 0.0F || f1 > 10.0F)
{
double d0 = entitylivingbase.posX - this.dragon.dragonPartHead.posX;
double d1 = entitylivingbase.posZ - this.dragon.dragonPartHead.posZ;
double d2 = MathHelper.clamp(MathHelper.wrapDegrees(180.0D - MathHelper.atan2(d0, d1) * (180D / Math.PI) - (double)this.dragon.rotationYaw), -100.0D, 100.0D);
this.dragon.randomYawVelocity *= 0.8F;
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1) + 1.0F;
float f3 = f2;
if (f2 > 40.0F)
{
f2 = 40.0F;
}
this.dragon.randomYawVelocity = (float)((double)this.dragon.randomYawVelocity + d2 * (double)(0.7F / f2 / f3));
this.dragon.rotationYaw += this.dragon.randomYawVelocity;
}
}
}
else if (this.scanningTime >= 100)
{
entitylivingbase = this.dragon.world.getNearestAttackablePlayer(this.dragon, 150.0D, 150.0D);
this.dragon.getPhaseManager().setPhase(PhaseList.TAKEOFF);
if (entitylivingbase != null)
{
this.dragon.getPhaseManager().setPhase(PhaseList.CHARGING_PLAYER);
((PhaseChargingPlayer)this.dragon.getPhaseManager().getPhase(PhaseList.CHARGING_PLAYER)).setTarget(new Vec3d(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ));
}
}
}
示例14: doLocalUpdate
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Gives the phase a chance to update its status.
* Called by dragon's onLivingUpdate. Only used when !worldObj.isRemote.
*/
public void doLocalUpdate()
{
++this.scanningTime;
EntityLivingBase entitylivingbase = this.dragon.worldObj.getNearestAttackablePlayer(this.dragon, 20.0D, 10.0D);
if (entitylivingbase != null)
{
if (this.scanningTime > 25)
{
this.dragon.getPhaseManager().setPhase(PhaseList.SITTING_ATTACKING);
}
else
{
Vec3d vec3d = (new Vec3d(entitylivingbase.posX - this.dragon.posX, 0.0D, entitylivingbase.posZ - this.dragon.posZ)).normalize();
Vec3d vec3d1 = (new Vec3d((double)MathHelper.sin(this.dragon.rotationYaw * 0.017453292F), 0.0D, (double)(-MathHelper.cos(this.dragon.rotationYaw * 0.017453292F)))).normalize();
float f = (float)vec3d1.dotProduct(vec3d);
float f1 = (float)(Math.acos((double)f) * (180D / Math.PI)) + 0.5F;
if (f1 < 0.0F || f1 > 10.0F)
{
double d0 = entitylivingbase.posX - this.dragon.dragonPartHead.posX;
double d1 = entitylivingbase.posZ - this.dragon.dragonPartHead.posZ;
double d2 = MathHelper.clamp_double(MathHelper.wrapDegrees(180.0D - MathHelper.atan2(d0, d1) * (180D / Math.PI) - (double)this.dragon.rotationYaw), -100.0D, 100.0D);
this.dragon.randomYawVelocity *= 0.8F;
float f2 = MathHelper.sqrt_double(d0 * d0 + d1 * d1) + 1.0F;
float f3 = f2;
if (f2 > 40.0F)
{
f2 = 40.0F;
}
this.dragon.randomYawVelocity = (float)((double)this.dragon.randomYawVelocity + d2 * (double)(0.7F / f2 / f3));
this.dragon.rotationYaw += this.dragon.randomYawVelocity;
}
}
}
else if (this.scanningTime >= 100)
{
entitylivingbase = this.dragon.worldObj.getNearestAttackablePlayer(this.dragon, 150.0D, 150.0D);
this.dragon.getPhaseManager().setPhase(PhaseList.TAKEOFF);
if (entitylivingbase != null)
{
this.dragon.getPhaseManager().setPhase(PhaseList.CHARGING_PLAYER);
((PhaseChargingPlayer)this.dragon.getPhaseManager().getPhase(PhaseList.CHARGING_PLAYER)).setTarget(new Vec3d(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ));
}
}
}
示例15: getLineScalarForClosestPoint
import net.minecraft.util.math.Vec3d; //導入方法依賴的package包/類
/**
* Line l = u + t*v. Return value of t that gives closest point to p.
* @param u - Point on line.
* @param v - Direction of line.
* @param p - Test point.
* @return t
*/
public static Double getLineScalarForClosestPoint(Vec3d u, Vec3d v, Vec3d p)
{
//System.out.println(v.dotProduct(v));
return v.dotProduct(p.subtract(u))/v.dotProduct(v);
}