Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I would like to move an object using the mouse. e.g: I would like to drag an object by clicking on it and then move it around the screen using the mouse. Any help on how to do this is appreciated. |
||||
|
+1 |
||||
|
See this thread: http://www.ambiera.com/forum.php... |
||||
|
wrote: See this thread: http://www.ambiera.com/forum.php... Thank you. Will try to add a script. If by then V5 is out i will rely on your expertise. :D Thanks and keep up the wonderful work!! |
||||
|
for those looking for an answer. Here is what i came up with so far. I can drag objects using the following script: function onFrameDrawing() { var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); var anode = ccbGetSceneNodeFromName("Container2"); var pos3d = ccbGet3DPosFrom2DPos(mouseX, mouseY); ccbSetSceneNodeProperty(anode, "Position", pos3d); } ccbRegisterOnFrameEvent(onFrameDrawing); I typed this script in "When clicked on this do something"->"Execute Javascript". Does what i needed, though the object is not where i want it to. If anyone can suggest any modifications, i would appreciate that. |
||||
|
FYI: Container2 is the name of your Scene Node! |
||||
|
Here is an updated code that works. All credits to niko. His recent 3D Object Grabbing script gave me the idea. However, it only works on CoperCube v5. If you have v4.5.1 like me, you can use the following JS Code: function onFrameDrawing() { var mouseX = ccbGetMousePosX(); var mouseY = ccbGetMousePosY(); var pos3d = ccbGet3DPosFrom2DPos(mouseX, mouseY); var positionCam = ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); var ray = pos3d.substract(positionCam); ray.normalize(); var anode = ccbGetSceneNodeFromName("YourSceneNode"); var positionNode = ccbGetSceneNodeProperty(anode, "Position"); this.distance = positionNode.substract(positionCam).getLength(); ray.x *= this.distance; ray.y *= this.distance; ray.z *= this.distance; var X = ray.x + positionCam.x; var Y = ray.y + positionCam.y; var Z = ray.z + positionCam.z; ccbSetSceneNodeProperty(anode , "Position", X, Y, Z); } ccbRegisterOnFrameEvent(onFrameDrawing); This in conjunction with "On clicked do something" does exactly what I need. Hope this helps anyone who needs it. And many thanks to nko for the hint on how to proceed. |
||||
|
how do i stop dragging it? and if i pick it up it is very far away from the camera pls answer me |
|