//Standard update, taken out of Relativistic Object public void Update() { //Grab our renderer. MeshRenderer tempRenderer = GetComponent <MeshRenderer>(); if (meshFilter != null && !state.MovementFrozen) { #region meshDensity //This is where I'm going to change our mesh density. //I'll take the model, and pass MeshDensity the mesh and unchanged vertices //If it comes back as having changed something, I'll edit the mesh. ObjectMeshDensity density = GetComponent <ObjectMeshDensity>(); if (density != null) { //Only run MeshDensity if the mesh needs to change, and if it's passed a threshold distance. if (rawVerts != null && density.change != null) { //This checks if we're within our large range, first mesh density circle //If we're within a distance of 40, split this mesh if (density.state == false && RecursiveTransform(rawVerts[0], meshFilter.transform).magnitude < 21000) { if (density.ReturnVerts(meshFilter.mesh, true)) { rawVerts = new Vector3[meshFilter.mesh.vertices.Length]; System.Array.Copy(meshFilter.mesh.vertices, rawVerts, meshFilter.mesh.vertices.Length); } } //If the object leaves our wide range, revert mesh to original state else if (density.state == true && RecursiveTransform(rawVerts[0], meshFilter.transform).magnitude > 21000) { if (density.ReturnVerts(meshFilter.mesh, false)) { rawVerts = new Vector3[meshFilter.mesh.vertices.Length]; System.Array.Copy(meshFilter.mesh.vertices, rawVerts, meshFilter.mesh.vertices.Length); } } } } #endregion //Send our object's v/c (Velocity over the Speed of Light) to the shader if (tempRenderer != null) { Vector3 tempViw = viw.ToMinkowski4Viw() / (float)state.SpeedOfLight; tempRenderer.materials[0].SetVector("_viw", tempViw); Matrix4x4 minkowski = Matrix4x4.identity; minkowski.m33 = 1; minkowski.m00 = -1; minkowski.m11 = -1; minkowski.m22 = -1; tempRenderer.materials[0].SetMatrix("_MixedMetric", minkowski); } //As long as our object is actually alive, perform these calculations if (transform != null)// && deathTime != 0) { //Here I take the angle that the player's velocity vector makes with the z axis float rotationAroundZ = RAD_2_DEG * Mathf.Acos(Vector3.Dot(state.PlayerVelocityVector, Vector3.forward) / state.PlayerVelocityVector.magnitude); if (state.PlayerVelocityVector.sqrMagnitude == 0) { rotationAroundZ = 0; } //Now we turn that rotation into a quaternion Quaternion rotateZ = Quaternion.AngleAxis(-rotationAroundZ, Vector3.Cross(state.PlayerVelocityVector, Vector3.forward)); //****************************************************************** //Place the vertex to be changed in a new Vector3 Vector3 riw = new Vector3(transform.position.x, transform.position.y, transform.position.z); riw -= state.playerTransform.position; //And we rotate our point that much to make it as if our magnitude of velocity is in the Z direction riw = rotateZ * riw; //Here begins the original code, made by the guys behind the Relativity game /**************************** * Start Part 6 Bullet 1 * */ //Rotate that velocity! Vector3 storedViw = rotateZ * viw; float c = -Vector3.Dot(riw, riw); //first get position squared (position dotted with position) float b = -(2 * Vector3.Dot(riw, storedViw)); //next get position dotted with velocity, should be only in the Z direction float a = (float)state.SpeedOfLightSqrd - Vector3.Dot(storedViw, storedViw); /**************************** * Start Part 6 Bullet 2 * **************************/ float tisw = (float)(((-b - (Math.Sqrt((b * b) - 4f * a * c))) / (2f * a))); //If we're past our death time (in the player's view, as seen by tisw) if (state.TotalTimeWorld + tisw > deathTime && deathTime != 0) { KillObject(); } if (state.TotalTimeWorld + tisw > startTime && !tempRenderer.enabled) { tempRenderer.enabled = true; } } //make our rigidbody's velocity the same as viw if (GetComponent <Rigidbody>() != null && !isParticle) { if (!double.IsNaN((double)state.SqrtOneMinusVSquaredCWDividedByCSquared) && (float)state.SqrtOneMinusVSquaredCWDividedByCSquared != 0) { Vector3 tempViw = viw; tempViw /= (float)state.SqrtOneMinusVSquaredCWDividedByCSquared; //Attempt to correct for acceleration: Vector3 playerPos = state.playerTransform.position; Vector3 playerVel = state.PlayerVelocityVector; tempViw /= (float)(1.0 + 1.0 / state.SpeedOfLightSqrd * Vector3.Dot(state.PlayerAccelerationVector, transform.position - playerPos)); GetComponent <Rigidbody>().velocity = tempViw; } //if (!double.IsNaN((double)state.InverseAcceleratedGamma) && (float)state.InverseAcceleratedGamma != 0) //{ // Vector3 tempViw = viw; // tempViw /= (float)state.InverseAcceleratedGamma; // GetComponent<Rigidbody>().velocity = tempViw; //} } else if (isParticle) { Vector3 tempViw = viw; tempViw /= (float)state.SqrtOneMinusVSquaredCWDividedByCSquared; //Attempt to correct for acceleration: Vector3 playerPos = state.playerTransform.position; Vector3 playerVel = state.PlayerVelocityVector; tempViw /= (float)(1.0 + 1.0 / state.SpeedOfLightSqrd * Vector3.Dot(state.PlayerAccelerationVector, transform.position - playerPos)); transform.position = transform.position + tempViw * Time.deltaTime; } //else if (isParticle) //{ // Vector3 tempViw = viw; // tempViw /= (float)state.InverseAcceleratedGamma; // transform.position = transform.position + tempViw * Time.deltaTime; //} } //If nothing is null, then set the object to standstill, but make sure its rigidbody actually has a velocity. else if (meshFilter != null && tempRenderer != null && GetComponent <Rigidbody>() != null) { GetComponent <Rigidbody>().velocity = Vector3.zero; } //This time transformation goes from world time to this objects personal time timer -= (float)(state.DeltaTimeWorld * (Math.Sqrt(1 - (viw.sqrMagnitude) / state.SpeedOfLightSqrd))); //If we've passed the time to explode, blow it up if (timer <= 0) { SetDeathTime(); timer = float.MaxValue; } }
public void Update() { //Grab our renderer. MeshRenderer tempRenderer = GetComponent <MeshRenderer>(); if (meshFilter != null && !state.MovementFrozen) { bool x = meshFilter != null; Debug.Log(x); #region meshDensity //This is where I'm going to change our mesh density. //I'll take the model, and pass MeshDensity the mesh and unchanged vertices //If it comes back as having changed something, I'll edit the mesh. ObjectMeshDensity density = GetComponent <ObjectMeshDensity>(); if (density != null) { //Only run MeshDensity if the mesh needs to change, and if it's passed a threshold distance. if (rawVerts != null && density.change != null) { //This checks if we're within our large range, first mesh density circle //If we're within a distance of 40, split this mesh if (density.state == false && RecursiveTransform(rawVerts[0], meshFilter.transform).magnitude < 21000) { if (density.ReturnVerts(meshFilter.mesh, true)) { rawVerts = new Vector3[meshFilter.mesh.vertices.Length]; System.Array.Copy(meshFilter.mesh.vertices, rawVerts, meshFilter.mesh.vertices.Length); } } //If the object leaves our wide range, revert mesh to original state else if (density.state == true && RecursiveTransform(rawVerts[0], meshFilter.transform).magnitude > 21000) { if (density.ReturnVerts(meshFilter.mesh, false)) { rawVerts = new Vector3[meshFilter.mesh.vertices.Length]; System.Array.Copy(meshFilter.mesh.vertices, rawVerts, meshFilter.mesh.vertices.Length); } } } } #endregion //Send our object's v/c (Velocity over the Speed of Light) to the shader if (tempRenderer != null) { Vector3 tempViw = viw / (float)state.SpeedOfLight; for (int i = 0; i < tempRenderer.materials.Length; i++) { tempRenderer.materials[i].SetVector("_viw", new Vector4(tempViw.x, tempViw.y, tempViw.z, 0)); } } //As long as our object is actually alive, perform these calculations if (transform != null) { //Here I take the angle that the player's velocity vector makes with the z axis float rotationAroundZ = RAD_2_DEG * Mathf.Acos(Vector3.Dot(state.PlayerVelocityVector, Vector3.forward) / state.PlayerVelocityVector.magnitude); if (state.PlayerVelocityVector.sqrMagnitude == 0) { rotationAroundZ = 0; } //Now we turn that rotation into a quaternion Quaternion rotateZ = Quaternion.AngleAxis(-rotationAroundZ, Vector3.Cross(state.PlayerVelocityVector, Vector3.forward)); //****************************************************************** //Place the vertex to be changed in a new Vector3 Vector3 riw = new Vector3(transform.position.x, transform.position.y, transform.position.z); riw -= state.playerTransform.position; //And we rotate our point that much to make it as if our magnitude of velocity is in the Z direction riw = rotateZ * riw; //Here begins the original code, made by the guys behind the Relativity game /**************************** * Start Part 6 Bullet 1 * */ //Rotate that velocity! Vector3 storedViw = rotateZ * viw; float c = -Vector3.Dot(riw, riw); //first get position squared (position doted with position) float b = -(2 * Vector3.Dot(riw, storedViw)); //next get position doted with velocity, should be only in the Z direction float a = (float)state.SpeedOfLightSqrd - Vector3.Dot(storedViw, storedViw); /**************************** * Start Part 6 Bullet 2 * **************************/ float tisw = (float)(((-b - (Math.Sqrt((b * b) - 4f * a * c))) / (2f * a))); //If we're past our death time (in the player's view, as seen by tisw) if (state.TotalTimeWorld + tisw > deathTime && deathTime != 0) { KillObject(); } if (state.TotalTimeWorld + tisw > startTime && !tempRenderer.enabled) { tempRenderer.enabled = true; if (GetComponent <AudioSource>() != null) { GetComponent <AudioSource>().enabled = true; } } } //make our rigidbody's velocity viw if (GetComponent <Rigidbody>() != null) { if (!double.IsNaN((double)state.SqrtOneMinusVSquaredCWDividedByCSquared) && (float)state.SqrtOneMinusVSquaredCWDividedByCSquared != 0) { Vector3 tempViw = viw; //ASK RYAN WHY THESE WERE DIVIDED BY THIS tempViw.x /= (float)state.SqrtOneMinusVSquaredCWDividedByCSquared; tempViw.y /= (float)state.SqrtOneMinusVSquaredCWDividedByCSquared; tempViw.z /= (float)state.SqrtOneMinusVSquaredCWDividedByCSquared; GetComponent <Rigidbody>().velocity = tempViw; } } } //If nothing is null, then set the object to standstill, but make sure its rigidbody actually has a velocity. else if (meshFilter != null && tempRenderer != null && GetComponent <Rigidbody>() != null) { GetComponent <Rigidbody>().velocity = Vector3.zero; } }
// Token: 0x06000080 RID: 128 RVA: 0x0000AD70 File Offset: 0x00008F70 private void Update() { MeshRenderer component = base.GetComponent <MeshRenderer>(); if (this.meshFilter != null && !this.state.MovementFrozen) { ObjectMeshDensity component2 = base.GetComponent <ObjectMeshDensity>(); if (component2 != null && this.rawVerts != null && component2.change != null) { if (!component2.state && this.RecursiveTransform(this.rawVerts[0], this.meshFilter.transform).magnitude < 21000f) { if (component2.ReturnVerts(this.meshFilter.mesh, true)) { this.rawVerts = new Vector3[this.meshFilter.mesh.vertices.Length]; Array.Copy(this.meshFilter.mesh.vertices, this.rawVerts, this.meshFilter.mesh.vertices.Length); } } else if (component2.state && this.RecursiveTransform(this.rawVerts[0], this.meshFilter.transform).magnitude > 21000f && component2.ReturnVerts(this.meshFilter.mesh, false)) { this.rawVerts = new Vector3[this.meshFilter.mesh.vertices.Length]; Array.Copy(this.meshFilter.mesh.vertices, this.rawVerts, this.meshFilter.mesh.vertices.Length); } } if (component != null) { Vector3 vector = this.viw / (float)this.state.SpeedOfLight; component.materials[0].SetVector("_viw", new Vector4(vector.x, vector.y, vector.z, 0f)); } if (base.transform != null && this.deathTime != 0f) { float num = 57.29578f * Mathf.Acos(Vector3.Dot(this.state.PlayerVelocityVector, Vector3.forward) / this.state.PlayerVelocityVector.magnitude); if (this.state.PlayerVelocityVector.sqrMagnitude == 0f) { num = 0f; } Quaternion rotation = Quaternion.AngleAxis(-num, Vector3.Cross(this.state.PlayerVelocityVector, Vector3.forward)); Vector3 vector2 = new Vector3(base.transform.position.x, base.transform.position.y, base.transform.position.z); vector2 -= this.state.playerTransform.position; vector2 = rotation * vector2; Vector3 vector3 = rotation * this.viw; float num2 = -Vector3.Dot(vector2, vector2); float num3 = -(2f * Vector3.Dot(vector2, vector3)); float num4 = (float)this.state.SpeedOfLightSqrd - Vector3.Dot(vector3, vector3); float num5 = (float)(((double)(-(double)num3) - Math.Sqrt((double)(num3 * num3 - 4f * num4 * num2))) / (double)(2f * num4)); if (this.state.TotalTimeWorld + (double)num5 > (double)this.deathTime) { UnityEngine.Object.Destroy(base.gameObject); } } if (base.GetComponent <Rigidbody>() != null && !double.IsNaN(this.state.SqrtOneMinusVSquaredCWDividedByCSquared) && (float)this.state.SqrtOneMinusVSquaredCWDividedByCSquared != 0f) { Vector3 velocity = this.viw; velocity.x /= (float)this.state.SqrtOneMinusVSquaredCWDividedByCSquared; velocity.y /= (float)this.state.SqrtOneMinusVSquaredCWDividedByCSquared; velocity.z /= (float)this.state.SqrtOneMinusVSquaredCWDividedByCSquared; base.GetComponent <Rigidbody>().velocity = velocity; } } else if (this.meshFilter != null && component != null && base.GetComponent <Rigidbody>() != null) { base.GetComponent <Rigidbody>().velocity = Vector3.zero; } }