コード例 #1
0
        public ActionResult CalculateDistances(int id)
        {
            RaceDetails details = _raceRepository.GetRaceDetails(UserContext.User.Id, UserContext.User.OrganizationId, id);

            if (details.Detail == null || details.Detail.EntityStateId != Dom.EntityType.Race.State.Open)
            {
                return(NotFoundResult());
            }

            Race race = _raceRepository.Get <Race>(id);

            race.RaceDistances.ToList().ForEach(x => _raceRepository.Delete(x));
            var members = race.RacePigeons.Select(m => m.Pigeon.Member).Distinct().ToList();

            foreach (var member in members)
            {
                race.RaceDistances.Add(new RaceDistance
                {
                    Distance = member.Address?.Latitude == null
                                                ? 0
                                                : CoordinatesManager.CalculateDistance(member.Address.Latitude, member.Address.Longitude,
                                                                                       race.Point.Address.Latitude, race.Point.Address.Longitude),
                    MemberId = member.Id
                });
            }
            _raceRepository.UnitOfWork.SaveChanges();

            return(RedirectToAction(Mvc.Controller.Race.Details, Mvc.Controller.Race.Name, new { id }));
        }
コード例 #2
0
 public CoordinatesController(CoordinatesManager coordinatesManager)
 {
     this.coordinatesManager = coordinatesManager;
 }
コード例 #3
0
        static void Main(string[] args)
        {
            Glut.glutInit();
            Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_DEPTH | Glut.GLUT_MULTISAMPLE);   // multisampling makes things beautiful!
            Glut.glutInitWindowSize(width, height);
            Glut.glutCreateWindow("OpenGL Tutorial");

            Glut.glutIdleFunc(OnRenderFrame);
            Glut.glutDisplayFunc(OnDisplay);

            Glut.glutKeyboardFunc(OnKeyboardDown);
            Glut.glutKeyboardUpFunc(OnKeyboardUp);

            Glut.glutCloseFunc(OnClose);
            Glut.glutReshapeFunc(OnReshape);

            // add our mouse callbacks for this tutorial
            Glut.glutMouseFunc(OnMouse);
            Glut.glutMotionFunc(OnMove);

            Gl.Enable(EnableCap.DepthTest);
            Gl.Enable(EnableCap.Blend);
            Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            // create our shader program
            program = new ShaderProgram(VertexShader, FragmentShader);

            // create our camera
            camera = new Camera(new Vector3(0, 0, 0), Quaternion.Identity);
            camera.SetDirection(new Vector3(0, 0, -1));

            // set up the projection and view matrix
            program.Use();
            program["projection_matrix"].SetValue(Matrix4.CreatePerspectiveFieldOfView(0.45f, (float)width / height, 0.1f, 1000f));
            //program["view_matrix"].SetValue(Matrix4.LookAt(new Vector3(0, 0, 10), Vector3.Zero, Vector3.Up));

            program["light_direction"].SetValue(new Vector3(0, 0, 1));

            program["normalTexture"].SetValue(1);

            brickDiffuse = new Texture("333.jpg");


            var sphereCoordinates = CoordinatesManager.GetSphereCoordinates().ToArray();

            var UVcoordinates = new List <Vector2>();

            for (int i = 0; i < sphereCoordinates.Length / 4; i++)
            {
                UVcoordinates.Add(new Vector2(0, 0));
                UVcoordinates.Add(new Vector2(1, 0));
                UVcoordinates.Add(new Vector2(1, 1));
                UVcoordinates.Add(new Vector2(0, 1));
            }
            var sphereUV = new VBO <Vector2>(UVcoordinates.ToArray());


            Vector3[] vertices = new Vector3[] {
                new Vector3(1, 1, -1), new Vector3(-1, 1, -1), new Vector3(-1, 1, 1), new Vector3(1, 1, 1),         // top
                new Vector3(1, -1, 1), new Vector3(-1, -1, 1), new Vector3(-1, -1, -1), new Vector3(1, -1, -1),     // bottom
                new Vector3(1, 1, 1), new Vector3(-1, 1, 1), new Vector3(-1, -1, 1), new Vector3(1, -1, 1),         // front face
                new Vector3(1, -1, -1), new Vector3(-1, -1, -1), new Vector3(-1, 1, -1), new Vector3(1, 1, -1),     // back face
                new Vector3(-1, 1, 1), new Vector3(-1, 1, -1), new Vector3(-1, -1, -1), new Vector3(-1, -1, 1),     // left
                new Vector3(1, 1, -1), new Vector3(1, 1, 1), new Vector3(1, -1, 1), new Vector3(1, -1, -1)
            };
            cube = new VBO <Vector3>(sphereCoordinates);

            Vector2[] uvs = new Vector2[] {
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1),
                new Vector2(0, 0), new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1)
            };
            cubeUV = CoordinatesManager.GetSphereUVCoordinates();

            List <uint> triangles = new List <uint>();

            for (uint i = 0; i < 6; i++)
            {
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 1);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4);
                triangles.Add(i * 4 + 2);
                triangles.Add(i * 4 + 3);
            }
            //cubeTriangles = new VBO<uint>(triangles.ToArray(), BufferTarget.ElementArrayBuffer);
            cubeTriangles =
                new VBO <uint>(Enumerable.Range(0, sphereCoordinates.Length * 4).Select(t => (uint)t).ToArray(),
                               BufferTarget.ElementArrayBuffer);

            // Vector3[] normals = Geometry.CalculateNormals(vertices, triangles.ToArray());
            //cubeNormals = new VBO<Vector3>(normals);



            // load the bitmap font for this tutorial
            font        = new BMFont("font24.fnt", "font24.png");
            fontProgram = new ShaderProgram(BMFont.FontVertexSource, BMFont.FontFragmentSource);

            fontProgram.Use();
            fontProgram["ortho_matrix"].SetValue(Matrix4.CreateOrthographic(width, height, 0, 1000));
            fontProgram["color"].SetValue(new Vector3(1, 1, 1));

            information = font.CreateString(fontProgram, "OpenGL C# Tutorial 15");

            watch = System.Diagnostics.Stopwatch.StartNew();

            Glut.glutMainLoop();
        }