Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
setting the rotation of a scene node to face the camera target

spicymilk
Registered User
Quote
2024-10-24 03:43:34

is it possible to have an action where when say a key is pressed i can get a scene node to face the camera target?

I would really appreciate any help thankyou


okeoke
Registered User
Quote
2024-10-24 09:39:13

// The following embedded xml is for the editor and describes how the action can be edited:
// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action
/*
<action jsname="action_NodeFaceCamera" description="Face active camera">
<property name="nodeToRotate" type="scenenode" default="" />
<property name="rotateOnlyHorizontally" type="bool" default="false" />
</action>
*/

action_NodeFaceCamera = function () {
}

action_NodeFaceCamera.prototype.execute = function (node) {
var activeCamPos = ccbGetSceneNodeProperty(ccbGetActiveCamera(), 'Position');
var nodePos = ccbGetSceneNodeProperty(this.nodeToRotate, 'Position');
var nodeRot = ccbGetSceneNodeProperty(this.nodeToRotate, 'Rotation');

var dirVect = nodePos.substract(activeCamPos);
var dist = dirVect.getLength();

var horAngle = (Math.atan2(dirVect.x, dirVect.z) * 180 / Math.PI) - 180;
var vertAngle = Math.atan2(dirVect.y, dist) * 180 / Math.PI;

ccbSetSceneNodeProperty(
this.nodeToRotate,
'Rotation',
this.rotateOnlyHorizontally ? nodeRot.x : vertAngle,
horAngle,
nodeRot.z
);
}


nodeToRotate - node which needed to be rotated towards active camera
rotateOnlyHorizontally - should be true in case it's not required to rotate vertically

demo:https://drive.google.com/file/d/...


ipreferironcube
Registered User
Quote
2024-10-24 20:26:53

does it work with exe or apk?


okeoke
Registered User
Quote
2024-10-24 21:04:44

It should work for windows and webgl. I never tried to build apk using coppercube.


spicymilk
Registered User
Quote
2024-10-26 18:10:46

Thankyou


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