Esempio n. 1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Object3D.emptyObject           = new Object3D();
            Object3D.emptyObject.MinCoords = new Vector3(-500, -500, -500);
            Object3D.emptyObject.MaxCoords = new Vector3(500, 500, 500);
            Object3D.emptyObject.Skeleton  = new Skeleton(Object3D.emptyObject);
            focusedObject = Object3D.emptyObject;

            SrkBinary.InitEmptyData();

            backgroundColor   = new Color(30, 30, 30);
            transformationBox = new TransformationBox();

            for (int i = 0; i < Program.args_.Length; i++)
            {
                string fname = Program.args_[i].ToLower();
                if (Path.GetExtension(fname) == ".dae")
                {
                    DAE dae = new DAE(fname);
                    dae.Parse();
                    dae.Skeleton.AllowBoneSelect = true;
                    dae.Skeleton.ShowIndices     = false;
                    focusedObject = dae;
                }
                if (Path.GetExtension(fname) == ".obj")
                {
                    OBJ obj = new OBJ(fname);
                    obj.Parse();
                    focusedObject = obj;
                }
                if (Path.GetExtension(fname) == ".mdlx")
                {
                    MDLX mdl = new MDLX(fname);
                    mdl.Parse();
                    mdl.Skeleton.AllowBoneSelect = true;
                    mdl.Skeleton.ShowIndices     = false;
                    focusedObject = mdl;
                }
                focusedObject.FileName = fname;
            }
            Controls.DefaultCamera();
            Controls.ResetCamToTarget();
        }
Esempio n. 2
0
            public static void MouseControls(GameWindow win)
            {
                mouseState    = Mouse.GetState(win);
                keyboardState = Keyboard.GetState();


                if (keyboardState.IsKeyDown(Keys.S) && !oldKeyboardState.IsKeyDown(Keys.S))
                {
                    mainCamera.Animated = !mainCamera.Animated;
                    if (mainCamera.Animated)
                    {
                        mainCamera.RotationX = 0;
                        mainCamera.RotationY = 0;
                    }
                }
                if (keyboardState.IsKeyDown(Keys.T) && !oldKeyboardState.IsKeyDown(Keys.T))
                {
                    View.AllowTextures = !View.AllowTextures;
                }
                if (keyboardState.IsKeyDown(Keys.I) && !oldKeyboardState.IsKeyDown(Keys.I))
                {
                    focusedObject.Skeleton.ShowIndices = !focusedObject.Skeleton.ShowIndices;
                }
                if (keyboardState.IsKeyDown(Keys.Enter) && !oldKeyboardState.IsKeyDown(Keys.Enter))
                {
                    if (focusedObject is MDLX)
                    {
                        MDLX mdl = focusedObject as MDLX;
                        if (!Directory.Exists(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + "-export"))
                        {
                            Directory.CreateDirectory(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + "-export");
                        }
                        mdl.ExportDAE(View.GetCurrentDirectory() + @"\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + @"-export\" + Path.GetFileNameWithoutExtension(mdl.FileName).ToUpper() + ".dae");
                    }
                }

                int wheelVal    = mouseState.ScrollWheelValue;
                int oldWheelVal = oldMouseState.ScrollWheelValue;


                bool allowCameraRotation    = MouseDragState == 0 && !View.focusedObject.Skeleton.HighlightedBone && keyboardState.IsKeyUp(Keys.LeftShift);
                bool allowCameraTranslation = MouseDragState == 0 && keyboardState.IsKeyUp(Keys.LeftShift);
                bool allowCameraZoom        = MouseDragState == 0 && keyboardState.IsKeyUp(Keys.LeftShift);

                if (allowCameraZoom)
                {
                    float step = focusedObject.Zoom / 10f;

                    if (wheelVal < oldWheelVal)
                    {
                        mainCamera.ZoomTarget += step;
                    }
                    else if (wheelVal > oldWheelVal)
                    {
                        mainCamera.ZoomTarget -= step;
                    }
                    if (mouseState.MiddleButton == ButtonState.Pressed)
                    {
                        ResetCamToTarget();
                    }
                }

                ShowLookAt = false;
                float factor = mainCamera.Animated ? 0.3333f : 1;


                float diffY = oldMouseState.Position.Y - mouseState.Position.Y;
                float diffX = oldMouseState.Position.X - mouseState.Position.X;

                if (allowCameraTranslation)
                {
                    if (mouseState.RightButton == ButtonState.Pressed)
                    {
                        ShowLookAt = true;
                        float dist = (focusedObject.Perimetre) / 500f;

                        if (keyboardState.IsKeyDown(Keys.LeftControl))
                        {
                            if (diffY != 0)
                            {
                                mainCamera.TranslationZ += diffY * factor * dist;
                            }
                            //mainCamera.MoveCameraForward((oldMouseState.Position.Y - mouseState.Position.Y) * dist * mainCamera.RollStep);
                        }
                        else
                        {
                            if (diffY != 0)
                            {
                                mainCamera.TranslationY += -diffY * factor * dist;
                            }
                            if (diffX != 0)
                            {
                                mainCamera.TranslationX += diffX * factor * dist * mainCamera.RollStep;
                            }

                            //mainCamera.MoveCameraUp((mouseState.Position.Y - oldMouseState.Position.Y) * dist);
                            //mainCamera.MoveCameraRight((oldMouseState.Position.X - mouseState.Position.X) * dist * mainCamera.RollStep);
                        }
                    }
                }

                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    if (oldMouseState.LeftButton == ButtonState.Released)
                    {
                        cameraTurnPress = allowCameraRotation;
                    }
                }
                else
                {
                    cameraTurnPress = false;
                }


                if (cameraTurnPress)
                {
                    ShowLookAt = true;

                    /*mainCamera.Pitch += MathHelper.ToRadians(oldMouseState.Position.Y - mouseState.Position.Y);
                     * mainCamera.Yaw += MathHelper.ToRadians(oldMouseState.Position.X - mouseState.Position.X) * mainCamera.RollStep;*/
                    if (diffY != 0)
                    {
                        mainCamera.RotationY += factor * MathHelper.ToRadians(diffY);
                    }

                    if (diffX != 0)
                    {
                        mainCamera.RotationX += factor * MathHelper.ToRadians(diffX) * mainCamera.RollStep;
                    }
                }

                oldMouseState    = mouseState;
                oldKeyboardState = keyboardState;
            }