<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Angel Arcoraci</title>
	<atom:link href="http://aarcoraci.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aarcoraci.wordpress.com</link>
	<description>Microsoft Student Partner - Mza - Arg</description>
	<lastBuildDate>Wed, 14 Dec 2011 00:35:04 +0000</lastBuildDate>
	<language>es</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='aarcoraci.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Angel Arcoraci</title>
		<link>http://aarcoraci.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aarcoraci.wordpress.com/osd.xml" title="Angel Arcoraci" />
	<atom:link rel='hub' href='http://aarcoraci.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Android WCF REST requests made simple (using JSON)</title>
		<link>http://aarcoraci.wordpress.com/2011/12/13/android-wcf-rest-requests-made-simple-using-json/</link>
		<comments>http://aarcoraci.wordpress.com/2011/12/13/android-wcf-rest-requests-made-simple-using-json/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 23:35:28 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">https://aarcoraci.wordpress.com/?p=88</guid>
		<description><![CDATA[I’ve been struggling for some time trying to get my Android phone to talk with a WCF REST web service. Finally I was able to do it and I decided to share the knowledge. A few things to consider first: I gave up trying to make it work using XML but I like JSON anyway. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=88&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been struggling for some time trying to get my Android phone to talk with a WCF REST web service. Finally I was able to do it and I decided to share the knowledge.</p>
<p>A few things to consider first:</p>
<blockquote>
<ol>
<li>I gave up trying to make it work using XML but I like JSON anyway. If you manage to get this working using xml headers please comment !</li>
<li>The response is not even ready yet, I just got excited I got this working. I’ll post an update later doing a JSON parsing of the response.</li>
<li>The C# WCF REST web service was built using the Online Pattern and not the default one: new project –&gt; online templates –&gt; WCF –&gt; WCF REST Service Template 40(CS)</li>
<li>The Operation Contracts are tagged to use JSON:
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;direction:ltr;text-align:left;margin:20px 0 10px;padding:4px;">
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;direction:ltr;text-align:left;border-style:none;margin:0;padding:0;">[OperationContract]
[WebInvoke(UriTemplate = <span style="color:#006080;">"ValidateCredentials"</span>,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    Method = <span style="color:#006080;">"POST"</span>,
    RequestFormat = System.ServiceModel.Web.WebMessageFormat.Json)]
<span style="color:#0000ff;">string</span> ValidateCredentials(<span style="color:#0000ff;">string</span> username, <span style="color:#0000ff;">string</span> password);</pre>
</div>
</li>
</ol>
</blockquote>
<p>About the Android code:</p>
<p>I want to stress that this is just a quick example of how I made it work, avoid making comments about the quality of the code please ! <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://aarcoraci.files.wordpress.com/2011/12/wlemoticon-smile.png?w=630" alt="Sonrisa" /></p>
<p>Notice I’ve obscured the IP address and port. Change that to suit your needs.</p>
<p>Also, I’m using a singleton pattern, you can avoid that too if you want to.</p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;direction:ltr;text-align:left;margin:20px 0 10px;padding:4px;">
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;direction:ltr;text-align:left;border-style:none;margin:0;padding:0;">package com.on3tech.on3fitness.net;</pre>
<p>import java.io.IOException;<br />
import java.io.InputStream;<br />
import java.io.UnsupportedEncodingException;<br />
import java.util.ArrayList;</p>
<p>import org.apache.http.HttpResponse;<br />
import org.apache.http.NameValuePair;<br />
import org.apache.http.client.ClientProtocolException;<br />
import org.apache.http.client.HttpClient;<br />
import org.apache.http.client.methods.HttpPost;<br />
import org.apache.http.entity.StringEntity;<br />
import org.apache.http.impl.client.DefaultHttpClient;<br />
import org.apache.http.<span style="color:#0000ff;">params</span>.HttpConnectionParams;<br />
import org.json.JSONException;<br />
import org.json.JSONObject;</p>
<p><span style="color:#0000ff;">public</span> final <span style="color:#0000ff;">class</span> RestClient {</p>
<p><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> final String URL = <span style="color:#006080;">&#8220;http://XXX.XXX.XXX.XXX:YYYY/AccountServices/ValidateCredentials&#8221;</span>;</p>
<p><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> RestClient instance = <span style="color:#0000ff;">new</span> RestClient();</p>
<p><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> RestClient getInstance() {<br />
<span style="color:#0000ff;">return</span> instance;<br />
}</p>
<p><span style="color:#0000ff;">private</span> RestClient() {</p>
<p>}</p>
<p><span style="color:#0000ff;">public</span> JSONObject sendJson(ArrayList&lt;NameValuePair&gt; <span style="color:#0000ff;">params</span>) {<br />
JSONObject result = <span style="color:#0000ff;">null</span>;</p>
<p>HttpClient client = <span style="color:#0000ff;">new</span> DefaultHttpClient();<br />
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);<br />
HttpResponse response;</p>
<p>JSONObject json = <span style="color:#0000ff;">new</span> JSONObject();</p>
<p><span style="color:#0000ff;">try</span> {<br />
HttpPost post = <span style="color:#0000ff;">new</span> HttpPost(URL);</p>
<p><span style="color:#0000ff;">for</span> (NameValuePair p : <span style="color:#0000ff;">params</span>){<br />
json.put(p.getName(), p.getValue());<br />
}</p>
<p>StringEntity se = <span style="color:#0000ff;">new</span> StringEntity(json.toString());</p>
<p>post.setEntity(se);<br />
post.setHeader(<span style="color:#006080;">&#8220;Accept&#8221;</span>, <span style="color:#006080;">&#8220;application/json&#8221;</span>);<br />
post.setHeader(<span style="color:#006080;">&#8220;Content-type&#8221;</span>, <span style="color:#006080;">&#8220;application/json&#8221;</span>);<br />
response = client.execute(post);<br />
<span style="color:#008000;">/* Checking response */</span><br />
<span style="color:#0000ff;">if</span> (response != <span style="color:#0000ff;">null</span>) {<br />
InputStream <span style="color:#0000ff;">in</span> = response.getEntity().getContent();<br />
}<br />
} <span style="color:#0000ff;">catch</span> (JSONException ex) {</p>
<p>} <span style="color:#0000ff;">catch</span> (UnsupportedEncodingException ex) {</p>
<p>} <span style="color:#0000ff;">catch</span> (ClientProtocolException ex) {</p>
<p>} <span style="color:#0000ff;">catch</span> (IOException ex) {</p>
<p>}</p>
<p><span style="color:#0000ff;">return</span> result;<br />
}</p>
<p>}</p>
</div>
<p>The problem I originally had were the headers ! I was getting “bad request” all the time. Seems the process of setting the headers on the HttpPost object is very precise.</p>
<p>To finish the example, this is how you make a call:</p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;direction:ltr;text-align:left;margin:20px 0 10px;padding:4px;">
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;direction:ltr;text-align:left;border-style:none;margin:0;padding:0;">ArrayList&lt;NameValuePair&gt; <span style="color:#0000ff;">params</span> = <span style="color:#0000ff;">new</span> ArrayList&lt;NameValuePair&gt;();
<span style="color:#0000ff;">params</span>.add(<span style="color:#0000ff;">new</span> BasicNameValuePair(<span style="color:#006080;">"username"</span>, <span style="color:#006080;">"username value"</span>));
<span style="color:#0000ff;">params</span>.add(<span style="color:#0000ff;">new</span> BasicNameValuePair(<span style="color:#006080;">"password"</span>, <span style="color:#006080;">"password value"</span>));</pre>
<p>RestClient.getInstance().sendJson(<span style="color:#0000ff;">params</span>);</p>
</div>
<p>The ideal scenario should be to have an URL as a parameter too. I’ll add that on a second update regarding this topic.</p>
<p>Again, I’m not doing anything with the response !!! Actually I don’t even know how I’ll work that out, but should be fairy simple from here.</p>
<p>Bests,</p>
<p>Angel</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/88/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/88/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/88/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=88&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2011/12/13/android-wcf-rest-requests-made-simple-using-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2011/12/wlemoticon-smile.png" medium="image">
			<media:title type="html">Sonrisa</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows Phone 7 &#8211; hacer web requests de forma simple</title>
		<link>http://aarcoraci.wordpress.com/2010/08/31/windows-phone-7-e28093-hacer-web-requests-de-forma-simple/</link>
		<comments>http://aarcoraci.wordpress.com/2010/08/31/windows-phone-7-e28093-hacer-web-requests-de-forma-simple/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 12:10:00 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[phone7]]></category>
		<category><![CDATA[http web request]]></category>
		<category><![CDATA[web request]]></category>
		<category><![CDATA[windows phone]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">https://aarcoraci.wordpress.com/2010/08/31/windows-phone-7-e28093-hacer-web-requests-de-forma-simple/</guid>
		<description><![CDATA[La célula de Mendoza esta intento buscar gente para hacer desarrollos en Windows Phone 7 y por mi cuenta (Angel) he estado haciendo algunas investigaciones. Por naturaleza de aplicación para celular, lo mas conveniente es hacer aplicaciones que consuman datos de algún web service. A veces es difícil encontrar como hacer esto, mas cuando la [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=85&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>La célula de Mendoza esta intento buscar gente para hacer desarrollos en Windows Phone 7 y por mi cuenta (Angel) he estado haciendo algunas investigaciones.</p>
<p>Por naturaleza de aplicación para celular, lo mas conveniente es hacer aplicaciones que consuman datos de algún web service. A veces es difícil encontrar como hacer esto, mas cuando la plataforma es tan nueva. Acá les voy a pasar un ejemplo de como hacerlo correctamente y de forma fácil:</p>
<div>
<pre class="code"><span style="color:blue;">        public void </span>GetXML(<span style="color:blue;">string </span>url)
        {
            <span style="color:#2b91af;">HttpWebRequest </span>request =                (<span style="color:#2b91af;">HttpWebRequest</span>)<span style="color:#2b91af;">HttpWebRequest</span>.Create(<span style="color:blue;">new </span><span style="color:#2b91af;">Uri</span>(url));
            request.Headers[<span style="color:#a31515;">&quot;user-agent&quot;</span>] = <span style="color:#a31515;">&quot;MSIE 7.0&quot;</span>;
            request.BeginGetResponse(<span style="color:blue;">new </span><span style="color:#2b91af;">AsyncCallback</span>(ReadCallback), request);
        }

        <span style="color:blue;">private void </span>ReadCallback(<span style="color:#2b91af;">IAsyncResult </span>asynchronousResult)
        {
            <span style="color:#2b91af;">HttpWebRequest </span>request =                 (<span style="color:#2b91af;">HttpWebRequest</span>)asynchronousResult.AsyncState;
            <span style="color:#2b91af;">HttpWebResponse </span>response =                 (<span style="color:#2b91af;">HttpWebResponse</span>)request.EndGetResponse(asynchronousResult);

            <span style="color:blue;">using </span>(<span style="color:#2b91af;">StreamReader </span>streamReader =                 <span style="color:blue;">new </span><span style="color:#2b91af;">StreamReader</span>(response.GetResponseStream()))
            {
                <span style="color:#2b91af;">XDocument </span>xmlDocument = <span style="color:#2b91af;">XDocument</span>.Load(streamReader);
            }                }</pre>
</div>
<p>El código hace un pedido a una url especificada y cuando obtiene la respuesta va al metodo ReadCallback (si van a actualizar algún control tengan en cuenta que están trabajando en hilos diferentes). Yo en el ejemplo cree un XDocument (es la version de XmlDocument en WP7), pero pueden usar un string o lo que deseen.</p>
<p>Como les decia, si van a actualizar un metodo, lo mejor es usar un delegado y un evento (estos son ejemplos, no le presten atencion a los metodos y argumentos)</p>
<p>1) Declaramos en nuestra clase ambos:</p>
<pre class="code"><span style="color:blue;">public delegate void </span><span style="color:#2b91af;">CharacterReceivedHandler</span>(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">CharacterReceivedEventArgs </span>e);
<span style="color:blue;">public event </span><span style="color:#2b91af;">CharacterReceivedHandler </span>CharacterReceived;</pre>
<p>2) Disparamos el evento cuando armamos el XDocument ( o lo que recibamos):</p>
<pre class="code"><span style="color:blue;"></span>&#160;<span style="color:blue;">if</span>(CharacterReceived != <span style="color:blue;">null</span>)
      CharacterReceived(<span style="color:blue;">this</span>,          <span style="color:blue;">new </span><span style="color:#2b91af;">CharacterReceivedEventArgs</span>() { Character = currentCharacter });</pre>
<p>3)En la clase que enganchamos el metodo hacemos lo siguiente: </p>
<pre class="code">connector.CharacterReceived += <span style="color:blue;">new </span><span style="color:#2b91af;">ArmoryConnector</span>.<span style="color:#2b91af;">CharacterReceivedHandler</span>(connector_CharacterReceived);

<font face="Courier New">…</font>


<span style="color:blue;">void </span>connector_CharacterReceived(<span style="color:blue;">object </span>sender, <span style="color:#2b91af;">CharacterReceivedEventArgs </span>e)
{&#160;&#160; <span style="color:blue;">this</span>.Dispatcher.BeginInvoke(<span style="color:blue;">delegate</span>()
  {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:green;">// Update controls here </span>  });
}
</pre>
<p><font face="Courier New">Ojala les sirva <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=85&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2010/08/31/windows-phone-7-e28093-hacer-web-requests-de-forma-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA &#8211; Your first Phone 7 Game in 3D !!!</title>
		<link>http://aarcoraci.wordpress.com/2010/03/16/xna-your-first-phone-7-game-in-3d/</link>
		<comments>http://aarcoraci.wordpress.com/2010/03/16/xna-your-first-phone-7-game-in-3d/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 14:06:01 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[phone7]]></category>
		<category><![CDATA[xna]]></category>
		<category><![CDATA[tutoriales]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2010/03/16/xna-your-first-phone-7-game-in-3d/</guid>
		<description><![CDATA[Heiya guys ! I’ll post a small tutorial on how to compile your first 3d game on windows phone 7 (using the emulator). First, you’ll need the developer tools WHICH ARE FREE !!! Get them RIGHT now: http://www.microsoft.com/express/Phone/ Now, lets get this started. First open VS2010 and create a new Windows Game. Camera I’ve prepared [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=83&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Heiya guys ! I’ll post a small tutorial on how to compile your first 3d game on windows phone 7 (using the emulator).</p>
<p>First, you’ll need the developer tools <strong>WHICH ARE FREE !!!</strong> Get them RIGHT now:</p>
<p><a href="http://www.microsoft.com/express/Phone/">http://www.microsoft.com/express/Phone/</a></p>
<p>Now, lets get this started. First open VS2010 and create a new Windows Game. </p>
<h4>Camera</h4>
<p>I’ve prepared a 3d camera suitable for a shooter. This means the camera is looking from upside down. You can feel free to use it in your projects. Here is the code:</p>
<table border="0" cellspacing="0" cellpadding="2" width="300">
<tbody>
<tr>
<td valign="top" width="300">
<pre class="code"><span style="color:blue;">   public static class </span><span style="color:#2b91af;">Camera
   </span>{
       <span style="color:blue;">public static </span><span style="color:#2b91af;">Matrix </span>World { <span style="color:blue;">get</span>; <span style="color:blue;">private set</span>; }
       <span style="color:blue;">public static </span><span style="color:#2b91af;">Matrix </span>View { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
       <span style="color:blue;">public static </span><span style="color:#2b91af;">Matrix </span>Projection { <span style="color:blue;">get</span>; <span style="color:blue;">private set</span>; }

       <span style="color:blue;">public static </span><span style="color:#2b91af;">BoundingFrustum </span>BoundingFrustum { <span style="color:blue;">get</span>; <span style="color:blue;">private set</span>; }

       <span style="color:blue;">public static </span><span style="color:#2b91af;">Vector3 </span>Position { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }

       <span style="color:green;">// needed attributes
       </span><span style="color:blue;">private static float </span>nearClip = 1.0f;
       <span style="color:blue;">private static float </span>farClip = 1000.0f;

       <span style="color:blue;">private static float </span>aspectRatio = 800 / 600; <span style="color:green;">// default aspect ratio
       </span><span style="color:blue;">public static float </span>AspectRatio
       {
           <span style="color:blue;">get </span>{ <span style="color:blue;">return </span>aspectRatio; }

           <span style="color:blue;">set
           </span>{
               aspectRatio = <span style="color:blue;">value</span>;
               UpdateMatrices();
           }

       }

       <span style="color:blue;">public static void </span>Update()
       {
           UpdateMatrices();
       }

       <span style="color:blue;">public static void </span>UpdateMatrices()
       {

           <span style="color:#2b91af;">Matrix </span>rotationMatrix = <span style="color:#2b91af;">Matrix</span>.CreateRotationX(<span style="color:#2b91af;">MathHelper</span>.ToRadians(90));
           <span style="color:#2b91af;">Vector3 </span>transformedReference = <span style="color:#2b91af;">Vector3</span>.Transform(<span style="color:#2b91af;">Vector3</span>.Forward, rotationMatrix);

           View = <span style="color:#2b91af;">Matrix</span>.CreateLookAt(Position, <span style="color:blue;">new </span><span style="color:#2b91af;">Vector3</span>(0, 0, 0), <span style="color:#2b91af;">Vector3</span>.Forward);
           Projection = <span style="color:#2b91af;">Matrix</span>.CreatePerspectiveFieldOfView(<span style="color:#2b91af;">MathHelper</span>.PiOver4, aspectRatio, nearClip, farClip);
           World = <span style="color:#2b91af;">Matrix</span>.Identity;

           World = <span style="color:#2b91af;">Matrix</span>.Identity;

           BoundingFrustum = <span style="color:blue;">new </span><span style="color:#2b91af;">BoundingFrustum</span>(View * Projection);
       }
   }</pre>
<p>        <a href="http://11011.net/software/vspaste"></a></td>
</tr>
</tbody>
</table>
<p>The code is quite simple. The UpdateMatrices does all the work.&#160; Notice I’ll I’m doing is transform the Forward vector with a 90 degrees angle. I know this is lame but I’ve choose this way to make it more graphical: In a normal FPS game you are pointing forward, if I rotate 90 degrees… well I know you get it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><font color="#800000">Note this:</font></p>
<p>Before we load the graphical device, we don’t know the viewport’s aspect ratio, so I’ve done it in a dynamic fashion, once you change the Camera’s ratio, it’ll recalculate the projection Matrix; this means you have to manually set the aspect ratio of the camera:</p>
<table border="0" cellspacing="0" cellpadding="2" width="300">
<tbody>
<tr>
<td valign="top" width="300">
<pre class="code"><span style="color:gray;">        /// &lt;summary&gt;
        /// </span><span style="color:green;">LoadContent will be called once per game and is the place to load
        </span><span style="color:gray;">/// </span><span style="color:green;">all of your content.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        </span><span style="color:blue;">protected override void </span>LoadContent()
        {
            <span style="color:green;">// Create a new SpriteBatch, which can be used to draw textures.
            </span>spriteBatch = <span style="color:blue;">new </span><span style="color:#2b91af;">SpriteBatch</span>(GraphicsDevice);

            <span style="color:green;">// TODO: use this.Content to load your game content here
            </span><span style="color:#2b91af;">Camera</span>.AspectRatio = GraphicsDevice.Viewport.AspectRatio;
        }</pre>
</td>
</tr>
</tbody>
</table>
<h1></h1>
</p>
<p>Also ! remember to update the camera !!</p>
<h4>Model</h4>
<p>Here is the great part. Nothing has changed ! You can draw your models just the way you did it in the XNA 3.1 versions.</p>
<p>In a few steps:</p>
<ol>
<li>Declare your model</li>
<li>Load it (notice the changes in the Content directory)</li>
<li>Transform it </li>
<li>Draw it</li>
</ol>
<p>The declaration is easy, but the process to add it to the project is a little bit different. Here is a screenshoot:</p>
<p><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="loadModel" border="0" alt="loadModel" src="http://aarcoraci.files.wordpress.com/2010/03/loadmodel.jpg?w=668&#038;h=268" width="668" height="268" /> </p>
<p>To load it, we use the same procedure as before:</p>
<table border="0" cellspacing="0" cellpadding="2" width="300">
<tbody>
<tr>
<td valign="top" width="300">
<pre class="code"><span style="color:blue;">protected override void </span>LoadContent()
{
    <span style="color:green;">// Create a new SpriteBatch, which can be used to draw textures.
    </span>spriteBatch = <span style="color:blue;">new </span><span style="color:#2b91af;">SpriteBatch</span>(GraphicsDevice);

    <span style="color:green;">// TODO: use this.Content to load your game content here
    </span><span style="color:#2b91af;">Camera</span>.AspectRatio = GraphicsDevice.Viewport.AspectRatio;
    model = Content.Load&lt;<span style="color:#2b91af;">Model</span>&gt;(<span style="color:#a31515;">&quot;raptorxxi&quot;</span>);
}</pre>
<p>        <a href="http://11011.net/software/vspaste"></a></td>
</tr>
</tbody>
</table>
<p>Here is our code to draw it (you can see the rest in the project).</p>
<table border="0" cellspacing="0" cellpadding="2" width="300">
<tbody>
<tr>
<td valign="top" width="300">
<pre class="code"><span style="color:gray;">/// &lt;summary&gt;
        /// </span><span style="color:green;">This is called when the game should draw itself.
        </span><span style="color:gray;">/// &lt;/summary&gt;
        /// &lt;param name=&quot;gameTime&quot;&gt;</span><span style="color:green;">Provides a snapshot of timing values.</span><span style="color:gray;">&lt;/param&gt;
        </span><span style="color:blue;">protected override void </span>Draw(<span style="color:#2b91af;">GameTime </span>gameTime)
        {
            GraphicsDevice.Clear(<span style="color:#2b91af;">Color</span>.CornflowerBlue);

            <span style="color:green;">// TODO: Add your drawing code here

            // Copy any parent transforms.
            </span><span style="color:#2b91af;">Matrix</span>[] transforms = <span style="color:blue;">new </span><span style="color:#2b91af;">Matrix</span>[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            <span style="color:green;">// Draw the model. A model can have multiple meshes, so loop.
            </span><span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
            {
                <span style="color:green;">// This is where the mesh orientation is set, as well
                // as our camera and projection.
                </span><span style="color:blue;">foreach </span>(<span style="color:#2b91af;">BasicEffect </span>effect <span style="color:blue;">in </span>mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.View = <span style="color:#2b91af;">Camera</span>.View;
                    effect.World = transforms[mesh.ParentBone.Index] * <span style="color:#2b91af;">Matrix</span>.CreateTranslation(<span style="color:#2b91af;">Vector3</span>.Zero);
                    effect.Projection = <span style="color:#2b91af;">Camera</span>.Projection;
                }
                <span style="color:green;">// Draw the mesh, using the effects set above.
                </span>mesh.Draw();

            }

            <span style="color:blue;">base</span>.Draw(gameTime);
        }</pre>
</td>
</tr>
</tbody>
</table>
<p>And there you go:</p>
<p>&#160;<img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="final" border="0" alt="final" src="http://aarcoraci.files.wordpress.com/2010/03/final.jpg?w=572&#038;h=714" width="572" height="714" /> </p>
</p>
<p><a href="http://cid-cb95020351c750f1.skydrive.live.com/self.aspx/Tutoriales/FirstPhone7Game.zip">Download the solution from HERE !!!!!</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=83&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2010/03/16/xna-your-first-phone-7-game-in-3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/03/loadmodel.jpg" medium="image">
			<media:title type="html">loadModel</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/03/final.jpg" medium="image">
			<media:title type="html">final</media:title>
		</media:content>
	</item>
		<item>
		<title>Multiple textures (or materials) on models</title>
		<link>http://aarcoraci.wordpress.com/2010/02/02/multiple-textures-or-materials-on-models/</link>
		<comments>http://aarcoraci.wordpress.com/2010/02/02/multiple-textures-or-materials-on-models/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 13:27:19 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[xna]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[hlsl]]></category>
		<category><![CDATA[multi texture]]></category>
		<category><![CDATA[multiple materials]]></category>
		<category><![CDATA[multiple texture]]></category>
		<category><![CDATA[shader]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2010/02/02/multiple-textures-or-materials-on-models/</guid>
		<description><![CDATA[Hi, this time I’ll play a little with effects (don’t worry, I’m awful at HLSL so this won’t be complicate). Generally, the problem in multi texture effects is to decide “how much” of each material apply. There are hundreds of approaches and different algorithms. I’ll use a very simple one: We have two textures, a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=80&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi, this time I’ll play a little with effects (don’t worry, I’m awful at HLSL so this won’t be complicate).</p>
<p>Generally, the problem in multi texture effects is to decide “how much” of each material apply. There are hundreds of approaches and different algorithms. I’ll use a very simple one: We have two textures, a base texture (for example a base skin texture for a character) and a brush texture (lets say, a piece of cloth). The second texture is a transparent texture with some areas painted. </p>
<p>What we are going to do is, take the base texture, and remove the areas that are not transparent on the second one. Although this sound complicated, this is super easy to do. I’ll post some code of the .fx file now:</p>
<p>First, notice I’ll be using two samplers. One for each texture I’ll be using.</p>
<table border="0" cellspacing="0" cellpadding="2" width="461">
<tbody>
<tr>
<td valign="top" width="459">
<p>texture TextureMap;           <br />sampler2D TextureMapSampler = sampler_state             <br />{             <br />&#160;&#160;&#160; texture = (TextureMap);             <br />&#160;&#160;&#160; AddressU = WRAP;             <br />&#160;&#160;&#160; AddressV = WRAP;             <br />&#160;&#160;&#160; MinFilter = LINEAR;             <br />&#160;&#160;&#160; MipFilter = LINEAR;             <br />&#160;&#160;&#160; MagFilter = LINEAR;             <br />}; </p>
<p>texture Brush0;           <br />sampler2D Brush0Sampler = sampler_state             <br />{             <br />&#160;&#160;&#160; texture = (Brush0);             <br />&#160;&#160;&#160; AddressU = WRAP;             <br />&#160;&#160;&#160; AddressV = WRAP;             <br />&#160;&#160;&#160; MinFilter = LINEAR;             <br />&#160;&#160;&#160; MipFilter = LINEAR;             <br />&#160;&#160;&#160; MagFilter = LINEAR;             <br />};</p>
</td>
</tr>
</tbody>
</table>
<p>I’ll skip the vertex shader since it’s very simple. I’ll go straight to the algorithm:</p>
<table border="0" cellspacing="0" cellpadding="2" width="512">
<tbody>
<tr>
<td valign="top" width="510">
<p>&#160; <font color="#008000">// this will remove part of the base texture in order to apply the second material             <br /></font>&#160;&#160;&#160; float amount = 1 &#8211; tex2D(Brush0Sampler, input.UV).a;            <br />&#160;&#160; output = (tex2D(TextureMapSampler, input.UV)) * amount;            <br />&#160;&#160; output += (tex2D(Brush0Sampler, input.UV));&#160;&#160; </p>
</td>
</tr>
</tbody>
</table>
<p>As you see, it’s really simple. 1 means full color without transparency. I’m removing the amount of color of the second texture. Piece of cake !</p>
<p>Now some XNA – C# code. First I’m loading an effect and applying to the model. Since a lot of people don’t know how to do this I’ll pos it.</p>
<table border="0" cellspacing="0" cellpadding="2" width="529">
<tbody>
<tr>
<td valign="top" width="527">
<pre class="code">model = Content.Load&lt;<span style="color:#2b91af;">Model</span>&gt;(<span style="color:#a31515;">&quot;cube&quot;</span>);
effect = Content.Load&lt;<span style="color:#2b91af;">Effect</span>&gt;(<span style="color:#a31515;">&quot;MultiTexture&quot;</span>);

<span style="color:green;">// apply the effect
</span><span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
{
    <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMeshPart </span>meshPart <span style="color:blue;">in </span>mesh.MeshParts)
    {
        meshPart.Effect = effect;
    }
}</pre>
</td>
</tr>
</tbody>
</table>
<p>And now, the drawing part where we assign the textures:</p>
<table border="0" cellspacing="0" cellpadding="2" width="543">
<tbody>
<tr>
<td valign="top" width="541">
<pre class="code"><span style="color:#2b91af;">Matrix </span>View = <span style="color:#2b91af;">Matrix</span>.CreateLookAt(<span style="color:blue;">new </span><span style="color:#2b91af;">Vector3</span>(0, 2, -6), <span style="color:#2b91af;">Vector3</span>.Zero, <span style="color:#2b91af;">Vector3</span>.UnitX);

<span style="color:#2b91af;">Matrix </span>Projection =
    <span style="color:#2b91af;">Matrix</span>.CreatePerspectiveFieldOfView(<span style="color:#2b91af;">MathHelper</span>.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1, 100);

<span style="color:#2b91af;">Matrix</span>[] container = <span style="color:blue;">new </span><span style="color:#2b91af;">Matrix</span>[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(container);

<span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
{
    <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">Effect </span>effect <span style="color:blue;">in </span>mesh.Effects)
    {
        effect.Parameters[<span style="color:#a31515;">&quot;view&quot;</span>].SetValue(View);
        effect.Parameters[<span style="color:#a31515;">&quot;projection&quot;</span>].SetValue(Projection);
        effect.Parameters[<span style="color:#a31515;">&quot;world&quot;</span>].SetValue(container[mesh.ParentBone.Index]
            * <span style="color:#2b91af;">Matrix</span>.CreateRotationY(<span style="color:#2b91af;">MathHelper</span>.ToRadians(rotation)));

        effect.Parameters[<span style="color:#a31515;">&quot;TextureMap&quot;</span>].SetValue(baseTexture);
        effect.Parameters[<span style="color:#a31515;">&quot;Brush0&quot;</span>].SetValue(secondTexture);
    }
    mesh.Draw();
}  </pre>
<p>        <a href="http://11011.net/software/vspaste"></a></td>
</tr>
</tbody>
</table>
<p>And of course, here is the <a href="http://cid-cb95020351c750f1.skydrive.live.com/self.aspx/Tutoriales/MultipleTexture.zip">solution to download !</a></p>
<p><a href="http://cid-cb95020351c750f1.skydrive.live.com/self.aspx/Tutoriales/MultipleTexture.zip"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="1254270360_page_white_visualstudio[2]" border="0" alt="1254270360_page_white_visualstudio[2]" src="http://aarcoraci.files.wordpress.com/2010/02/1254270360_page_white_visualstudio2.png?w=32&#038;h=32" width="32" height="32" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=80&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2010/02/02/multiple-textures-or-materials-on-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/02/1254270360_page_white_visualstudio2.png" medium="image">
			<media:title type="html">1254270360_page_white_visualstudio[2]</media:title>
		</media:content>
	</item>
		<item>
		<title>Per Mesh Bounding Box tutorial</title>
		<link>http://aarcoraci.wordpress.com/2010/01/20/per-mesh-bounding-box-tutorial/</link>
		<comments>http://aarcoraci.wordpress.com/2010/01/20/per-mesh-bounding-box-tutorial/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 19:21:15 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2010/01/20/per-mesh-bounding-box-tutorial/</guid>
		<description><![CDATA[This article will show you how to build a dictionary of bounding boxes and link them in the code. Why ? Because many times, the model you want to use in your game is quite complex and it’s build upon many meshes. And you may need to know, for example, if a certain part is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=78&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article will show you how to build a dictionary of bounding boxes and link them in the code.</p>
<p>Why ? Because many times, the model you want to use in your game is quite complex and it’s build upon many meshes. And you may need to know, for example, if a certain part is clicked. If you have axis oriented objects (maybe walls, floors, etc) this solution can help you.</p>
<p>Solution: It’s quite simple. Since I don’t have much time for posting I’ll just post both, the processor and the code needed to access the boxes. Also, I’ll leave some tips.</p>
<p>First, this is the code for the processor:</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="color:blue;">using </span>System;
<span style="color:blue;">using </span>System.Collections.Generic;
<span style="color:blue;">using </span>System.Linq;
<span style="color:blue;">using </span>Microsoft.Xna.Framework;
<span style="color:blue;">using </span>Microsoft.Xna.Framework.Graphics;
<span style="color:blue;">using </span>Microsoft.Xna.Framework.Content.Pipeline;
<span style="color:blue;">using </span>Microsoft.Xna.Framework.Content.Pipeline.Graphics;
<span style="color:blue;">using </span>Microsoft.Xna.Framework.Content.Pipeline.Processors;

<span style="color:blue;">namespace </span>PerMeshBoundingBox
{
    [<span style="color:#2b91af;">ContentProcessor</span>(DisplayName = <span style="color:#a31515;">&quot;CustomModelProcessor&quot;</span>)]
    <span style="color:blue;">public class </span><span style="color:#2b91af;">CustomModelProcessor </span>:
        <span style="color:#2b91af;">ModelProcessor
    </span>{
        <span style="color:blue;">public override </span><span style="color:#2b91af;">ModelContent </span>Process(<span style="color:#2b91af;">NodeContent </span>input, <span style="color:#2b91af;">ContentProcessorContext </span>context)
        {
            <span style="color:#2b91af;">ModelContent </span>output = <span style="color:blue;">base</span>.Process(input, context);

            <span style="color:green;">// stores a bounding box per mesh inside the model - we link the bounding box to the mesh using it's name
            </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:#2b91af;">BoundingBox</span>&gt; boundingBoxes = <span style="color:blue;">new </span><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:#2b91af;">BoundingBox</span>&gt;();

            <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">NodeContent </span>currentNodeContent <span style="color:blue;">in </span>input.Children)
            {
                <span style="color:green;">// data needed to build a bounding box
                </span><span style="color:blue;">float </span>minX = <span style="color:blue;">float</span>.MaxValue;
                <span style="color:blue;">float </span>minY = <span style="color:blue;">float</span>.MaxValue;
                <span style="color:blue;">float </span>minZ = <span style="color:blue;">float</span>.MaxValue;
                <span style="color:blue;">float </span>maxX = <span style="color:blue;">float</span>.MinValue;
                <span style="color:blue;">float </span>maxY = <span style="color:blue;">float</span>.MinValue;
                <span style="color:blue;">float </span>maxZ = <span style="color:blue;">float</span>.MinValue;

                <span style="color:blue;">if </span>(currentNodeContent <span style="color:blue;">is </span><span style="color:#2b91af;">MeshContent</span>)
                {
                    <span style="color:#2b91af;">MeshContent </span>meshContent = (<span style="color:#2b91af;">MeshContent</span>)currentNodeContent;

                    <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">Vector3 </span>basev <span style="color:blue;">in </span>meshContent.Positions)
                    {
                        <span style="color:#2b91af;">Vector3 </span>v = basev;
                        <span style="color:blue;">if </span>(v.X &lt; minX)
                            minX = v.X;

                        <span style="color:blue;">if </span>(v.Y &lt; minY)
                            minY = v.Y;

                        <span style="color:blue;">if </span>(v.Z &lt; minZ)
                            minZ = v.Z;

                        <span style="color:blue;">if </span>(v.X &gt; maxX)
                            maxX = v.X;

                        <span style="color:blue;">if </span>(v.Y &gt; maxY)
                            maxY = v.Y;

                        <span style="color:blue;">if </span>(v.Z &gt; maxZ)
                            maxZ = v.Z;
                    }

                    <span style="color:green;">// creates a new bounding box associated to the mesh name
                    </span><span style="color:blue;">string </span>meshName = currentNodeContent.Name;
                    <span style="color:#2b91af;">BoundingBox </span>boundingBox =
                        <span style="color:blue;">new </span><span style="color:#2b91af;">BoundingBox</span>(<span style="color:blue;">new </span><span style="color:#2b91af;">Vector3</span>((<span style="color:blue;">float</span>)minX, (<span style="color:blue;">float</span>)minY, -(<span style="color:blue;">float</span>)minZ),
                            <span style="color:blue;">new </span><span style="color:#2b91af;">Vector3</span>((<span style="color:blue;">float</span>)maxX, (<span style="color:blue;">float</span>)maxY, -(<span style="color:blue;">float</span>)maxZ));

                    boundingBoxes.Add(meshName, boundingBox);
                }
            }
            <span style="color:green;">// stores the bounding box inside the tag property
            </span>output.Tag = boundingBoxes;

            <span style="color:blue;">return </span>output;
        }
    }
}</pre>
</td>
</tr>
</tbody>
</table>
<p>This processor will store a dictionary of bounding boxes inside the Tag property of a model. What’s important here is that each bounding box is linked to the mesh using the mesh name.</p>
<p>The code needed to grab the boxes can be something like this:</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:#2b91af;">BoundingBox</span>&gt; sceneBoundingBoxes =
                (<span style="color:#2b91af;">Dictionary</span>&lt;<span style="color:blue;">string</span>, <span style="color:#2b91af;">BoundingBox</span>&gt;)model.Tag;            </pre>
</td>
</tr>
</tbody>
</table>
<p>And what’s most important. You have to transform each box according to the mesh bones.</p>
<table border="0" cellspacing="0" cellpadding="2" width="400">
<tbody>
<tr>
<td valign="top" width="400">
<pre class="code"><span style="color:#2b91af;">Matrix </span>transforms = <span style="color:#2b91af;">Matrix</span>.CreateTranslation(position);

<span style="color:#2b91af;">Matrix</span>[] bones = <span style="color:blue;">new </span><span style="color:#2b91af;">Matrix</span>[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(bones);</pre>
<p>        <a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
{
    <span style="color:#2b91af;">BoundingBox </span>currentBoundingBox = sceneBoundingBoxes[mesh.Name];
    currentBoundingBox.Max =
        <span style="color:#2b91af;">Vector3</span>.Transform(currentBoundingBox.Max, bones[mesh.ParentBone.Index] * transforms);
    currentBoundingBox.Min =
        <span style="color:#2b91af;">Vector3</span>.Transform(currentBoundingBox.Min, bones[mesh.ParentBone.Index] * transforms);
}  </pre>
</td>
</tr>
</tbody>
</table>
<p>The code above this line just transform the bounding box according some position (for example, some place where you are placing a model). Note you can add any transform you want.</p>
<p><strong>IMPORTANT</strong></p>
<p>Just as I pointed in the last tutorial, This <strong>WONT WORK</strong> if you are not applying the transformations to the model in your design program. In blender, before exporting, you have to select the models you are exporting and click CONTROL + A + 1 (what the tutorial on how to export models to blender).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=78&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2010/01/20/per-mesh-bounding-box-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>
	</item>
		<item>
		<title>Blender to XNA (fbx) &#8211; understanding the model</title>
		<link>http://aarcoraci.wordpress.com/2010/01/11/blender-to-xna-fbx-understanding-the-model/</link>
		<comments>http://aarcoraci.wordpress.com/2010/01/11/blender-to-xna-fbx-understanding-the-model/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 15:09:34 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[xna]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[export to fbx]]></category>
		<category><![CDATA[fbx]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2010/01/11/blender-to-xna-fbx-understanding-the-model/</guid>
		<description><![CDATA[I’ll apologize for my English since it’s not my native language, but I’ll try to make myself as clear as possible. Many people don’t understand very well the process (or at least the basics) of exporting a mesh to XNA from Blender. There are a few basic concepts that the user should know. First, I’ll [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=76&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ll apologize for my English since it’s not my native language, but I’ll try to make myself as clear as possible.</p>
<p>Many people don’t understand very well the process (or at least the basics) of exporting a mesh to XNA from Blender. There are a few basic concepts that the user should know.</p>
<p>First, I’ll describe a scenario and then, I’ll enumerate what you should know: Suppose we have our game and we need a 3d object to be displayed. We all have done this in the past, but sometimes we just don’t understand why our object is not behaving the way it should we we apply a transformation. Even worse, some times we don’t even know where to place a camera because we don’t understand the “size” of the model.</p>
<p>I’ll try to explain those points here, I cannot assure I’ll be able to do it in a simple way, maybe because of my rusty english or maybe because it’s just a little hard (I’,m sure it’s because of my enlgish).</p>
<h5>Object’s center position:</h5>
<p>In blender, we you are creating or editing a model, you will notice a pink dot; This dot is used as reference to apply transforms. When you export the model to XNA, this little dot is also exported as a parent bone, and we apply a transformation this bone is also used as reference. </p>
<p><img style="display:inline;border-width:0;" title="s1" border="0" alt="s1" src="http://aarcoraci.files.wordpress.com/2010/01/s1.jpg?w=580&#038;h=218" width="580" height="218" /> </p>
<p>For example, we have a scenario with a plane as a the floor placed in Y = 0 and we want to add a cube in some position, so we go to blender to create our cube:</p>
<p>In blender we add a cube to an empty project (as shown in the picture above) and we export it (without ANY modification), the reference point will be in the center of the volume. (Notice the pink dot in the screenshot above).</p>
<p>As I said before, our floor is at Y = 0, and we want the cube to be placed above the floor (the bottom face should be at Y = 0 too). To achieve this, we translate our cube to (2,0,1) . This position, should be above the floor, since our Y component is 0. </p>
<p>If we do such transformation, we’ll notice our cube is half above, half under the floor: this is because we have tell XNA to move THE PINK DOT to (2,0,1). If you understood all this, you already know how to fix this: We have to change the position of the pink dot in blender.</p>
<h5>How to do this:</h5>
<p>Create a cube in blender and be sure it’s on the 0,0,0 position. You can do this by selecting the cube and open the transform properties dialog (<strong><em>N shortcut</em></strong>). You’ll notice 3 fields: LocX, LocY and LocZ. Set them with 0 and you’ll have it centered.</p>
<p>Go to edit mode (<strong><em>TAB key</em></strong>) and&#160; choose face as selection mode (<strong><em>Ctrl + Tab –&gt; faces</em></strong>). Now select the bottom face:</p>
<p><img style="display:inline;border-width:0;" title="s2" border="0" alt="s2" src="http://aarcoraci.files.wordpress.com/2010/01/s2.jpg?w=580&#038;h=218" width="580" height="218" />&#160;</p>
<p>Nothing strange so far, we have just added a new object (in this case a cube), we have centered it&#160; and now we have selected a face we want as reference in our game. </p>
<p>Now, we are going to move that little dot from the center of the volume to the center of the bottom face: With the bottom face selected,&#160; press <strong><em>SHIFT + S</em></strong>; this will bring the “align dialog” popup, Choose “<strong><em>Cursor –&gt; Active</em></strong>”. You’ll notice that the cursor (not the pink dot) will be placed in the center of the bottom face.</p>
<p>Now, to translate the pink dot, exit edit mode (<strong><em>TAB key</em></strong>) and in the buttons window choose, in the Mesh tab choose “Center Cursor”. Now, you should have your reference centered in the bottom face.</p>
<p><img style="display:inline;border-width:0;" title="s3" border="0" alt="s3" src="http://aarcoraci.files.wordpress.com/2010/01/s3.jpg?w=403&#038;h=149" width="403" height="149" /> </p>
<p><img style="display:inline;border-width:0;" title="s4" border="0" alt="s4" src="http://aarcoraci.files.wordpress.com/2010/01/s4.jpg?w=580&#038;h=218" width="580" height="218" /> </p>
<h5><font color="#800000">Important !!!</font></h5>
<p>Many people doesn’t know this, but when you modify a model, the transformations are not directly mapped to XNA. If you are noticing different units or scales ALWAYS apply all transformation to the model: Select the model and press <strong><em>Ctrl + A&#160; + 1</em></strong>. You can also achieve this by selecting the model and from the menu go to:</p>
<p>Object –&gt; Clear/Apply –&gt; Apply Scale/rotation to Obj Data</p>
<h5>About the size:</h5>
<p>There seems to be a bug or something with the fbx exporter and objects are scaled 10 times from blender to XNA. To solve this, in the export window change the Scale to 0.01.</p>
<p><img style="display:inline;border-width:0;" title="s5" border="0" alt="s5" src="http://aarcoraci.files.wordpress.com/2010/01/s5.jpg?w=332&#038;h=390" width="332" height="390" /> </p>
<p>Please notice that this can be applied to several type of objects. Characters and trees may have the reference under their feet but maybe planets or stars will be OK with their reference point in the center.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=76&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2010/01/11/blender-to-xna-fbx-understanding-the-model/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/01/s1.jpg" medium="image">
			<media:title type="html">s1</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/01/s2.jpg" medium="image">
			<media:title type="html">s2</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/01/s3.jpg" medium="image">
			<media:title type="html">s3</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/01/s4.jpg" medium="image">
			<media:title type="html">s4</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2010/01/s5.jpg" medium="image">
			<media:title type="html">s5</media:title>
		</media:content>
	</item>
		<item>
		<title>Links de descargas actualizados</title>
		<link>http://aarcoraci.wordpress.com/2009/10/13/links-de-descargas-actualizados/</link>
		<comments>http://aarcoraci.wordpress.com/2009/10/13/links-de-descargas-actualizados/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 13:29:51 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2009/10/13/links-de-descargas-actualizados/</guid>
		<description><![CDATA[Por si a alguien no les funcionaban los revise y actualicé. Perdón por las molestias !<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=70&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Por si a alguien no les funcionaban los revise y actualicé. Perdón por las molestias !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=70&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2009/10/13/links-de-descargas-actualizados/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA tutorial 3 &#8211; colisiones :serie 1:</title>
		<link>http://aarcoraci.wordpress.com/2009/10/09/xna-tutorial-3-colisiones-serie-1/</link>
		<comments>http://aarcoraci.wordpress.com/2009/10/09/xna-tutorial-3-colisiones-serie-1/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 12:16:00 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[xna]]></category>
		<category><![CDATA[tutoriales]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2009/10/09/xna-tutorial-3-colisiones-serie-1/</guid>
		<description><![CDATA[En este artículo voy a comentar como estoy manejando la detección de colisiones con los limites del área dibujada. Antes de empezar, hay que aclarar el concepto de “bounding frustum”. Básicamente y en cristiano es el área o volumen que estamos dibujando. Esta limitado por planos donde los mas importantes son el front y el [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=63&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div><img src="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" alt="" /> <img src="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" alt="" /> <img src="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" alt="" /></div>
<p>En este artículo voy a comentar como estoy manejando la detección de colisiones con los limites del área dibujada.</p>
<p>Antes de empezar, hay que aclarar el concepto de “bounding frustum”. Básicamente y en cristiano es el área o volumen que estamos dibujando. Esta limitado por planos donde los mas importantes son el <strong>front </strong>y el <strong>back </strong>(que por ahora no vamos a usar). Para ver mejor el concepto pueden visitar esta <a href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.boundingfrustum.aspx" target="_blank">dirección</a>.</p>
<p>Este es el gráfico (el cual es bastante auto explicativo):</p>
<p><a href="http://aarcoraci.wordpress.com/2009/10/09/xna-tutorial-3-colisiones-serie-1/" target="_blank"><img style="border-right:0;border-top:0;display:inline;border-left:0;border-bottom:0;" title="Bb195165.BoundingFrustum_ViewFrustum(en-us,XNAGameStudio.31)" src="http://aarcoraci.files.wordpress.com/2009/10/bb195165-boundingfrustum_viewfrustumenusxnagamestudio-31.gif?w=480&#038;h=207" border="0" alt="Bb195165.BoundingFrustum_ViewFrustum(en-us,XNAGameStudio.31)" width="480" height="207" /></a></p>
<p>La única diferencia es que nosotros tenemos girado todo 90º:</p>
<p><a href="http://aarcoraci.files.wordpress.com/2009/10/camara.jpg"><img style="border-right:0;border-top:0;display:block;float:none;margin-left:auto;border-left:0;margin-right:auto;border-bottom:0;" title="camara" src="http://aarcoraci.files.wordpress.com/2009/10/camara_thumb.jpg?w=512&#038;h=512" border="0" alt="camara" width="512" height="512" /></a>Otro concepto que debemos conocer es el de <strong>Collision Sphere</strong>: esto es una esfera con el volumen suficiente para contener un modelo en tres dimensiones.  Lo bueno de utilizar este tipo de objetos para la detección de colisiones es que cuando rotamos o movemos el modelo, actualizar  la esfera es muy fácil (ya que no varía, es solo un punto y un radio). Un punto muy negativo es que para cálculos complejos no es precisa, pero para este ejemplo sobra.</p>
<p>El algoritmo para crearla se sitúa en el método load (necesitamos la información del modelo)</p>
<pre class="code"><span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
    collisionSphere = <span style="color:#2b91af;">BoundingSphere</span>.CreateMerged(collisionSphere, mesh.BoundingSphere);</pre>
<h3>Algoritmo</h3>
<p>Como dije antes, el <strong>bounding frustum</strong> es un área delimitada por planos. Lo que vamos a hacer, utilizando métodos de las clases, es ver si existe una intersección entre la esfera (bounding sphere) que contiene a la nave y los limites del frutum. Esta prueba debemos hacerla en la <strong>próxima</strong> posición, por lo que creamos un vector y una esfera de prueba.</p>
<pre class="code"><span style="color:green;">// control de posicion para la coordenada x
</span><span style="color:#2b91af;">Vector3 </span>collisionTestVector = <span style="color:#2b91af;">Vector3</span>.Zero;
<span style="color:#2b91af;">BoundingSphere </span>collisionTestSphere;

collisionTestVector.X = position.X + movement.X;
collisionTestVector.Z = position.Z;
collisionTestVector.Y = movement.Y;

collisionTestSphere = <span style="color:blue;">new </span><span style="color:#2b91af;">BoundingSphere</span>(collisionTestVector, collisionSphere.Radius);

<span style="color:blue;">if </span>(<span style="color:#2b91af;">Camera</span>.BoundingFrustum.Contains(collisionTestSphere) == <span style="color:#2b91af;">ContainmentType</span>.Intersects)
    movement.X = 0;</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Ese código muestra como fue realizado para la coordenada X. En el ejemplo esta también implementado para Z.</p>
<p><a href="http://cid-cb95020351c750f1.skydrive.live.com/self.aspx/MSP/XNrAptor%5E_tutorial%5E_3.rar">Desde este link </a>pueden descargar la solución.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=63&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2009/10/09/xna-tutorial-3-colisiones-serie-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" medium="image" />

		<media:content url="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" medium="image" />

		<media:content url="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" medium="image" />

		<media:content url="http://aarcoraci.files.wordpress.com/2009/10/bb195165-boundingfrustum_viewfrustumenusxnagamestudio-31.gif" medium="image">
			<media:title type="html">Bb195165.BoundingFrustum_ViewFrustum(en-us,XNAGameStudio.31)</media:title>
		</media:content>

		<media:content url="http://aarcoraci.files.wordpress.com/2009/10/camara_thumb.jpg" medium="image">
			<media:title type="html">camara</media:title>
		</media:content>
	</item>
		<item>
		<title>Slides CodeCamp 2009 &#8211; Desarrollo de juegos con XNA</title>
		<link>http://aarcoraci.wordpress.com/2009/10/02/slides-codecamp-2009-desarrollo-de-juegos-con-xna/</link>
		<comments>http://aarcoraci.wordpress.com/2009/10/02/slides-codecamp-2009-desarrollo-de-juegos-con-xna/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 12:31:42 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[MSP]]></category>
		<category><![CDATA[xna]]></category>
		<category><![CDATA[codecamp]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2009/10/02/slides-codecamp-2009-desarrollo-de-juegos-con-xna/</guid>
		<description><![CDATA[Para el que las quiera, acá dejo las diapositivas de mi charla en la CodeCamp 2009: LINK DE DESCARGA Disfruten !<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=60&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Para el que las quiera, acá dejo las diapositivas de mi charla en la CodeCamp 2009:</p>
<p><a href="http://aph02a.bay.livefilestore.com/y1pm55dMW8hDC3BQff2uwoyXsBMf-U5Zvvr54S2p_gT4wwM9Ky8U74eF8hk2ozYNkWedO1Mze90LLMJEZyPlthGMW4IkEBwylum/codecamp%202009.pptx?download">LINK DE DESCARGA</a></p>
<p>Disfruten !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=60&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2009/10/02/slides-codecamp-2009-desarrollo-de-juegos-con-xna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA tutorial 2 &#8211; clase AirCraft</title>
		<link>http://aarcoraci.wordpress.com/2009/10/01/xna-tutorial-2-clase-aircraft/</link>
		<comments>http://aarcoraci.wordpress.com/2009/10/01/xna-tutorial-2-clase-aircraft/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:25:09 +0000</pubDate>
		<dc:creator>aarcoraci</dc:creator>
				<category><![CDATA[xna]]></category>
		<category><![CDATA[tutoriales]]></category>

		<guid isPermaLink="false">http://aarcoraci.wordpress.com/2009/10/01/xna-tutorial-2-clase-aircraft/</guid>
		<description><![CDATA[En el artículo anterior use un modelo para mostrar que la cámara funcionaba como era esperado, pero la forma de dibujarlo era desprolija y estaba dentro de la clase Game1. Hoy voy a separar esa información para tenerla ordenada y de paso discutir un poco la clase AirCraft que vendría siendo el avión que vamos [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=53&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div><img src="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" alt="" /> <img src="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" alt="" /> <img src="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" alt="" /></div>
<p>En el artículo anterior use un modelo para mostrar que la cámara funcionaba como era esperado, pero la forma de dibujarlo era desprolija y estaba dentro de la clase Game1. Hoy voy a separar esa información para tenerla ordenada y de paso discutir un poco la clase AirCraft que vendría siendo el avión que vamos a controlar.</p>
<p>Entre los atributos principales tenemos el modelo, la textura y la posición. Los demás atributos son secundarios (pero aún útiles) y están explicados en el código.</p>
<p>Estoy haciendo un esfuerzo y voy a dejar algunos comentarios en español (aunque parezca mentira me cuesta recordar esto), pero si algún lector tiene una duda puede preguntar vía comentario.</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">AirCraft
</span>{
    <span style="color:blue;">private </span><span style="color:#2b91af;">Model </span>model;
    <span style="color:blue;">private </span><span style="color:#2b91af;">Texture2D </span>texture;
    <span style="color:blue;">private </span><span style="color:#2b91af;">Vector3 </span>position;

    <span style="color:blue;">private string </span>modelAsset = <span style="color:#a31515;">"untitled"</span>;
    <span style="color:blue;">private string </span>textureAsset = <span style="color:#a31515;">"Ship_06"</span>;

    <span style="color:blue;">private float </span>speed = 20;

    <span style="color:blue;">public </span>AirCraft(<span style="color:#2b91af;">Vector3 </span>position)
    {
        <span style="color:blue;">this</span>.position = position;
    }

    <span style="color:blue;">public void </span>Load(<span style="color:#2b91af;">ContentManager </span>content)
    {
        model = content.Load&lt;<span style="color:#2b91af;">Model</span>&gt;(modelAsset);
        texture = content.Load&lt;<span style="color:#2b91af;">Texture2D</span>&gt;(textureAsset);
    }

    <span style="color:blue;">public void </span>Update(<span style="color:#2b91af;">GameTime </span>gameTime)
    {
        <span style="color:#2b91af;">Vector3 </span>movement = <span style="color:#2b91af;">Vector3</span>.Zero;

        <span style="color:green;">// cuanto tiempo paso desde el ultimo frame hasta el actual
        </span><span style="color:blue;">float </span>deltaT = (<span style="color:blue;">float</span>)gameTime.ElapsedGameTime.TotalSeconds;
        <span style="color:green;">/*
         * DeltaT sirve para calcular la cantidad de unidades que nos movemos en este frame.
         * Si decidimos que la velocidad de la entidad (nave) es de 1 metro por segundo,
         * hay que realizar una regla de tres
         * ya que en un segundo pueden entrar varios (muchos generalmente) frames.
         * */

        // actualizamos el vector movement que indica cuanto nos movemos en este frame particular
        </span><span style="color:blue;">if </span>(<span style="color:#2b91af;">Keyboard</span>.GetState().IsKeyDown(<span style="color:#2b91af;">Keys</span>.Left))
            movement.X -= deltaT * speed;
        <span style="color:blue;">else if </span>(<span style="color:#2b91af;">Keyboard</span>.GetState().IsKeyDown(<span style="color:#2b91af;">Keys</span>.Right))
            movement.X += deltaT * speed;

        <span style="color:green;">// actualizamos la posicion
        </span>position += movement;
    }

    <span style="color:blue;">public void </span>Draw()
    {
        <span style="color:green;">/*
         * Para dibujar el modelo copiamos sus transformaciones a una matriz.
         * Esto sirve para luego aplicar calculos matematicos a cada set de
         * transformaciones de cada mesh.
         * */

        </span><span style="color:#2b91af;">Matrix</span>[] contenedor = <span style="color:blue;">new </span><span style="color:#2b91af;">Matrix</span>[model.Bones.Count];
        model.CopyAbsoluteBoneTransformsTo(contenedor);

        <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">ModelMesh </span>mesh <span style="color:blue;">in </span>model.Meshes)
        {
            <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">BasicEffect </span>effect <span style="color:blue;">in </span>mesh.Effects)
            {
                effect.World = contenedor[mesh.ParentBone.Index]
                    * <span style="color:#2b91af;">Matrix</span>.CreateTranslation(position);
                effect.View = <span style="color:#2b91af;">Camera</span>.View;
                effect.Projection = <span style="color:#2b91af;">Camera</span>.Projection;
                effect.TextureEnabled = <span style="color:blue;">true</span>;
                effect.Texture = texture;
            }
            mesh.Draw();
        }
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>La clase es bastante auto explicativa, pero si tienen dudas dejen el comentario.</p>
<p>Acá dejo la solución para que la <a href="http://cid-cb95020351c750f1.skydrive.live.com/self.aspx/MSP/XNrAptor%5E_tutorial%5E_2.rar" target="_self">descarguen</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aarcoraci.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aarcoraci.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aarcoraci.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aarcoraci.wordpress.com&amp;blog=5871759&amp;post=53&amp;subd=aarcoraci&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aarcoraci.wordpress.com/2009/10/01/xna-tutorial-2-clase-aircraft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/93ca23f5e0cb3e720b42b26b1391f9b6?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">aarcoraci</media:title>
		</media:content>

		<media:content url="http://aph02a.bay.livefilestore.com/y1pNh3vbSwmvG64gpdb_Kk5z5IuKKsR9JyraUhkwxthUJhZEyJ7sU8ozKX1etO4N5DtFY_MVtf2KWb2coKgUOD3yKMxY4HJ0lee/skull_16x16.gif" medium="image" />

		<media:content url="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" medium="image" />

		<media:content url="http://aph02a.bay.livefilestore.com/y1plDyXGe3C5Ua4eGGmWS4ln6hG78yZp5nEkooxP3Ti7GVlRhSSJ7uwocP6bF0u84PQKdVitYzBDbFiIVB2Lyx_fMZyYIpH9k-N/skull_16x16_grey.gif" medium="image" />
	</item>
	</channel>
</rss>
