Beispiel #1
0
        private void TestZ(GLMatrixCalc c, Vector4[] boundingbox, float zpoint)
        {
            Vector4[] modelboundingbox = boundingbox.Transform(c.ModelMatrix);

            Vector4[] intercepts = new Vector4[6];
            Vector3[] texpoints  = new Vector3[6];
            int       count      = 0;

            modelboundingbox[0].FindVectorFromZ(modelboundingbox[1], ref intercepts, ref texpoints, new Vector3(0, 9, 0), ref count, zpoint);
            modelboundingbox[1].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref texpoints, new Vector3(9, 1, 0), ref count, zpoint);
            modelboundingbox[3].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref texpoints, new Vector3(1, 9, 0), ref count, zpoint);
            modelboundingbox[0].FindVectorFromZ(modelboundingbox[3], ref intercepts, ref texpoints, new Vector3(9, 0, 0), ref count, zpoint);

            modelboundingbox[4].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref texpoints, new Vector3(0, 9, 1), ref count, zpoint);
            modelboundingbox[5].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(9, 1, 1), ref count, zpoint);
            modelboundingbox[7].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(1, 9, 1), ref count, zpoint);
            modelboundingbox[4].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref texpoints, new Vector3(9, 0, 1), ref count, zpoint);

            modelboundingbox[0].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref texpoints, new Vector3(0, 0, 9), ref count, zpoint);
            modelboundingbox[1].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref texpoints, new Vector3(0, 1, 9), ref count, zpoint);
            modelboundingbox[2].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref texpoints, new Vector3(1, 1, 9), ref count, zpoint);
            modelboundingbox[3].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref texpoints, new Vector3(1, 0, 9), ref count, zpoint);

            if (count >= 3)
            {
                Vector4 avg    = intercepts.Average();
                float[] angles = new float[6];
                for (int i = 0; i < count; i++)
                {
                    angles[i] = -(float)Math.Atan2(intercepts[i].Y - avg.Y, intercepts[i].X - avg.X);        // all on the same z plane, so x/y only need be considered
                    System.Diagnostics.Debug.WriteLine("C" + intercepts[i].ToStringVec() + " ang " + angles[i].Degrees() + " t " + texpoints[i]);
                }
            }
        }
        private void ControllerDraw(Controller3D mc, ulong unused)
        {
            ((GLMatrixCalcUniformBlock)items.UB("MCUB")).Set(gl3dcontroller.MatrixCalc);        // set the matrix unform block to the controller 3d matrix calc.


            Vector4[] modelboundingbox = boundingbox.Transform(gl3dcontroller.MatrixCalc.ModelMatrix);

            for (int i = 0; i < boundingbox.Length; i++)
            {
                System.Diagnostics.Debug.WriteLine(i + " = " + modelboundingbox[i].ToStringVec());
            }

            modelboundingbox.MinMaxZ(out int minz, out int maxz);

            System.Diagnostics.Debug.WriteLine("min " + minz + " max " + maxz);
            indicatorlinebuffer.StartWrite(0, sizeof(float) * 4 * 2);
            indicatorlinebuffer.Write(boundingbox[minz]);
            indicatorlinebuffer.Write(boundingbox[maxz]);
            indicatorlinebuffer.StopReadWrite();

            float percent = 0.2f;
            float zdist   = modelboundingbox[maxz].Z - modelboundingbox[minz].Z;

            {
                float zpoint = modelboundingbox[maxz].Z - zdist * percent;
                //System.Diagnostics.Debug.WriteLine("Zpoint is" + zpoint);

                Vector4[] intercepts = new Vector4[6];
                int       count      = 0;
                modelboundingbox[0].FindVectorFromZ(modelboundingbox[1], ref intercepts, ref count, zpoint);
                modelboundingbox[1].FindVectorFromZ(modelboundingbox[2], ref intercepts, ref count, zpoint);
                modelboundingbox[2].FindVectorFromZ(modelboundingbox[3], ref intercepts, ref count, zpoint);
                modelboundingbox[3].FindVectorFromZ(modelboundingbox[0], ref intercepts, ref count, zpoint);

                modelboundingbox[4].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref count, zpoint);
                modelboundingbox[5].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref count, zpoint);
                modelboundingbox[6].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref count, zpoint);
                modelboundingbox[7].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref count, zpoint);

                modelboundingbox[0].FindVectorFromZ(modelboundingbox[4], ref intercepts, ref count, zpoint);
                modelboundingbox[1].FindVectorFromZ(modelboundingbox[5], ref intercepts, ref count, zpoint);
                modelboundingbox[2].FindVectorFromZ(modelboundingbox[6], ref intercepts, ref count, zpoint);
                modelboundingbox[3].FindVectorFromZ(modelboundingbox[7], ref intercepts, ref count, zpoint);

                // texturecoords can be worked out by zpercent and knowing its direction (x,y,z)..

                if (count >= 3)
                {
                    Vector4 avg    = intercepts.Average();
                    float[] angles = new float[6];
                    for (int i = 0; i < count; i++)
                    {
                        angles[i] = -(float)Math.Atan2(intercepts[i].Y - avg.Y, intercepts[i].X - avg.X);        // all on the same z plane, so x/y only need be considered
                        System.Diagnostics.Debug.WriteLine("C" + intercepts[i].ToStringVec() + " " + angles[i].Degrees());
                    }

                    Array.Sort(angles, intercepts, 0, count);       // sort by angles, sorting intercepts, from 0 to count

                    for (int i = 0; i < count; i++)
                    {
                        //    System.Diagnostics.Debug.WriteLine(intercepts[i].ToStringVec() + " " + angles[i].Degrees());
                    }

                    interceptpointbuffer.StartWrite(0, sizeof(float) * 4 * count);
                    int ji = 0;
                    for (; ji < count; ji++)
                    {
                        interceptpointbuffer.Write(intercepts[ji]);
                    }
                    interceptpointbuffer.StopReadWrite();
                    interceptri.DrawCount = count;

                    surfacebuffer.StartWrite(0, sizeof(float) * 4 * (2 + count));
                    surfacebuffer.Write(avg);
                    for (ji = 0; ji < count; ji++)
                    {
                        surfacebuffer.Write(intercepts[ji]);
                    }

                    surfacebuffer.Write(intercepts[0]);
                    surfacebuffer.StopReadWrite();

                    surfaceri.DrawCount = count + 2;
                }
            }

            rObjects.Render(glwfc.RenderState, gl3dcontroller.MatrixCalc);

            this.Text = "Looking at " + gl3dcontroller.MatrixCalc.LookAt + " dir " + gl3dcontroller.PosCamera.CameraDirection + " eye@ " + gl3dcontroller.MatrixCalc.EyePosition + " Dist " + gl3dcontroller.MatrixCalc.EyeDistance;
        }
Beispiel #3
0
 public static float Average(this Vector4 vector)
 {
     return(vector.Average(Axes.XYZW));
 }