public void Center(Button button)
 {
     if (editorCamera != null)
     {
         bool    Success = false;
         Vector3 Result  = Vector3.Zero;
         Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);
         if (Success)
         {
             editorCamera.Position.set(Result);
         }
     }
 }
Beispiel #2
0
        public void Draw3D(Camera3D camera)
        {
            Camera3DObject c = (Camera3DObject)ParentScene.MyCamera.get();

            if (c != null)
            {
                Vector3 Result  = Vector3.Zero;
                bool    Success = false;
                Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);

                WorldMatrix = c.ScaleMatrix * Matrix.CreateTranslation(Result);
                ColorEffectHolder.SetWorld(WorldMatrix);
                ColorEffectHolder.SetFromCamera(camera);

                foreach (EffectPass pass in ColorEffectHolder.MyEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();


                    Game1.graphics.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(
                        PrimitiveType.LineList,
                        PointList,
                        0,             // vertex buffer offset to add to each element of the index buffer
                        PointCount,    // number of vertices in pointList
                        Indicies,      // the index buffer
                        0,             // first index element to read
                        PointCount / 2 // number of primitives to draw
                        );
                }


                ColorSetEffectHolder.Collection["Color"].SetValue(Color.LightGray.ToVector4());
                ColorSetEffectHolder.SetFromCamera(camera);
                ColorSetEffectHolder.SetWorld(WorldMatrix);
                Render.DrawModel(CubeModel, ColorSetEffectHolder.MyEffect);
                Vector3 ScreenPos = WorldViewer.self.MyViewport.Project(Vector3.Zero, camera.ProjectionMatrix, camera.ViewMatrix, WorldMatrix);
                ScreenPositions[3] = new Vector2(ScreenPos.X, ScreenPos.Y);


                Model EndModel = controlMode == ControlMode.Move ? ArrowModel :
                                 controlMode == ControlMode.Rotate ? BallModel : CubeModel;
                for (int i = 0; i < 3; i++)
                {
                    ColorSetEffectHolder.Collection["Color"].SetValue(PointColors[i].ToVector4());
                    ColorSetEffectHolder.SetWorld(ModelMatricies[i] * WorldMatrix);
                    Render.DrawModel(EndModel, ColorSetEffectHolder.MyEffect);
                    ScreenPos          = WorldViewer.self.MyViewport.Project(Vector3.Zero, camera.ProjectionMatrix, camera.ViewMatrix, ModelMatricies[i] * WorldMatrix);
                    ScreenPositions[i] = new Vector2(ScreenPos.X, ScreenPos.Y);
                }
            }
        }
        public void RotateSelected(Vector3 Force, Vector3 Origin)
        {
            Vector3 Result  = Vector3.Zero;
            bool    Success = false;

            Basic3DObject.GetAveragePosition(SelectedGameObjects, ref Result, ref Success);

            foreach (GameObject g in SelectedGameObjects)
            {
                if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
                {
                    Basic3DObject b = (Basic3DObject)g;
                    b.ApplyRotate(Force, Result, false);
                }
            }
        }
Beispiel #4
0
        public override void Update(GameTime gameTime, Window Updater)
        {
            if (CurrentMode != LockMode.None)
            {
                if (MouseManager.mouseState.LeftButton == ButtonState.Pressed)
                {
                    bool    Success = false;
                    Vector3 Result  = Vector3.Zero;
                    Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);

                    Vector3 Direction = -Vector3.One;
                    if (CurrentMode == LockMode.MoveX)
                    {
                        Direction = new Vector3(1, 0, 0);
                    }
                    if (CurrentMode == LockMode.MoveY)
                    {
                        Direction = new Vector3(0, 1, 0);
                    }
                    if (CurrentMode == LockMode.MoveZ)
                    {
                        Direction = new Vector3(0, 0, 1);
                    }

                    Vector2 MouseMult = Vector2.One;

                    if (CurrentMode != LockMode.MoveAll)
                    {
                        Vector2 CenterScreenPos = ScreenPositions[3];
                        Vector2 ScreenPos2D     = ScreenPositions[CurrentMode == LockMode.MoveX ? 0 : CurrentMode == LockMode.MoveY ? 1 : 2];
                        MouseMult = Vector2.Normalize(ScreenPos2D - CenterScreenPos);
                    }

                    Vector2        MouseForce = new Vector2(MouseManager.MousePosition.X - MouseLockPosition.X, MouseManager.MousePosition.Y - MouseLockPosition.Y) * MouseMult / 1000;
                    Camera3DObject c          = (Camera3DObject)ParentScene.MyCamera.get();
                    float          Value      = (MouseForce.X + MouseForce.Y) * c.ZoomDistance.get();

                    switch (controlMode)
                    {
                    case ControlMode.Move:
                        ParentScene.MoveSelected(Value * Direction);
                        break;

                    case ControlMode.Rotate:
                        ParentScene.RotateSelected(Value * Direction, Result);
                        break;

                    case ControlMode.Scale:
                        ParentScene.ScaleSelected(Vector3.One + Value / 300 * Direction, Result);
                        break;
                    }
                }
                else
                {
                    Game1.self.IsMouseVisible = true;
                    CurrentMode = LockMode.None;
                }
                Mouse.SetPosition((int)MouseLockPosition.X, (int)MouseLockPosition.Y);
            }

            base.Update(gameTime, Updater);
        }