2 Replies - 1254 Views - Last Post: 07 December 2012 - 09:00 PM

#1 Lost_My_Password  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-November 12

Placing a Model in XNA with a Mouse Click

Posted 06 December 2012 - 07:15 PM

So I've finally created my first 3D environment and need a little advice on how to draw a model with the click of a button.

I've tried a few ideas and I've gotten it to the point where I can click and the model is drawn on the mouse position and follows the mouse around but I want to drop the model in the last position it was in when i release the button.

I tried binding a new position to the previous mousestate but the previous mousestate is constantly changing with the move of the mouse...

In what way would I take a 'snapshot' of the previous mouse position so I can bind the values to a new vector3 position without it changing on me?

Is This A Good Question/Topic? 0
  • +

Replies To: Placing a Model in XNA with a Mouse Click

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Placing a Model in XNA with a Mouse Click

Posted 07 December 2012 - 06:48 AM

Why not create a vector3 that holds the position of the mouse when it is originally clicked, and doesn't change until a new click is detected? This will give you a way to keep track of the initial position that you can use whenever you feel you need it.
Was This Post Helpful? 0
  • +
  • -

#3 Lost_My_Password  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-November 12

Re: Placing a Model in XNA with a Mouse Click

Posted 07 December 2012 - 09:00 PM

Here is the code I'm working with... I know it's a mess but I've been trying different things all day and for some reason I just can't get it quite right.



        private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
        {

            ResetRenderStates();

            Vector3 targetVector = new Vector3(camera.target.X, 0, camera.target.Z);

            Matrix targetVectorMatrix = Matrix.CreateTranslation(targetVector);
            
            Matrix[] transforms = new Matrix[model.Bones.Count];
            
            model.CopyAbsoluteBoneTransformsTo(transforms);    

            foreach (ModelMesh mesh in model.Meshes)
                {               
                foreach (BasicEffect effect in mesh.Effects)
                    {
                       effect.EnableDefaultLighting();
                       
                       Matrix final = new Matrix();
                       Matrix testMatrix = new Matrix();
                                         
                       world = transforms[mesh.ParentBone.Index];
                                                                                            
                       if (placeModel == true)
                            {                                  
                               final += world * targetVectorMatrix;
                               testMatrix = final;
                               effect.World = testMatrix;
                            }
                        
                       if (prevMouse.MiddleButton == ButtonState.Pressed)
                       {
                           placeModel = true;
                           
                       }
                        
                        effect.World = testMatrix;
                        effect.View = view;
                        effect.Projection = projection;

                        effect.FogEnabled = false;
                        effect.FogStart = camera.Near;
                        effect.FogEnd = camera.Far;
                        effect.FogColor = new Vector3(0, 0, 0);
                    }
                    mesh.Draw();
                }
            }






When I start up the project I have nothing on the screen except my grid. When I click the middle mouse button the model shows up on my target and follows the X and Z of my target around. But I don't want it to follow the target after it's drawn and I'm stumped :(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1