Dragging an object on a plane with respect to the camera

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












this is a long description but I hope the solution is simple:



I have a 3D pointCloud with a box (displayed at 0,0,0) and I want to drag the box on the XY plane with my mouse cursor (Zero movement on the Z axis) I can access the box transformation matrix and manipulate it and I have all the camera parameters.



My first approach was to keep the element (3,4) of the box's homogeneous transformation matrix fixed and let the other elements of the position vector change freely, it works well in normal conditions (image 1), but when I changed the camera position (image 2) I was no longer able to drag the box "towards" me. So I tried to use a "picker" to get the 3D position of the mouse cursor and move the box to that x,y position,however, the problem is when the camera is close to the level of the box or when it's rotated (same image 2 and image 3), the x,y,z values of the cursor in the images shows why I was unable to move the box using the picker.



The axis directions, the camera position and orientation,different cursor positions(white boxes),and the 3D positions of the cursor are all shown in each image(The values are not entierly exact).



I did some experiments and the best results I could get are from these 2 equations (I got them by trial and error) but the results need further improvements :



 // **position[0],[1],[2]** is the (x, y, z) position of the mouse cursor respectively.
// **camOrientation[0],[1],[2]** is the orientation of the camera around (x, y, z)respectively.
camOrientation[1] = 90 - camOrientation[1];// the orientation around the
Y axis(The subtraction gave me best results).

// Calculating the new X, Y position of the box.
// The new X position =The X position of the cursor +[cos(orientation around X axis)*the Z position of the cursor] + [cos(orientation around Y axis)*the Z position of the cursor]
// The same applies for the new Y value but instead of **cos** I used **sin** and the first argumetn is the Y position of the cursor.

double XValue = position[0] + cos(camOrientation[0] * 3.14159 / 180) * position[2] + cos(camOrientation[1] * 3.14159 / 180) * position[2];
double YValue = position[1] + sin(camOrientation[0] * 3.14159 / 180) * position[2] + sin(camOrientation[1] * 3.14159 / 180) * position[2];

// Applying the values to the box matrix.(translate the box to the new x,y position)
BoxMatrix->SetElement(0, 3, XValue);
BoxMatrix->SetElement(1, 3, YValue);


My question, is there a mathematical approach or equation to get the expected results right, because it seems a standard problem but I couldn't find a solution.(I posted my question on the computerGraphics stack exchange but didn't get any answers, I hope I'm in the right forum and that I'm not off-topic)



image 1 defaultimage 2 frontimage 3 top







share|cite|improve this question





















  • (1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
    – Tamim Boubou
    20 hours ago











  • So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
    – mvw
    20 hours ago










  • Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
    – Tamim Boubou
    20 hours ago










  • What kind of 3D API is that?
    – mvw
    20 hours ago










  • VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
    – Tamim Boubou
    20 hours ago















up vote
0
down vote

favorite












this is a long description but I hope the solution is simple:



I have a 3D pointCloud with a box (displayed at 0,0,0) and I want to drag the box on the XY plane with my mouse cursor (Zero movement on the Z axis) I can access the box transformation matrix and manipulate it and I have all the camera parameters.



My first approach was to keep the element (3,4) of the box's homogeneous transformation matrix fixed and let the other elements of the position vector change freely, it works well in normal conditions (image 1), but when I changed the camera position (image 2) I was no longer able to drag the box "towards" me. So I tried to use a "picker" to get the 3D position of the mouse cursor and move the box to that x,y position,however, the problem is when the camera is close to the level of the box or when it's rotated (same image 2 and image 3), the x,y,z values of the cursor in the images shows why I was unable to move the box using the picker.



The axis directions, the camera position and orientation,different cursor positions(white boxes),and the 3D positions of the cursor are all shown in each image(The values are not entierly exact).



I did some experiments and the best results I could get are from these 2 equations (I got them by trial and error) but the results need further improvements :



 // **position[0],[1],[2]** is the (x, y, z) position of the mouse cursor respectively.
// **camOrientation[0],[1],[2]** is the orientation of the camera around (x, y, z)respectively.
camOrientation[1] = 90 - camOrientation[1];// the orientation around the
Y axis(The subtraction gave me best results).

// Calculating the new X, Y position of the box.
// The new X position =The X position of the cursor +[cos(orientation around X axis)*the Z position of the cursor] + [cos(orientation around Y axis)*the Z position of the cursor]
// The same applies for the new Y value but instead of **cos** I used **sin** and the first argumetn is the Y position of the cursor.

double XValue = position[0] + cos(camOrientation[0] * 3.14159 / 180) * position[2] + cos(camOrientation[1] * 3.14159 / 180) * position[2];
double YValue = position[1] + sin(camOrientation[0] * 3.14159 / 180) * position[2] + sin(camOrientation[1] * 3.14159 / 180) * position[2];

// Applying the values to the box matrix.(translate the box to the new x,y position)
BoxMatrix->SetElement(0, 3, XValue);
BoxMatrix->SetElement(1, 3, YValue);


My question, is there a mathematical approach or equation to get the expected results right, because it seems a standard problem but I couldn't find a solution.(I posted my question on the computerGraphics stack exchange but didn't get any answers, I hope I'm in the right forum and that I'm not off-topic)



image 1 defaultimage 2 frontimage 3 top







share|cite|improve this question





















  • (1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
    – Tamim Boubou
    20 hours ago











  • So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
    – mvw
    20 hours ago










  • Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
    – Tamim Boubou
    20 hours ago










  • What kind of 3D API is that?
    – mvw
    20 hours ago










  • VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
    – Tamim Boubou
    20 hours ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











this is a long description but I hope the solution is simple:



I have a 3D pointCloud with a box (displayed at 0,0,0) and I want to drag the box on the XY plane with my mouse cursor (Zero movement on the Z axis) I can access the box transformation matrix and manipulate it and I have all the camera parameters.



My first approach was to keep the element (3,4) of the box's homogeneous transformation matrix fixed and let the other elements of the position vector change freely, it works well in normal conditions (image 1), but when I changed the camera position (image 2) I was no longer able to drag the box "towards" me. So I tried to use a "picker" to get the 3D position of the mouse cursor and move the box to that x,y position,however, the problem is when the camera is close to the level of the box or when it's rotated (same image 2 and image 3), the x,y,z values of the cursor in the images shows why I was unable to move the box using the picker.



The axis directions, the camera position and orientation,different cursor positions(white boxes),and the 3D positions of the cursor are all shown in each image(The values are not entierly exact).



I did some experiments and the best results I could get are from these 2 equations (I got them by trial and error) but the results need further improvements :



 // **position[0],[1],[2]** is the (x, y, z) position of the mouse cursor respectively.
// **camOrientation[0],[1],[2]** is the orientation of the camera around (x, y, z)respectively.
camOrientation[1] = 90 - camOrientation[1];// the orientation around the
Y axis(The subtraction gave me best results).

// Calculating the new X, Y position of the box.
// The new X position =The X position of the cursor +[cos(orientation around X axis)*the Z position of the cursor] + [cos(orientation around Y axis)*the Z position of the cursor]
// The same applies for the new Y value but instead of **cos** I used **sin** and the first argumetn is the Y position of the cursor.

double XValue = position[0] + cos(camOrientation[0] * 3.14159 / 180) * position[2] + cos(camOrientation[1] * 3.14159 / 180) * position[2];
double YValue = position[1] + sin(camOrientation[0] * 3.14159 / 180) * position[2] + sin(camOrientation[1] * 3.14159 / 180) * position[2];

// Applying the values to the box matrix.(translate the box to the new x,y position)
BoxMatrix->SetElement(0, 3, XValue);
BoxMatrix->SetElement(1, 3, YValue);


My question, is there a mathematical approach or equation to get the expected results right, because it seems a standard problem but I couldn't find a solution.(I posted my question on the computerGraphics stack exchange but didn't get any answers, I hope I'm in the right forum and that I'm not off-topic)



image 1 defaultimage 2 frontimage 3 top







share|cite|improve this question













this is a long description but I hope the solution is simple:



I have a 3D pointCloud with a box (displayed at 0,0,0) and I want to drag the box on the XY plane with my mouse cursor (Zero movement on the Z axis) I can access the box transformation matrix and manipulate it and I have all the camera parameters.



