Created
December 11, 2011 17:00
-
-
Save acidsound/1461554 to your computer and use it in GitHub Desktop.
pseudo AR - Calculate Position
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 void setPositions() { | |
// isFlat 을 구분하여 목적지 아이콘 위치를 이동한다. | |
if (isAR) { | |
for (int i = 0; i < relativeLayoutPosition.getChildCount(); i++) { | |
View v = relativeLayoutPosition.getChildAt(i); | |
if (v.getTag() != null) { | |
JSONObject position = (JSONObject) v.getTag(); | |
ImageView imageViewPosition = (ImageView) v; | |
double lat2=0; | |
double lon2=0; | |
try { | |
lat2=position.getDouble("latitude"); | |
lon2=position.getDouble("longitude"); | |
} catch (JSONException e) { | |
// e.printStackTrace(); | |
} | |
double lat1; | |
double lon1; | |
if (((GlobalApplication) getApplication()).getIsDebug()) { | |
// for Debug : 고정좌표로 테스트 | |
lat1=37.5162174; | |
lon1=127.1181762; | |
} else { | |
lat1=latOrigin; | |
lon1=lonOrigin; | |
} | |
double absDegree = 180-Math.atan2(lat2-lat1, lon2-lon1)*180/Math.PI; | |
double relDegree = (360+absDegree-currentDegree)%360; | |
double distance = getDistance(lat1, lon1, lat2, lon2); | |
// 보정값 | |
double correctionRatio = 3000; | |
int relX; | |
int relY; | |
int POVDegree = 45; | |
if (isFlat) { | |
relX = (int) (relativeLayoutPosition.getWidth()/2 + (correctionRatio * distance * Math.cos(relDegree * Math.PI / 180))); | |
relY = (int) (relativeLayoutPosition.getHeight()/2 + (correctionRatio * distance * Math.sin(relDegree * Math.PI / 180))); | |
} else { | |
relX = (int) (((relDegree+POVDegree) % 360) * relativeLayoutPosition.getWidth() / (POVDegree*2)); | |
relY = (int) (relativeLayoutPosition.getHeight() - correctionRatio * distance); | |
} | |
RelativeLayout.LayoutParams imageParamsPosition = new RelativeLayout.LayoutParams( | |
RelativeLayout.LayoutParams.WRAP_CONTENT, | |
RelativeLayout.LayoutParams.WRAP_CONTENT); | |
imageParamsPosition.setMargins(relX, relY, 0, 0); | |
if(relX<0 || relY<0 || relX>relativeLayoutPosition.getWidth() || relY > relativeLayoutPosition.getHeight()) { | |
imageViewPosition.setVisibility(View.GONE); | |
} else { | |
imageViewPosition.setVisibility(View.VISIBLE); | |
} | |
imageViewPosition.setLayoutParams(imageParamsPosition); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment