aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorUbitUmarov2018-05-07 17:29:19 +0100
committerUbitUmarov2018-05-07 17:29:19 +0100
commit4837a8a8fab0d8ed69c94236f6a52a754c9480ba (patch)
tree33dc3a335830aabc36702311e82da224a418646a /OpenSim
parentbreaking map (warp3d) (diff)
downloadopensim-SC-4837a8a8fab0d8ed69c94236f6a52a754c9480ba.zip
opensim-SC-4837a8a8fab0d8ed69c94236f6a52a754c9480ba.tar.gz
opensim-SC-4837a8a8fab0d8ed69c94236f6a52a754c9480ba.tar.bz2
opensim-SC-4837a8a8fab0d8ed69c94236f6a52a754c9480ba.tar.xz
breaking map (warp3d); remove warp3d viewport code not realy used and confusing my last neuron
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs203
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Viewport.cs166
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs86
3 files changed, 193 insertions, 262 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
index 622b16c..95fa567 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs
@@ -83,7 +83,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
83 public static Bitmap Splat(ITerrainChannel terrain, 83 public static Bitmap Splat(ITerrainChannel terrain,
84 UUID[] textureIDs, float[] startHeights, float[] heightRanges, 84 UUID[] textureIDs, float[] startHeights, float[] heightRanges,
85 uint regionPositionX,uint regionPositionY, 85 uint regionPositionX,uint regionPositionY,
86 IAssetService assetService, bool textureTerrain, bool averagetextureTerrain) 86 IAssetService assetService, bool textureTerrain, bool averagetextureTerrain, bool FlipedY)
87 { 87 {
88 Debug.Assert(textureIDs.Length == 4); 88 Debug.Assert(textureIDs.Length == 4);
89 Debug.Assert(startHeights.Length == 4); 89 Debug.Assert(startHeights.Length == 4);
@@ -294,38 +294,79 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
294 // pixel data directly 294 // pixel data directly
295 if(usecolors) 295 if(usecolors)
296 { 296 {
297 unsafe 297 if(FlipedY)
298 { 298 {
299 for(int y = 0; y < 256; ++y) 299 unsafe
300 { 300 {
301 int ty = (int)((255 - y) * yFactor); 301 for(int y = 0; y < 256; ++y)
302 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride; 302 {
303 int ty = (int)(y * yFactor);
304 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
305
306 for(int x = 0; x < 256; ++x)
307 {
308 int tx = (int)(x * xFactor);
309 float height = (float)terrain[tx, ty];
310 float layer = getLayerTex(height, x, y,
311 (uint)tx + regionPositionX, (uint)ty + regionPositionY,
312 startHeights, heightRanges);
313
314 // Select two textures
315 int l0 = (int)layer;
316 int l1 = Math.Min(l0 + 1, 3);
317
318 float layerDiff = layer - l0;
319
320 float a = mapColorsRed[l0];
321 float b = mapColorsRed[l1];
322 *(ptrO++) = (byte)(a + layerDiff * (b - a));
323
324 a = mapColorsGreen[l0];
325 b = mapColorsGreen[l1];
326 *(ptrO++) = (byte)(a + layerDiff * (b - a));
303 327
304 for(int x = 0; x < 256; ++x) 328 a = mapColorsBlue[l0];
329 b = mapColorsBlue[l1];
330 *(ptrO++) = (byte)(a + layerDiff * (b - a));
331 }
332 }
333 }
334 }
335 else
336 {
337 unsafe
338 {
339 for(int y = 0; y < 256; ++y)
305 { 340 {
306 int tx = (int)(x * xFactor); 341 int ty = (int)((255 - y) * yFactor);
307 float height = (float)terrain[tx, ty]; 342 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
308 float layer = getLayerTex(height, x, (255 - y),
309 (uint)tx + regionPositionX, (uint)ty + regionPositionY,
310 startHeights, heightRanges);
311 343
312 // Select two textures 344 for(int x = 0; x < 256; ++x)
313 int l0 = (int)layer; 345 {
314 int l1 = Math.Min(l0 + 1, 3); 346 int tx = (int)(x * xFactor);
347 float height = (float)terrain[tx, ty];
348 float layer = getLayerTex(height, x, (255 - y),
349 (uint)tx + regionPositionX, (uint)ty + regionPositionY,
350 startHeights, heightRanges);
351
352 // Select two textures
353 int l0 = (int)layer;
354 int l1 = Math.Min(l0 + 1, 3);
315 355
316 float layerDiff = layer - l0; 356 float layerDiff = layer - l0;
317 357
318 float a = mapColorsRed[l0]; 358 float a = mapColorsRed[l0];
319 float b = mapColorsRed[l1]; 359 float b = mapColorsRed[l1];
320 *(ptrO++) = (byte)(a + layerDiff * (b - a)); 360 *(ptrO++) = (byte)(a + layerDiff * (b - a));
321 361
322 a = mapColorsGreen[l0]; 362 a = mapColorsGreen[l0];
323 b = mapColorsGreen[l1]; 363 b = mapColorsGreen[l1];
324 *(ptrO++) = (byte)(a + layerDiff * (b - a)); 364 *(ptrO++) = (byte)(a + layerDiff * (b - a));
325 365
326 a = mapColorsBlue[l0]; 366 a = mapColorsBlue[l0];
327 b = mapColorsBlue[l1]; 367 b = mapColorsBlue[l1];
328 *(ptrO++) = (byte)(a + layerDiff * (b - a)); 368 *(ptrO++) = (byte)(a + layerDiff * (b - a));
369 }
329 } 370 }
330 } 371 }
331 } 372 }
@@ -343,42 +384,86 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
343 detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat) 384 detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
344 }; 385 };
345 386
346 for(int y = 0; y < 256; y++) 387 if(FlipedY)
347 { 388 {
348 int ty = (int)((255 - y) * yFactor); 389 for(int y = 0; y < 256; y++)
349 int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride; 390 {
391 int ty = (int)(y * yFactor);
392 int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
350 393
351 for(int x = 0; x < 256; x++) 394 for(int x = 0; x < 256; x++)
395 {
396 int tx = (int)(x * xFactor);
397 float height = (float)terrain[tx, ty];
398 float layer = getLayerTex(height, x, y,
399 (uint)tx + regionPositionX, (uint)ty + regionPositionY,
400 startHeights, heightRanges);
401
402 // Select two textures
403 int l0 = (int)layer;
404 int l1 = Math.Min(l0 + 1, 3);
405
406 int patchOffset = (tx & 0x0f) * 3 + ypatch;
407 byte* ptrA = (byte*)datas[l0].Scan0 + patchOffset;
408 byte* ptrB = (byte*)datas[l1].Scan0 + patchOffset;
409 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
410
411 float aB = *(ptrA + 0);
412 float aG = *(ptrA + 1);
413 float aR = *(ptrA + 2);
414
415 float bB = *(ptrB + 0);
416 float bG = *(ptrB + 1);
417 float bR = *(ptrB + 2);
418
419 float layerDiff = layer - l0;
420
421 // Interpolate between the two selected textures
422 *(ptrO + 0) = (byte)(aB + layerDiff * (bB - aB));
423 *(ptrO + 1) = (byte)(aG + layerDiff * (bG - aG));
424 *(ptrO + 2) = (byte)(aR + layerDiff * (bR - aR));
425 }
426 }
427 }
428 else
429 {
430 for(int y = 0; y < 256; y++)
352 { 431 {
353 int tx = (int)(x * xFactor); 432 int ty = (int)((255 - y) * yFactor);
354 float height = (float)terrain[tx, ty]; 433 int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
355 float layer = getLayerTex(height, x, (255 - y), 434
356 (uint)tx + regionPositionX, (uint)ty + regionPositionY, 435 for(int x = 0; x < 256; x++)
357 startHeights, heightRanges); 436 {
358 437 int tx = (int)(x * xFactor);
359 // Select two textures 438 float height = (float)terrain[tx, ty];
360 int l0 = (int)layer; 439 float layer = getLayerTex(height, x, (255 - y),
361 int l1 = Math.Min(l0 + 1, 3); 440 (uint)tx + regionPositionX, (uint)ty + regionPositionY,
362 441 startHeights, heightRanges);
363 int patchOffset = (tx & 0x0f) * 3 + ypatch; 442
364 byte* ptrA = (byte*)datas[l0].Scan0 + patchOffset; 443 // Select two textures
365 byte* ptrB = (byte*)datas[l1].Scan0 + patchOffset; 444 int l0 = (int)layer;
366 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; 445 int l1 = Math.Min(l0 + 1, 3);
367 446
368 float aB = *(ptrA + 0); 447 int patchOffset = (tx & 0x0f) * 3 + ypatch;
369 float aG = *(ptrA + 1); 448 byte* ptrA = (byte*)datas[l0].Scan0 + patchOffset;
370 float aR = *(ptrA + 2); 449 byte* ptrB = (byte*)datas[l1].Scan0 + patchOffset;
371 450 byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
372 float bB = *(ptrB + 0); 451
373 float bG = *(ptrB + 1); 452 float aB = *(ptrA + 0);
374 float bR = *(ptrB + 2); 453 float aG = *(ptrA + 1);
375 454 float aR = *(ptrA + 2);
376 float layerDiff = layer - l0; 455
377 456 float bB = *(ptrB + 0);
378 // Interpolate between the two selected textures 457 float bG = *(ptrB + 1);
379 *(ptrO + 0) = (byte)(aB + layerDiff * (bB - aB)); 458 float bR = *(ptrB + 2);
380 *(ptrO + 1) = (byte)(aG + layerDiff * (bG - aG)); 459
381 *(ptrO + 2) = (byte)(aR + layerDiff * (bR - aR)); 460 float layerDiff = layer - l0;
461
462 // Interpolate between the two selected textures
463 *(ptrO + 0) = (byte)(aB + layerDiff * (bB - aB));
464 *(ptrO + 1) = (byte)(aG + layerDiff * (bG - aG));
465 *(ptrO + 2) = (byte)(aR + layerDiff * (bR - aR));
466 }
382 } 467 }
383 } 468 }
384 469
@@ -420,6 +505,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
420 heightRanges[1], heightRanges[3], 505 heightRanges[1], heightRanges[3],
421 pctX, pctY); 506 pctX, pctY);
422 heightRange = Utils.Clamp(heightRange, 0f, 255f); 507 heightRange = Utils.Clamp(heightRange, 0f, 255f);
508 if(heightRange == 0f)
509 return 0;
423 510
424 // Generate two frequencies of perlin noise based on our global position 511 // Generate two frequencies of perlin noise based on our global position
425 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting 512 // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
@@ -435,8 +522,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
435 522
436 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it 523 // Combine the current height, generated noise, start height, and height range parameters, then scale all of it
437 float layer = ((height + noise - startHeight) / heightRange) * 4f; 524 float layer = ((height + noise - startHeight) / heightRange) * 4f;
438 if(Single.IsNaN(layer))
439 return 0;
440 return Utils.Clamp(layer, 0f, 3f); 525 return Utils.Clamp(layer, 0f, 3f);
441 } 526 }
442 } 527 }
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Viewport.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Viewport.cs
deleted file mode 100644
index 5ea4d29..0000000
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/Viewport.cs
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Drawing;
30using OpenMetaverse;
31
32namespace OpenSim.Region.CoreModules.World.Warp3DMap
33{
34 public class Viewport
35 {
36 private const float DEG_TO_RAD = (float)Math.PI / 180f;
37 private static readonly Vector3 UP_DIRECTION = Vector3.UnitZ;
38
39 public Vector3 Position;
40 public Vector3 LookDirection;
41 public float FieldOfView;
42 public float NearPlaneDistance;
43 public float FarPlaneDistance;
44 public int Width;
45 public int Height;
46 public bool Orthographic;
47 public float OrthoWindowWidth;
48 public float OrthoWindowHeight;
49
50 public Viewport(Vector3 position, Vector3 lookDirection, float fieldOfView, float farPlaneDist, float nearPlaneDist, int width, int height)
51 {
52 // Perspective projection mode
53 Position = position;
54 LookDirection = lookDirection;
55 FieldOfView = fieldOfView;
56 FarPlaneDistance = farPlaneDist;
57 NearPlaneDistance = nearPlaneDist;
58 Width = width;
59 Height = height;
60 Orthographic = false;
61 }
62
63 public Viewport(Vector3 position, Vector3 lookDirection, float farPlaneDist, float nearPlaneDist, int width, int height, float orthoWindowWidth, float orthoWindowHeight)
64 {
65 // Orthographic projection mode
66 Position = position;
67 LookDirection = lookDirection;
68 FarPlaneDistance = farPlaneDist;
69 NearPlaneDistance = nearPlaneDist;
70 Width = width;
71 Height = height;
72 OrthoWindowWidth = orthoWindowWidth;
73 OrthoWindowHeight = orthoWindowHeight;
74 Orthographic = true;
75 }
76
77 public Point VectorToScreen(Vector3 v)
78 {
79 Matrix4 m = GetWorldToViewportMatrix();
80 Vector3 screenPoint = v * m;
81 return new Point((int)screenPoint.X, (int)screenPoint.Y);
82 }
83
84 public Matrix4 GetWorldToViewportMatrix()
85 {
86 Matrix4 result = GetViewMatrix();
87 result *= GetPerspectiveProjectionMatrix();
88 result *= GetViewportMatrix();
89
90 return result;
91 }
92
93 public Matrix4 GetViewMatrix()
94 {
95 Vector3 zAxis = -LookDirection;
96 zAxis.Normalize();
97
98 Vector3 xAxis = Vector3.Cross(UP_DIRECTION, zAxis);
99 xAxis.Normalize();
100
101 Vector3 yAxis = Vector3.Cross(zAxis, xAxis);
102
103 Vector3 position = Position;
104 float offsetX = -Vector3.Dot(xAxis, position);
105 float offsetY = -Vector3.Dot(yAxis, position);
106 float offsetZ = -Vector3.Dot(zAxis, position);
107
108 return new Matrix4(
109 xAxis.X, yAxis.X, zAxis.X, 0f,
110 xAxis.Y, yAxis.Y, zAxis.Y, 0f,
111 xAxis.Z, yAxis.Z, zAxis.Z, 0f,
112 offsetX, offsetY, offsetZ, 1f);
113 }
114
115 public Matrix4 GetPerspectiveProjectionMatrix()
116 {
117 float aspectRatio = (float)Width / (float)Height;
118
119 float hFoV = FieldOfView * DEG_TO_RAD;
120 float zn = NearPlaneDistance;
121 float zf = FarPlaneDistance;
122
123 float xScale = 1f / (float)Math.Tan(hFoV / 2f);
124 float yScale = aspectRatio * xScale;
125 float m33 = (zf == double.PositiveInfinity) ? -1 : (zf / (zn - zf));
126 float m43 = zn * m33;
127
128 return new Matrix4(
129 xScale, 0f, 0f, 0f,
130 0f, yScale, 0f, 0f,
131 0f, 0f, m33, -1f,
132 0f, 0f, m43, 0f);
133 }
134
135 public Matrix4 GetOrthographicProjectionMatrix(float aspectRatio)
136 {
137 float w = Width;
138 float h = Height;
139 float zn = NearPlaneDistance;
140 float zf = FarPlaneDistance;
141
142 float m33 = 1 / (zn - zf);
143 float m43 = zn * m33;
144
145 return new Matrix4(
146 2f / w, 0f, 0f, 0f,
147 0f, 2f / h, 0f, 0f,
148 0f, 0f, m33, 0f,
149 0f, 0f, m43, 1f);
150 }
151
152 public Matrix4 GetViewportMatrix()
153 {
154 float scaleX = (float)Width * 0.5f;
155 float scaleY = (float)Height * 0.5f;
156 float offsetX = 0f + scaleX;
157 float offsetY = 0f + scaleY;
158
159 return new Matrix4(
160 scaleX, 0f, 0f, 0f,
161 0f, -scaleY, 0f, 0f,
162 0f, 0f, 1f, 0f,
163 offsetX, offsetY, 0f, 1f);
164 }
165 }
166}
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
index b41a27c..b4659cc 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
@@ -156,65 +156,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
156 156
157 #region IMapImageGenerator Members 157 #region IMapImageGenerator Members
158 158
159 private Vector3 cameraPos;
160 private Vector3 cameraDir;
161 private int viewWitdh = 256;
162 private int viewHeigth = 256;
163 private float fov;
164 private bool orto;
165
159 public Bitmap CreateMapTile() 166 public Bitmap CreateMapTile()
160 { 167 {
161 /* this must be on all map, not just its image
162 if ((DateTime.Now - lastImageTime).TotalSeconds < 3600)
163 {
164 return (Bitmap)lastImage.Clone();
165 }
166 */
167
168 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); 168 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
169 if (renderers.Count > 0) 169 if (renderers.Count > 0)
170 { 170 {
171 m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); 171 m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
172 } 172 }
173 173
174 Vector3 camPos = new Vector3( 174 cameraPos = new Vector3(
175 (m_scene.RegionInfo.RegionSizeX) * 0.5f, 175 (m_scene.RegionInfo.RegionSizeX) * 0.5f,
176 (m_scene.RegionInfo.RegionSizeY) * 0.5f, 176 (m_scene.RegionInfo.RegionSizeY) * 0.5f,
177 250f); 177 250f);
178 // Viewport viewing down onto the region
179 Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f,
180 (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY,
181 (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY);
182 178
183 Bitmap tile = CreateMapTile(viewport); 179 cameraDir = -Vector3.UnitZ;
180 viewWitdh = (int)m_scene.RegionInfo.RegionSizeX;
181 viewHeigth = (int)m_scene.RegionInfo.RegionSizeY;
182 orto = true;
183
184 Bitmap tile = GenMapTile();
184 m_primMesher = null; 185 m_primMesher = null;
185 return tile; 186 return tile;
186/*
187 lastImage = tile;
188 lastImageTime = DateTime.Now;
189 return (Bitmap)lastImage.Clone();
190 */
191 } 187 }
192 188
193 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) 189 public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float pfov, int width, int height, bool useTextures)
194 { 190 {
195 Viewport viewport = new Viewport(camPos, camDir, fov, Constants.RegionSize, 0.1f, width, height); 191 List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory());
196 return CreateMapTile(viewport); 192 if (renderers.Count > 0)
193 {
194 m_primMesher = RenderingLoader.LoadRenderer(renderers[0]);
195 }
196
197 cameraPos = camPos;
198 cameraDir = camDir;
199 viewWitdh = width;
200 viewHeigth = height;
201 fov = pfov;
202 orto = false;
203
204 Bitmap tile = GenMapTile();
205 m_primMesher = null;
206 return tile;
197 } 207 }
198 208
199 public Bitmap CreateMapTile(Viewport viewport) 209 private Bitmap GenMapTile()
200 { 210 {
201 m_colors.Clear(); 211 m_colors.Clear();
202 212
203 int width = viewport.Width;
204 int height = viewport.Height;
205
206 WarpRenderer renderer = new WarpRenderer(); 213 WarpRenderer renderer = new WarpRenderer();
207 214
208 if(!renderer.CreateScene(width, height)) 215 if(!renderer.CreateScene(viewWitdh, viewHeigth))
209 return new Bitmap(width,height); 216 return new Bitmap(viewWitdh, viewHeigth);
210 217
211 #region Camera 218 #region Camera
212 219
213 warp_Vector pos = ConvertVector(viewport.Position); 220 warp_Vector pos = ConvertVector(cameraPos);
214 warp_Vector lookat = warp_Vector.add(ConvertVector(viewport.Position), ConvertVector(viewport.LookDirection)); 221 warp_Vector lookat = warp_Vector.add(pos, ConvertVector(cameraDir));
215 222
216 223 if(orto)
217 renderer.Scene.defaultCamera.setOrthographic(true, viewport.OrthoWindowWidth, viewport.OrthoWindowHeight); 224 renderer.Scene.defaultCamera.setOrthographic(true, viewWitdh, viewHeigth);
225 else
226 renderer.Scene.defaultCamera.setFov(fov);
218 227
219 renderer.Scene.defaultCamera.setPos(pos); 228 renderer.Scene.defaultCamera.setPos(pos);
220 renderer.Scene.defaultCamera.lookAt(lookat); 229 renderer.Scene.defaultCamera.lookAt(lookat);
@@ -234,7 +243,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
234 renderer.Scene.destroy(); 243 renderer.Scene.destroy();
235 renderer.Reset(); 244 renderer.Reset();
236 renderer = null; 245 renderer = null;
237 viewport = null;
238 246
239 m_colors.Clear(); 247 m_colors.Clear();
240 GC.Collect(); 248 GC.Collect();
@@ -303,28 +311,31 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
303 npointsy++; 311 npointsy++;
304 312
305 // Create all the vertices for the terrain 313 // Create all the vertices for the terrain
314 // for texture fliped on Y
306 warp_Object obj = new warp_Object(); 315 warp_Object obj = new warp_Object();
307 warp_Vector pos; 316 warp_Vector pos;
308 float x, y; 317 float x, y;
318 float tv;
309 for (y = 0; y < regionsy; y += diff) 319 for (y = 0; y < regionsy; y += diff)
310 { 320 {
321 tv = y * invsy;
311 for (x = 0; x < regionsx; x += diff) 322 for (x = 0; x < regionsx; x += diff)
312 { 323 {
313 pos = ConvertVector(x , y , (float)terrain[(int)x, (int)y]); 324 pos = ConvertVector(x , y , (float)terrain[(int)x, (int)y]);
314 obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f - y * invsy)); 325 obj.addVertex(new warp_Vertex(pos, x * invsx, tv ));
315 } 326 }
316 pos = ConvertVector(x , y , (float)terrain[(int)(x - diff), (int)y]); 327 pos = ConvertVector(x , y , (float)terrain[(int)(x - diff), (int)y]);
317 obj.addVertex(new warp_Vertex(pos, 1.0f, 1.0f - y * invsy)); 328 obj.addVertex(new warp_Vertex(pos, 1.0f, tv));
318 } 329 }
319 330
320 int lastY = (int)(y - diff); 331 int lastY = (int)(y - diff);
321 for (x = 0; x < regionsx; x += diff) 332 for (x = 0; x < regionsx; x += diff)
322 { 333 {
323 pos = ConvertVector(x , y , (float)terrain[(int)x, lastY]); 334 pos = ConvertVector(x , y , (float)terrain[(int)x, lastY]);
324 obj.addVertex(new warp_Vertex(pos, x * invsx, 0f)); 335 obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f));
325 } 336 }
326 pos = ConvertVector(x , y , (float)terrain[(int)(x - diff), lastY]); 337 pos = ConvertVector(x , y , (float)terrain[(int)(x - diff), lastY]);
327 obj.addVertex(new warp_Vertex(pos, 1.0f, 0f)); 338 obj.addVertex(new warp_Vertex(pos, 1.0f, 1.0f));
328 339
329 // Now that we have all the vertices, make another pass and 340 // Now that we have all the vertices, make another pass and
330 // create the list of triangle indices. 341 // create the list of triangle indices.
@@ -376,10 +387,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
376 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); 387 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);
377 388
378 warp_Texture texture; 389 warp_Texture texture;
390 // get texture fliped on Y
379 using (Bitmap image = TerrainSplat.Splat( 391 using (Bitmap image = TerrainSplat.Splat(
380 terrain, textureIDs, startHeights, heightRanges, 392 terrain, textureIDs, startHeights, heightRanges,
381 m_scene.RegionInfo.WorldLocX, m_scene.RegionInfo.WorldLocY, 393 m_scene.RegionInfo.WorldLocX, m_scene.RegionInfo.WorldLocY,
382 m_scene.AssetService, m_textureTerrain, m_textureAvegareTerrain)) 394 m_scene.AssetService, m_textureTerrain, m_textureAvegareTerrain, true))
383 texture = new warp_Texture(image); 395 texture = new warp_Texture(image);
384 396
385 warp_Material material = new warp_Material(texture); 397 warp_Material material = new warp_Material(texture);