Source: Renderables/IllumRenderable.js

  1. /*
  2. * File: IllumRenderable.js
  3. *
  4. * LightRenderable with light illumination
  5. */
  6. /*jslint node: true, vars: true */
  7. /*global gEngine, Renderable, LightRenderable, Material */
  8. /* find out more about jslint: http://www.jslint.com/help.html */
  9. // Constructor and object definition
  10. "use strict"; // Operate in Strict mode such that variables must be declared before used!
  11. /**
  12. * Default Constructor<p>
  13. * LightRenderable with light illumination
  14. * @param {Texture} myTexture Texture to be associated by object.
  15. * @param {type} myNormalMap normal map resource id
  16. * @returns {IllumRenderable} new instance of IllumRenderable
  17. * @class IllumRenderable
  18. */
  19. function IllumRenderable(myTexture, myNormalMap) {
  20. LightRenderable.call(this, myTexture);
  21. Renderable.prototype._setShader.call(this, gEngine.DefaultResources.getIllumShader());
  22. // here is the normal map resource id
  23. this.mNormalMap = myNormalMap;
  24. // Normal map texture coordinate will reproduce the corresponding sprite sheet
  25. // This means, the normal map MUST be based on the sprite sheet
  26. // Material for this Renderable
  27. this.mMaterial = new Material();
  28. }
  29. gEngine.Core.inheritPrototype(IllumRenderable, LightRenderable);
  30. //<editor-fold desc="Public Methods">
  31. //**-----------------------------------------
  32. // Public methods
  33. //**-----------------------------------------
  34. /**
  35. * Draw function called by GameLoop
  36. * @param {Camera} aCamera camera to draw to
  37. * @returns {void}
  38. * @memberOf IllumRenderable
  39. */
  40. IllumRenderable.prototype.draw = function (aCamera) {
  41. gEngine.Textures.activateNormalMap(this.mNormalMap);
  42. // Here thenormal map texture coordinate is copied from those of
  43. // the corresponding sprite sheet
  44. this.mShader.setMaterialAndCameraPos(this.mMaterial, aCamera.getPosInPixelSpace());
  45. LightRenderable.prototype.draw.call(this, aCamera);
  46. };
  47. /**
  48. * Return the Renderable material
  49. * @returns {Material} IllumRenderable material
  50. * @memberOf IllumRenderable
  51. */
  52. IllumRenderable.prototype.getMaterial = function () { return this.mMaterial; };
  53. //--- end of Public Methods
  54. //</editor-fold>