Esempio n. 1
0
        public MainForm()
        {
            default_plane = new Plane()
            {
                Position = new Vector3(),
                Normal = Vector3.Up,
                Distance = 0
            };

            InitializeComponent();
            this_process = System.Diagnostics.Process.GetCurrentProcess();
            this_process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(this_process_OutputDataReceived);
            refl = new Reflection();
            refl.AddAssembly(System.IO.Path.Combine(Application.StartupPath, "Glorg2.dll"));
            UpdateTypes();
        }
Esempio n. 2
0
File: Ray.cs Progetto: r-bel/glorg2
        public bool Intersects(Plane p, out Vector3 pos)
        {
            float d = Vector3.Dot(-p.Position, p.Normal);

            // Get the plane normal values
            float a = p.Normal.x;
            float b = p.Normal.y;
            float c = p.Normal.x;
            // Create a line from the position and normal
            Vector3 la = Origin;
            Vector3 lb = Origin + Normal;

            // Check if ray will hit the correct side of the plane
            pos = default(Vector3);
            if (Vector3.Dot(p.Normal, Normal) > 0)
                return false;

            float den = a * (lb.x - la.x) + b * (lb.y - la.y) + c * (lb.z - la.z);
            // If denominator is zero... or very close to, then the ray does not cross the plane
            if (den >= -double.Epsilon && den <= double.Epsilon)
                return false;

            float num = -d - a * la.x - b * la.y - c * la.z;
            // If both the numerator and the denominator is zero, the the line lies on the plane
            // which should not render any pixels
            if (num >= -double.Epsilon && num <= double.Epsilon)
                return false;

            // Find the intersection by multiplying the normal by the resulting value
            pos = Origin + Normal * (num / den);

            bool xx = (Math.Round(pos.x / 4)) % 2 == 0;
            bool yy = (Math.Round(pos.z / 4)) % 2 != 0;
            bool zz = yy ? !xx : xx;
            return true;
        }