Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool Visable(Vector2 Position, Vector2 ObjectPosition, float LineOfSight, float Rotation, float Angle)
- {
- if (Utilities.Distance(Position, ObjectPosition) <= LineOfSight)
- {
- float rotation = Utilities.UnitAngle(Rotation);
- Vector2 Direction = Utilities.VectorDirection(Position, ObjectPosition);
- float Theta = Utilities.VectorDirection(Direction);
- if (rotation - Angle < 0)
- {
- float lol = Utilities.UnitAngle(rotation - Angle);
- if (Theta > lol)
- return true;
- }
- if (Direction.X > 0)
- Theta = (float)(2 * Math.PI - Theta);
- if (Theta > rotation - Angle & Theta < rotation + Angle)
- return true;
- else return false;
- }
- else return false;
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- namespace Testing_Project
- {
- public static class Utilities
- {
- private static Random random = new Random((int)DateTime.Now.Ticks);
- static Utilities() { }
- //Random
- /// <summary> A random value between min and max </summary>
- public static int Random(int min, int max)
- {
- return random.Next(min, max);
- }
- //// <summary> A random double; If negitive is true then value is between -max and max. If false then value is between 0 and max. </summary>
- /// <summary>
- /// A random double.
- /// </summary>
- /// <param name="max">The maximum value the function can return</param>
- /// <param name="negitive">If false, the minimum value will be 0. If true, the minimum value will be -max.</param>
- public static double Random(double max, bool negitive)
- {
- if (negitive) return (random.NextDouble() * max * 2) - max;
- else return random.NextDouble() * max;
- }
- //Vector Math
- public static float Distance(Vector2 Position1, Vector2 Position2)
- {
- float x = Position1.X - Position2.X;
- float y = Position1.Y - Position2.Y;
- return (float)Math.Sqrt(x * x + y * y);
- }
- public static Vector2 Normalize(Vector2 input)
- {
- input.Normalize();
- if (float.IsNaN(input.X))
- input = new Vector2(0);
- return input;
- }
- public static Vector2 VectorDirection(float Rotation)
- {
- Vector2 oh = new Vector2(-1 * (float)Math.Sin(Rotation), (float)Math.Cos(Rotation));
- Vector2 lol = Utilities.Normalize(new Vector2(-1 * (float)Math.Sin(Rotation), (float)Math.Cos(Rotation)));
- return Utilities.Normalize(new Vector2(-1 * (float)Math.Sin(Rotation), (float)Math.Cos(Rotation)));
- }
- public static Vector2 VectorDirection(Vector2 PointOfReferance, Vector2 ObjectPosition)
- {
- return Utilities.Normalize(ObjectPosition - PointOfReferance);
- }
- public static float VectorDirection(Vector2 Direction)
- {
- Direction = Utilities.Normalize(Direction);
- return (float)Math.Acos(Direction.Y);
- }
- public static float UnitAngle(float Rotation)
- {
- while (Rotation > 2 * Math.PI)
- Rotation -= (float)(2 * Math.PI);
- while (Rotation < 0)
- Rotation += (float)(2 * Math.PI);
- return Rotation;
- }
- public static float VectorDirectionPropper(Vector2 Direction)
- {
- double pi = Math.PI;
- float x = Direction.X;
- float y = Direction.Y;
- float theta = Utilities.VectorDirection(Direction);
- /*
- if (x > 0 & y > 0) theta = -(float)(Math.PI - theta);
- if (x < 0 & y > 0) theta = (float)(Math.PI - theta);
- if (x < 0 & y < 0) theta = (float)(Math.PI + theta);
- if (x > 0 & y < 0) theta = theta;
- */
- return theta;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement