Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class MathF : MonoBehaviour
- {
- public GameObject cube;
- public GameObject cilinder;
- void Update()
- {
- if (Input.GetKey(KeyCode.Space))
- {
- SmoothStepUpdate();
- }
- }
- //Conversor de graus para radianos
- public float deg = 30.0F;
- void Degrees2Rad()
- {
- float rad = deg * Mathf.Deg2Rad;
- Debug.Log(deg + "degrees are equal to " + rad + " radians.");
- Vector3 radMove = new Vector3(rad, 0, 0);
- transform.position += radMove * Time.deltaTime;
- }
- //Retorna a menor valor que uma float pode ter diferente de zero
- bool isEqual(float a, float b)
- {
- if (a >= b - Mathf.Epsilon && a <= b + Mathf.Epsilon)
- return true;
- else
- return false;
- }
- void Infinity()
- {
- Debug.DrawLine(Vector3.zero, Vector3.forward * 100);
- if (Physics.Raycast(Vector3.zero, Vector3.forward, Mathf.Infinity))
- print("There is something in front of the object!");
- else
- print("Vazio existencial");
- }
- void NegativeInfinity()
- {
- Debug.Log(Mathf.NegativeInfinity);
- }
- public float radius = 30;
- void PI()
- {
- float perimeter = 2 * Mathf.PI * radius;
- Debug.Log("The perimeter of the circle is: " + perimeter);
- Vector3 radMove = new Vector3(0, 0, perimeter);
- transform.position += radMove * Time.deltaTime;
- }
- public float rad = 15;
- void Rad2Degrees()
- {
- float deg = rad * Mathf.Rad2Deg;
- Debug.Log(rad + " radians are equal to " + deg + " degrees.");
- Vector3 radMove = new Vector3(0, 0, rad);
- transform.position += radMove * Time.deltaTime;
- }
- public float abs = -10.5f;
- void AbsoluteValue()
- {
- Debug.Log(Mathf.Abs(abs));
- float newAbs = Mathf.Abs(this.gameObject.transform.position.y);
- print(newAbs);
- }
- public float arcCos;
- void ArcCosine()
- {
- print(Mathf.Acos(arcCos));
- Vector3 coss = new Vector3(arcCos, arcCos, arcCos);
- transform.position += coss * Time.deltaTime;
- }
- //Retorna o Episulum de duas floats
- void Approximately()
- {
- if (Mathf.Approximately(1.0F, 10.0F / 10.0F))
- print("The values are approximately the same");
- if (Mathf.Approximately(cilinder.transform.position.x * 0, cube.transform.position.x))
- print("?");
- }
- //Retorna o seno do arco
- public float sinArc;
- void SinArc()
- {
- float test = cilinder.transform.position.y;
- print(Mathf.Asin(test));
- }
- //Tamgente do arco (Mesmo esquema)
- void TanArc()
- {
- //Do tests
- print(Mathf.Atan(0.5F));
- }
- //Returns the angle in radians whose Tan is y/x.
- //Return value is the angle between the x-axis and a 2D vector starting at zero and terminating at(x, y).
- //Note: This function takes account of the cases where x is zero and returns the correct angle rather than throwing a division by zero exception
- //Seta a posição do cilindro (Alvo qualquer) position(3,3,33) e estuda mais isso aqui
- public Transform target;
- void TangentBetween2Values()
- {
- Vector3 relative = transform.InverseTransformPoint(target.position);
- float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
- cube.transform.Rotate(0, angle, 0);
- }
- //retorna menor int igual ou menor que a float
- public float c;
- void CeilCalc()
- {
- // Prints 10
- Debug.Log(Mathf.Ceil(10.0F));
- // Prints 11
- Debug.Log(Mathf.Ceil(10.2F));
- // Prints 11
- Debug.Log(Mathf.Ceil(10.7F));
- // Prints -10
- Debug.Log(Mathf.Ceil(-10.0F));
- // Prints -10
- Debug.Log(Mathf.Ceil(-10.2F));
- // Prints -10
- Debug.Log(Mathf.Ceil(-10.7F));
- }
- float shit = 10;
- void CeilToInt()
- {
- var what = (Mathf.CeilToInt(shit));
- //Debug.Log(Mathf.CeilToInt(10.0F));
- //Debug.Log(Mathf.CeilToInt(10.2F));
- //Debug.Log(Mathf.CeilToInt(10.7F));
- //Debug.Log(Mathf.CeilToInt(-10.0F));
- //Debug.Log(Mathf.CeilToInt(-10.2F));
- //Debug.Log(Mathf.CeilToInt(-10.7F));
- Debug.Log(what.GetType());
- }
- //Clamp easy
- void Clampeia()
- {
- cube.transform.position = new Vector3(Mathf.Clamp(Time.time, 1.0F, 3.0F), 0, 0);
- //Another lvl of clamp
- // Clamps the value 10 to be between 1 and 3.
- // prints 3 to the console
- Debug.Log(Mathf.Clamp(10, 1, 3));
- //Clampada binaria
- cilinder.transform.position = new Vector3(Mathf.Clamp01(Time.time), 0, 0);
- }
- //Closest powers of 2, perfect numbers :D
- void PoderDo2()
- {
- Debug.Log(Mathf.ClosestPowerOfTwo(7));
- Debug.Log(Mathf.ClosestPowerOfTwo(19));
- }
- public int numberOfSides;
- public float polygonRadius;
- public Vector2 polygonCenter;
- //Coseno da parada (feel the power!!!)
- void DrawBusiness()
- {
- DebugDrawPolygon(polygonCenter, polygonRadius, numberOfSides);
- }
- //Estudar com calma:
- // Draw a polygon in the XY plane with a specfied position, number of sides
- // and radius.
- void DebugDrawPolygon(Vector2 center, float radius, int numSides)
- {
- // The corner that is used to start the polygon (parallel to the X axis).
- Vector2 startCorner = new Vector2(radius, 0) + polygonCenter;
- // The "previous" corner point, initialised to the starting corner.
- Vector2 previousCorner = startCorner;
- // For each corner after the starting corner...
- for (int i = 1; i < numSides; i++)
- {
- // Calculate the angle of the corner in radians.
- float cornerAngle = 2f * Mathf.PI / (float)numSides * i;
- // Get the X and Y coordinates of the corner point.
- Vector2 currentCorner = new Vector2(Mathf.Cos(cornerAngle) * radius, Mathf.Sin(cornerAngle) * radius) + polygonCenter;
- // Draw a side of the polygon by connecting the current corner to the previous one.
- Debug.DrawLine(currentCorner, previousCorner);
- // Having used the current corner, it now becomes the previous corner.
- previousCorner = currentCorner;
- }
- // Draw the final side by connecting the last corner to the starting corner.
- Debug.DrawLine(startCorner, previousCorner);
- }
- //QUE CODE DELICIA
- float amplitudeX = 10.0f;
- float amplitudeY = 5.0f;
- float omegaX = 1.0f;
- float omegaY = 5.0f;
- float index;
- public void MoveByCosNSin()
- {
- index += Time.deltaTime;
- float x = amplitudeX * Mathf.Cos(omegaX * index);
- float y = Mathf.Abs(amplitudeY * Mathf.Sin(omegaY * index));
- cube.transform.localPosition = new Vector3(x, y, 0);
- }
- //Calcula a menor diferença entre dois angulos por degraus
- // VAI AJUDAR NO DELTA PRA CARALHO
- //estuda mais isso
- void MinorDifByDegree()
- {
- Debug.Log(Mathf.DeltaAngle(1080, 90));
- }
- // elevado à potência e
- //Math.Pow computes x y for some x and y.
- //Math.Exp computes e x for some x, where e is Euler's number.
- //Exp é bem mais rapido que Pow
- public float e = 6;
- void ElevadoAPotencia()
- {
- print(Mathf.Exp(e));
- }
- //Returns the largest integer smaller to or equal to f.
- //wtf???
- void Floor()
- {
- Debug.Log(Mathf.Floor(10.0F));
- Debug.Log(Mathf.Floor(10.2F));
- Debug.Log(Mathf.Floor(10.7F));
- Debug.Log(Mathf.Floor(-10.0F));
- Debug.Log(Mathf.Floor(-10.2F));
- Debug.Log(Mathf.Floor(-10.7F));
- }
- //wtf² mas vira int :D tipo uma classe lá em cima.
- void FloorToInt()
- {
- Debug.Log(Mathf.FloorToInt(10.0F));
- Debug.Log(Mathf.FloorToInt(10.2F));
- Debug.Log(Mathf.FloorToInt(10.7F));
- Debug.Log(Mathf.FloorToInt(-10.0F));
- Debug.Log(Mathf.FloorToInt(-10.2F));
- Debug.Log(Mathf.FloorToInt(-10.7F));
- }
- //Calculates the linear parameter t that produces the interpolant value within the range[a, b].
- //Estuda depopis
- public float walkSpeed = 5.0F;
- public float runSpeed = 10.0F;
- public float speed = 8.0F;
- void StartLinearParameter()
- {
- float parameter = Mathf.InverseLerp(walkSpeed, runSpeed, speed);
- }
- //bool retorna positivo se for uma potencia de 2
- void IsPowerOf2()
- {
- //Booleano pra caralho
- Debug.Log(Mathf.IsPowerOfTwo(7));
- Debug.Log(Mathf.IsPowerOfTwo(32));
- }
- //Lerp Business tu conhece
- // animate the game object from -1 to +1 and back
- public float minimum = -1.0F;
- public float maximum = 1.0F;
- // starting value for the Lerp
- static float t = 0.0f;
- void LerpUpdate()
- {
- // animate the position of the game object...
- cilinder.transform.position = new Vector3(Mathf.Lerp(minimum, maximum, t), 0, 0);
- // .. and increate the t interpolater
- t += 0.5f * Time.deltaTime;
- // now check if the interpolator has reached 1.0
- // and swap maximum and minimum so game object moves
- // in the opposite direction.
- if (t > 1.0f)
- {
- float temp = maximum;
- maximum = minimum;
- minimum = temp;
- t = 0.0f;
- }
- }
- //Lerp de sempre mas 360 graus irmão
- public float minAngle = 0.0F;
- public float maxAngle = 90.0F;
- void LerpAngleUpdate()
- {
- float angle = Mathf.LerpAngle(minAngle, maxAngle, Time.time);
- cube.transform.eulerAngles = new Vector3(0, angle, 0);
- }
- //The parameter t is not clamped and a value based on a and b is supported.
- //If t is less than zero, or greater than one, then LerpUnclamped will result in a return value outside the range a to b.
- void Lerpada()
- {
- Debug.Log(Mathf.LerpUnclamped(1, 20, 2));
- }
- //Debugadando (Retorna o logaritimo da parada)
- void DebugaLogaritmo()
- {
- Debug.Log(Mathf.Log(6, 2));
- }
- //Debugadando (Retorna o logaritimo da parada com base 10)
- void DebugaLogaritmo10()
- {
- Debug.Log(Mathf.Log10(100));
- }
- //Retorna o máximo entre dois valores
- void Maxxx()
- {
- Debug.Log(Mathf.Max(1.2f, 2.4f));
- }
- //Retorna o mínimo entre dois valores
- void Minnn()
- {
- Debug.Log(Mathf.Min(666, 777));
- }
- //This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta.
- //Negative values of maxDelta pushes the value away from target.
- //ESTUDA MAIS DPS
- public float currStrength;
- public float maxStrength;
- public float recoveryRate;
- void MoveTowardsUpdate()
- {
- currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime);
- }
- //Mesma fita de cima só que com rotations (Estuda ssapórra
- public float targetAngle = 270.0F;
- public float speedAngle = 45.0F;
- void MoveTowardsAngleUpdate()
- {
- float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetAngle, speedAngle * Time.deltaTime);
- transform.eulerAngles = new Vector3(0, angle, 0);
- }
- //Next power of 2
- void NextPower2()
- {
- Debug.Log(Mathf.NextPowerOfTwo(7));
- Debug.Log(Mathf.NextPowerOfTwo(139));
- }
- //Perlin Noise (Pesquise mais a respeito na documentação, não tenho interesse nisso no momento) https://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html
- //Mathf.PerlinNoise
- //Vai e volta bro :D
- void PingaPong()
- {
- cube.transform.position = new Vector3(Mathf.PingPong(Time.time, 3), transform.position.y, transform.position.z);
- }
- //Mesma coisa que o Mathf.Exp porém mais lerdo :S
- void Powwww()
- {
- print(Mathf.Pow(6, 1.8F));
- }
- //Da loop no valor e nunca vai ser menor que 0 ou maior que o limite :D
- //Obs: very nice
- void Repete()
- {
- cilinder.transform.position = new Vector3(Mathf.Repeat(Time.time, 3), transform.position.y, transform.position.z);
- }
- //Não entendi porra nenhuma
- //Obs: "If the number ends in .5 so it is halfway between two integers, one of which is even and the other odd, the even number is returned."
- //Essa parada de número primo chamou atenção, olha melhor depois :D
- void Round()
- {
- // Prints 10
- Debug.Log(Mathf.Round(10.0f));
- // Prints 10
- Debug.Log(Mathf.Round(10.2f));
- // Prints 11
- Debug.Log(Mathf.Round(10.7f));
- // Prints 10
- Debug.Log(Mathf.Round(10.5f));
- // Prints 12
- Debug.Log(Mathf.Round(11.5f));
- // Prints -10
- Debug.Log(Mathf.Round(-10.0f));
- // Prints -10
- Debug.Log(Mathf.Round(-10.2f));
- // Prints -11
- Debug.Log(Mathf.Round(-10.7f));
- // Prints -10
- Debug.Log(Mathf.Round(-10.5f));
- // Prints -12
- Debug.Log(Mathf.Round(-11.5f));
- }
- //Denovo essa merda, converte pra int a mesma fita de cima
- //Obs: Apesar do trocadilho no nome do metodo não tem spin nenhum. (Até que prove ao contrário)
- void SpinMeAround()
- {
- Debug.Log(Mathf.RoundToInt(10.0F));
- Debug.Log(Mathf.RoundToInt(10.2F));
- Debug.Log(Mathf.RoundToInt(10.7F));
- Debug.Log(Mathf.RoundToInt(10.5F));
- Debug.Log(Mathf.RoundToInt(11.5F));
- Debug.Log(Mathf.RoundToInt(-10.0F));
- Debug.Log(Mathf.RoundToInt(-10.2F));
- Debug.Log(Mathf.RoundToInt(-10.7F));
- Debug.Log(Mathf.RoundToInt(-10.5F));
- Debug.Log(Mathf.RoundToInt(-11.5F));
- //Basciamente mesma logica aplicada no CeilCalc
- }
- //Sign
- void Sign()
- {
- Debug.Log(Mathf.Sign(-10));
- Debug.Log(Mathf.Sign(10));
- }
- //Estuda mais isso aqui deppis
- public Transform alllvo;
- public float smoothTime = 0.3F;
- private float yVelocity = 0.0F;
- void SmoothDampUpdate()
- {
- float newPosition = Mathf.SmoothDamp(transform.position.y, alllvo.position.y, ref yVelocity, smoothTime);
- cube.transform.position = new Vector3(transform.position.x, newPosition, transform.position.z);
- }
- //Mesmo de cima porém com rotation :D (Util pro delta talvez)
- public Transform alllvo2;
- public float smooth = 0.3F;
- public float distance = 5.0F;
- private float yVelocity2 = 0.0F;
- void SmoothDampAngleUpdate()
- {
- float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, alllvo2.eulerAngles.y, ref yVelocity, smooth);
- Vector3 position = alllvo2.position;
- position += Quaternion.Euler(0, yVelocity2, 0) * new Vector3(0, 0, -distance);
- cube.transform.position = position;
- cube.transform.LookAt(alllvo2);
- }
- //Basicamente um lerp porém a velocidade vai aumentando com o tempo
- public float minimumSmoothStep = 10.0F;
- public float maximumSmoothStep = 20.0F;
- public float duration = 5.0F;
- private float startTime;
- void SmoothStepUpdate()
- {
- startTime = Time.time;
- float t = (Time.time - startTime) / duration;
- cube.transform.position = new Vector3(Mathf.SmoothStep(minimumSmoothStep, maximumSmoothStep, t), 0, 0);
- }
- //Raiz quadrada pitagoras o de sempre
- // The formula made famous by Pythagoras, also used internally by
- // Vector3.Distance and several other standard functions.
- float HypotenuseLength(float sideALength, float sideBLength)
- {
- return Mathf.Sqrt(sideALength * sideALength + sideBLength * sideBLength);
- }
- //N vou explicar isso
- void Tangente()
- {
- print(Mathf.Tan(0.5F));
- }
- //***TRIGONOMETRIA***//
- //Oscillator por Seno:
- Vector3 oscillatorStartPosition;
- void Oscillator()
- {
- oscillatorStartPosition = cube.transform.position;
- float x = oscillatorStartPosition.x;
- float y = 20 * Mathf.Sin(Time.timeSinceLevelLoad) + oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- cilinder.transform.position = new Vector3(x, y, z);
- }
- //SENO E COSCENO (Again)
- public bool useSin;
- public bool useCos;
- void UpdateOscillator()
- {
- oscillatorStartPosition = cilinder.transform.position;
- float x = oscillatorStartPosition.x;
- float y = oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- if (useSin)
- y = y + 20 * Mathf.Sin(Time.timeSinceLevelLoad);
- if (useCos)
- x = x + 20 * Mathf.Cos(Time.timeSinceLevelLoad);
- cilinder.transform.position = new Vector3(x, y, z);
- }
- //Phase Shift
- void UpdatePhaseShift()
- {
- oscillatorStartPosition = cilinder.transform.position;
- float x = oscillatorStartPosition.x;
- float y = oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- if (useSin)
- y = y + 20 * Mathf.Sin(Time.timeSinceLevelLoad);
- if (useCos)
- x = x + 20 * Mathf.Sin(Time.timeSinceLevelLoad + Mathf.PI/2);
- cilinder.transform.position = new Vector3(x, y, z);
- }
- //Tangente
- void TanOscillator()
- {
- oscillatorStartPosition = cilinder.transform.position;
- float x = oscillatorStartPosition.x;
- float y = oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- z = z + 10 * Mathf.Tan(Time.timeSinceLevelLoad * 3);
- cilinder.transform.position = new Vector3(x, y, z);
- }
- //Amplitude e frequência
- //Recomendavel copiar só esse algoritmo e colocar em varios objetos :)
- public float amplitude; //Copie e de um valor menor valor para cada um que passar (coloque um do lado do outro que vai ser da hora, irmão)
- public float frequency;
- public float phaseShift;
- void UpdateAmplitudeAndFrequency()
- {
- oscillatorStartPosition = cilinder.transform.position;
- float x = oscillatorStartPosition.x;
- float y = oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- if (useSin)
- y = y + 20 * Mathf.Sin(Time.timeSinceLevelLoad*frequency+phaseShift);
- if (useCos)
- x = x + 20 * Mathf.Cos(Time.timeSinceLevelLoad * frequency + phaseShift);
- transform.position = new Vector3(x, y, z);
- }
- //Usar nos animais fugindo (veja a viabilidade)
- void RunBambis()
- {
- oscillatorStartPosition = cilinder.transform.position;
- float x = oscillatorStartPosition.x;
- float y = oscillatorStartPosition.y;
- float z = oscillatorStartPosition.z;
- z = z + 10 * Mathf.Sin(Time.timeSinceLevelLoad) / Mathf.Cos(Time.timeSinceLevelLoad);
- transform.position = new Vector3(x, y, z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement