Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
Get clicked point on a sceneNode

meledith
Registered User
Quote
2011-02-01 12:07:42

Hi,

I'm actually working on moving meshes following a path.
I will have a list of availables PathSceneNode. I need to select the right PathSceneNode when the user click on a point in the room in order to indicate that this is the end point.

But I didn't success to get the right position : when I handle the click on the room scene node, and try to convert the 2D position on 3D coordinates, the points didn't match at all the real position in the sceneNode (I have some 1813, -1444, -2500, when the coordinates are -50, -12.4, -40)

Maybe I'm doing wrong ? Is there another way to get the clicked position on a sceneNode ?

I'm doing this for now:

            var pieceNode = scene.getSceneNodeFromName('Piece1');
var handleclick = function()
{
var X = engine.getMouseX();
var Y = engine.getMouseY();

var pos = engine.get3DPositionFrom2DPosition(X,Y);
alert('X: ' + pos.X + ' Y: ' + pos.Y + ' Z: ' + pos.Z );
}

var animator = new CL3D.Animator(engine.getScene(), engine, handleclick);
pieceNode.addAnimator(animator);



niko
Moderator
Quote
2011-02-01 16:25:53

Hi,

your code gets just any point in 3d space from the 2D position. Notice that in 3D, a position on the screen is not really a 3D point, but actually a 3D line. So that function returns just any point on that line. It starts from the position of your current camera and goes through that point returned by get3DPositionFrom2DPosition(). Maybe that's what was causing your confusion.

To test if your click is on a specifc scene node, simply collide that line with for example the bounding box of your scene node. CopperLicht includes several methods for doing this.


meledith
Registered User
Quote
2011-02-07 15:20:29

Sorry, I was busy on another project.

I tried what you said, and I understand now much better. I think this is working, thanks you.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Inte?national" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact