Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > CopperCube Open discussion
Drag object using mouse

Phoenix
Guest
Quote
2014-09-26 00:53:18

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.


bob
Guest
Quote
2014-09-26 09:39:07

+1


niko
Moderator
Quote
2014-09-26 19:03:37

See this thread: http://www.ambiera.com/forum.php...


Phoenix
Guest
Quote
2014-09-26 19:32:06

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!!


Phoenix
Guest
Quote
2014-09-30 00:24:05

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.


Phoenix
Guest
Quote
2014-09-30 00:41:40

FYI: Container2 is the name of your Scene Node!


Phoenix
Guest
Quote
2014-10-03 18:01:48

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.


mr.luckypants
Guest
Quote
2020-11-04 17:20:05

how do i stop dragging it?
and if i pick it up it is very far away from the camera
pls answer me


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (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