Last active
August 29, 2015 14:07
-
-
Save oscarcs/55eb8bd0fde61ecd05fb to your computer and use it in GitHub Desktop.
Depthsorting funtimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getSort() | |
{ | |
var sortval:Float = 0; | |
var curAngle = loop(((FlxG.camera.angle-90) * Math.PI) / 180); | |
var r = Math.sqrt(Math.pow(top.getGraphicMidpoint().x - player.x, 2) + Math.pow(top.getGraphicMidpoint().y - player.y, 2)); | |
var phi = Math.atan2(top.getGraphicMidpoint().x - player.x, top.getGraphicMidpoint().y - player.y) + Math.PI; | |
var topAngle = curAngle; | |
var botAngle = loop(curAngle + Math.PI); | |
var avgAngle = (topAngle + botAngle) / 2; | |
var botFlag = false; | |
var alpha:Float = 0; | |
var smalldiff = Math.min(loop(topAngle - phi), loop(botAngle - phi)); | |
if (loop(topAngle - phi) == smalldiff) | |
{ | |
botFlag = false; | |
alpha = topAngle; | |
} | |
else | |
{ | |
botFlag = true; | |
alpha = botAngle; | |
} | |
if (phi == avgAngle) | |
{ | |
sortval = 0; | |
return sortval; | |
} | |
if (alpha == phi) | |
{ | |
sortval = r; | |
return sortval; | |
} | |
var a = phi - alpha; | |
sortval = r * Math.sin(a); | |
sortval = Math.abs(sortval); | |
if (botFlag == true) | |
{ | |
sortval *= -1; | |
} | |
return sortval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment