Jump to content
  • Advertisement
Sign in to follow this  
BlackJoker

Relative object movement in 3d space

This topic is 1152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI. I am trying to implement drag object with mouse by finding intersection between the ray and a plane. And seems coords is OK, but I cannot move object correctly. I want it to move relative to the camera X and Y axis (Right and Up) but instead of this I receive opposite direction movement.

 

Only one case when it moving correctly - when camera is along Z axis. In all other cases, object moves incorrect.

To move relatively I multiply camera relative axis (Rigth or Up) to the delta vector (difference between current and new object positions) given by the intersection test and when add them to the current position.

 

Could someone point me what I am doing wrong and why cannot drag object correctly on the all axis?

Maybe I am missing something very basic?

Edited by BlackJoker

Share this post


Link to post
Share on other sites
Advertisement

Sure.

Here is my intersection test

p = new Plane(EntityWorld.SelectedEntity.GetRelativePosition(), cameraController.UserControlledCamera.ViewMatrix.Forward);
                  var ray = CalculateRay(MouseManager.RelativeCoordinates, cameraController.UserControlledCamera,
                     Matrix.Identity);

                  var intersects = ray.Intersects(ref p, out coordinates);
                  if (intersects)
                  {
                     var relative = EntityWorld.SelectedEntity.GetRelativePosition();
                     var res = coordinates - relative;
                     EntityWorld.SelectedEntity.MoveRelXY(
                           cameraController.UserControlledCamera.ViewMatrix.Right,
                           cameraController.UserControlledCamera.ViewMatrix.Up,
                           res);
                  }

And here is details for MoveRelXY:

public static void MoveRelXY(this Entity inEntity, Vector3 relX, Vector3 relY, Vector3 delta)
      {
         stack.Clear();
         stack.Push(inEntity);
         while (stack.Count > 0)
         {
            Entity current = stack.Pop();

            var position = current.GetComponent<PositionComponent>();

            if (position != null)
            {
               var pos1 = Vector3.Multiply(relX, delta);
               var pos2 = Vector3.Multiply(relY, delta);
               var result = pos1 + pos2;
               position.AbsolutePosition += result;
            }

            foreach (Entity child in current.Dependencies)
            {
               stack.Push(child);
            }
         }
      }

Share this post


Link to post
Share on other sites

so you're doing a raypick, which gives you the moveto location in the world, from which you get the displacement vector from current position in the world to the moveto location in the world ?

 

i don't really see where camera up and right vectors come into play...

Share this post


Link to post
Share on other sites

They come into play here:

EntityWorld.SelectedEntity.MoveRelXY(
                           cameraController.UserControlledCamera.ViewMatrix.Right,
                           cameraController.UserControlledCamera.ViewMatrix.Up,
                           res);

Share this post


Link to post
Share on other sites

Hey ya.

 

You need a offset from the 3d object centre you clicked and the pick point. and apply that with the new mouse to 3dworld location.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!