Exemple #1
0
        protected void checkVertices()
        {
            Ray r = GetMouseRay(new Vector2(prevMState.Position.X, prevMState.Position.Y), GraphicsDevice.Viewport, effect);

            r.Position  = new Vector3(r.Position.X, r.Position.Z, r.Position.Y);
            r.Direction = new Vector3(r.Direction.X, r.Direction.Z, r.Direction.Y);
            // Vector3D x1 =  new Vector3D(cameraX + offsetX, cameraY + offsetY, cameraZ + offsetZ);
            //Vector3D x2 = new Vector3D(centerX + offsetX, centerY + offsetY, centerZ + offsetZ);
            Vector3D x1 = new Vector3D(r.Position);
            Vector3D x2 = new Vector3D(r.Position + r.Direction);
            //Program.useCheckingPoint = true;
            // Program.checkingPoint = new System.Numerics.Vector3(x2.X,x2.Z,x2.Y);
            // Program.updateVertices();
            Vector3D miniPoint  = new Vector3D();
            float    ptDistance = float.MaxValue;

            targetV = null;
            foreach (SoulsFormats.FLVER.Vertex v in Program.vertices)
            {
                if (v.Positions[0] == null)
                {
                    continue;
                }
                float dis = Vector3D.calculateDistanceFromLine(new Vector3D(v.Positions[0]), x1, x2);
                if (ptDistance > dis)
                {
                    miniPoint  = new Vector3D(v.Positions[0]);
                    ptDistance = dis;
                    targetV    = v;
                }
            }

            if (Program.setVertexPos)
            {
                targetV.Positions[0] = new Vector3D(Program.setVertexX, Program.setVertexY, Program.setVertexZ).toNumV3();
            }

            Program.useCheckingPoint = true;
            Program.checkingPoint    = new System.Numerics.Vector3(miniPoint.X, miniPoint.Y, miniPoint.Z);

            if (targetV.Normals != null && targetV.Normals.Count > 0)
            {
                Program.checkingPointNormal = new System.Numerics.Vector3(targetV.Normals[0].X, targetV.Normals[0].Y, targetV.Normals[0].Z);
            }
            else
            {
                Program.checkingPointNormal = new System.Numerics.Vector3(0, 0, 0);
            }

            Program.updateVertices();

            if (targetV != null)
            {
                string text = Program.FormatOutput(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(targetV));
                int    l    = text.Length / 2;
                System.Windows.Forms.MessageBox.Show(text.Substring(0, l), "Vertex info1:");
                System.Windows.Forms.MessageBox.Show(text.Substring(l, text.Length - l), "Vertex info2:");
            }
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        ///

        protected void checkVerticesSilent()
        {
            Ray r = GetMouseRay(new Vector2(prevMState.Position.X, prevMState.Position.Y), GraphicsDevice.Viewport, effect);

            r.Position  = new Vector3(r.Position.X, r.Position.Z, r.Position.Y);
            r.Direction = new Vector3(r.Direction.X, r.Direction.Z, r.Direction.Y);
            // Vector3D x1 =  new Vector3D(cameraX + offsetX, cameraY + offsetY, cameraZ + offsetZ);
            //Vector3D x2 = new Vector3D(centerX + offsetX, centerY + offsetY, centerZ + offsetZ);
            Vector3D x1 = new Vector3D(r.Position);
            Vector3D x2 = new Vector3D(r.Position + r.Direction);
            //Program.useCheckingPoint = true;
            // Program.checkingPoint = new System.Numerics.Vector3(x2.X,x2.Z,x2.Y);
            // Program.updateVertices();
            Vector3D miniPoint  = new Vector3D();
            float    ptDistance = float.MaxValue;

            targetV     = null;
            targetVinfo = null;

            for (int i = 0; i < Program.vertices.Count; i++)
            //  foreach (SoulsFormats.FLVER.Vertex v in Program.vertices)
            {
                SoulsFormats.FLVER.Vertex v = Program.vertices[i];
                if (v.Positions[0] == null)
                {
                    continue;
                }
                float dis = Vector3D.calculateDistanceFromLine(new Vector3D(v.Positions[0]), x1, x2);
                if (ptDistance > dis)
                {
                    miniPoint   = new Vector3D(v.Positions[0]);
                    ptDistance  = dis;
                    targetV     = v;
                    targetVinfo = Program.verticesInfo[i];
                }
            }

            if (Program.setVertexPos)
            {
                targetV.Positions[0] = new Vector3D(Program.setVertexX, Program.setVertexY, Program.setVertexZ).toNumV3();
            }

            Program.useCheckingPoint = true;
            Program.checkingPoint    = new System.Numerics.Vector3(miniPoint.X, miniPoint.Y, miniPoint.Z);

            if (targetV.Normals != null && targetV.Normals.Count > 0)
            {
                Program.checkingPointNormal = new System.Numerics.Vector3(targetV.Normals[0].X, targetV.Normals[0].Y, targetV.Normals[0].Z);
            }
            else
            {
                Program.checkingPointNormal = new System.Numerics.Vector3(0, 0, 0);
            }

            Program.updateVertices();
        }
Exemple #3
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState state  = Keyboard.GetState();
            MouseState    mState = Mouse.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                Application.Exit();
            }

            float delta = (float)gameTime.ElapsedGameTime.TotalSeconds;



            //Marine_Yes00.mp3



            if (mState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && IsActive)
            {
                float mdx = mState.X - prevMState.X;
                float mdy = mState.Y - prevMState.Y;
                {
                    System.Numerics.Vector3 p  = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);
                    System.Numerics.Vector3 p2 = Program.RotatePoint(p, 0, 0, -mdx * 0.01f);
                    cameraX = p2.X;
                    cameraY = p2.Y;
                    cameraZ = p2.Z;
                }
                {
                    System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);

                    float nX = cameraY;
                    float nY = -cameraX;


                    System.Numerics.Vector3 p2 = Program.RotateLine(p, new System.Numerics.Vector3(0, 0, 0),
                                                                    new System.Numerics.Vector3(nX, nY, 0), mdy * 0.01f);


                    cameraX = p2.X;
                    cameraY = p2.Y;
                    cameraZ = p2.Z;
                }
            }

            if (mState.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && IsActive)
            {
                float mdx = mState.X - prevMState.X;
                float mdy = mState.Y - prevMState.Y;

                // offsetZ += mdy * 3 * delta;

                Vector3D upV      = new Vector3D(0, 0, 1);
                Vector3D forwardV = new Vector3D(cameraX, cameraY, cameraZ);
                Vector3D rightV   = Vector3D.crossPorduct(upV, forwardV).normalize();
                Vector3D camUpV   = Vector3D.crossPorduct(forwardV, rightV).normalize();

                Vector3D offsetV = new Vector3D(offsetX, offsetY, offsetZ);
                offsetV = offsetV - new Vector3D(rightV.X * mdx * 0.01f, rightV.Y * mdx * 0.01f, rightV.Z * mdx * 0.01f);
                offsetV = offsetV + new Vector3D(camUpV.X * mdy * 0.01f, camUpV.Y * mdy * 0.01f, camUpV.Z * mdy * 0.01f);

                offsetX = offsetV.X;
                offsetY = offsetV.Y;
                offsetZ = offsetV.Z;
                //offsetX -= mdx* 1 * delta * rightV.X;
                //offsetY -= mdx * 1 * delta * rightV.Y;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F1))
            {
                renderMode = RenderMode.Line;
            }
            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F2))
            {
                renderMode = RenderMode.Triangle;
            }
            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                renderMode = RenderMode.Both;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.B) && !prevState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.B))
            {
                Program.boneDisplay = !Program.boneDisplay;
                Program.updateVertices();
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.M) && !prevState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.M))
            {
                Program.dummyDisplay = !Program.dummyDisplay;
                Program.updateVertices();
            }

            //1.73 Added focus detect
            if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && this.IsActive && false)
            {
                Ray r = GetMouseRay(new Vector2(mState.Position.X, mState.Position.Y), GraphicsDevice.Viewport, effect);
                r.Position  = new Vector3(r.Position.X, r.Position.Z, r.Position.Y);
                r.Direction = new Vector3(r.Direction.X, r.Direction.Z, r.Direction.Y);
                // Vector3D x1 =  new Vector3D(cameraX + offsetX, cameraY + offsetY, cameraZ + offsetZ);
                //Vector3D x2 = new Vector3D(centerX + offsetX, centerY + offsetY, centerZ + offsetZ);
                Vector3D x1 = new Vector3D(r.Position);
                Vector3D x2 = new Vector3D(r.Position + r.Direction);
                //Program.useCheckingPoint = true;
                // Program.checkingPoint = new System.Numerics.Vector3(x2.X,x2.Z,x2.Y);
                // Program.updateVertices();
                Vector3D miniPoint  = new Vector3D();
                float    ptDistance = float.MaxValue;
                SoulsFormats.FLVER.Vertex targetV = null;
                foreach (SoulsFormats.FLVER.Vertex v in Program.vertices)
                {
                    if (v.Positions[0] == null)
                    {
                        continue;
                    }
                    float dis = Vector3D.calculateDistanceFromLine(new Vector3D(v.Positions[0]), x1, x2);
                    if (ptDistance > dis)
                    {
                        miniPoint  = new Vector3D(v.Positions[0]);
                        ptDistance = dis;
                        targetV    = v;
                    }
                }

                if (Program.setVertexPos)
                {
                    targetV.Positions[0] = new Vector3D(Program.setVertexX, Program.setVertexY, Program.setVertexZ).toNumV3();
                }

                Program.useCheckingPoint = true;
                Program.checkingPoint    = new System.Numerics.Vector3(miniPoint.X, miniPoint.Y, miniPoint.Z);

                if (targetV.Normals != null && targetV.Normals.Count > 0)
                {
                    Program.checkingPointNormal = new System.Numerics.Vector3(targetV.Normals[0].X, targetV.Normals[0].Y, targetV.Normals[0].Z);
                }
                else
                {
                    Program.checkingPointNormal = new System.Numerics.Vector3(0, 0, 0);
                }

                Program.updateVertices();

                if (targetV != null)
                {
                    string text = Program.FormatOutput(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(targetV));
                    int    l    = text.Length / 2;
                    System.Windows.Forms.MessageBox.Show(text.Substring(0, l), "Vertex info1:");
                    System.Windows.Forms.MessageBox.Show(text.Substring(l, text.Length - l), "Vertex info2:");
                }
            }

            if (mState.ScrollWheelValue - prevMState.ScrollWheelValue > 0)
            {
                //mouseY -= (50 * delta);
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);



                cameraX = p.X - 0.5f * (float)(p.X / p.Length());
                cameraY = p.Y - 0.5f * (float)(p.Y / p.Length());
                cameraZ = p.Z - 0.5f * (float)(p.Z / p.Length());
            }

            if (mState.ScrollWheelValue - prevMState.ScrollWheelValue < 0)
            {
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);


                cameraX = p.X + 0.5f * (float)(p.X / p.Length());
                cameraY = p.Y + 0.5f * (float)(p.Y / p.Length());
                cameraZ = p.Z + 0.5f * (float)(p.Z / p.Length());
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                System.Numerics.Vector3 p  = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);
                System.Numerics.Vector3 p2 = Program.RotatePoint(p, 0, 0, 5 * delta);
                cameraX = p2.X;
                cameraY = p2.Y;
                cameraZ = p2.Z;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                System.Numerics.Vector3 p  = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);
                System.Numerics.Vector3 p2 = Program.RotatePoint(p, 0, 0, -5 * delta);
                cameraX = p2.X;
                cameraY = p2.Y;
                cameraZ = p2.Z;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                //mouseY -= (50 * delta);
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);


                System.Numerics.Vector3 p2 = Program.RotateLine(p, new System.Numerics.Vector3(0, 0, 0),
                                                                new System.Numerics.Vector3(cameraY, -cameraX, 0), 3 * delta);
                cameraX = p2.X;
                cameraY = p2.Y;
                cameraZ = p2.Z;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);


                System.Numerics.Vector3 p2 = Program.RotateLine(p, new System.Numerics.Vector3(0, 0, 0),
                                                                new System.Numerics.Vector3(cameraY, -cameraX, 0), -3 * delta);
                cameraX = p2.X;
                cameraY = p2.Y;
                cameraZ = p2.Z;
            }


            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.OemComma))
            {
                //mouseY -= (50 * delta);
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);



                cameraX = p.X - 3 * delta * (float)(p.X / p.Length());
                cameraY = p.Y - 3 * delta * (float)(p.Y / p.Length());
                cameraZ = p.Z - 3 * delta * (float)(p.Z / p.Length());
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.OemPeriod))
            {
                System.Numerics.Vector3 p = new System.Numerics.Vector3(cameraX, cameraY, cameraZ);


                cameraX = p.X + 3 * delta * (float)(p.X / p.Length());
                cameraY = p.Y + 3 * delta * (float)(p.Y / p.Length());
                cameraZ = p.Z + 3 * delta * (float)(p.Z / p.Length());
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad8))
            {
                offsetZ += 3 * delta;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad2))
            {
                offsetZ -= 3 * delta;;
            }

            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad4))
            {
                Vector3D upV      = new Vector3D(0, 0, 1);
                Vector3D forwardV = new Vector3D(cameraX, cameraY, cameraZ);
                Vector3D rightV   = Vector3D.crossPorduct(upV, forwardV).normalize();

                offsetX -= 3 * delta * rightV.X;
                offsetY -= 3 * delta * rightV.Y;
                //offsetZ -= 3 * delta; ;
            }
            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad6))
            {
                Vector3D upV      = new Vector3D(0, 0, 1);
                Vector3D forwardV = new Vector3D(cameraX, cameraY, cameraZ);
                Vector3D rightV   = Vector3D.crossPorduct(upV, forwardV).normalize();

                offsetX += 3 * delta * rightV.X;
                offsetY += 3 * delta * rightV.Y;
                //offsetZ -= 3 * delta; ;
            }
            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad5))
            {
                Vector3D forwardV = new Vector3D(cameraX, cameraY, cameraZ).normalize();


                offsetX -= 3 * delta * forwardV.X;
                offsetY -= 3 * delta * forwardV.Y;
                offsetZ -= 3 * delta * forwardV.Z;
                //offsetZ -= 3 * delta; ;
            }
            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad0))
            {
                Vector3D forwardV = new Vector3D(cameraX, cameraY, cameraZ).normalize();

                offsetX += 3 * delta * forwardV.X;
                offsetY += 3 * delta * forwardV.Y;
                offsetZ += 3 * delta * forwardV.Z;
                //offsetZ -= 3 * delta; ;
            }

            //new Vector3(cameraX + offsetX, cameraY + offsetY, cameraZ + offsetZ)



            /* if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D1)) { Program.rotOrder = RotationOrder.XYZ; Program.updateVertices(); }
             * if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D2)) { Program.rotOrder = RotationOrder.XZY; Program.updateVertices(); }
             * if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D3)) { Program.rotOrder = RotationOrder.YXZ; Program.updateVertices(); }
             * if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D4)) { Program.rotOrder = RotationOrder.YZX; Program.updateVertices(); }
             * if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D5)) { Program.rotOrder = RotationOrder.ZXY; Program.updateVertices(); }
             * if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D6)) { Program.rotOrder = RotationOrder.ZYX; Program.updateVertices(); }*/



            if (state.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F))
            {
                Program.updateVertices();
            }
            //mouseX = Mouse.GetState().Position.X;
            //mouseY = Mouse.GetState().Position.Y;
            // TODO: Add your update logic here

            prevState  = state;
            prevMState = mState;
            base.Update(gameTime);
        }