class EAIExample { private static void OnBrowserEvent(Vrml.EAI.Event.BrowserEvent evt) { // Exit the program when there is an error or Avalon gets closed switch (evt.get_ID()) { case Vrml.EAI.Event.BrowserEvent.INITIALIZED: break; case Vrml.EAI.Event.BrowserEvent.SHUTDOWN: case Vrml.EAI.Event.BrowserEvent.URL_ERROR: case Vrml.EAI.Event.BrowserEvent.CONNECTION_ERROR: System.Environment.Exit(0); } } private static float[] red = { 1, 0, 0 }; private static float[] green = { 0, 1, 0 }; private static Vrml.EAI.Field.EventInSFColor set_diffuseColor; private static void OnIsOverChanged(Vrml.EAI.Event.VrmlEvent evt) { // Change the color of the sphere to red when the mouse pointer is over the // sphere, and back to green when it is not Vrml.EAI.Field.EventOutSFBool isOver = (Vrml.EAI.Field.EventOutSFBool)evt.get_Source(); set_diffuseColor.SetValue(isOver.GetValue() == true ? red : green); } public static void main(String[] args) { Vrml.EAI.Browser browser = null; try { // Initialize the connection System.Net.IPAddress address = System.Net.Dns.GetHostEntry("localhost").get_AddressList()[0]; browser = Vrml.EAI.BrowserFactory.GetBrowser(address, 4848); // Tell the browser to call our OnBrowserEvent method in case of an event browser.AddBrowserDelegate(new Vrml.EAI.Event.BrowserDelegate(OnBrowserEvent)); // Get the isOver event out of the TouchSensor node Vrml.EAI.Node touchSensor = browser.GetNode("touchSensor"); Vrml.EAI.Field.EventOutSFBool isOver = (Vrml.EAI.Field.EventOutSFBool)touchSensor.GetEventOut("isOver"); // Get the set_diffuseColor event in of the Material node Vrml.EAI.Node material = browser.GetNode("material"); set_diffuseColor = (Vrml.EAI.Field.EventInSFColor)material.GetEventIn("set_diffuseColor"); // Tell the isOver event out to call our OnIsOverChanged method in case of an event isOver.AddVrmlEventDelegate(new Vrml.EAI.Event.VrmlEventDelegate(OnIsOverChanged)); // Wait forever while (true) System.Threading.Thread.Sleep(1000); } catch (Throwable all) { all.printStackTrace(); } finally { if (browser != null) browser.Dispose(); } } }