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
By Anonymous on the 13th of May 2009 05:04:05 PM
Download |
Raw |
Embed |
Report
/// <summary>
/// Project a 3D point given it's world coordinates and the viewing <see cref="Camera"/> to 2D screen space.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
/// <param name="camera">The viewing camera</param>
/// <param name="position">World position of the point to be projected</param>
/// <returns></returns>
public static Vector2 GetScreenCoords(Camera camera, Vector3 position)
{
// projection calculation
Vector4 v4
= new Vector4
(position.
x, position.
y, position.
z, 1.0f
);
Vector4 pos = camera.ProjectionMatrix * camera.ViewMatrix * v4;
Vector2 screenPos
= new Vector2
(pos.
x / pos.
w,
-pos.
y / pos.
w);
// normalize screen position
screenPos.x = (screenPos.x + 1.0f) * 0.5f;
screenPos.y = (screenPos.y + 1.0f) * 0.5f;
return screenPos;
}
Submit a correction or amendment below.
Make A New Post