Moving examples, mapgenerator, and VisualParamGenerator to Programs folder (SVN is seriously ruined still, don't check out yet)
git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1961 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Windows.Forms;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenMetaverse.GUITestClient
|
||||
{
|
||||
public class HeightmapInterface : Interface
|
||||
{
|
||||
private PictureBox[,] Boxes = new PictureBox[16, 16];
|
||||
|
||||
public HeightmapInterface(frmTestClient testClient)
|
||||
{
|
||||
Name = "Heightmap";
|
||||
Description = "Displays a graphical heightmap of the current simulator";
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Client.Terrain.OnLandPatch += new TerrainManager.LandPatchCallback(Terrain_OnLandPatch);
|
||||
Client.Settings.STORE_LAND_PATCHES = true;
|
||||
|
||||
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;
|
||||
//box.MouseUp += new MouseEventHandler(box_MouseUp);
|
||||
((System.ComponentModel.ISupportInitialize)(box)).EndInit();
|
||||
|
||||
TabPage.Controls.Add(box);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
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 colorVal = Helpers.FloatToByte(height, 0.0f, 60.0f);
|
||||
int lesserVal = (int)((float)colorVal * 0.75f);
|
||||
Color color;
|
||||
|
||||
if (height >= simulator.WaterHeight)
|
||||
color = Color.FromArgb(lesserVal, colorVal, lesserVal);
|
||||
else
|
||||
color = Color.FromArgb(lesserVal, lesserVal, colorVal);
|
||||
|
||||
patch.SetPixel(xp, yp, color);
|
||||
}
|
||||
}
|
||||
|
||||
Boxes[x, y].Image = (System.Drawing.Image)patch;
|
||||
}
|
||||
}
|
||||
}
|
||||
145
Programs/examples/GUITestClient/Interfaces/MinimapInterface.cs
Normal file
145
Programs/examples/GUITestClient/Interfaces/MinimapInterface.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using OpenMetaverse;
|
||||
using System.Net;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OpenMetaverse.GUITestClient
|
||||
{
|
||||
public class MinimapInterface : Interface
|
||||
{
|
||||
//A magic number to calculate index sim y coord from actual coord
|
||||
private const int GRID_Y_OFFSET = 1279;
|
||||
//Base URL for web map api sim images
|
||||
private const String MAP_IMG_URL = "http://secondlife.com/apps/mapapi/grid/map_image/";
|
||||
private PictureBox world = new PictureBox();
|
||||
private Button cmdRefresh = new Button();
|
||||
private System.Drawing.Image mMapImage = null;
|
||||
private string oldSim = String.Empty;
|
||||
|
||||
public MinimapInterface(frmTestClient testClient)
|
||||
{
|
||||
Name = "Minimap";
|
||||
Description = "Displays a graphical minimap of the current simulator";
|
||||
}
|
||||
|
||||
private void map_onclick(object sender, System.EventArgs e)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
private void cmdRefresh_onclick(object sender, System.EventArgs e)
|
||||
{
|
||||
printMap();
|
||||
}
|
||||
|
||||
public void printMap()
|
||||
{
|
||||
Bitmap map = new Bitmap(256, 256, PixelFormat.Format32bppRgb);
|
||||
Font font = new Font("Tahoma", 8, FontStyle.Bold);
|
||||
Pen mAvPen = new Pen(Brushes.GreenYellow, 1);
|
||||
Brush mAvBrush = new SolidBrush(Color.Green);
|
||||
String strInfo = String.Empty;
|
||||
|
||||
// Get new background map if necessary
|
||||
if (mMapImage == null || oldSim != Client.Network.CurrentSim.Name)
|
||||
{
|
||||
oldSim = Client.Network.CurrentSim.Name;
|
||||
mMapImage = DownloadWebMapImage();
|
||||
}
|
||||
|
||||
// Create in memory bitmap
|
||||
using (Graphics g = Graphics.FromImage(map))
|
||||
{
|
||||
// Draw background map
|
||||
g.DrawImage(mMapImage, new Rectangle(0, 0, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel);
|
||||
|
||||
// Draw all avatars
|
||||
Client.Network.CurrentSim.AvatarPositions.ForEach(
|
||||
delegate(LLVector3 pos)
|
||||
{
|
||||
Rectangle rect = new Rectangle((int)Math.Round(pos.X, 0) - 2, 255 - ((int)Math.Round(pos.Y, 0) - 2), 4, 4);
|
||||
g.FillEllipse(mAvBrush, rect);
|
||||
g.DrawEllipse(mAvPen, rect);
|
||||
}
|
||||
);
|
||||
|
||||
// Draw self ;)
|
||||
Rectangle myrect = new Rectangle((int)Math.Round(Client.Self.SimPosition.X, 0) - 3, 255 - ((int)Math.Round(Client.Self.SimPosition.Y, 0) - 3), 6, 6);
|
||||
g.FillEllipse(new SolidBrush(Color.Yellow), myrect);
|
||||
g.DrawEllipse(new Pen(Brushes.Goldenrod, 1), myrect);
|
||||
|
||||
// Draw region info
|
||||
strInfo = string.Format("Sim {0}/{1}/{2}/{3}\nAvatars {4}", Client.Network.CurrentSim.Name,
|
||||
Math.Round(Client.Self.SimPosition.X, 0),
|
||||
Math.Round(Client.Self.SimPosition.Y, 0),
|
||||
Math.Round(Client.Self.SimPosition.Z, 0),
|
||||
Client.Network.CurrentSim.AvatarPositions.Count);
|
||||
g.DrawString(strInfo, font, Brushes.DarkOrange, 4, 4);
|
||||
}
|
||||
// update picture box with new map bitmap
|
||||
world.BackgroundImage = map;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
((System.ComponentModel.ISupportInitialize)(world)).BeginInit();
|
||||
world.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
world.Size = new System.Drawing.Size(256, 256);
|
||||
world.Visible = true;
|
||||
world.Click += new System.EventHandler(this.map_onclick);
|
||||
((System.ComponentModel.ISupportInitialize)(world)).EndInit();
|
||||
|
||||
//((System.ComponentModel.ISupportInitialize)(cmdRefresh)).BeginInit();
|
||||
cmdRefresh.Text = "Refresh";
|
||||
cmdRefresh.Size = new System.Drawing.Size(80, 24);
|
||||
cmdRefresh.Left = world.Left + world.Width + 20;
|
||||
cmdRefresh.Click += new System.EventHandler(this.cmdRefresh_onclick);
|
||||
cmdRefresh.Visible = true;
|
||||
//((System.ComponentModel.ISupportInitialize)(world)).EndInit();
|
||||
|
||||
TabPage.Controls.Add(world);
|
||||
TabPage.Controls.Add(cmdRefresh);
|
||||
}
|
||||
|
||||
// Ripped from "Terrain Sculptor" by Cadroe with minors changes
|
||||
// http://spinmass.blogspot.com/2007/08/terrain-sculptor-maps-sims-and-creates.html
|
||||
private System.Drawing.Image DownloadWebMapImage()
|
||||
{
|
||||
HttpWebRequest request = null;
|
||||
HttpWebResponse response = null;
|
||||
String imgURL = "";
|
||||
GridRegion currRegion;
|
||||
|
||||
Client.Grid.GetGridRegion(Client.Network.CurrentSim.Name, GridLayerType.Terrain, out currRegion);
|
||||
try
|
||||
{
|
||||
//Form the URL using the sim coordinates
|
||||
imgURL = MAP_IMG_URL + currRegion.X.ToString() + "-" +
|
||||
(GRID_Y_OFFSET - currRegion.Y).ToString() + "-1-0";
|
||||
//Make the http request
|
||||
request = (HttpWebRequest)HttpWebRequest.Create(imgURL);
|
||||
request.Timeout = 5000;
|
||||
request.ReadWriteTimeout = 20000;
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
return System.Drawing.Image.FromStream(response.GetResponseStream());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), "Error Downloading Web Map Image");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using OpenMetaverse;
|
||||
|
||||
namespace OpenMetaverse.GUITestClient
|
||||
{
|
||||
class TeleportInterface : Interface
|
||||
{
|
||||
private System.Windows.Forms.Button cmdTeleport;
|
||||
private System.Windows.Forms.TextBox txtLocation;
|
||||
private System.Windows.Forms.Label lblLocation;
|
||||
|
||||
public TeleportInterface(frmTestClient testClient)
|
||||
{
|
||||
Name = "Teleport";
|
||||
Description = "Teleport your's agent in SL Grid";
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
txtLocation = new System.Windows.Forms.TextBox();
|
||||
txtLocation.Size = new System.Drawing.Size(238, 24);
|
||||
txtLocation.Top = 100;
|
||||
txtLocation.Left = 12;
|
||||
|
||||
lblLocation = new System.Windows.Forms.Label();
|
||||
lblLocation.Size = new System.Drawing.Size(238, 24);
|
||||
lblLocation.Top = txtLocation.Top - 16;
|
||||
lblLocation.Left = txtLocation.Left;
|
||||
lblLocation.Text = "Location (eg: sim/x/y/z)";
|
||||
|
||||
cmdTeleport = new System.Windows.Forms.Button();
|
||||
cmdTeleport.Size = new System.Drawing.Size(120, 24);
|
||||
cmdTeleport.Top = 100; cmdTeleport.Left = 257;
|
||||
cmdTeleport.Text = "Teleport !";
|
||||
cmdTeleport.Click += new System.EventHandler(this.cmdTeleport_OnClick);
|
||||
|
||||
TabPage.Controls.Add(txtLocation);
|
||||
TabPage.Controls.Add(lblLocation);
|
||||
TabPage.Controls.Add(cmdTeleport);
|
||||
}
|
||||
|
||||
private void cmdTeleport_OnClick(object sender, System.EventArgs e)
|
||||
{
|
||||
String destination = txtLocation.Text.Trim();
|
||||
|
||||
string[] tokens = destination.Split(new char[] { '/' });
|
||||
if (tokens.Length != 4)
|
||||
goto error_handler;
|
||||
|
||||
string sim = tokens[0];
|
||||
float x, y, z;
|
||||
if (!float.TryParse(tokens[1], out x) ||
|
||||
!float.TryParse(tokens[2], out y) ||
|
||||
!float.TryParse(tokens[3], out z))
|
||||
{
|
||||
goto error_handler;
|
||||
}
|
||||
|
||||
if (Client.Self.Teleport(sim, new LLVector3(x, y, z)))
|
||||
MessageBox.Show("Teleported to " + Client.Network.CurrentSim, "Teleport");
|
||||
else
|
||||
MessageBox.Show("Teleport failed: " + Client.Self.TeleportMessage, "Teleport");
|
||||
return;
|
||||
|
||||
error_handler:
|
||||
MessageBox.Show("Location must to be sim/x/y/z", "Teleport");
|
||||
}
|
||||
|
||||
public override void Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user