Skip to content

Instantly share code, notes, and snippets.

@Realitian
Created September 23, 2019 06:20
Show Gist options
  • Select an option

  • Save Realitian/56e0cc4d5526f34ea6f8d71b98de90eb to your computer and use it in GitHub Desktop.

Select an option

Save Realitian/56e0cc4d5526f34ea6f8d71b98de90eb to your computer and use it in GitHub Desktop.
Convert WorldSpaceCoordinate To ScreenSpaceCoordinate
flagScreenPos = projectionMatrix * modelViewMatrix * pos3dWSC;
float sx = flagScreenPos.x/flagScreenPos.w;
float sy = flagScreenPos.y/flagScreenPos.w;
float lx = (1 + sx)/2.0 * view.bounds.size.width;
float ly = (1 - sy)/2.0 * view.bounds.size.height;
if ( !isnan(lx) && !isnan(ly) ){
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGRect frame = self.label.frame;
self.label.text = @"text";
frame.origin.x=lx - 10;
frame.origin.y=ly - 10;
frame.size.width = 200;
frame.size.height = 50;
self.label.frame= frame;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment