Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
rotate the "camera" by scripts?

misterpaint
Registered User
Quote
2022-12-22 15:39:44

Is possibile to rotate the "camera" by scripts on buttons?
I have 2 buttons, arrow right and arrow left.
I would like when a user click on right or left arrow, the "camera" rotate like happens with mouse or fingers on screen.

I dont know if that is possible...


sven
Registered User
Quote
2022-12-22 16:10:30

Its possible.

You can rotate camera target around camera position.

There is action set camera target.. maybe its possible without script if you add node and childnode to it.. put camera at node position and set camera target to childnode position..so you rotate node and its child rotates with it so the camera target ( havent done it with this way so no idea does it work )


samgrady
Registered User
Quote
2022-12-23 01:02:31

here is easy way to make something like camera rotation
put camera inside pivot node and put this code inside "before first drawing do something"

var cam_pos = null; //camera pivot position need for camera target
var cam_dir = null; //camera direction (y axis) need for rotate and target
var cam_rot_spd = 2; //rotating speed

function camera_setup(pivot){
//this function is called every few milliseconds
//'pivot' the name of the scene node used as the camera pivot
this.camera_pivot = ccbGetSceneNodeFromName(pivot); //set camera pivot
cam_pos = ccbGetSceneNodeProperty(this.camera_pivot,"PositionAbs"); //get pivot position
cam_dir = ccbGetSceneNodeProperty(this.camera_pivot,"Rotation").y; //get pivot direction
//set camera target to 10 in pivot direction
//cam_pos.x+Math.sin(cam_dir/57.29)*10 && cam_pos.z+Math.cos(cam_dir/57.29)*10
ccbSetSceneNodeProperty(ccbGetCurrentNode(),"Target",cam_pos.x+Math.sin(cam_dir/57.29)*10,cam_pos.y,cam_pos.z+Math.cos(cam_dir/57.29)*10);
}
function camera_rotation(left, right){
//call this function on key pressed, has two boolean 'left' and 'right'
if(left) cam_dir -= cam_rot_spd;
else if(right) cam_dir += cam_rot_spd;
//set pivot rotation
ccbSetSceneNodeProperty(this.camera_pivot,"Rotation",0,cam_dir,0);
}



Create reply:


Posted by: (you are not logged in)


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