NMapLightSource.qml 914 B

12345678910111213141516171819202122232425262728293031323334
  1. import QtQuick 2.0
  2. /* Light source for the normal mapping shader */
  3. Item {
  4. id: root
  5. // The position of light, read-only to keep translate
  6. property real lightPosX: priv.lPosX + lightTranslateX
  7. property real lightPosY: priv.lPosY + lightTranslateY
  8. // Translate position, for e.g. animating light slightly
  9. property real lightTranslateX: 0
  10. property real lightTranslateY: 0
  11. // The intensity of light
  12. property real lightIntensity: 0.4;
  13. // Set the position for light, forces inside the area
  14. function setLightPos(xpos, ypos) {
  15. priv.lPosX = Math.min(root.width, Math.max(0, xpos));
  16. priv.lPosY = Math.min(root.height, Math.max(0, ypos));
  17. }
  18. // This item should fill the whole area where light is used
  19. anchors.fill: parent
  20. Item {
  21. id: priv
  22. property real lPosX: root.width/2;
  23. property real lPosY: root.height/2;
  24. }
  25. }