public void pause() { moving = !moving; //react to the collision oldVx = PhysicsCalculator.calculateRecoilVelocity(jImpulse, projMass, gunBallVelocity); gunBallVelocityFinal = oldVx; targetVelocity = PhysicsCalculator.calculateRecoilVelocity(-jImpulse, targetMass, targetVelocity); momentumFinal.x = PhysicsCalculator.calculateMomentum(projMass, oldVx); momentumFinal.y = PhysicsCalculator.calculateMomentum(targetMass, targetVelocity); momentumFinal.z = momentumFinal.x + momentumFinal.y; }
public void pause() { moving = !moving; collided = true; float x = Mathf.Abs(gunball.transform.position.x - target.transform.position.x); float z = Mathf.Sqrt(1 - Mathf.Pow(x, 2)); gunball.transform.position = new Vector3(gunball.transform.position.x, gunball.transform.position.y, target.transform.position.z - z); //react to the collision gunBallVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(jImpulse, projMass, gunBallVelocity); targetVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(-jImpulse, targetMass, targetVelocity); //Lab #10 normals.x = target.transform.position.x - gunball.transform.position.x; normals.z = target.transform.position.z - gunball.transform.position.z; jNormal = (jImpulse * normals.z) + (0 * normals.x); tangentials.z = normals.x * -1; tangentials.x = normals.z; bulletinitialNormal = (gunBallVelocity * normals.z) + (0 * normals.x); bulletinitialTang = (gunBallVelocity * tangentials.z) + (0 * tangentials.x); targetinitialNormal = (targetVelocity * normals.z) + (0 * normals.x); targetinitialTang = (targetVelocity * tangentials.z) + (0 * tangentials.z); bulletZfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.z; bulletZfinalTang = (bulletinitialTang * tangentials.z); targetZfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.z; targetZfinalTang = (targetinitialTang * tangentials.z); //z velocities bulletZfinal = bulletZfinalNormal + bulletZfinalTang; targetZfinal = targetZfinalNormal + targetZfinalTang; bulletXfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.x; bulletXfinalTang = (bulletinitialTang * tangentials.x); targetXfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.x; targetXfinalTang = targetinitialTang * tangentials.x; //x velocities bulletXFinal = bulletXfinalNormal + bulletXfinalTang; targetXFinal = targetXfinalNormal + targetXfinalTang; //bullet, target, final //momentum momentumInitialZ.x = projMass * gunBallVelocity; momentumInitialZ.y = targetMass * targetVelocity; momentumInitialZ.z = momentumInitialZ.x + momentumInitialZ.y; momentumFinalZ.x = projMass * bulletZfinal; momentumFinalZ.y = targetMass * targetZfinal; momentumFinalZ.z = momentumFinalZ.x + momentumFinalZ.y; momentumInitialX.x = 0f; momentumInitialX.y = 0f; momentumInitialX.z = momentumInitialX.x + momentumInitialX.y; momentumFinalX.x = projMass * bulletXFinal; momentumFinalX.y = targetMass * targetXFinal; momentumFinalX.z = momentumFinalX.x + momentumFinalX.y; //energy energyInitialZ.x = 0.5f * projMass * gunBallVelocity * gunBallVelocity; energyInitialZ.y = 0.5f * targetMass * targetVelocity * targetVelocity; energyInitialZ.z = energyInitialZ.x + energyInitialZ.y; energyFinalZ.x = 0.5f * projMass * bulletZfinal * bulletZfinal; energyFinalZ.y = 0.5f * targetMass * targetZfinal * targetZfinal; energyFinalZ.z = energyFinalZ.x + energyFinalZ.y; energyInitialX.x = 0.5f * projMass * 0.0f * 0.0f; energyInitialX.y = 0.5f * targetMass * 0.0f * 0.0f; energyInitialX.z = energyInitialX.x + energyInitialX.y; energyFinalX.x = 0.5f * projMass * bulletXFinal * bulletXFinal; energyFinalX.y = 0.5f * targetMass * targetXFinal * targetXFinal; energyFinalX.z = energyFinalX.x + energyFinalX.y; totalEnergy = energyFinalX.z + energyFinalZ.z; }
public void pause() { moving = !moving; collided = true; R1.x = gunball.transform.position.x; R1.y = gunball.transform.position.y; R1.z = gunball.transform.position.z; R2.x = target.transform.position.x; R2.y = target.transform.position.y; R2.z = target.transform.position.z; P.z = target.transform.position.z - 0.5f; P.x = gunball.transform.position.x + (target.transform.position.x - gunball.transform.position.x) / 2; //reposition the cube gunball.transform.position = new Vector3(gunball.transform.position.x, gunball.transform.position.y, target.transform.position.z - 1); //Lab #10 normals.x = target.transform.position.x - gunball.transform.position.x; normals.z = target.transform.position.z - gunball.transform.position.z; //lab #11 additions lowCaseR1 = PhysicsCalculator.calculateSubtractVector(P, gunball.transform.position); lowCaseR2 = PhysicsCalculator.calculateSubtractVector(P, target.transform.position); //hacky fix :) normals.x = 0; tangentials.z = normals.x; //-------------------------------- jImpulse = PhysicsCalculator.calculateJImpulse((gunBallVelocity - targetVelocity), e, projMass, targetMass, normals, lowCaseR1, lowCaseR2, moi1, moi2); omegaBallF = -(omegaBallI + Vector3.Cross(lowCaseR1, (normals * jImpulse)) / moi1); omegaTargetF = omegaTargetI + Vector3.Cross(lowCaseR2, (normals * jImpulse)) / moi2; //Lab #10 jNormal = (jImpulse * normals.z) + (0 * normals.x); //react to the collision gunBallVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(jNormal, projMass, gunBallVelocity); targetVelocityFinal = PhysicsCalculator.calculateRecoilVelocity(-jNormal, targetMass, targetVelocity); tangentials.z = normals.x * -1; tangentials.x = normals.z; bulletinitialNormal = (gunBallVelocity * normals.z) + (0 * normals.x); bulletinitialTang = (gunBallVelocity * tangentials.z) + (0 * tangentials.x); targetinitialNormal = (targetVelocity * normals.z) + (0 * normals.x); targetinitialTang = (targetVelocity * tangentials.z) + (0 * tangentials.z); //final normals bulletZfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.z; bulletZfinalTang = (bulletinitialTang * tangentials.z); targetZfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.z; targetZfinalTang = (targetinitialTang * tangentials.z); //z velocities bulletZfinal = bulletZfinalNormal + bulletZfinalTang; targetZfinal = targetZfinalNormal + targetZfinalTang; bulletXfinalNormal = (jNormal / projMass + bulletinitialNormal) * normals.x; bulletXfinalTang = (bulletinitialTang * tangentials.x); targetXfinalNormal = ((-jNormal) / targetMass + targetinitialNormal) * normals.x; targetXfinalTang = targetinitialTang * tangentials.x; //x velocities bulletXFinal = bulletXfinalNormal + bulletXfinalTang; targetXFinal = targetXfinalNormal + targetXfinalTang; //bullet, target, final //momentum momentumInitialZ.x = projMass * gunBallVelocity; momentumInitialZ.y = targetMass * targetVelocity; momentumInitialZ.z = momentumInitialZ.x + momentumInitialZ.y; momentumFinalZ.x = projMass * bulletZfinal; momentumFinalZ.y = targetMass * targetZfinal; momentumFinalZ.z = momentumFinalZ.x + momentumFinalZ.y; momentumInitialX.x = 0f; momentumInitialX.y = 0f; momentumInitialX.z = momentumInitialX.x + momentumInitialX.y; momentumFinalX.x = projMass * bulletXFinal; momentumFinalX.y = targetMass * targetXFinal; momentumFinalX.z = momentumFinalX.x + momentumFinalX.y; //energy energyInitialZ.x = 0.5f * projMass * gunBallVelocity * gunBallVelocity; energyInitialZ.y = 0.5f * targetMass * targetVelocity * targetVelocity; energyInitialZ.z = energyInitialZ.x + energyInitialZ.y; energyFinalZ.x = 0.5f * projMass * bulletZfinal * bulletZfinal; energyFinalZ.y = 0.5f * targetMass * targetZfinal * targetZfinal; energyFinalZ.z = energyFinalZ.x + energyFinalZ.y; energyInitialX.x = 0.5f * projMass * 0.0f * 0.0f; energyInitialX.y = 0.5f * targetMass * 0.0f * 0.0f; energyInitialX.z = energyInitialX.x + energyInitialX.y; energyFinalX.x = 0.5f * projMass * bulletXFinal * bulletXFinal; energyFinalX.y = 0.5f * targetMass * targetXFinal * targetXFinal; energyFinalX.z = energyFinalX.x + energyFinalX.y; //rotational energy rotEnergy.x = (0.5f * moi1 * omegaBallF.y * omegaBallF.y); rotEnergy.y = (0.5f * moi2 * omegaTargetF.y * omegaTargetF.y); rotEnergy.z = rotEnergy.x + rotEnergy.y; totalEnergy = energyFinalZ.z + (0.5f * moi1 * omegaBallF.y * omegaBallF.y) + (0.5f * moi2 * omegaTargetF.y * omegaTargetF.y); //gunball momentum values Vector3 gunballInitialMomentum = new Vector3(momentumInitialX.x, 0.0f, momentumInitialZ.x); //nothing happening in x, hence why it's 0 Vector3 gunballFinalMomentum = new Vector3(0.0f, 0.0f, momentumFinalZ.x); //target momentum values Vector3 targetInitialMomentum = new Vector3(momentumInitialX.y, 0.0f, momentumInitialZ.y); //nothing happening in x, hence why it's 0 Vector3 targetFinalMomentum = new Vector3(0.0f, 0.0f, momentumFinalZ.y); LInitial = PhysicsCalculator.calculateAngularMomentum(lowCaseR1, lowCaseR2, gunballInitialMomentum, targetInitialMomentum); LFinal1 = Vector3.Cross(lowCaseR1, gunballFinalMomentum) + (moi1 * omegaBallF); LFinal2 = Vector3.Cross(lowCaseR2, targetFinalMomentum) + (moi2 * omegaTargetF); LFinalTotal = LFinal1 + LFinal2; }