Files
libremetaverse/libsecondlife-cs/examples/Heightmap/frmHeightmap.cs
John Hurliman 9d23185b24 * Added the Heightmap example program
* Upped the login timeout to 60 seconds

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@930 52acb1d6-8a22-11de-b505-999d5b087335
2007-01-31 16:10:56 +00:00

86 lines
3.1 KiB
C#

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;
using libsecondlife;
namespace Heightmap
{
public partial class frmHeightmap : Form
{
private SecondLife Client = new SecondLife();
private System.Windows.Forms.PictureBox[,] Boxes = new System.Windows.Forms.PictureBox[16, 16];
public frmHeightmap(string firstName, string lastName, string password)
{
Client.Terrain.OnLandPatch += new TerrainManager.LandPatchCallback(Terrain_OnLandPatch);
string start = NetworkManager.StartLocation("Miramare", 128, 128, 40);
Dictionary<string, object> loginvals = Client.Network.DefaultLoginValues(firstName, lastName, password,
start, "Heightmap", "jhurliman@wsu.edu", false);
if (!Client.Network.Login(loginvals, "https://login.aditi.lindenlab.com/cgi-bin/login.cgi"))
{
Console.WriteLine("Login failed: " + Client.Network.LoginError);
Application.Exit();
}
// Build the picture boxes
this.SuspendLayout();
for (int y = 0; y < 16; y++)
{
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;
box.Location = new System.Drawing.Point(x * 16, y * 16);
box.Size = new System.Drawing.Size(16, 16);
box.Visible = true;
((System.ComponentModel.ISupportInitialize)(box)).EndInit();
this.Controls.Add(box);
}
}
this.ResumeLayout();
InitializeComponent();
}
void Terrain_OnLandPatch(Simulator simulator, int x, int y, int width, float[] data)
{
if (x >= 16 || y >= 16)
{
Console.WriteLine("Bad patch coordinates, x = " + x + ", y = " + y);
return;
}
if (width != 16)
{
Console.WriteLine("Unhandled patch size " + width + "x" + width);
return;
}
Bitmap patch = new Bitmap(16, 16, PixelFormat.Format24bppRgb);
for (int yp = 0; yp < 16; yp++)
{
for (int xp = 0; xp < 16; xp++)
{
float height = data[yp * 16 + xp];
int color = Helpers.FloatToByte(height, 0.0f, 40.0f);
patch.SetPixel(xp, yp, Color.FromArgb(color, color, color));
}
}
Boxes[x, y].Image = (Image)patch;
}
}
}