Ambiera ForumDiscussions, Help and Support. |
|
| [ 1 2 ] Page 1 of 2 |
|
|||||
|
i have some 3d object in scene. this objects defined by new type of scene node derived from SceneNode. How can i select one of them by mouse? Thanks for response |
||||
|
Hi, there are multiple possibilities on how to do this. For all versions, you need to calculate a 3d line from your 2d mouse cursor position, this is done like this (taken from the tutorial): // calculate the start and end 3d point of the line, the beinning being The most simple version would be to calculate a 3d bounding box of your scene node. Simply include all 3d points in a 3d box using code like this: var box = new Box3d(); And with this box, you can simply test collision using box.intersectsWithLine(startLine, endLine). Should you have moved your scene node using the .Pos, .Scale or .Rot attributes, you need to transform the 3d box before testing it for collision of course, this is simply possible using yourSceneNode.getAbsolutePosition().transformBoxEx(box); |
||||
|
A more precise collision testing, polygon based instead of bounding box based would be by using a TriangleSelector. If you are using indices and vertices to draw your scene node, simply create a Mesh (http://www.ambiera.com/copperlic...) from that, by filling some Meshbuffers and adding them to the mesh. (You can also use this to draw your 3d geometry, btw). Then, create a a MeshTriangleSelector (http://www.ambiera.com/copperlic...) from it. Collision then is very simple: yourtriangleselector.getCollisionPointWithLine(startLine, endLine, true) |
||||
|
Many thanks |
||||
|
&921; am having some troubles selecting scene nodes with mouse click using code. I am loading a scene from CopperCube and then i clone and reposition a mesh from the scene several times. I use : var startLine = Camera.getAbsolutePosition(); var endLine = get3DPositionFrom2DPosition(CopperLicht.getMouseX, CopperLicht.getMouseY); and then intersectsWithLine(startLine, endLine) for each node to test for collision on mouse click. I also tried : getAbsolutePosition().transformBoxEx(box).intersectsWithLine(startLine, endLine) None seem to work. Any help please? P.S I couldnt find any help in the documentation since transformBoxEx() isnt mentioned. Shall i try Irrlicht forums ? |
||||
|
The most simple way to react on clicks on scene nodes is by using a animator: http://www.ambiera.com/copperlic... But to solve your problem: Maybe your problem is that the end Line point is to near to your camera? Simply extend it a bit, that's what I did with the code above: var endLine = startLine.add(cam.getTarget().substract(startLine).multiplyWithScal(2000)); |
||||
|
Although the animator code looks very simple it doesnt work or i cant make it work. I load the coppercube scene, get my scenenode to a var, add a clickanimator using : var animator = new Animator(engine.getScene(), engine, myFunction); mySceneNode.addAnimator(animator); in my simple example myFunction is just setting scene node visible to false but nothing happens. The only way to made it work was by using CopperCube and calling a javascript function in the action field. |
||||
|
Here is a sample code and the screenshot of it :
In the InitCube i add an Animator for each node. When i click it nothing happens. Can anyone please tell me what i am doing wrong? Thanks in advance. |
||||
|
By just looking through your code, the last part doesn't appear to make much sense. I would change it to this: update: Ah, the forum remove some word from the code, maybe it wasn't that wrong, see comment below
|
||||
|
I put the animator declaration inside loop but still doesnt work I dont think there is a problem with the code. I even tried a very simple scene with only one cube and one ClickAnimator. I didnt got any response with mouse click on it. |
||||
|
Ok, I found your problem, CopperLicht had a bug when you did this just the way you do. It's now fixed in version 1.1.1. |
||||
|
I am glad it was a bug. I was begining to wonder about my IQ I'll do it with CopperCube until next version of CopperLicht is out. Thanks for the responce. |
||||
|
Fixed typo above: I meant it's already fixed in version 1.1.1 :) |
||||
|
I am on 1.1.0 . Downloading 1.1.1 asap Update : It is working BUT i think Animator calls the function for every node that collides with the ray and not only just the function from the first. |
||||
|
That's because the animator doesn't know anything about the other cubes. There are several ways to solve this problem: - You could either solve this by implementing the line-collision code yourself as the code in the beginning of this thread shows. - Construct your scene using CopperCube instead. The editor will tell copperLicht which items are there in the world. - Use the MetaTriangleSelector from scene.getCollisionGeometry() and add all the cubes to the world there. That's basically also what CopperCube does. |
||||
| [ 1 2 ] Page 1 of 2 |
|
|