Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
how to trigger a custom animators event

simon_marklar
Registered User
Quote
2011-09-13 08:18:30

Hi,

First off thanks for copperlicht. i've used irrlicht before and love the way it works. but i have a question :)

i've made a custom animation node whos purpose is to get keyboard input and then rotate the node depending on the keypress. I know there is a rotator animator already but the animateNode behavior is not what I want ( or at least i think its not.. might experiment with it ).

I know that the animateNode function is being called, but the event is not ( i dont see my console log messages ). Do i need to register the animator?

here's my code for the custom animator:

var Rotator = function( engine )
{
this.DesiredRot = new CL3D.Vect3d();
this.Animate = false;
//this.init();
}

Rotator.prototype = new CL3D.Animator();
Rotator.prototype. = function(e)
{
console.log("in rotator input");

this.DesiredRot.X = 0;
this.DesiredRot.Y = 0;
var key = String.fromCharCode(e.keyCode);

if ( key == 'D')
{
this.DesiredRot.X += 90;

}
if ( key == 'S')
{
this.DesiredRot.Y += 180;
}
if ( key == 'A')
{
this.DesiredRot.X += 270;
}

this.Animate = true;

engine.handleKeyDown(e);
}

Rotator.prototype.animateNode = function( n, timeMs )
{
if ( !this.Animate )
return;

//console.log( "animating rotator");
var currentRot = new CL3D.Quaternion( 0, 0, 0, 1 );
currentRot.setFromEuler( n.Rot.X, n.Rot.Y, n.Rot.Z );
var desiredRotQ = new CL3D.Quaternion( 0, 0, 0, 1 );
desiredRotQ.setFromEuler( this.DesiredRot.X, this.DesiredRot.Y, this.DesiredRot.Z );

var slerp = new CL3D.Quaternion();
slerp.slerp( currentRot, desiredRotQ, 0.1 );

slerp.toEuler( n.Rot );

this.Animate = false;
}


im not sure the function will work the way i want, but thats besides the point. I should be seeing console.log messages on a key press, but im not.

thanks!


niko
Moderator
Quote
2011-09-13 19:21:24

Hi,

you need to do key and mouse management yourself in this case, but if you prefer relying on CopperLicht for that, there are some private function where you can register your animator. From your animator, call for example this:


copperlicht.registerAnimatorForKeyUp(this);
copperlicht.registerAnimatorForKeyDown(this);



simon_marklar
Registered User
Quote
2011-09-14 07:12:28

Thanks for a response! :)

I had to register both keyDown and keyUp events before it worked, but it worked.

fyi , when i only registered keyUp i got the following message:
this.RegisteredAnimatorsForKeyDown[a] is undefined

when i only register keyDown it wont work at all.

thank you very much!


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