Package com.flansmod.common.vector

Examples of com.flansmod.common.vector.Vector3f


    float speed = 0.5F * type.throwSpeed;
    motionX = axes.getXAxis().x * speed;
    motionY = axes.getXAxis().y * speed;
    motionZ = axes.getXAxis().z * speed;
    if(type.spinWhenThrown)
      angularVelocity = new Vector3f(0F, 0F, 10F);
    if(type.throwSound != null)
      PacketPlaySound.sendSoundPacket(posX, posY, posZ, FlansMod.soundRange, dimension, type.throwSound, true);
  }
View Full Code Here


      prevRotationPitch = axes.getPitch();
      prevRotationRoll = axes.getRoll();
      if(angularVelocity.lengthSquared() > 0.00000001F)
        axes.rotateLocal(angularVelocity.length(), angularVelocity.normalise(null));

      Vector3f posVec = new Vector3f(posX, posY, posZ);
      Vector3f motVec = new Vector3f(motionX, motionY, motionZ);
      Vector3f nextPosVec = Vector3f.add(posVec, motVec, null);
     
      //Raytrace the motion of this grenade
      MovingObjectPosition hit = worldObj.rayTraceBlocks(posVec.toVec3(), nextPosVec.toVec3());
      //If we hit block
      if(hit != null && hit.typeOfHit == MovingObjectType.BLOCK)
      {
        //Get the blockID and block material
        Block block = worldObj.getBlock(hit.blockX, hit.blockY, hit.blockZ);
        Material mat = block.getMaterial();
       
        //If this grenade detonates on impact, do so
        if(type.explodeOnImpact)
          detonate();
       
        //If we hit glass and can break it, do so
        else if(type.breaksGlass && mat == Material.glass && TeamsManager.canBreakGlass)
        {
          worldObj.setBlockToAir(hit.blockX, hit.blockY, hit.blockZ);
          FlansMod.proxy.playBlockBreakSound(hit.blockX, hit.blockY, hit.blockZ, block);
        }
       
        //If this grenade does not penetrate blocks, hit the block instead
        //The grenade cannot bounce if it detonated on impact, so hence the "else" condition
        else if(!type.penetratesBlocks)
        {       
          Vector3f hitVec = new Vector3f(hit.hitVec);
          //Motion of the grenade pre-hit
          Vector3f preHitMotVec = Vector3f.sub(hitVec, posVec, null);
          //Motion of the grenade post-hit
          Vector3f postHitMotVec = Vector3f.sub(motVec, preHitMotVec, null);
         
          //Reflect postHitMotVec based on side hit
          int sideHit = hit.sideHit;
          switch(sideHit)
          {
          case 0 : case 1 : postHitMotVec.setY(-postHitMotVec.getY()); break;
          case 4 : case 5 : postHitMotVec.setX(-postHitMotVec.getX()); break;
          case 2 : case 3 : postHitMotVec.setZ(-postHitMotVec.getZ()); break;
          }
         
          //Calculate the time interval spent post reflection
          float lambda = Math.abs(motVec.lengthSquared()) < 0.00000001F ? 1F : postHitMotVec.length() / motVec.length();
          //Scale the post hit motion by the bounciness of the grenade
          postHitMotVec.scale(type.bounciness / 2);
         
          //Move the grenade along the new path including reflection
          posX += preHitMotVec.x + postHitMotVec.x;
          posY += preHitMotVec.y + postHitMotVec.y;
          posZ += preHitMotVec.z + postHitMotVec.z;
         
          //Set the motion
          motionX = postHitMotVec.x / lambda;
          motionY = postHitMotVec.y / lambda;
          motionZ = postHitMotVec.z / lambda;
         
          //Reset the motion vector
          motVec = new Vector3f(motionX, motionY, motionZ);
         
          //Give it a random spin
          float randomSpinner = 90F;
          Vector3f.add(angularVelocity, new Vector3f(rand.nextGaussian() * randomSpinner, rand.nextGaussian() * randomSpinner, rand.nextGaussian() * randomSpinner), angularVelocity);
          //Slow the spin based on the motion
          angularVelocity.scale(motVec.lengthSquared());
         
          //Play the bounce sound
          if(motVec.lengthSquared() > 0.01D)
            playSound(type.bounceSound, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
         
          //If this grenade is sticky, stick it to the block
          if(type.sticky)
          {
            //Move the grenade to the point of contact
            posX = hitVec.x;
            posY = hitVec.y;
            posZ = hitVec.z;
            //Stop all motion of the grenade
            motionX = motionY = motionZ = 0;
            angularVelocity.set(0F, 0F, 0F);
           
            float yaw = axes.getYaw();
           
            switch(hit.sideHit)
            {
            case 0 : axes.setAngles(yaw, 180F, 0F); break;
            case 1 : axes.setAngles(yaw, 0F, 0F); break;
            case 2 : axes.setAngles(270F, 90F, 0F); axes.rotateLocalYaw(yaw); break;
            case 3 : axes.setAngles(90F, 90F, 0F); axes.rotateLocalYaw(yaw); break;
            case 4 : axes.setAngles(180F, 90F, 0F); axes.rotateLocalYaw(yaw); break;
            case 5 : axes.setAngles(0F, 90F, 0F); axes.rotateLocalYaw(yaw); break;
            }

            //Set the stuck flag on
            stuck = true;
            stuckToX = hit.blockX;
            stuckToY = hit.blockY;
            stuckToZ = hit.blockZ;
          }
        }
      }
      //We didn't hit a block, continue as normal
      else
      {
        posX += motionX;
        posY += motionY;
        posZ += motionZ;
      }
 
      //Update the grenade position
      setPosition(posX, posY, posZ);
    }
   
    if(type.stickToThrower)
    {
      if(thrower == null || thrower.isDead)
        setDead();
      else setPosition(thrower.posX, thrower.posY, thrower.posZ);
    }
   
    //If throwing this grenade at an entity should hurt them, this bit checks for entities in the way and does so
    //(Don't attack entities when stuck to stuff)
    if(type.damageVsLiving > 0 && !stuck)
    {
      Vector3f motVec = new Vector3f(motionX, motionY, motionZ);
      List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox);
      for(Object obj : list)
      {
        if(obj == thrower && ticksExisted < 10 || motVec.lengthSquared() < 0.01D)
          continue;
        if(obj instanceof EntityLivingBase)
          ((EntityLivingBase)obj).attackEntityFrom(getGrenadeDamage(), type.damageVsLiving * motVec.lengthSquared() * 3);
      }
    }
 
    //Apply gravity
    motionY -= 9.81D / 400D * type.fallSpeed;
 
View Full Code Here

    setRotation(data.readFloat(), data.readFloat());
    prevRotationYaw = rotationYaw;
    prevRotationPitch = rotationPitch;
    axes.setAngles(rotationYaw, rotationPitch, 0F);
    if(type.spinWhenThrown)
      angularVelocity = new Vector3f(0F, 0F, 10F);
  }
View Full Code Here

            //If the driveable is at its server position and does not have the next update, it should just simulate itself as a server side driveable would, so continue
    }
   
    //Movement

    Vector3f amountToMoveCar = new Vector3f();
   
    for(EntityWheel wheel : wheels)
    {
      if(wheel == null)
        continue;
     
      //Hacky way of forcing the car to step up blocks
      onGround = true;
      wheel.onGround = true;
     
      //Update angles
      wheel.rotationYaw = axes.getYaw();
      //Front wheels
      if(!type.tank && (wheel.ID == 2 || wheel.ID == 3))
      {
        wheel.rotationYaw += wheelsYaw;
      }
     
      wheel.motionX *= 0.9F;
      wheel.motionY *= 0.9F;
      wheel.motionZ *= 0.9F;
     
      //Apply gravity
      wheel.motionY -= 0.98F / 20F;
     
      //Apply velocity
      //If the player driving this is in creative, then we can thrust, no matter what
      boolean canThrustCreatively = !TeamsManager.vehiclesNeedFuel || (seats != null && seats[0] != null && seats[0].riddenByEntity instanceof EntityPlayer && ((EntityPlayer)seats[0].riddenByEntity).capabilities.isCreativeMode);
      //Otherwise, check the fuel tanks!
      if(canThrustCreatively || data.fuelInTank > data.engine.fuelConsumption * throttle)
      {
        if(getVehicleType().tank)
        {
          boolean left = wheel.ID == 0 || wheel.ID == 3;
         
          float turningDrag = 0.02F;
          wheel.motionX *= 1F - (Math.abs(wheelsYaw) * turningDrag);
          wheel.motionZ *= 1F - (Math.abs(wheelsYaw) * turningDrag);
         
          float velocityScale = 0.04F * (throttle > 0 ? type.maxThrottle : type.maxNegativeThrottle) * data.engine.engineSpeed;
          float steeringScale = 0.1F * (wheelsYaw > 0 ? type.turnLeftModifier : type.turnRightModifier);
          float effectiveWheelSpeed = (throttle + (wheelsYaw * (left ? 1 : -1) * steeringScale)) * velocityScale;
          wheel.motionX += effectiveWheelSpeed * Math.cos(wheel.rotationYaw * 3.14159265F / 180F);
          wheel.motionZ += effectiveWheelSpeed * Math.sin(wheel.rotationYaw * 3.14159265F / 180F);
         
 
        }
        else
        {
          //if(getVehicleType().fourWheelDrive || wheel.ID == 0 || wheel.ID == 1)
          {
            float velocityScale = 0.1F * throttle * (throttle > 0 ? type.maxThrottle : type.maxNegativeThrottle) * data.engine.engineSpeed;
            wheel.motionX += Math.cos(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale;
            wheel.motionZ += Math.sin(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale;
          }
         
          //Apply steering
          if(wheel.ID == 2 || wheel.ID == 3)
          {
            float velocityScale = 0.01F * (wheelsYaw > 0 ? type.turnLeftModifier : type.turnRightModifier) * (throttle > 0 ? 1 : -1);
   
            wheel.motionX -= wheel.getSpeedXZ() * Math.sin(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * wheelsYaw;
            wheel.motionZ += wheel.getSpeedXZ() * Math.cos(wheel.rotationYaw * 3.14159265F / 180F) * velocityScale * wheelsYaw;
          }
          else
          {
            wheel.motionX *= 0.9F;
            wheel.motionZ *= 0.9F;
          }
        }
      }
     
      if(type.floatOnWater && worldObj.isAnyLiquid(wheel.boundingBox))
      {
        wheel.motionY += type.buoyancy;
      }

      wheel.moveEntity(wheel.motionX, wheel.motionY, wheel.motionZ);
     
      //Pull wheels towards car
      Vector3f targetWheelPos = axes.findLocalVectorGlobally(getVehicleType().wheelPositions[wheel.ID].position);
      Vector3f currentWheelPos = new Vector3f(wheel.posX - posX, wheel.posY - posY, wheel.posZ - posZ);
     
      Vector3f dPos = ((Vector3f)Vector3f.sub(targetWheelPos, currentWheelPos, null).scale(getVehicleType().wheelSpringStrength));
       
      if(dPos.length() > 0.001F)
      {
        wheel.moveEntity(dPos.x, dPos.y, dPos.z);
        dPos.scale(0.5F);
        Vector3f.sub(amountToMoveCar, dPos, amountToMoveCar);
      }
    }
   
    moveEntity(amountToMoveCar.x, amountToMoveCar.y, amountToMoveCar.z);
   
    if(wheels[0] != null && wheels[1] != null && wheels[2] != null && wheels[3] != null)
    {
      Vector3f frontAxleCentre = new Vector3f((wheels[2].posX + wheels[3].posX) / 2F, (wheels[2].posY + wheels[3].posY) / 2F, (wheels[2].posZ + wheels[3].posZ) / 2F);
      Vector3f backAxleCentre = new Vector3f((wheels[0].posX + wheels[1].posX) / 2F, (wheels[0].posY + wheels[1].posY) / 2F, (wheels[0].posZ + wheels[1].posZ) / 2F);
     
      float dx = frontAxleCentre.x - backAxleCentre.x;
      float dy = frontAxleCentre.y - backAxleCentre.y;
      float dz = frontAxleCentre.z - backAxleCentre.z;
     
View Full Code Here

  public long time;
 
  public PlayerSnapshot(EntityPlayer p)
  {
    player = p;
    pos = new Vector3f(p.posX, p.posY, p.posZ);
    if(FlansMod.proxy.isThePlayer(p))
      pos = new Vector3f(p.posX, p.posY - 1.6F, p.posZ);
    hitboxes = new ArrayList<PlayerHitbox>();
   
    RotatedAxes bodyAxes = new RotatedAxes(p.renderYawOffset, 0F, 0F);
    RotatedAxes headAxes = new RotatedAxes(p.rotationYawHead - p.renderYawOffset, 0F, -p.rotationPitch);
   
    hitboxes.add(new PlayerHitbox(player, bodyAxes, new Vector3f(0F, 0F, 0F), new Vector3f(-0.25F, 0F, -0.15F), new Vector3f(0.5F, 1.4F, 0.3F), EnumHitboxType.BODY));   
    hitboxes.add(new PlayerHitbox(player, bodyAxes.findLocalAxesGlobally(headAxes), new Vector3f(0.0F, 1.4F, 0F), new Vector3f(-0.25F, 0F, -0.25F), new Vector3f(0.5F, 0.5F, 0.5F), EnumHitboxType.HEAD));
   
    //Calculate rotation of arms using modified code from ModelBiped
    float yHead = (p.rotationYawHead - p.renderYawOffset) / (180F / (float)Math.PI);
        float xHead = p.rotationPitch / (180F / (float)Math.PI);
   
        float zRight = 0.0F;
        float zLeft = 0.0F;
        float yRight = -0.1F + yHead - ((float)Math.PI / 2F);
        float yLeft = 0.1F + yHead + 0.4F - ((float)Math.PI / 2F);
        float xRight = -((float)Math.PI / 2F) + xHead;
        float xLeft = -((float)Math.PI / 2F) + xHead;
       
        zRight += MathHelper.cos(p.ticksExisted * 0.09F) * 0.05F + 0.05F;
        zLeft -= MathHelper.cos(p.ticksExisted * 0.09F) * 0.05F + 0.05F;
        xRight += MathHelper.sin(p.ticksExisted * 0.067F) * 0.05F;
        xLeft -= MathHelper.sin(p.ticksExisted * 0.067F) * 0.05F;
           
    RotatedAxes leftArmAxes = (new RotatedAxes()).rotateGlobalPitchInRads(xLeft).rotateGlobalYawInRads((float)Math.PI + yLeft).rotateGlobalRollInRads(-zLeft);
    RotatedAxes rightArmAxes = (new RotatedAxes()).rotateGlobalPitchInRads(xRight).rotateGlobalYawInRads((float)Math.PI + yRight).rotateGlobalRollInRads(-zRight);
   
    float originZRight = MathHelper.sin(-p.renderYawOffset * 3.14159265F / 180F) * 5.0F / 16F;
    float originXRight = -MathHelper.cos(-p.renderYawOffset * 3.14159265F / 180F) * 5.0F / 16F;

    float originZLeft = -MathHelper.sin(-p.renderYawOffset * 3.14159265F / 180F) * 5.0F / 16F;
    float originXLeft  = MathHelper.cos(-p.renderYawOffset * 3.14159265F / 180F) * 5.0F / 16F;
   
    hitboxes.add(new PlayerHitbox(player, bodyAxes.findLocalAxesGlobally(leftArmAxes), new Vector3f(originXLeft, 1.3F, originZLeft), new Vector3f(-2F / 16F, -0.6F, -2F / 16F), new Vector3f(0.25F, 0.7F, 0.25F), EnumHitboxType.LEFTARM))
    hitboxes.add(new PlayerHitbox(player, bodyAxes.findLocalAxesGlobally(rightArmAxes), new Vector3f(originXRight, 1.3F, originZRight), new Vector3f(-2F / 16F, -0.6F, -2F / 16F), new Vector3f(0.25F, 0.7F, 0.25F), EnumHitboxType.RIGHTARM))
   
    //Add box for right hand shield
    ItemStack playerRightHandStack = player.getCurrentEquippedItem();
    if(playerRightHandStack != null && playerRightHandStack.getItem() instanceof ItemGun)
    {
      GunType gunType = ((ItemGun)playerRightHandStack.getItem()).type;
      if(gunType.shield)
      {
        hitboxes.add(new PlayerHitbox(player, bodyAxes.findLocalAxesGlobally(rightArmAxes), new Vector3f(originXRight, 1.3F, originZRight), new Vector3f(gunType.shieldOrigin.y, -1.05F + gunType.shieldOrigin.x, -1F / 16F + gunType.shieldOrigin.z), new Vector3f(gunType.shieldDimensions.y, gunType.shieldDimensions.x, gunType.shieldDimensions.z), EnumHitboxType.RIGHTITEM))
      }
     
      //Add left hand shield box
      PlayerData data = PlayerHandler.getPlayerData(player);
      if(gunType.oneHanded && data.offHandGunSlot != 0)
      {
        ItemStack leftHandStack = null;
        //Client side other players
        if(player.worldObj.isRemote && !FlansMod.proxy.isThePlayer(player))
          leftHandStack = data.offHandGunStack;
        else leftHandStack = player.inventory.getStackInSlot(data.offHandGunSlot - 1);
       
        if(leftHandStack != null && leftHandStack.getItem() instanceof ItemGun)
        {
          GunType leftGunType = ((ItemGun)leftHandStack.getItem()).type;
          if(leftGunType.shield)
          {
            hitboxes.add(new PlayerHitbox(player, bodyAxes.findLocalAxesGlobally(leftArmAxes), new Vector3f(originXLeft, 1.3F, originZLeft), new Vector3f(leftGunType.shieldOrigin.y, -1.05F + leftGunType.shieldOrigin.x, -1F / 16F + leftGunType.shieldOrigin.z), new Vector3f(leftGunType.shieldDimensions.y, leftGunType.shieldDimensions.x, leftGunType.shieldDimensions.z), EnumHitboxType.LEFTITEM))
          }
        }
      }
    }
  }
View Full Code Here

  }
 
  public ArrayList<BulletHit> raytrace(Vector3f origin, Vector3f motion)
  { 
    //Get the bullet raytrace vector into local coordinates
    Vector3f localOrigin = Vector3f.sub(origin, pos, null);
    //Prepare a list for the hits
    ArrayList<BulletHit> hits = new ArrayList<BulletHit>();   
   
    //Check each hitbox for a hit
    for(PlayerHitbox hitbox : hitboxes)
View Full Code Here

  public ModelProtoTitan()
  {
    int textureX = 256;
    int textureY = 256;
   
    hipsAttachmentPoint = new Vector3f(-12.1F / 16F, 36F / 16F, 0F);
   
    //Body
    bodyModel = new ModelRendererTurbo[8];
   
    bodyModel[0] = new ModelRendererTurbo(this, 0, 0, textureX, textureY);
View Full Code Here


  public ModelZeroTitan()
  {
   
    hipsAttachmentPoint = new Vector3f(-50F / 16F, 120F / 16F, 0F);
   
    bodyModel = new ModelRendererTurbo[65];
    bodyModel[0] = new ModelRendererTurbo(this, 0, 100, textureX, textureY); // Box 0
    bodyModel[1] = new ModelRendererTurbo(this, 0, 130, textureX, textureY); // Box 8
    bodyModel[2] = new ModelRendererTurbo(this, 0, 150, textureX, textureY); // Box 9
View Full Code Here

    ammoModel = new ModelRendererTurbo[1];
   
    ammoModel[0] = new ModelRendererTurbo(this, 13, 0, textureX, textureY);
    ammoModel[0].addBox(-0.9F, -0.75F, -0.5F, 1.8F, 4, 1);
   
    barrelAttachPoint = new Vector3f(6.5F / 16F, 4F / 16F, 0F);
   
    scopeAttachPoint = new Vector3f(3F / 16F, 5F / 16F, 0F);
    scopeIsOnSlide = true;
   
    gunSlideDistance = 0.25F;
    animationType = EnumAnimationType.PISTOL_CLIP;
  }
View Full Code Here

      {
        MechaItemType toolType = ((ItemMechaAddon)heldItem).type;
       
        float reach = toolType.reach * mechaType.reach;
       
        Vector3f lookOrigin = new Vector3f((float)mechaType.seats[0].x / 16F, (float)mechaType.seats[0].y / 16F + seats[0].riddenByEntity.getMountedYOffset(), (float)mechaType.seats[0].z / 16F);
        lookOrigin = axes.findLocalVectorGlobally(lookOrigin);
        Vector3f.add(lookOrigin, new Vector3f(posX, posY, posZ), lookOrigin);
   
        Vector3f lookVector = axes.findLocalVectorGlobally(seats[0].looking.findLocalVectorGlobally(new Vector3f(reach, 0F, 0F)));
       
        worldObj.spawnEntityInWorld(new EntityDebugVector(worldObj, lookOrigin, lookVector, 20));
       
        Vector3f lookTarget = Vector3f.add(lookVector, lookOrigin, null);
       
        MovingObjectPosition hit = worldObj.rayTraceBlocks(lookOrigin.toVec3(), lookTarget.toVec3());
       
        //MovingObjectPosition hit = ((EntityLivingBase)seats[0].riddenByEntity).rayTrace(reach, 1F);
        if(hit != null && hit.typeOfHit == MovingObjectType.BLOCK)
        {
          if(breakingBlock == null || breakingBlock.x != hit.blockX || breakingBlock.y != hit.blockY || breakingBlock.z != hit.blockZ)
View Full Code Here

TOP

Related Classes of com.flansmod.common.vector.Vector3f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.