32 namespace OpenSim.
Region.CoreModules.
World.Warp3DMap
36 private const float DEG_TO_RAD = (float)Math.PI / 180f;
37 private static readonly Vector3 UP_DIRECTION = Vector3.UnitZ;
39 public Vector3 Position;
40 public Vector3 LookDirection;
41 public float FieldOfView;
42 public float NearPlaneDistance;
43 public float FarPlaneDistance;
46 public bool Orthographic;
47 public float OrthoWindowWidth;
48 public float OrthoWindowHeight;
50 public Viewport(Vector3 position, Vector3 lookDirection,
float fieldOfView,
float farPlaneDist,
float nearPlaneDist,
int width,
int height)
54 LookDirection = lookDirection;
55 FieldOfView = fieldOfView;
56 FarPlaneDistance = farPlaneDist;
57 NearPlaneDistance = nearPlaneDist;
62 public Viewport(Vector3 position, Vector3 lookDirection,
float farPlaneDist,
float nearPlaneDist,
int width,
int height,
float orthoWindowWidth,
float orthoWindowHeight)
66 LookDirection = lookDirection;
67 FarPlaneDistance = farPlaneDist;
68 NearPlaneDistance = nearPlaneDist;
71 OrthoWindowWidth = orthoWindowWidth;
72 OrthoWindowHeight = orthoWindowHeight;
78 Matrix4 m = GetWorldToViewportMatrix();
79 Vector3 screenPoint = v * m;
80 return new Point((
int)screenPoint.X, (
int)screenPoint.Y);
85 Matrix4 result = GetViewMatrix();
86 result *= GetPerspectiveProjectionMatrix();
87 result *= GetViewportMatrix();
94 Vector3 zAxis = -LookDirection;
97 Vector3 xAxis = Vector3.Cross(UP_DIRECTION, zAxis);
100 Vector3 yAxis = Vector3.Cross(zAxis, xAxis);
102 Vector3 position = Position;
103 float offsetX = -Vector3.Dot(xAxis, position);
104 float offsetY = -Vector3.Dot(yAxis, position);
105 float offsetZ = -Vector3.Dot(zAxis, position);
108 xAxis.X, yAxis.X, zAxis.X, 0f,
109 xAxis.Y, yAxis.Y, zAxis.Y, 0f,
110 xAxis.Z, yAxis.Z, zAxis.Z, 0f,
111 offsetX, offsetY, offsetZ, 1f);
116 float aspectRatio = (float)Width / (
float)Height;
118 float hFoV = FieldOfView * DEG_TO_RAD;
119 float zn = NearPlaneDistance;
120 float zf = FarPlaneDistance;
122 float xScale = 1f / (float)Math.Tan(hFoV / 2f);
123 float yScale = aspectRatio * xScale;
124 float m33 = (zf == double.PositiveInfinity) ? -1 : (zf / (zn - zf));
125 float m43 = zn * m33;
138 float zn = NearPlaneDistance;
139 float zf = FarPlaneDistance;
141 float m33 = 1 / (zn - zf);
142 float m43 = zn * m33;
153 float scaleX = (float)Width * 0.5f;
154 float scaleY = (float)Height * 0.5f;
155 float offsetX = 0f + scaleX;
156 float offsetY = 0f + scaleY;
162 offsetX, offsetY, 0f, 1f);
Matrix4 GetWorldToViewportMatrix()
Matrix4 GetViewportMatrix()
Matrix4 GetOrthographicProjectionMatrix(float aspectRatio)
Point VectorToScreen(Vector3 v)
Viewport(Vector3 position, Vector3 lookDirection, float farPlaneDist, float nearPlaneDist, int width, int height, float orthoWindowWidth, float orthoWindowHeight)
Matrix4 GetPerspectiveProjectionMatrix()