2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
namespace Heightmap
|
|
|
|
|
{
|
|
|
|
|
public partial class frmHeightmap : Form
|
|
|
|
|
{
|
2008-07-21 21:12:59 +00:00
|
|
|
private GridClient Client = new GridClient();
|
2007-04-28 20:54:02 +00:00
|
|
|
private PictureBox[,] Boxes = new PictureBox[16, 16];
|
|
|
|
|
private System.Timers.Timer UpdateTimer = new System.Timers.Timer(1000);
|
|
|
|
|
private string FirstName, LastName, Password;
|
|
|
|
|
|
|
|
|
|
double heading = -Math.PI;
|
|
|
|
|
|
|
|
|
|
public frmHeightmap(string firstName, string lastName, string password)
|
|
|
|
|
{
|
|
|
|
|
FirstName = firstName;
|
|
|
|
|
LastName = lastName;
|
|
|
|
|
Password = password;
|
|
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
Client.Network.LoginProgress += Network_OnLogin;
|
2008-01-08 20:48:22 +00:00
|
|
|
|
2007-04-28 20:54:02 +00:00
|
|
|
// Throttle land up and other things down
|
|
|
|
|
Client.Throttle.Cloud = 0;
|
|
|
|
|
Client.Throttle.Land = 1000000;
|
|
|
|
|
Client.Throttle.Wind = 0;
|
|
|
|
|
|
|
|
|
|
Client.Settings.MULTIPLE_SIMS = false;
|
|
|
|
|
|
|
|
|
|
// Build the picture boxes
|
|
|
|
|
this.SuspendLayout();
|
2008-08-27 02:41:14 +00:00
|
|
|
for (int y = 0; y < 16; y++) // Box 0,0 is on the top left
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
for (int x = 0; x < 16; x++)
|
|
|
|
|
{
|
|
|
|
|
Boxes[x, y] = new System.Windows.Forms.PictureBox();
|
|
|
|
|
PictureBox box = Boxes[x, y];
|
|
|
|
|
((System.ComponentModel.ISupportInitialize)(box)).BeginInit();
|
|
|
|
|
box.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
|
|
|
|
box.Name = x + "," + y;
|
2008-08-27 02:41:14 +00:00
|
|
|
box.Location = new System.Drawing.Point(x * 18, y * 18);
|
|
|
|
|
box.Size = new System.Drawing.Size(18, 18);
|
2007-04-28 20:54:02 +00:00
|
|
|
box.Visible = true;
|
|
|
|
|
box.MouseUp += new MouseEventHandler(box_MouseUp);
|
|
|
|
|
((System.ComponentModel.ISupportInitialize)(box)).EndInit();
|
|
|
|
|
|
|
|
|
|
this.Controls.Add(box);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.ResumeLayout();
|
|
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-28 08:01:52 +00:00
|
|
|
private void Network_OnLogin(object sender, LoginProgressEventArgs e)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2009-10-28 08:01:52 +00:00
|
|
|
if (e.Status == LoginStatus.Success)
|
2008-01-08 20:48:22 +00:00
|
|
|
{
|
|
|
|
|
UpdateTimer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateTimer_Elapsed);
|
|
|
|
|
UpdateTimer.Start();
|
|
|
|
|
}
|
2009-10-28 08:01:52 +00:00
|
|
|
else if (e.Status == LoginStatus.Failed)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-05-14 07:33:57 +00:00
|
|
|
Console.WriteLine("Login failed: " + Client.Network.LoginMessage);
|
2007-04-28 20:54:02 +00:00
|
|
|
Console.ReadKey();
|
|
|
|
|
this.Close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-01-08 20:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmHeightmap_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
Client.Terrain.LandPatchReceived += new EventHandler<LandPatchReceivedEventArgs>(Terrain_LandPatchReceived);
|
2008-01-08 20:48:22 +00:00
|
|
|
// Only needed so we can do lookups with TerrainHeightAtPoint
|
|
|
|
|
Client.Settings.STORE_LAND_PATCHES = true;
|
|
|
|
|
|
|
|
|
|
LoginParams loginParams = Client.Network.DefaultLoginParams(FirstName, LastName, Password, "Heightmap",
|
|
|
|
|
"1.0.0");
|
|
|
|
|
Client.Network.BeginLogin(loginParams);
|
2008-08-27 02:41:14 +00:00
|
|
|
|
|
|
|
|
this.SetDesktopLocation(1600, 0);
|
|
|
|
|
// FIXME: This really should be modified in frmHeightmap.Designer.cs, but the Prebuild bug is
|
|
|
|
|
// preventing that right now
|
|
|
|
|
this.SetClientSizeCore(18 * 16, 18 * 16);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void box_MouseUp(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
for (int y = 0; y < 16; y++)
|
|
|
|
|
{
|
|
|
|
|
for (int x = 0; x < 16; x++)
|
|
|
|
|
{
|
|
|
|
|
if (Boxes[x, y] == sender)
|
|
|
|
|
{
|
|
|
|
|
float height;
|
2010-04-21 00:00:54 +00:00
|
|
|
if (Client.Network.CurrentSim.TerrainHeightAtPoint(x * 16 + e.X, y * 16 + e.Y, out height))
|
2008-08-27 02:41:14 +00:00
|
|
|
MessageBox.Show( string.Format("{0},{1}:{2}",x*16+e.X,255-(y*16+e.Y),height) );
|
2007-04-28 20:54:02 +00:00
|
|
|
else
|
|
|
|
|
MessageBox.Show("Unknown height");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UpdateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Spin our camera in circles at the center of the sim to load all the terrain
|
|
|
|
|
heading += 0.5d;
|
|
|
|
|
if (heading > Math.PI) heading = -Math.PI;
|
|
|
|
|
|
2007-11-06 09:26:10 +00:00
|
|
|
Client.Self.Movement.UpdateFromHeading(heading, false);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-17 12:30:30 +00:00
|
|
|
void Terrain_LandPatchReceived(object sender, LandPatchReceivedEventArgs e)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
if (e.X >= 16 || e.Y >= 16)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
Console.WriteLine("Bad patch coordinates, x = " + e.X + ", y = " + e.Y);
|
2007-04-28 20:54:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-17 12:30:30 +00:00
|
|
|
if (e.PatchSize != 16)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
Console.WriteLine("Unhandled patch size " + e.PatchSize + "x" + e.PatchSize);
|
2007-04-28 20:54:02 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bitmap patch = new Bitmap(16, 16, PixelFormat.Format24bppRgb);
|
|
|
|
|
|
|
|
|
|
for (int yp = 0; yp < 16; yp++)
|
|
|
|
|
{
|
|
|
|
|
for (int xp = 0; xp < 16; xp++)
|
|
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
float height = e.HeightMap[(15-yp) * 16 + xp]; // data[0] is south west
|
2007-04-28 20:54:02 +00:00
|
|
|
Color color;
|
2010-03-17 12:30:30 +00:00
|
|
|
if (height >= e.Simulator.WaterHeight)
|
2008-08-27 02:41:14 +00:00
|
|
|
{
|
2010-03-17 12:30:30 +00:00
|
|
|
float maxVal = (float)Math.Log(Math.Abs(512+1-e.Simulator.WaterHeight),2);
|
|
|
|
|
float lgHeight = (float)Math.Log(Math.Abs(height + 1 - e.Simulator.WaterHeight), 2);
|
|
|
|
|
int colorVal1 = Utils.FloatToByte(lgHeight, e.Simulator.WaterHeight, maxVal);
|
|
|
|
|
int colorVal2 = Utils.FloatToByte(height, e.Simulator.WaterHeight, 25.0f);
|
2008-08-27 02:41:14 +00:00
|
|
|
color = Color.FromArgb(255, colorVal2, colorVal1);
|
|
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
else
|
2008-08-27 02:41:14 +00:00
|
|
|
{
|
|
|
|
|
const float minVal = -5.0f;
|
2010-03-17 12:30:30 +00:00
|
|
|
float maxVal = e.Simulator.WaterHeight;
|
2008-10-06 22:34:38 +00:00
|
|
|
int colorVal1 = Utils.FloatToByte(height, -5.0f, minVal + (maxVal - minVal) * 1.5f);
|
|
|
|
|
int colorVal2 = Utils.FloatToByte(height, -5.0f, maxVal);
|
2008-08-27 02:41:14 +00:00
|
|
|
color = Color.FromArgb(colorVal1, colorVal2, 255);
|
|
|
|
|
}
|
|
|
|
|
patch.SetPixel(xp, yp, color); // 0, 0 is top left
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-17 12:30:30 +00:00
|
|
|
Boxes[e.X, 15-e.Y].Image = (System.Drawing.Image)patch;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void frmHeightmap_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Client.Network.Logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-08-27 02:41:14 +00:00
|
|
|
}
|