Subdomain Posts
VB.NET | 9 hours ago
None | 10 hours ago
None | 17 hours ago
None | 19 hours ago
None | 19 hours ago
None | 19 hours ago
VB.NET | 1 day ago
None | 3 days ago
Recent Posts
Java 5 | 56 sec ago
None | 1 min ago
None | 1 min ago
None | 1 min ago
C++ | 1 min ago
None | 2 min ago
C++ | 2 min ago
None | 2 min ago
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Domain Reports
Please check out our new and improved Firefox Add-on. hide message
By Anonymous on the 13th of May 2009 05:04:05 PM Download | Raw | Embed | Report
  1.         /// <summary>
  2.         /// Project a 3D point given it's world coordinates and the viewing <see cref="Camera"/> to 2D screen space.
  3.         /// </summary>
  4.         /// <remarks>
  5.         /// The screen space is assumed to be in range [0..1] in both x and y dimensions, where 0 means the left/top and 1 the right/bottom edge.
  6.         /// </remarks>
  7.         /// <param name="camera">The viewing camera</param>
  8.         /// <param name="position">World position of the point to be projected</param>
  9.         /// <returns></returns>
  10.         public static Vector2 GetScreenCoords(Camera camera, Vector3 position)
  11.         {
  12.             // projection calculation
  13.             Vector4 v4 = new Vector4(position.x, position.y, position.z, 1.0f);
  14.             Vector4 pos = camera.ProjectionMatrix * camera.ViewMatrix * v4;
  15.             Vector2 screenPos = new Vector2(pos.x / pos.w, -pos.y / pos.w);
  16.            
  17.             // normalize screen position
  18.             screenPos.x = (screenPos.x + 1.0f) * 0.5f;
  19.             screenPos.y = (screenPos.y + 1.0f) * 0.5f;
  20.  
  21.             return screenPos;
  22.         }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: