- #1
TheShermanTanker
- 13
- 4
Hello there!
I'm a newcomer and just started doing Physics as there is one part of my current project requires it to do so.
Recently, while reading up a game's source code, I came across something that I couldn't figure out. Below is the portion of the code that handles the velocity calculations when a bullet is fired:
I can understand most of it, but this part:
float var9 = MathHelper.sqrt_double(motX * motX + motY * motY + motZ * motZ);
I cannot. What does squaring the velocity on all 3 axes, adding them up and square rooting all of them again yield? What does the variable var9 stand for?
And again this part:
float var10 = MathHelper.sqrt_double(motX * motX + motZ * motZ); //What does this part do??
also confuses me. Its similar but leaves out the velocity on the y-axis. What do var9 and var10 stand for?
I really appreciate any help given. Thanks :D
I'm a newcomer and just started doing Physics as there is one part of my current project requires it to do so.
Recently, while reading up a game's source code, I came across something that I couldn't figure out. Below is the portion of the code that handles the velocity calculations when a bullet is fired:
Java:
public void launchProjectile(double motX, double motY, double motZ, float bulletPower, float dispersion) {
float var9 = MathHelper.sqrt_double(motX * motX + motY * motY + motZ * motZ); //This part is what I cannot figure out
motX /= (double)var9;
motY /= (double)var9;
motZ /= (double)var9;
motX += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)dispersion;
motY += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)dispersion;
motZ += this.rand.nextGaussian() * (double)(this.rand.nextBoolean() ? -1 : 1) * 0.007499999832361937D * (double)dispersion; //Sets bullet dispersion
motX *= (double)bulletPower;
motY *= (double)bulletPower;
motZ *= (double)bulletPower; //Modifies bullet speed
this.motionX = motX;
this.motionY = motY;
this.motionZ = motZ; //Sets the motion of all three axes just to be sure
float var10 = MathHelper.sqrt_double(motX * motX + motZ * motZ); //What does this part do??
this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(motX, dispersion) * 180.0D / Math.PI);
this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(motY, (double)var10) * 180.0D / Math.PI); //Some rotation calculations
this.ticksInGround = 0;
}
I can understand most of it, but this part:
float var9 = MathHelper.sqrt_double(motX * motX + motY * motY + motZ * motZ);
I cannot. What does squaring the velocity on all 3 axes, adding them up and square rooting all of them again yield? What does the variable var9 stand for?
And again this part:
float var10 = MathHelper.sqrt_double(motX * motX + motZ * motZ); //What does this part do??
also confuses me. Its similar but leaves out the velocity on the y-axis. What do var9 and var10 stand for?
I really appreciate any help given. Thanks :D