topical media & game development

talk show tell print

math -- animation 15

math(s) / tutorial(s)

basic perspective(s)



  scale = fl / (fl + zpos);
  sprite.scaleX = sprite.scaleY = scale;
  sprite.alpha = scale;  // optional
  sprite.x = vanishingPointX + xpos * scale;
  sprite.y = vanishingPointY + ypos * scale;
  

Z sorting(s)



  // array of 3D object with zpos property;
  objectArray.sortOn("zpos", Array.DESCENDING | Array.NUMERIC);
  for (var i:unint; i < numObjects; i++) {
    setChildIndex(objectArray[i].i);
  }
  

coordinate rotation(s)



  x1 = Math.cos(angleZ) * xpos - Math.sin(angleZ) * ypos;
  y1 = Math.cos(angleZ) * ypos + Math.sin(angleZ) * xpos;
  
  x1 = Math.cos(angleY) * xpos - Math.sin(angleY) * zpos;
  z1 = Math.cos(angleY) * zpos + Math.sin(angleY) * xpos;
  
  y1 = Math.cos(angleX) * ypos - Math.sin(angleX) * zpos;
  z1 = Math.cos(angleX) * zpos + Math.sin(angleX) * ypos;
  

3D distance(s)



  distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
  


(C) Æliens 23/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.