Articles from November 2011



3D HTML5 games for iPhone

I been looking for a good 3D JavaScript engine that will allow us to make some kind of html5 game on a mobile but none of them really work on iphones.
Today I found this: https://github.com/mrdoob/three.js#readme

Most of the examples do not work with an iphone as they have to many polygons but some do work at 30 frames per second !

These work well in iPhone (3Gs):
http://mrdoob.github.com/three.js/examples/canvas_geometry_cube.html
http://mrdoob.github.com/three.js/examples/canvas_interactive_cubes.html

This one does not work on iphone (you need to be able to click) but looks like fun. Create a 3d model here: http://mrdoob.com/projects/voxels/ When you finish creating your 3D model the url will be longer copy it to your iphone and you will see your 3d model.

ZK – Communicating with the server

Using Javascript instead of zscript  to calculate a value means you don’t have to communicate with the server until necessary but how do you send data back to the server? I could not find a complete answer so here is my answer below:

In your zul page you will need a textbox (hidden if you want)

<textbox id="serverComm" class="serverComm"></textbox>

Your Javascript put something like this to trigger event

    zk.Widget.$($(".serverComm")).setValue("value to send");
    wid = zk.Widget.$($(".serverComm"));
    zAu.send(new zk.Event(wid, 'onUser', location));

In your “GenericForwardComposer” you need to listen for the event:

	Textbox serverComm;
	public void onUser$serverComm(Event event) throws Exception {
		Event eventx = Events.getRealOrigin((ForwardEvent)event);
		String test = eventx.getData().toString();
		System.out.println(test);
	}

So you don’t make the same mistakes I made:

  • don’t make your on event like “onMyEvent” I think  “onUser” is an event made just for this.
  • I tried sending value without the textbox but it just did not work.

 

GeoLocation using Google API

I been trying to get the users GEO-location so I can pre-fill one of the questions with the users country. This code did the trick

the HTML:

<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAA-O3c-Om9OcvXMOJXreXHAxQGj0PqsCtxKvarsoS-iqLdqZSKfxS27kJqGZajBjvuzOBLizi931BUow"></script>
<script type="text/javascript" src="/js/geoIP.js" ></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<div class="countryDiv"/>
	<input>
</div>

 

 

the Script:

google.load("maps", "2", {callback: initialize});

  function initialize() {

    // Initialize default values
    var latlng = new google.maps.LatLng(37.4419, -100.1419);
    var location = "";

    // If ClientLocation was filled in by the loader, use that info instead
    if (google.loader.ClientLocation) {
      latlng = new google.maps.LatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
      location = "" + getFormattedLocation() + "";
    }
   	alert(location);
   	$(".countryDiv input").val(""+location);
  }

  function getFormattedLocation() {

	  return google.loader.ClientLocation.address.country;
  }