void RotateGuiControl(EControl sender, float alpha, Texture guiTexture, GuiRenderer renderer) { Rect controlRect = sender.GetScreenRectangle(); Rect screenMapRect = sender.GetScreenRectangle(); Vec2 size = controlRect.GetSize(); float angle = MathFunctions.DegToRad(alpha); float smallRadius = 0.03f; float bigRadius = 0.8f; float width = 0.15f; Vec2 U = new Vec2(+(float)Math.Cos(angle), +(float)Math.Sin(angle)); Vec2 V = new Vec2(-(float)Math.Sin(angle), +(float)Math.Cos(angle)); Vec2 P1 = bigRadius * U + V * width / 2; Vec2 P2 = bigRadius * U - V * width / 2; Vec2 P3 = smallRadius * U + V * width / 2; Vec2 P4 = smallRadius * U - V * width / 2; float X1 = Vec2.Dot(P1, Vec2.XAxis); float Y1 = Vec2.Dot(P1, Vec2.YAxis); float X2 = Vec2.Dot(P2, Vec2.XAxis); float Y2 = Vec2.Dot(P2, Vec2.YAxis); float X3 = Vec2.Dot(P3, Vec2.XAxis); float Y3 = Vec2.Dot(P3, Vec2.YAxis); float X4 = Vec2.Dot(P4, Vec2.XAxis); float Y4 = Vec2.Dot(P4, Vec2.YAxis); X1 = controlRect.Left + (X1 + 1) / 2 * size.X ; Y1 = controlRect.Top + (Y1 + 1) / 2 * size.Y ; X2 = controlRect.Left + (X2 + 1) / 2 * size.X; Y2 = controlRect.Top + (Y2 + 1) / 2 * size.Y ; X3 = controlRect.Left + (X3 + 1) / 2 * size.X; Y3 = controlRect.Top + (Y3 + 1) / 2 * size.Y ; X4 = controlRect.Left + (X4 + 1) / 2 * size.X; Y4 = controlRect.Top + (Y4 + 1) / 2 * size.Y ; List<GuiRenderer.TriangleVertex> vert = new List<GuiRenderer.TriangleVertex>(6); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X1, Y1), new ColorValue(1, 1, 1, 1), new Vec2(0, 0))); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X2, Y2), new ColorValue(1, 1, 1, 1), new Vec2(1, 0))); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X4, Y4), new ColorValue(1, 1, 1, 1), new Vec2(0, 1))); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X3, Y3), new ColorValue(1, 1, 1, 1), new Vec2(1, 1))); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X4, Y4), new ColorValue(1, 1, 1, 1), new Vec2(0, 1))); vert.Add(new GuiRenderer.TriangleVertex(new Vec2(X2, Y2), new ColorValue(1, 1, 1, 1), new Vec2(1, 0))); renderer.AddTriangles(vert, guiTexture, false); }
//Draw minimap void Minimap_RenderUI( EControl sender, GuiRenderer renderer ) { Rect screenMapRect = sender.GetScreenRectangle(); Bounds initialBounds = Map.Instance.InitialCollisionBounds; Rect mapRect = new Rect( initialBounds.Minimum.ToVec2(), initialBounds.Maximum.ToVec2() ); Vec2 mapSizeInv = new Vec2( 1, 1 ) / mapRect.Size; //draw units Vec2 screenPixel = new Vec2( 1, 1 ) / new Vec2( EngineApp.Instance.VideoMode.Size.ToVec2() ); foreach( Entity entity in Map.Instance.Children ) { RTSUnit unit = entity as RTSUnit; if( unit == null ) continue; Rect rect = new Rect( unit.MapBounds.Minimum.ToVec2(), unit.MapBounds.Maximum.ToVec2() ); rect -= mapRect.Minimum; rect.Minimum *= mapSizeInv; rect.Maximum *= mapSizeInv; rect.Minimum = new Vec2( rect.Minimum.X, 1.0f - rect.Minimum.Y ); rect.Maximum = new Vec2( rect.Maximum.X, 1.0f - rect.Maximum.Y ); rect.Minimum *= screenMapRect.Size; rect.Maximum *= screenMapRect.Size; rect += screenMapRect.Minimum; //increase 1 pixel rect.Maximum += new Vec2( screenPixel.X, -screenPixel.Y ); ColorValue color; if( playerFaction == null || unit.Intellect == null || unit.Intellect.Faction == null ) color = new ColorValue( 1, 1, 0 ); else if( playerFaction == unit.Intellect.Faction ) color = new ColorValue( 0, 1, 0 ); else color = new ColorValue( 1, 0, 0 ); renderer.AddQuad( rect, color ); } //Draw camera borders { Camera camera = RendererWorld.Instance.DefaultCamera; if( camera.Position.Z > 0 ) { Plane groundPlane = new Plane( 0, 0, 1, 0 ); Vec2[] points = new Vec2[ 4 ]; for( int n = 0; n < 4; n++ ) { Vec2 p = Vec2.Zero; switch( n ) { case 0: p = new Vec2( 0, 0 ); break; case 1: p = new Vec2( 1, 0 ); break; case 2: p = new Vec2( 1, 1 ); break; case 3: p = new Vec2( 0, 1 ); break; } Ray ray = camera.GetCameraToViewportRay( p ); float scale; groundPlane.RayIntersection( ray, out scale ); Vec3 pos = ray.GetPointOnRay( scale ); if( ray.Direction.Z > 0 ) pos = ray.Origin + ray.Direction.GetNormalize() * 10000; Vec2 point = pos.ToVec2(); point -= mapRect.Minimum; point *= mapSizeInv; point = new Vec2( point.X, 1.0f - point.Y ); point *= screenMapRect.Size; point += screenMapRect.Minimum; points[ n ] = point; } for( int n = 0; n < 4; n++ ) renderer.AddLine( points[ n ], points[ ( n + 1 ) % 4 ], new ColorValue( 1, 1, 1 ), screenMapRect ); } } }
// TASK: Draw minimap void Minimap_RenderUI(EControl sender, GuiRenderer renderer) { Rect screenMapRect = sender.GetScreenRectangle(); //Get Map Rectange Bounds initialBounds = Map.Instance.InitialCollisionBounds; Rect mapRect = new Rect(initialBounds.Minimum.ToVec2(), initialBounds.Maximum.ToVec2()); Vec2 mapSizeInv = new Vec2(1, 1) / mapRect.Size; Unit playerUnit = GetPlayerUnit(); Rect rect = new Rect(playerUnit.MapBounds.Minimum.ToVec2(), playerUnit.MapBounds.Maximum.ToVec2() ); //Get position in the worldmap 2d image float worldMapX = (playerUnit.Position.X + 500) / 1000 * 512; float worldMapY = (playerUnit.Position.Y + 500) / 1000 * 512; //Get begin cliped rectange postion in the worldmap 2d image float x1 = worldMapX - 56; float y1 = worldMapY - 56; float x2 = x1 + 128; float y2 = x2 + 128; //Convert to % unit : 0.00...1.00 float fx1 = x1 / 512.0f; float fy1 = (float)y1 / 512.0f; float fx2 = x2 / 512.0f; float fy2 = y2 / 512.0f; Rect coordRect = new Rect(fx1, fy1, fx2, fy2); minimapControl.BackTextureCoord = coordRect; // //draw units // Vec2 screenPixel = new Vec2(1, 1) / new Vec2(EngineApp.Instance.VideoMode.Size.ToVec2()); // { // ////Loading texture to the engine // //Texture texture = null; // //string mapDirectory = Path.GetDirectoryName(mapName); // //string textureName = mapDirectory + "\\Data\\Minimap"; // //string textureFileName = "Minimap"; // //bool finded = false; // //string[] extensions = new string[] { "dds", "tga", "png", "jpg" }; // //foreach (string extension in extensions) // //{ // // textureFileName = textureName + "." + extension; // // if (VirtualFile.Exists(textureFileName)) // // { // // finded = true; // // break; // // } // //} // //if (finded) // // texture = TextureManager.Instance.Load(textureFileName); // Unit playerUnit = GetPlayerUnit(); // Rect rect = new Rect(playerUnit.MapBounds.Minimum.ToVec2(), // playerUnit.MapBounds.Maximum.ToVec2() // ); // rect -= mapRect.Minimum; // rect.Minimum *= mapSizeInv; // rect.Maximum *= mapSizeInv; // rect.Minimum = new Vec2(rect.Minimum.X, 1.0f - rect.Minimum.Y); // rect.Maximum = new Vec2(rect.Maximum.X, 1.0f - rect.Maximum.Y); // rect.Minimum *= screenMapRect.Size; // rect.Maximum *= screenMapRect.Size; // rect += screenMapRect.Minimum; // //increase 1 pixel // rect.Maximum += new Vec2(screenPixel.X, -screenPixel.Y); // ColorValue color; // if (playerUnit.Intellect == null || playerUnit.Intellect.Faction == null) // color = new ColorValue(1, 1, 0); // else // color = new ColorValue(1, 0, 0); // renderer.AddQuad(rect, color); // } // //foreach (Entity entity in Map.Instance.Children) // //{ // // GameCharacter unit = entity as GameCharacter; // // if (unit == null) // // continue; // // Rect rect = new Rect(unit.MapBounds.Minimum.ToVec2(), unit.MapBounds.Maximum.ToVec2()); // // rect -= mapRect.Minimum; //// rect.Minimum *= mapSizeInv; //// rect.Maximum *= mapSizeInv; //// rect.Minimum = new Vec2(rect.Minimum.X, 1.0f - rect.Minimum.Y); //// rect.Maximum = new Vec2(rect.Maximum.X, 1.0f - rect.Maximum.Y); //// rect.Minimum *= screenMapRect.Size; //// rect.Maximum *= screenMapRect.Size; //// rect += screenMapRect.Minimum; //// //increase 1 pixel //// rect.Maximum += new Vec2(screenPixel.X, -screenPixel.Y); //// ColorValue color; //// if (unit.Intellect == null || unit.Intellect.Faction == null) //// color = new ColorValue(1, 1, 0); //// else //// color = new ColorValue(1, 0, 0); //// renderer.AddQuad(rect, color); ////} // //Draw camera borders // { // // Camera camera = RendererWorld.Instance.DefaultCamera; // // if (camera.Position.Z > 0) // // { // // Plane groundPlane = new Plane(0, 0, 1, 0); // // Vec2[] points = new Vec2[4]; // // for (int n = 0; n < 4; n++) // // { // // Vec2 p = Vec2.Zero; // // switch (n) // // { // // case 0: p = new Vec2(0, 0); break; // // case 1: p = new Vec2(1, 0); break; // // case 2: p = new Vec2(1, 1); break; // // case 3: p = new Vec2(0, 1); break; // // } // // Ray ray = camera.GetCameraToViewportRay(p); // // float scale; // // groundPlane.RayIntersection(ray, out scale); // // Vec3 pos = ray.GetPointOnRay(scale); // // if (ray.Direction.Z > 0) // // pos = ray.Origin + ray.Direction.GetNormalize() * 10000; // // Vec2 point = pos.ToVec2(); // // point -= mapRect.Minimum; // // point *= mapSizeInv; // // point = new Vec2(point.X, 1.0f - point.Y); // // point *= screenMapRect.Size; // // point += screenMapRect.Minimum; // // points[n] = point; // // } // // for (int n = 0; n < 4; n++) // // renderer.AddLine(points[n], points[(n + 1) % 4], new ColorValue(1, 1, 1), // // screenMapRect); // // } // } }