private MathVector GetAverageVector(List <MathVector> list)
        {
            var result = new MathVector();

            for (int i = 0; i < list[0].Dimensions; i++)
            {
                double sum   = 0.0;
                int    count = 0;

                for (int j = 0; j < list.Count; j++)
                {
                    sum += list[j][i];
                    count++;
                }

                result.Add(sum / count);
            }

            return(result);
        }
예제 #2
0
        public List <MathVector> rayVectors()
        {
            // Do a bunch of nasty math and get all the vectors we're interested in <3

            if (castRayVectors == null)
            {
                castRayVectors = new List <MathVector>();
                castRayVectors.Add(cameraDirection);

                double pixelsRightLeft = 480;
                double pixelsUpDown    = 320;

                double pixelsPerGapRightLeft = pixelsRightLeft / VECTORSRIGHTLEFT;
                double pixelsPerGapUpDown    = pixelsUpDown / VECTORSUPDOWN;

                for (int i = 0; i < (VECTORSRIGHTLEFT / 2); i++)
                {
                    for (int j = 0; j < (VECTORSUPDOWN / 2); j++)
                    {
                        // note that we are doing all our math in a transformed basis where the camera normal = [1,0,0]
                        double upDownAngle    = i * pixelsPerGapUpDown * VIEWINGANGLEUPDOWN / (pixelsUpDown / 2);
                        double rightLeftAngle = j * pixelsPerGapRightLeft * VIEWINGANGLERIGHTLEFT / (pixelsRightLeft / 2);

                        MathVector xyVect = mathUtils.CreateVector(new double[] { Math.Cos(upDownAngle),
                                                                                  Math.Sin(upDownAngle),
                                                                                  0 });
                        MathVector xzVect = mathUtils.CreateVector(new double[] { Math.Cos(rightLeftAngle),
                                                                                  0,
                                                                                  Math.Sin(rightLeftAngle) });
                        MathVector Q1Ray = (xyVect.Add(xzVect)).Normalise;

                        xyVect = mathUtils.CreateVector(new double[] { Math.Cos(-upDownAngle),
                                                                       Math.Sin(-upDownAngle),
                                                                       0 });
                        xzVect = mathUtils.CreateVector(new double[] { Math.Cos(rightLeftAngle),
                                                                       0,
                                                                       Math.Sin(rightLeftAngle) });
                        MathVector Q2Ray = (xyVect.Add(xzVect)).Normalise;

                        xyVect = mathUtils.CreateVector(new double[] { Math.Cos(-upDownAngle),
                                                                       Math.Sin(-upDownAngle),
                                                                       0 });
                        xzVect = mathUtils.CreateVector(new double[] { Math.Cos(-rightLeftAngle),
                                                                       0,
                                                                       Math.Sin(-rightLeftAngle) });
                        MathVector Q3Ray = (xyVect.Add(xzVect)).Normalise;

                        xyVect = mathUtils.CreateVector(new double[] { Math.Cos(upDownAngle),
                                                                       Math.Sin(upDownAngle),
                                                                       0 });
                        xzVect = mathUtils.CreateVector(new double[] { Math.Cos(-rightLeftAngle),
                                                                       0,
                                                                       Math.Sin(-rightLeftAngle) });
                        MathVector Q4Ray = (xyVect.Add(xzVect)).Normalise;

                        castRayVectors.Add(transformBack(Q1Ray));
                        castRayVectors.Add(transformBack(Q2Ray));
                        castRayVectors.Add(transformBack(Q3Ray));
                        castRayVectors.Add(transformBack(Q4Ray));

                        // the most extreme vectors will be the last ones we loop to, so we'll just
                        // set these values every time, and we'll get the correct ones when we are done
                        edgeOfQ1 = Q1Ray;
                        edgeOfQ2 = Q2Ray;
                        edgeOfQ3 = Q3Ray;
                        edgeOfQ4 = Q4Ray;
                    }
                }
            }
            return(castRayVectors);
        }