My first approach was to keep the element (3,4) of the box's homogeneous transformation matrix fixed and let the other elements of the position vector change freely, it works well in normal conditions (image 1), but when I changed the camera position (image 2) I was no longer able to drag the box "towards" me. So I tried to use a "picker" to get the 3D position of the mouse cursor and move the box to that x,y position,however, the problem is when the camera is close to the level of the box or when it's rotated (same image 2 and image 3), the x,y,z values of the cursor in the images shows why I was unable to move the box using the picker.



The axis directions, the camera position and orientation,different cursor positions(white boxes),and the 3D positions of the cursor are all shown in each image(The values are not entierly exact).



I did some experiments and the best results I could get are from these 2 equations (I got them by trial and error) but the results need further improvements :



 // **position[0],[1],[2]** is the (x, y, z) position of the mouse cursor respectively.
// **camOrientation[0],[1],[2]** is the orientation of the camera around (x, y, z)respectively.
camOrientation[1] = 90 - camOrientation[1];// the orientation around the
Y axis(The subtraction gave me best results).

// Calculating the new X, Y position of the box.
// The new X position =The X position of the cursor +[cos(orientation around X axis)*the Z position of the cursor] + [cos(orientation around Y axis)*the Z position of the cursor]
// The same applies for the new Y value but instead of **cos** I used **sin** and the first argumetn is the Y position of the cursor.

double XValue = position[0] + cos(camOrientation[0] * 3.14159 / 180) * position[2] + cos(camOrientation[1] * 3.14159 / 180) * position[2];
double YValue = position[1] + sin(camOrientation[0] * 3.14159 / 180) * position[2] + sin(camOrientation[1] * 3.14159 / 180) * position[2];

// Applying the values to the box matrix.(translate the box to the new x,y position)
BoxMatrix->SetElement(0, 3, XValue);
BoxMatrix->SetElement(1, 3, YValue);


My question, is there a mathematical approach or equation to get the expected results right, because it seems a standard problem but I couldn't find a solution.(I posted my question on the computerGraphics stack exchange but didn't get any answers, I hope I'm in the right forum and that I'm not off-topic)



image 1 defaultimage 2 frontimage 3 top









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited 20 hours ago
























asked 21 hours ago









Tamim Boubou

184




184











  • (1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
    – Tamim Boubou
    20 hours ago











  • So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
    – mvw
    20 hours ago










  • Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
    – Tamim Boubou
    20 hours ago










  • What kind of 3D API is that?
    – mvw
    20 hours ago










  • VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
    – Tamim Boubou
    20 hours ago

















  • (1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
    – Tamim Boubou
    20 hours ago











  • So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
    – mvw
    20 hours ago










  • Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
    – Tamim Boubou
    20 hours ago










  • What kind of 3D API is that?
    – mvw
    20 hours ago










  • VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
    – Tamim Boubou
    20 hours ago
















(1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
– Tamim Boubou
20 hours ago





(1,0,0) would be one unit "in" the screen as it's my X axis direction so yes, that would move it one unit. My main problem is finding the new coordinates that I need to move the box to. taking the X and Y values of the mouse cursor and simply applying them to the transformation matrix didn't work.
– Tamim Boubou
20 hours ago













So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
– mvw
20 hours ago




So your difficulty is translating 2D coordinates from the mouse pointer into something useful within the 3D world?
– mvw
20 hours ago












Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
– Tamim Boubou
20 hours ago




Yes !, I can get the 3D mouse coordinates ,But using them correctly is my problem. As I mentioned, the equations I tried worked almost correctly, but they need improvements and I couldn't find out how.
– Tamim Boubou
20 hours ago












What kind of 3D API is that?
– mvw
20 hours ago




What kind of 3D API is that?
– mvw
20 hours ago












VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
– Tamim Boubou
20 hours ago





VTK (Visualization Toolkit) I'm using what's called vtkPicker, The documentation at link says: superclass for 3D geometric pickers (uses ray cast) vtkPicker is used to select instances of vtkProp3D by shooting a ray into a graphics window and intersecting with the actor's bounding box. The ray is defined from a point defined in window (or pixel) coordinates, and a point located from the camera's position.
– Tamim Boubou
20 hours ago
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2872873%2fdragging-an-object-on-a-plane-with-respect-to-the-camera%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2872873%2fdragging-an-object-on-a-plane-with-respect-to-the-camera%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What is the equation of a 3D cone with generalised tilt?

Color the edges and diagonals of a regular polygon

Relationship between determinant of matrix and determinant of adjoint?