Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function showHint(objName, text, color) {
  2.     var ifObj = document.getElementById('infoHint')
  3.     if (ifObj) {
  4.         ifObj.innerHTML = '';
  5.     }
  6.     var obj = scene.getObjectByName(objName);
  7.     var position = obj.matrixWorld.getPosition().clone();  
  8.     var vector = position.project(camera);
  9.     var percX = (vector.x + 1) / 2;
  10.     var percY = (-vector.y + 1) / 2;
  11.     var leftpx = percX * window.innerWidth;
  12.     var toppx = percY * window.innerHeight;
  13.     var hintDiv = document.createElement('div');
  14.     hintDiv.innerHTML = text;
  15.     hintDiv.id = 'infoHint';
  16.     var quater = getQuater(leftpx, toppx);
  17.    
  18.     hintDiv.style.left = leftpx + 10 + 'px';
  19.     hintDiv.style.bottom = window.innerHeight - toppx + 'px';
  20.    
  21.     if (color) {
  22.         hintDiv.style.background = color;
  23.     }  
  24.     $("#webGL_container").append(hintDiv);
  25. }
  26.  
  27. function getQuater(left, top) {
  28.     var wh = window.innerWidth/2;
  29.     var hh = window.innerHeight/2;
  30.     if (left < wh && top < hh) {
  31.         return 1;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement