Advertisement
Guest User

FuckboyCarlos

a guest
Nov 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /*
  2. * MyCircularAnimation
  3. * @constructor
  4. */
  5.  
  6. function MyCircularAnimation(scene,speed,center,radius,startang,rotang){
  7. CGFobject.call(this,scene);
  8. this.scene = scene;
  9. this.speed = speed;
  10. this.center = center;
  11. this.radius = radius;
  12. this.startang = startang * DEGREE_TO_RAD;
  13. this.rotang = rotang* DEGREE_TO_RAD;
  14. this.end = false; //end flag
  15. this.matrix = mat4.create();
  16. this.span = (this.rotang*this.radius)/this.speed;
  17. this.time = 0;
  18. };
  19.  
  20. MyCircularAnimation.prototype = Object.create(CGFobject.prototype);
  21. MyCircularAnimation.prototype.constructor = MyCircularAnimation;
  22.  
  23.  
  24. MyCircularAnimation.prototype.update = function(time){
  25. //checks if animation ended
  26. if(this.end){
  27. return this.matrix;
  28. }
  29.  
  30. //checks if it is the last movement of animation
  31. if(this.time > this.span){
  32. this.end = true;
  33. this.time = this.span;
  34. }
  35.  
  36. let matrixTmp = mat4.create();
  37.  
  38. mat4.translate(matrixTmp,matrixTmp,this.center);
  39. mat4.rotateY(matrixTmp,matrixTmp,this.startang + (this.time /this.span)*this.rotang);
  40. mat4.translate(matrixTmp,matrixTmp,[this.radius,0,0]);
  41.  
  42. if(this.rotang>0)
  43. mat4.rotateY(matrixTmp,matrixTmp,90 * DEGREE_TO_RAD);
  44.  
  45. this.time += time/1000;
  46. this.matrix = matrixTmp;
  47. }
  48.  
  49. //return the animation matrix
  50. MyCircularAnimation.prototype.getMatrix = function(){
  51. return this.matrix;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement