public void Draw() { RLVector2 formattedPosition; formattedPosition.x = GetPosition().x; formattedPosition.y = GetPosition().y; Rectangle spriteRect = new Rectangle(); spriteRect.x = 0; spriteRect.y = 0; spriteRect.width = image.width; spriteRect.height = image.height; Rectangle posRect = new Rectangle(); posRect.x = globalTransform.m7; posRect.y = globalTransform.m8; posRect.width = image.width; posRect.height = image.height; RLVector2 origin = new RLVector2(); origin.x = spriteOrigin.x; origin.y = spriteOrigin.y; DrawTexturePro(texture, spriteRect, posRect, origin, GetRotation(), RLColor.WHITE); List <GameObject> childrenCurrent = new List <GameObject>(children); foreach (GameObject child in childrenCurrent) { child.Draw(); } }
static void UpdateTexture() { //for math.atan2 when both variables are zero, it returns the wrong thing. so it is removed. //then the points are ordered by their angle points = points.Where(p => p.y != origin.y || p.x != origin.x).OrderBy(p => - Math.Atan2(p.y - origin.y, p.x - origin.x)).ToArray(); //a new array where everything is reletive to the origin is set. //[0] in the array is set to be the origin. (DrawTriangleFan requires the origin to be at that position) //the last value in the array is set to be the same as the first value in the array so that the final triangle is drawn to complete the loop //-screen offset is added to everything so that the triangle fan is drawn in the middle of the render texture instead of the top left corner RLVector2[] plusOrigin = new RLVector2[points.Length + 2]; for (int i = 0; i < points.Length; i++) { plusOrigin[i + 1] = points[i] - origin - screenOffset; } plusOrigin[0] = -1 * screenOffset; plusOrigin[plusOrigin.Length - 1] = plusOrigin[1]; //this basically makes a texture based on the triangle fan BeginTextureMode(lineOfSightTexture); ClearBackground(RLColor.BLACK); DrawTriangleFan(plusOrigin, plusOrigin.Length, RLColor.WHITE); EndTextureMode(); //the triangle fan covers all the areas the player can see. those areas are drawn as white on the render texture, everything else is black }
public static Vector2 get_vector(RLVector2 _vector) { Vector2 result = new Vector2(); result.x = _vector.x; result.y = _vector.y; return(result); }
// --------------------- // // PUBLIC STATIC METHODS // // --------------------- // public static RLVector2 get_RLVector2(Vector2 _vector) { RLVector2 result = new RLVector2(); result.x = _vector.x; result.y = _vector.y; return(result); }
//-------------------------------------------------------------- //-------------------------------------------------------------- public static Vector2 ToVector2(this RLVector2 vec) { Vector2 result; result.x = vec.x; result.y = vec.y; return(result); }
//-------------------------------------------------------------- //-------------------------------------------------------------- public static void DrawTexture(Texture2D texture, Matrix3 transform, Colour color) { Vector2 xAxis = new Vector2(); xAxis.x = transform.m1; xAxis.y = transform.m2; Vector2 yAxis = new Vector2(); yAxis.x = transform.m4; yAxis.y = transform.m5; //Note - the angle of a unit circle count up when they go anticlockwise, //but because in Raylib land positive Y is down, a positive angle will //be clockwise. float angle = (float)Math.Atan2(xAxis.y, xAxis.x); float scaleX = xAxis.Magnitude(); float scaleY = yAxis.Magnitude(); //The portion of the image to render Rectangle source = new Rectangle(); source.width = texture.width; source.height = texture.height; //Origin to rotate around RLVector2 origin = new RLVector2(); origin.x = texture.width * 0.5f; origin.y = texture.height * 0.5f; //The target position and size to render at Rectangle destination = new Rectangle(); destination.x = transform.m7; destination.y = transform.m8; destination.width = source.width * scaleX; destination.height = source.height * scaleY; //We multiply the angle by 180/pi because the matrix library for the project //works in radians (that's what the unit tests require) but RayLib expects degrees. float degrees = angle * 180.0f / (float)Math.PI; //Convert our color class to a raylib colour RLColor rlColor = new RLColor(color.GetRed(), color.GetGreen(), color.GetBlue(), color.GetAlpha()); //Draw texture DrawTexturePro(texture, source, destination, origin, degrees, rlColor); }
//-------------------------------------------------------------- //-------------------------------------------------------------- public static Vector2 GetMousePosition() { RLVector2 pos = Raylib.Raylib.GetMousePosition(); return(pos.ToVector2()); }