ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > Help with CopperCube
forum topic indicator setting the rotation of a scene node to face the camera target
person icon
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

person icon
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/...

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

does it work with exe or apk?

person icon
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.

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

Thankyou


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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