Friday, 28 December 2007

Mechanical Trumpeter... First cyborg ever?

Deutsches Museum, at München, shows the Mechanical Trumpeter.


Built in 1810, it is powered by winding up a spring. It plays music and moves... Incredible...

First cyborg ever?

Not only in Munich... Madrid rocks too...

A couple of weeks ago, in Madrid...









Only in Munich... (II)

I promised to post some more pics. Here they are...






Cheers...



Wednesday, 26 December 2007

Using generics to constraint the max change rate in variables

I´ve posted this article to TheCodeProject which talks about using generics to constraint the maximum change rate of a variable.

It´s very simple, but a good introduction to generics. Might be useful for real-time applications or for anything where you want to constraint how many times a variable can change it´s value in a certain period of time, regardless of it´s type of course (that´s where generics come in).

It´s a beginners tutorial. Hope I´ve explained it well enough. Anyway, ask for any help you may need.

Cheers

Friday, 21 December 2007

Calendario Tórrido del Maligno

Dios, a pocas fallezo de la risa...

en este link tenéis una entrada en el blog del maligno que merece la pena leer. Él y sus secuaces han hecho un Calendario Tórrido que es la caña, y además con fines benéficos.

Como me ha parecido una idea cojonuda, a ver si os pasáis todos por ahí y colaboráis con 12 lereles que seguro podéis dejar de gastaros en una lotería, que por otra parte no os va a tocar.

Así podréis comprobar como David Salgado cada vez se parece más a Arnold Schwarzenegger (o como carajo se escriba).

Genial la idea Txema !

Tuesday, 18 December 2007

Crysis 3000 barrel explosion physics demo

Take the Separating Axis Theorem. Build a collision detection system based on it, with several primitives, like barrels, boxes, and all the stuff. Stick there a rigid body response module and a really really stable numerical integration algorithm.

Is it fun enough to try that monster with just a couple of barrels? I guess it´s not...

http://www.youtube.com/watch?v=YG5qDeWHNmk

A more detailed explanation:

http://www.youtube.com/watch?v=VaHS-y_mapQ&feature=related

NVIDIA's 3-way SLI: Can we finally play Crysis? Me parto !

Aquí tenéis un artículo muy interesante acerca del 3-way SLI mode de nVidia... o de cómo pulirte el sueldo de un trienio en un sistema gráfico...

Mola mucho el titulillo: "NVIDIA's 3-way SLI: Can we finally play Crysis?"

Me parto !!! juas !!!...

Thursday, 13 December 2007

Simax en AutoBild

Ha sido una semana muuuy liada, pero por fin tengo un momento para publicar esta entrada. Simax ha sido entrevistado y publicado en la revista AutoBild, nº 108.

Si te das prisa, todavía estas a tiempo de encontrarla en los quioscos... hasta mañana viernes, que sale el siguiente número!

Saludos!

Tuesday, 11 December 2007

Only in Munich...

Last week, I could spend some days at Munich. Beautiful city, beautiful cars, and very nice people. Where else can you see things like this...



this (a 911 turbo on the back)...


this...

or this...


More pics coming!!

Monday, 3 December 2007

Sinclair ZX Spectrum +2. Maravilloso... sniff....

El otro día rescaté de una caja un libro que me llenó de nostalgia.



Es el manual de usuario de un ordenador que todavía conservo y, en principio, debería funcionar. Lo tengo bien guardado, junto con un montón de cintas con juegos, y un buen paquete de revistas MicroHobby: publicación especializada en este hardware, editada por aquellos años y que yo nunca me perdía, a pesar de requerir gran parte de mi paga. He encontrado una web maravillosa que rinde un merecido tributo a esta revista: http://www.microhobby.org/Ahí podéis descargaros un montón de números en PDF. Muchas gracias !!!

En fín, que corría el año 1987, y por aquel entonces los MegaHerzios se escribían con cuatro decimales: 3.5469 Mhz era el poder brutal de esta máquina. Claro que debido al sistema de compartición de RAM entre el procesador y el sistema de vídeo, la frecuencia se veía reducida a 2.66 Mhz.

Y eso que esta era la versión pija del Spectrum, que originalmente tenía 48K. Básicamente, el 128K era un 48K tuneado. Llevaba el mismo procesador, el mítico Z80, pero con más RAM y puertos de comunicación para impresoras, joysticks y demás. La pera, vamos...

Pero... ¿quién necesitaba más? Al fin y al cabo, el Goody (Opera, 1987), el DynamiteDan (Mirrorsoft, 1985), el HeadOverHeels (Ocean, 1987), La Abadía del Crimen (Opera, 1988), funcionaban perfectamente... Qué nostalgia! Eran juegos maravillosos, la verdad... Aqui, la portada del Goody, versión Amstrad.



Y por cierto, no se si alguien se acuerda, pero los equipos de desarrollo españoles eran de los mejorcitos de nivel internacional: Opera, Topo, Zigurat, Dinamic...

Por aquel entonces, los juegos se hacían entre dos personas que no dormían ni comían hasta terminar el proyecto. Es el caso de Paco Menéndez y Juan Delcán, responsables de "La abadía del crimen". Por cierto, desde 2001 Paco Giner se encarga de este remake para PC.

Desde que los juegos se convirtieron en una actividad muchimillonaria, los equipos de desarrollo Españoles fueron perdiendo la batalla contra los de otras nacionalidades, seguramente porque no fueron capaces de encontrar gente en España con la suficiente visión como para invertir su dinero en "hacer jueguecillos para los chavales".

Qué lastima que tanto talento se desperdiciara en este país... De momento, empresas como Pyro y compañía luchan por hacer resurgir la llamada "edad de oro del soft español", aunque obviamente, hoy en día es mucho más complicado.
Yo por mi parte, siempre trataré de aportar mi pequeño granito de arena. En fin... ánimo !




Friday, 30 November 2007

HTC Touch + GPS BlueTooth + tomtom6 for dummies

Si te preguntas como configurar tu HTC Touch con un receptor GPS BlueTooth para usar el navegador tomtom 6, sigue leyendo.
En este tutorial, voy a utilizar el siguiente receptor GPS:



Holux M-1200. 70 pavos aprox. en el MediaMarkt, aunque he visto gente en foros que lo ha pillado hasta por 40 en intesné.

Todavía no lo he probado en un viaje largo, pero por ahora parece que va de coña, y es muy pequeño. La semana que viene le dare chicha en Alemania, a ver cómo se porta...

En fín, al lío: Primer paso, enciende el Holux M-1200.

Segundo paso, abre el CommManager de tu HTC Touch y selecciona Configuración -> BlueTooth




Siguiente paso. Añadir un nuevo dispositivo BlueTooth y emparejarlo con tu HTC. En las fotos vais a ver que ya está añadido (lo siento, soy muy vago y me ha dado pereza quitarlo, aunque sean 20 segundos). Voy a hacer como si no, y voy a crearlo otra vez: Seleccionar la opción "Añadir nuevo dispositivo"


El HTC buscará dispositivos BlueTooth cerca y mostrará en una lista todos los que encuentre, entre ellos, el Holux.


Selecciona el Holux y pulsa en "Siguiente". Aparecerá la pantalla de configuración de la asociación, emparejamiento, o como te de la gana de llamarle. Como la siguiente:



En ella marca la opción "Puerto serie" y pulsa sobre "Finalizar".

Después, hay que cambiar un par de cositas en la configuración BlueTooth. Ve a la pestaña "Puertos" y pulsa sobre "Nuevo puerto saliente":


En la siguiente pantalla selecciona tu dispositivo (en este caso Holux M-1200) y pulsa en "Siguiente". Llegarás a una pantalla como esta:



En ella selecciona uno de los puertos COM de la lista y asegúrate de NO MARCAR la opción "Conexión segura".


Nota: Si no sabes qué puerto COM elegir, tienes dos opciones: probar uno a uno hasta que funciones, o usar un programita como el que trae el Holux M-1200: GPS MiniViewer, que tiene una opción para escanear todos los puertos diciéndote en cuales encuentra GPS y en cuales no.

Una vez seleccionado el puerto, pulsa en "Finalizar" y vuelve a la configuración BlueTooth, esta vez para ir a la pestaña "Seguridad":







Asegúrate de dejar la opción "Autenticación (llave maestra) requerida" DESMARCADA.

Pulsa en Ok, y ya está. El tomtom6 te debería reconocer el GPS.

Nota1: Ten en cuenta que a veces al tomtom le cuesta un rato reconocer el GPS

Nota2: Si el GPS que usas no es el del ejemplo, la configuración puede variar. Lo mejor es que mires bien en su manual, sobre todo las cosas relacionadas con seguridad, etc.

Nota3: Para usar el GPS bluetooth con el tomtom no es necesario que toques nada en la opción "External GPS" de la pantalla Inicio->Configuracion->System. Déjalo como está.









HTC Touch + HTC EndKey application

I recently installed the HTC EndKey application in my HTC Touch, and I must advise you not to do so, mainly due to:

1.- This app is not very useful for the Touch, as it only gives you quick shortcuts for funcs like: lock phone (the htc touch is lockable via a long press in the red button), vibration mode (easily accesible in the speaker config icon), airplane mode (it may be useful if you take a plane twice a day...)...

2.- It seems that there´s no single way in the hell to remove it, appart a hard reset. When you install it, the HTC Touch warns you about it, because its a WM5 app. That should be no problem, but when you try to uninstall it, an error occurs, and it´s not removed.

If anyone knows how to uninstall without doing a hard reset, please post it here...

Cheers !

Automatic Lightmap Generation for Generic Sets of Geometry in Real Time Simulation

Siguiendo en el baúl de los recuerdos. No encuentro link al pdf, pero éste es el título de un Short Paper que publiqué en el año 2002 junto a mis mentores Alex García Alonso y Luis Matey.

Fué la primera aproximación a la técnica desarrollada para atlas de coordenadas genéricos.

Seguiré buscando a ver si se puede bajar de algún sitio.

Hi !

Texturas precomputadas para aplicaciones en tiempo real

Hace ya algunos años, publiqué un artículo en colaboración con mis dos mentores (Dr. Luis Matey y Dr. Alex García Alonso), que llevaba el título:

APLICACIONES AVANZADAS DEL USO DE TEXTURAS
PRECOMPUTADAS EN ENTORNOS DE SIMULACIÓN EN TIEMPO
REAL
En la revista de ingeniería industrial de la Universidad de Bío Bío, en Chile.
En ese artículo se describía una propuesta diferente para generar lo que hoy se conoce como "Atlas de Coordenadas" de forma automática, para la aplicación de lightmaps y otras técnicas a mallas geométricas genéricas.
Os dejo aqui el link por si a alguien le apetece echarle un vistazo.
Saludos.

Charla XNA. Microsoft CodeCamp 2007

Muy buenas, he visto Microsoft ha subido a este link el PowerPoint de mi charla sobre XNA para el CodeCamp de 2007 en Huelva. Os pongo el link por si os apetece bajarlo.


Esa charla fué compartida con el gran Javier Cantón (DirectX MVP). Podéis ver un video aqui.

Saludos!

Thursday, 29 November 2007

Escrito contra la violencia

Me ha gustado un un escrito que me han enviado contra la violencia. Ahí va...

-----

grupo disidente de realidad,
que seguís con rabia luchando,
matando, arrasando y robando.

"ofrecemos la paz,
mas no alcéis vuestras manos blanqueadas,
que huelen a sepultura"... ¡decís!

la paz no se ofrece matando;
y confundidos,
¿sepultura?
más bien ternura...

y no es olor, porque no huele,
más bien se siente...

la gente quiere vivir, amar y por qué no,
también odiar, pero... ¿matar?

matan libertad, expresión y sentimiento,
matan a un pueblo
harto de tiranía y opresión,
!queremos pasión!
desquiciado cabrón,
entra ya en razón.

verdad es que preferimos morir
a vivir arrodillados,
pero es que...
¿acaso lo estás?
¿o mancillado?,

porque tu libertad termina,
donde comienza la mía,
nunca aceptaré tu tiranía.

H. Heltz

XBox360 Controller for Windows - PC

Last week, I bought an additional XBox360 controller. In this case, I bought the wired version, because I wanted to use it with my PC without the need for an additional wireless adapter.





I must say it works flawlessly on the PC. You just need a special driver found here.

You can use it with XNA as well, though now, with the XNA GameStudio 2.0, you can read many other controller types, not only the XBox gamepad.

Cheers!

Tuesday, 27 November 2007

GPS on a plane at 940 kmh

I´ve found this video on YouTube of a guy in a plane with his GPS at 940 km/h.

Impressive!

Specs:

GPS bluetooth Leadtek 9553 (SirfIII Bt Gps)
HP Ipaq
Tomtom v 5.42.

Nueve palabras que las mujeres utilizan ;) ...

Esta mañana, uno de los secuaces que no mento por temor a provocar un divorcio, me ha enviado un email que me ha hecho mucha gracia... Ahí va...

NUEVE PALABRAS QUE LAS MUJERES UTILIZAN...

1.) VALE: Esta es la palabra que las mujeres utilizan para finalizar una
discusión cuando han decidido que ellas tienen la razón y ahora debes
callarte.

2.) CINCO MINUTOS: Si se esta arreglando, significa MEDIA HORA. CINCO
MINUTOS son solo cinco minutos si te han concedido cinco minutos
adicionales para terminar de ver el partido antes de salir para ayudar con
la compra.

3.) NADA: Es la calma antes de la tormenta. Significa ALGO. Y deberías
estar totalmente alerta. Discusiones que empiezan con NADA, normalmente
acaban con VALE (Ver punto 1).

4.) NO HAY PROBLEMA (también ADELANTE-HAZLO o NO-NO ME MOLESTA): Es un
reto, y para nada darte permiso. Ni se te ocurra hacerlo!

5.) GRAN SUSPIRO: En realidad, es una palabra pero habitualmente los
hombres no la entienden. Un suspiro alto y claro significa que ella piensa
que eres idiota y se pregunta por qué esta perdiendo el tiempo discutiendo
sobre NADA (Ver punto 3 para entender el significado de NADA).

6.) MUY BIEN: Esta es una de las frases más peligrosas que una mujer puede
decir a un hombre. MUY BIEN significa que ella meditara cuidadosamente
antes de decidir cómo y cuándo pagarás por tu equivocación.

7.) GRACIAS: Una mujer te agradece algo. No preguntes. No dudes. Solo di DE
NADA.

8.) ES IGUAL (también TU MISMO): Es la forma femenina de mandarte a la
mierda.

9.) TRANQUILO, LO HE ENTENDIDO (también LO HE PILLADO): Otra frase
peligrosa donde las haya, que significa que aunque la mujer ha dicho al
hombre en repetidas ocasiones que haga algo, finalmente lo esta haciendo
ella misma. Esto más tarde empujará al hombre a preguntar "QUE PASA?"
Para saber la respuesta de la mujer, ver punto 3.

XNA Image Reflector. Latest Best Picks

The XNAImageReflector article at TheCodeProject hast been included in the Last Best Picks list today. You can read the article here.

Monday, 26 November 2007

TheCodeProject article: easy rendering with XNA inside a Windows Form

Ive just seen that my last article about "Easy rendering with XNA inside a Windows Form" at TheCodeProject has been placed in the "Last Best Picks" list of the site.

You can read other articles about XNA and game development here.

Cheers!

Sunday, 25 November 2007

TheCodeProject Article. XNAImageReflector

Yesterday, my article about XNAImageReflector was accepted, edited and moved to another url in TheCodeProject.

I updated the link in the previous post, but anyway, paste it again here:

http://www.codeproject.com/csharp/XNA_Image_Reflector.asp

Cheers!

TheCodeProject Article: XNA integration with WinForms (II)

Yesterday, my article about integration of XNA and WinForms was accepted, edited and moved to another url in TheCodeProject.

I updated the link in the previous post, but anyway, paste it again here:


http://www.codeproject.com/game/XNA_and_WinForms.asp


Cheers!

Friday, 23 November 2007

XNA Image Reflector. Easily create web2.0-like reflected images

XNA is for games, but not just for games! ;)


I finally posted the XNAImageReflector article to TheCodeProject. It includes full source code, screenshots, instructions and programming details.


About XNAImageReflector:


It´s an application that integrates XNA rendering and maths with Windows Forms. and that lets you create images like this one in 5 seconds:







Hope you like it!

Tuesday, 20 November 2007

XNA Game Studio 2.0 (beta) released !

XNA Game Studio 2.0 (beta) has been released. You can see some installation instructions here.



It finally includes VisualStudio 2005 support (non-express versions). Something really demanded in the last months.

Can´t wait to try it!

Monday, 19 November 2007

TheCodeProject article: XNA Billiards Visual Demo

Today, I have uploaded another article to TheCodeProject. You can find it here.


I paste here the introduction:

This article is an example of 3D rendering and content processing with XNA, and a good start for those you want to start learning XNA. Although it´s not a full working Billiards game (that will be another article), it can be a good starting point for one too.
It´s not intended to show the best way of doing anything, it´s just a quick example I´ve made in four or five ours. Any improvement is really welcome!
It covers the following topics:
  • Content processor development
  • Content exporting from 3DSMax, including Max shaders, ready to use with XNA
  • Content loading
  • 3D rendering, with and without Max Shaders
  • Basic camera development
  • Basic Sprite management
  • Basic custom user interface development
  • Mouse reading
  • Scene and 3d models management
  • Settings serialization with XML
  • Additional model properties implementation
Hope you like it.

Forza MotorSport 2 bug. Front wheels driven Porsche?

This video shows a bug in ForzaMotorSport 2 demo for the XBox360.

The Porsche 911 is front wheels driven, what is actually a heresy for car enthusiasts.

Maybe it was fixed in release version... Anybody knows?

Coleguillas del TechEd Developers 2007

Aqui me he encontrado una entrada en el blog del gran Ramón Tebar, Microsoft MSP y compañero de fatigas en el TechEd 2007 en Barcelona.

La verdad es que lo pasamos fenomenal. Aqui Ramón y otro grande, recién MVP DirectX Javier Cantón, conmigo:



Muchas gracias por las fotos Ramontxu!


Friday, 16 November 2007

Double Buffer Graphics in C# + GDI (II)

This happens sometimes to me.

As a C++ programmer, when I moved to .net I was not used to have things done there for me, so I tended to do everything on my own (I found myself once programming a method to search a substring inside a string... ;), and today it happened again.

Augusto Ruiz has left a comment in my last post about GDI DoubleBuffering that is worth to mention, because all the DoubleBuffer implementation I showed in the last post, can be overriden by a simple property of the control you are going to render in:

public class DoubleBufferedPanel : Panel
{
public DoubleBufferredPanel()
{
this.DoubleBuffered = true;
}
}

This property is inherited from Control, so any windows control has it, but is protected. Thats why you need to create a custom Panel, Button, or whatever you want to use as rendering target. Just change its value in the constructor and that´s it!

The previous implementation still has it´s advantages, like a full control on the rendering and presentation process, but for simple cases this way is muuuuuch simpler.

Can´t understand why a google on this topic shows CodeProject entries talking about a custom implementation like the previous one, and no one talks about this way. Probably because it´s too simple and everybody knows it... je je...

Great!

TheCodeProject article: easy integration between XNA and Windows Forms

I have just posted this article to TheCodeProject, it talks about how to render XNA graphics inside a Windows form.



Better graphics in XBox360 than in PlayStation3 ?

Today, watching some videos in one of my favourite sites, I´ve found a comparison between Assassin´s Creed for XBox360 and PlayStation3.

Link: http://www.gametrailers.com/game/2581.html




It´s quite impressive to see that XBox360 beats the PS3 up in this game. Some people say it´s just a contrast or gamma adjustment issue, but I don´t think so. We must trust the GameTrailers people to be professional and to have made the comparison with the same adjustments.





In the XBox360 version there´s more detail and, to my eyes, there´s some cool HDR which doesn´t appear in the PS3 version (see picture above).



It´s true that consoles need some time to do their best, and the PS3 is much younger than the XBox, but for the same reason, it also has better hardware (in theory).


Who knows...

Thursday, 15 November 2007

XNA Image Reflector. Easily create web 2.0 reflected images

In the last months or years, every single power point I see, with a decent design and look, includes pictures that have been "reflected" vertically, as if they where in the top of a reflecting table or so... it´s the so-called "web 2.0 reflection". Just like this one:


This kind of effect can be easily done with Photoshop or whatever, just reflecting the image and aplying a distort and a gradient mask, but hey! those 5 minutes per image are priceless! So I decided to make a small app that allows you to create this kind of effect in 5 seconds.

Probably there´s already something similar out there (see below), but I do it just for fun and to practice some new things I´m explaining below. I will upload the source code here or at TheCodeProject, so you all can check how it´s done.

Specs:
  • Automatic reflection using a reflection polygon to specify the shape of the form to reflect
  • Automatic reflection distortion
  • Automatic alpha gradient with different gradient modes
  • Image resizing and re-locating
  • Post-processing effects for reflection: Blur, Alpha Texture, ...
  • Supports following formats: BMP, JPEG, TGA, PNG, DDS, DIB, HDR, PPM, PFM

Technical info:

  • Developed in Visual C# Express
  • All the maths and graphics done with XNA
  • Shows integration between XNA and Windows Forms

An example:

1.- Take the original picture:


2.- Apply my XNAImageReflector: with blur post processing turned on

As you can see, the cool thing of all this stuff (appart from the post-proc effects) is that you can build a path that will define the shape of the reflection. Not just vertical or horizontal reflections, which are Ok for non-perspective objects, but that doesn´t work well on logos like this one.

3.- Save the final image:

Other examples created with XNAImageReflector:



This one shows the Alpha Texture post processing effect too:

Similar projects and tutorials I´ve found:


Cheers!







Wednesday, 14 November 2007

XNA easy and efficient primitive rendering (PrimitiveBatch)

Recently, I got into the situation where I had to render a simple line in a 2D view, in XNA. As the fixed func. pipeline is no longer available, in order to do so you would have to deal with a shader. Probably a BasicEffect or another one created to render 2D lines.

I just googled up for "xna 2d rendering" and I´ve found this article in ZiggyWare (a must for any XNA developer). It shows how to do some basic collision detection between polygons, but as far as it also renders those polygons with lines, I was interested on it.

To draw all the lines there, he uses the PrimitiveBatch class, a very helpful class developed in one of the XNA samples available here, that I honestly didn´t take the time to look at. It behaves in a similar way as the SpriteBatch, basically:

batch.Begin( primitiveType );

batch.AddVertex( Vector2D);
...
batch.AddVertex( Vector2D);

batch.End();

And that´s it. Easy, ain´t it?

Cheers!

Tuesday, 13 November 2007

The real Cooperative Gaming

I´ve found a picture of what should be the so-called "cooperative gaming":


This is friendship, isn´t it?

Juas !...

Tetris a.k.a "Cuadrados de Rusia"

Y es que así es como parece que conocen en China al Tetris.


Yo ya sabía que era un juego adictivo, porque me dejaba casi todas las monedas de 25 pelas que componían mi paga en la jodía maquinilla, pero es que esta noticia me ha dejado "pa'llá":


Una anciana china de 72 años, adicta a los vídeojuegos desde hace dos décadas

La colega (se llama Liu Zhi), que se inició en este aciago mundo con el Tetris, empieza a jugar a las 9 de la mañana y termina a las 10 de la noche, y si no la vigilan, se olvida hasta de comer.


No me quiero imaginar qué nivel de experiencia tendrá en el WOW ! Debe ser la portadora de la "espada de las mil verdades".


Juas !....

Diez sorpresas al renovar el DNI (y el pasaporte de propina)

Hace dos años que me tocó visitar la oficina de Pamplona por última vez, para renovar el pasaporte. No voy a aburriros con los detalles de mi visita, símplemente diré que la experiencia fué horrorosa, y el trámite me llevó dos mañanas enteras (de pedir fiesta en el curro, claro).

Desde entonces, he leído en la prensa unas 12 noticias referentes a cambios en el modo de funcionar de la oficina: que si con cita previa, que si sin cita previa, que si con cita por telefono, que si el telefono siempre comunica, que si la gente se amotina, que si las colas llegan hasta Lérida, etc, etc.

Con todo esto, renovar el DNI se había convertido para mi en algo tan incómodo como ir al dentista, por lo que lo he retrasado todo lo posible. Claro que tras más de dos meses caducado, he decidido que hoy era el día, que hoy debía armarme de paciencia y "pasar el trago".

Obviamente, después de tanto cambio en la forma de funcionar, no tenía ni idea de si debía pedir cita previa o no, así que he llamado al Tfno de información a preguntar y.... primera sorpresa: ¡no comunicaba! Allí me han dicho que solo debía pasar por la oficina y coger número.

Antaño, yo era de los que estaba plantado como un chopo para las 8h de la mañana en la puerta de la comisaría, y a pesar de eso era el 25 en la cola. Hoy por diferentes motivos, no he podido ir antes de las 9:30. segunda sorpresa: ¡no había una cola que diera la vuelta a la manzaña!

Bueno, la cosa no va mal...

Entro en la oficina, y me llevo la tercera sorpresa: ¡Hay un puesto de información fuera, donde puedes pedir número e informarte sin apenas hacer cola! Alli me han dado el número 58, con una hora de atención aproximada de las 10:30.

Me tomo mi café matutino, me leo el diario, y a eso de las 10:15 entro de nuevo en la oficina a esperar. Mientras veo pasar los números, me doy cuenta de lo que supone la cuarta sorpresa: hay unos 8-10 puestos de atención, y la cosa parece que va rápido.

Pues sí, ciertamente la atención es bastante ligera, y pronto llega lo que constituye la quinta sorpresa: ¡me atienden casi a la hora que me habían dícho, a las 10:38!. La verdad es que por ahora, la cosa no puede ir mejor.

Me siento ante el funcionario, y la sexta sorpresa me da de golpe en la cara: tras unas gafas y camisa de cuadros, me atiende un funcionario con cara amable y muy majete, con el que he llegado incluso a charlar.

Dios, esta oficina está irreconocible... casi siento añoranza por aquellas caras de perro, aquellas frases dichas a media-gana, aquellas miradas de "es usted el hombre más tonto del mundo, porque ha traído fotos que no valen"... ¿Será que la eficiencia y la mejoría en la atención al público ha repercutido en un buen-rollo generalizado? ¡Qué gusto!

Prosigo con la séptima sorpresa: El funcionario me pregunta qué deseo, y yo, como me conozco el percal, le digo que renovar el DNI y, "si se puede", también el pasaporte.

Por supuesto, me esperaba algo del palo...: "no, lo siento, para renovar también el pasaporte tiene que coger otro número, para ir a la ventanilla XX, sellar la instancia, y volver a coger otro número para venir aqui de nuevo". ¡Pues no, señores! Ante mi demanda, el noble funcionario ha respondido con un escueto "por supuesto", que me ha puesto los pelillos como picos de escarpias...

Más sorpresas, más.... la octava sorpresa llega en el momento de ver si traía todo lo necesario. Ese instante en el que un sudor frío comienza a aparecer en tu espalda, a la par que el colega tras el mostrador te pide las fotos. Y allí llegas tu, como buen español castizo con tu sobre lleno de 200 fotos de fotógrafo, que te han costado un riñon, porque probablemente te pediran 2 para el DNI, 4 para el pasaporte, y 2 más de recuerdo. Pues no, el personaje va y me pide 1 (una) foto para ambos trámites... ¿cómo puede ser? Pues muy sencillo, porque la vida avanza que es una barbaridad, y esa foto solo la usan para escanearla, y luego la copian por ordenador. ¡INCREÍBLE! ... ¡UN APLAUSO PARA LOS CABALLEROS.... !

En fin, pago los 25 lereles de rigor (porque hay cosas que no cambian ;), echo el garabato, me toman las huellas (cuidadín que ahora estamos todos fichados, y ya no va a pasar como en el CSI, que no tienen tus huellas hasta que no haces algo malo...) y cuando ya parecía que iba terminando, y que ya no había hueco para más sorpresas, llegan la novena y la décima sorpresa, ambas de sopetón, y sin aviso, tan de repente que casi me desmayo al saber que tanto el DNI como el Pasaporte íban a entregármelos EN EL MOMENTO. Y es que el operario pulsa en un botón mágico, y de una maquinita fabricada por INDRA sale tu nuevo y reluciente DNI electrónico.

Ante tales echos y estas 10 sorpresas, solo me quedan decir dos palabras:

im-presionante...

Enhorabuena, señores funcionarios, por fin han entrado ustedes en el siglo 20 (que no en el 21, ya que eso llegará cuando podamos renovar el DNI por internet).

De todos modos no vayáis a haceros demasiadas ilusiones, ya que me han reconocido que hoy era un buen día. No os prometo nada mañana...

Salu2!

Tuesday, 6 November 2007

TechEd 2007. More C# 3 features. Object and collection initializers

Another great feature of C# version 3, shown in the TechEd today and yesterday is Object Initializers.

Working as expressions, we can create and initialize objects in a single statement. Imagine we have a class Provider, with properties Name and email. We can do the following:

Provider prv = new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" }

That will create the object and initialize every property we include between the brackets.

In a very similar way work the Collection Initializers, where we can add new items to a collection in the same statement we create it:

List list = new List()
{
new Provider(),
new Provider(),
....
}

And those two features can be nested in the following way:

List list = new List()
{
new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" },
new Provider() { Name="AMD", email = "amd@amd.com" },
....
}

Cheers!

TechEd 2007. .NET Language Integrated Query (LINQ)

The last session I attended on monday was:

The .NET Language Integrated Query (LINQ) Framework

by Luca Bolognese (Senior Program Manager, Microsoft).

For anyone thas has worked in data access components, software, or have struggled at anytime with databases, this represents a huge step forward in terms of productivity, robustness, understandability, and efficiency.

I´m no expert in such issues but, to my eyes, it´s just as if you could write SQL sentences right in the middle of your C# code, combined with the power of .net of course. In addition to that, LINQ can work against almost any kind of data source (SQL data bases, xml, arrays, collections, etc), and serve as well as a datasource for dataBinding.

An example:

[Assume "names" is a collection of strings, an array or whatever]

List<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();

The full LINQ sentence is evaluated as a single expression, but is executed in steps. First, every string in "names" is selected and returned to the second sentence. This one applies a filter selecting those with length == 5 and returns another collection, which is ordered in the third sentence. And so on... as complex as you may need.

I asked Luka how the debugger behaves in this sentences, and he said that LINQ sentences are watched in a special window which allows to see each step of the execution. This is something I´m definately waiting to try.

Just as a last note, LINQ doesn´t always behave this way, as this would be very inefficient. If the collection it´s parsing is just that, something that implements iEnumerable, it behaves so, parsing each element in the collection, iterating through the full array.

BUT, the interesting thing is: if the collection being parsed also implements iQueryable, it behaves differently, building a full query from the LINQ sentences and executing it, as once, at the end. This obviously would make debuggin more difficult, but is the efficient way to execute certain types of queries.

Cheers!

TechEd 2007. VStudio 2008, C# 3, Automatic Properties

Just following the previous post, I keep talking about the session by Daniel Moth (http://www.danielmoth.com/Blog ), yesterday in the TechEd.

He showed another C# 3 new feature that is extremely useful: Automatic Properties.

You not tired about writing something like this?

private int mNumCustomers;
public int NumCustomers
{
get{return mNumCustomers;}
set{mNumCustomers = value;}
}

This is a pain in the ass... You are supposed to use properties, to be clear, clean, robust, elegant, and a good christian, but writing them is painful. Yes, refactoring helped quite a bit, but it´s still something... don´t know... slow and uncomfortable.

Well, Microsoft says that is there to make us more productive, as there it is:

Automatic Properties a.k.a JustWriteThis:

public int NumCustomers{get; set;}

The language will take care of creating the private equivalent variable, just for us. We don´t need to write it. Just specify if you want the get and set, the get only, etc, and there it is!

Again, more productivity...

TechEd 2007. VisualStudio 2008, C# 3, MultiTargeting and Anonymous Types

Yesterday, from 16 to 17:15, Daniel Moth (http://www.danielmoth.com/Blog ) introduced the new features of VStudio 2008 and .Net Framework 3.5. It was a very impressive session, fun and interesting.

Specially exciting the new multi-targeting feature of VStudio 2008. It´s a way to tell the environment which .Net Framework version your project will target, through the project´s properties window. Just selecting in a comboBox if it targets version 2.0, 3.0, or 3.5. By selecting one of them, all of the version features are enabled or disabled for your project, and it´s possible to switch between them without loosing work. Your project will just adapt to that perfectly.

Just as a tip, VStudio 2008 finally has the option "Open folder in windows explorer" in the context menu of the solution explorer... Yeeeeeaaahhhh ! Cannot imagine why something that simple didn´t appear before. No more navigating to bin\debug folder....

Also found quite interesting some of the new C# 3 features, like anonymous types. Didn´t you find redundant something like this before?

Form f = new Form();

Why do I have to say that "f" is a windows form twice? No more, just write something like this:

var f = new Form();

And the compiler will infer that "f" is a windows form just reading the code on the right part of the sentence. It´s important to mark that this has no performance impact, as it´s just a compiler feature. Each time you compile, the MSIL code generated will definately contain the declaration in the old way. It´s just a helper right there for you, just to be more productive. And of course it works with anything:

var a = 5;
var a = 5f;
var a = new Class1();
var a = "";

Great!

TechEd 2007. KeyNote by S. Somasegar

Yesterday, at 14:00 we attended the keynote of the TechEd2007, by Microsoft´s developer division corporate vice-president, Mr. S. Somasegar.



He presented the new key features of Microsoft developments plattform: VisualStudio 2008, .Net Framework 3.5, SilverLight, the Expression Studio tools, etc.


To summarize, he presented an important part of what we are going to see in deeper detail through this next days.

More later...

Sunday, 4 November 2007

TechEd Barcelona. 2007


Tomorrow I´m traveling to Barcelona to attend the Microsoft TechEd Developers 2007. I´d be glad to meet you there if you also attend.
I´ll try to post session comments here too, at the end of each day.
Cheers!
-----
Mañana viajo a Barcelona para asistir al TechEd Developers 2007 que Microsoft organiza esta semana.
Estaré encantado de veros por allí si estáis, y también trataré de postear comentarios, impresiones o resúmenes de las sesiones a las que vaya asistiendo.
Saludos!


Monday, 29 October 2007

De operadoras de telefonía y otras torturas...

Cada vez invierto menos tiempo en ver la televisión, lo reconozco, pero como cada vez hay más y más anuncios, al final termino "tragando" la misma cantidad de publicidad que siempre. De esta forma todo queda equilibrado, y no corro el riesgo de convertirme en un troglodita desconectado que no sabe quién ha ganado el puto Gran Hermano este año...

El otro día, entre cuarto de hora y cuarto de hora de Sleepers, en una de mis sesiones diarias de tv-marketing, tuve la gozosa experiencia de ver otro anuncio más de telefónica. Esta vez, nos regalan el ADSL de 10 Mb. Fíjate tu... no se cansan de repetir una y otra vez en el anuncio, que su ADSL es de gratix.

Claro está, mientras dicen eso, hay una carrera de letras en "Arial 6.5" que pasan por la parte baja de la pantalla, a tal velocidad que constituyen un ejemplo perfecto de lo que, en edición de video o animación se denomina: "motion blur"...

Por supuesto, en esas letras se dice algo así como: "Promoción válida durante los 30 primeros segundos de uso. A partir de ahí, 40 lereles, como toda la puta vida..."

Y digo yo... ¿Cuando van a dejar de tratarnos como si fueramos subnormáticos profundos?

A mi, personalmente, ya me harta tanta bobada y soplaguindez...

Nota: que quede claro que todas las operadoras hacen lo mismo. Comento el anuncio de telefonica porque es el último que ví, nada más...

Thursday, 25 October 2007

Great master of chess trying Simax

Several months ago, we had the pleasure to receive at our facilities to the great master of chess Miguel Illescas.

He was trying one of the first prototypes of the simax simulator. Although it was in a very primitive stage, he liked it and enjoyed a ride with a Volkswagen Polo.

I include this post now, because I´ve received this link with some info about it (Basque Language)

http://www.xake.net/6Gogoratzen/2007_EUS/2007-05-29%20Miguel%20Illescas,%20xakelaria%20eta%20informatikaria%20-Berria-n.htm

XNA Game Studio 2.0

It seems that version 2 of XNA Game Studio is around the corner. We are all willing to test the new features described here:

http://blogs.msdn.com/xna/archive/2007/08/13/announcing-xna-game-studio-2-0.aspx

Just one note: it will finally work with all versions of Visual Studio (2005 professional, ...).

Cheers!

MSFT Madrid

Today, I had the chance to visit Microsoft facilities in Madrid. It´s a beautiful place as you can see:


Good to work here, specially after you see several XBox360 at the entrance ;)

Thank you guys!

Wednesday, 24 October 2007

Photoshop CS3 Layers. Select all pixels & rasterize effects

I´ve been messing around with Photoshop CS3 and I´ve found a couple of things I´d like to share with you.

In versions of PS prior to the CS2, only one layer in the layer palette could be selected at a time. Now, there´s the possibility to select more than one layer and work with them alltogether, in the typical ctrl+click way to select and de-select layers.

This is great, but that combination (ctrl+click) was previously used to select all layer´s visible pixels. So now, how is this thing done? Well, after 15 minutes trying, searching, and desperating, I´ve realized it´s the very same thing, but clicking in the layer´s thumbnail instead of any part of layers entrance.

Second trick I´ve found here:

http://graphicssoft.about.com/cs/photoshop/qt/flatlayereffect.htm

HOWTO flatten, or rasterize all layer´s effects:

If you have applied some effects to a layer, all of them keep editable at all the time. This is also great but if you need at some time to "apply" all that effects, rasterize them in the layer and reset all the effects properties, so you can work again with the modified layer "from scratch", there is no obvious option to do so.

A very easy way to do this, is to create an empty layer and place it just below the layer you want to flatten. Then merge that layer down (ctrl+E) to the empty layer you just created and voilá! all the effects get applied and disappeared.

Cheers!

Thursday, 27 September 2007

Tutorial de desarrollo de Juegos: Diseño basado en componentes

No siempre voy a hacerlo, pero hoy me veo con fuerzas y voy a tratar de escribir este tutorial en ambos idiomas. Allá va...

Si habéis leído algo sobre XNA, probablemente hayáis visto un concepto que, aunque lleva ya bastantes años por ahí, su aplicación en el sector de los videojuegos es bastante nueva y especialmente apropiada. Estoy hablando del: Desarrollo basado en componentes.

La idea es diseñar todos los objetos del juego siguiendo un mismo interfaz:


// Inicialización del objeto, construcción de recursos, etc
void Initialize();

// Actualización: Incluye toda la lógica del juego necesaria para el objeto
void Update(double pAppTime, float pElapsedTime);

// Dibujado, en los casos que proceda
void Render(Device pGraphicsDevice);

Los parámetros de esos métodos pueden variar a gusto del consumidor. XNA o DX9 tienen sus parámetros típicos, pero tu usa aquellos con los que te sientas cómodo.

Lo importante de todo esta metodología es que mantiene una estructura de aplicación muy muy simple, fácil de comprender y de extender, ya que todos los objetos se comportan de la misma manera. Si lo piensas bien, practicamente nunca vas a necesitar nada fuera de esos tres métodos.

En los siguientes posts bajo este mismo TAG, iré incluyendo un tutorial que muestra el desarrollo de un juego muy sencillo, del estilo al arkanoid, que sigue este patrón o filosofía. Está basado en C# y GDI, y aunque no es nada complicado, sirve para mostrar este concepto.

Saludiños!

Game Development Tutorial: Component based design or more precisely, the Interface used in CBD

If you´ve read something about XNA, you have probably seen a concept that, though it´s out there for many years now, it´s quite new and specially appropiate for games: Component based programming.

Some people pointed out that I´m talking more about the interface used in the Component Based Design of XNA than the CBD itself, and they are right. Absolutely right.

The important idea I wanted to transmit here is the convenience of using game objects or components that share an interface like the following:

// Object initialization, boot up, etc
void Initialize();

// State update: Put your game logic in here
void Update(double pAppTime, float pElapsedTime);

// Draw method: draw the object if needed
void Render(Device pGraphicsDevice);

The important thing about this methodology is that it keeps a very simple application structure, and every component behaves in the very same way. If you think about it, most of the times you don´t need anything appart from those 3 methods.

In the following posts in this same tag, I´ll include a very simple arkanoid-like game application that follows this mothodology. It´s quite simple, C# and GDI based, but it performs pretty well and shows what I´m talking about.

Cheers!

Tuesday, 25 September 2007

Double Buffer Graphics in C# + GDI

Hi all,

recently, I was building a test application that needed some basic graphic drawing to show some physical values in real time. I wanted to do it simple and fast, so I didn´t want to deal with all the DirectX stuff (devices, resources, etc). That´s why I went into the simple Windows Forms GDI solution.

I wrote the program and run fine but, as expected, flickering appeared all around when animation came into scene. This is something that was obviously going to happen, so I decided to remember the old times and search for a double buffer drawing solution.

It is very simple to fix this behavior, just draw everything appart, to a different surface, and then dump the whole picture to the screen. Among the different solutions I found over the internet, one of the best and most simple is the code included below (NT Almond. 2003):

Just include it in a class and perform all the rendering through its Graphics object.

et voilá!



using System;
using System.Drawing;

namespace GDIDB
{
///


/// Class to implement Double Buffering
/// NT Almond
/// 24 July 2003
///

///
public class DBGraphics
{
private Graphics graphics;
private Bitmap memoryBitmap;
private int width;
private int height;

///
/// Default constructor
///

public DBGraphics()
{
width = 0;
height = 0;
}

///
/// Creates double buffer object
///

/// Window forms Graphics Object
/// width of paint area
/// height of paint area
/// true/false if double buffer is created
public bool CreateDoubleBuffer( Graphics g, int width, int height )
{
if ( width <= 0 height <= 0 ) return false; if ( width != this.width height != this.height memoryBitmap == null graphics == null ) { if ( memoryBitmap != null ) { memoryBitmap.Dispose(); memoryBitmap = null; } if ( graphics != null ) { graphics.Dispose(); graphics = null; } this.width = width; this.height = height; memoryBitmap = new Bitmap( width, height ); graphics = Graphics.FromImage( memoryBitmap ); } return true; } ///
/// Renders the double buffer to the screen
///

/// Window forms Graphics Object
public void Render( Graphics g )
{
if ( memoryBitmap != null )
g.DrawImage( memoryBitmap, new Rectangle( 0, 0, width, height ), 0, 0, width, height, GraphicsUnit.Pixel );
}

///
///
///

/// true if double buffering can be achieved
public bool CanDoubleBuffer()
{
return graphics != null;
}

///
/// Accessor for memory graphics object
///

public Graphics g
{
get
{
return graphics;
}
}
}
}

Code found here, among other sites:
http://www.koders.com/csharp/fid8D1742BF7E30AEB520A0548A95C99DD48CDAA645.aspx

Tuesday, 18 September 2007

Simax en Navarparty 2007

Muy buenas,

hace ya bastante tiempo que no escribo en el blog. Como dirían algunos... busy, busy, busy...

En fin, que este viernes estaré en la Navarparty (Pamplona), presentando el proyecto Simax y respondiendo a cualquier duda que salga. También habrá alguna demo del sistema, técnica, etc.

El horario provisional es 17:30 de la tarde. Si por algún motivo cambia, podréis verlo actualizado aqui:

http://www.navarparty.org/content/view/69/115/

Salu2!

Wednesday, 11 July 2007

New simax video. ABS braking practice

In the following link:

http://stage6.divx.com/user/graphicdna/video/1403012/Simax-DS--Practica-con-ABS---ABS-Braking-practice

you can find the latest Simax Project video. An exercise practicing braking with and without Anti-lock Braking System.

cheers!

Tuesday, 3 July 2007

Discover the Logitech G25

As you probably already know, the G25´s shifter is extremely functional as it can be configured as an h-pattern shifter or a sequential shifter.

What maybe you don´t know yet is that you can push the shifter down when h-pattern mode is selected. "Pushing down and setting a gear", will result in a different button than just "setting that gear".

This feature allows you to simulate, for example, a 6-gear car gearbox, configuring the reverse in the push-and-first_gear or push_and_sixth gear, just like in many real cars.

The G25 is fantastic !

Wednesday, 27 June 2007

Unveiling the power of the Porsche 911

Take a look at the newest Simax Project video. It shows a high speed ride with the Porsche 911 Carrera through a highway, closed to traffic.

http://stage6.divx.com/user/graphicdna/video/1351013/Simax-DS--Porsche-911-highway-ride--HD

More info at: www.simax.es

Tuesday, 19 June 2007

Simax HiRes Videos

Muy buenas, estamos subiendo los videos del proyecto Simax al siguiente link:

http://stage6.divx.com/user/graphicdna/videos/group:uservideos

Stage6 soporta videos HD, así que hasta nuevo aviso, todos los futuros videos serán subidos allí.

Saludos

-----

Hi, we are uploading all the simax videos to:

http://stage6.divx.com/user/graphicdna/videos/group:uservideos

They are HD, so every new video will appear there too.

Cheers!

Monday, 18 June 2007

Artículo en Expansión&Empleo

En el siguiente enlace:

http://www.expansionyempleo.com/edicion/expansionyempleo/emprendedores_y_franquicias/informacion_al_empresario/es/desarrollo/1003698.html

podéis leer un artículo publicado en Expansión&Empleo (suplemento del periódico Expansión) en el que hablan del pasado CodeCamp de Microsoft.

Saludos!

Friday, 15 June 2007

Simax Driving Simulator, Ejercicio formativo elemental

Muy buenas,

este post lo escribo en español porque el nuevo video de Simax también está en castellano, así que ná...

En el siguiente link:

http://www.youtube.com/watch?v=RObi53UJoDk

Tenéis el último video del proyecto simax, uno de los ejercicios formativos disponibles en el simulador, destinado a la práctica de las maniobras más básicas necesarias para el manejo de un turismo con transmisión manual, en este caso un Porsche 911... (no hubiera estado mal aprender a conducir con este coche, en lugar del Ibiza que tenían en mi autoescuela... ;)

Espero guste !

Un saludo,

Friday, 8 June 2007

Simax Porsche 911 Carrera S trailer

There´s a new Simax video available. You can find it here:

http://www.youtube.com/watch?v=q6VLp3Q4xdM

It shows some visual details of a Porsche 911 Carrera inside the engine of the Simax simulator. All scenes have been taken from live action in the simulator (no rendered scenes or post processing).

Hope you like it.

Cheers!

Monday, 4 June 2007

Microsoft CodeCamp. June 2007. El Rocío, Huelva

Hi there !

It´s been long ago since the last time I wrote a post. I´ve been really busy with the Simax project and the recent events. I haven´t visited the MSDN forums much neither, but I hope to start getting more time for my own since now.


This last weekend I had the chance to go to El Rocio (Huelva, Spain), where took place the Microsoft Codecamp. It´s a wonderful place with really good weather and food, and a must for any tourist visiting the south of Spain.

I personally enjoyed a lot my time there, and must thank Microsoft´s people (Jose, Alfonso, Beatriz, Maribel, Ethel, ...) for all the good work done there. It was GREAT !


We were accomodated in this wonderful bungalow camping:





and the agenda included lots of interesting sessions: http://www.microsoft.com/spanish/msdn/spain/eventos/codeagenda.mspx.



In the morning, I gave an introduction to XNA development, followed by a more technical XNA session by Javier Canton (http://www.codeplex.com/XNACommunity), who showed some very interesting visual effects, using XNA post-production shaders. Good work Javier!.







Later on, I presented the Simax Project and made a short demo showing the features of the driving simulator:






It would be too long to talk about every other session, but I must include a special mention to "El diván de Monica", really fun and instructive, in which Miguel Egea (http://blogs.solidq.com/ES/megea), Unai Zorrilla (http://geeks.ms/blogs/unai/) and Alejandro Mezcua (http://www.byteabyte.net/) were interviewed by Monica, and talked about their great experience in the industry, giving very good advices to all of us.


Of course, I cannot finish this post without talking about the last chart of the first day: "El rock ha muerto" (Rock is dead), by Chema Alonso (http://elladodelmal.blogspot.com/) and Ricardo Varela (http://phobeo.com). What can I say... Just take a look by yourself:


This has been, with no doubt, the funniest session I´ve ever seen. And was instructive too !!

Finally, I also have to thank Daniel Romano, Carlos Ibarra and Fernando Lacunza for their help with the shipment to the CodeCamp. It was hard, but you made it... Thanks !!


Thanks a lot to everyone !!!!!

Friday, 23 March 2007

Easy Drag&Drop from DataGridView control

The DataGridView control does not implement any method for doing Drag&Drop of items or rows out of it, but it can easily be done with some custom code. This first example will hande dragging of entire rows out of the DataGridView:

private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
// If the datagrid has any selected row, and the mouse moves outside the datagridView,
// start the drag.
if (this.dataGridView1.SelectedRows.Count > 0 &&
!this.dataGridView1.ClientRectangle.Contains(e.X, e.Y))
{
// Proceed with the drag and drop, passing in the list of selected rows. You can
// assign any DragDropEffect you´d like here.
dataGridView1.DoDragDrop(dataGridView1.SelectedRows, DragDropEffects.Move);
}
}
}

This method determines that a dragging operation is being performed if the cursor gets out of the client rectangle of the grid, with the left button pressed (and any row selected).

It handles correctly a multi-select situation but it´s behavior is more "natural" if multiSelect is set to false, because while the cursor is inside the DataGrid, a drag will make the grid to select multiple rows. As soon as the cursor gets out the control, a Drag&Drop operation is started.

This is a verey simple and efficient way of handling this, but there are other possibilities.

Tipically, a windows application decides that a dragging operation is being performed if the mouse coursor travels (with the left button pressed) a certain distance, not necessarily out of the DataGridView like in the previous example. This minimum distance is a system configuration variable that can be found in: SystemInformation.DragSize.

Doing so is a more standard way and it also allows to drag and drop items inside the DataGridView. An easy way to handle this, is to keep track of a Rectangle defined at mouse down, with the dimensions of that DragSize. Some sample code:

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// Get the index of the item the mouse is below.
DataGridView.HitTestInfo hInfo = this.dataGridView1.HitTest(e.X, e.Y);

// Will just handle if hitted a cell. You can test whatever kind of intersection you like here
if(hInfo.Type == DataGridViewHitTestType.Cell)
{
// The DragSize indicates the size that the mouse must move to consider a drag operation
Size dragSize = SystemInformation.DragSize;

// Create a rectangle using the DragSize, with the mouse position being
// at the center of the rectangle.
mMinDistanceRectangle = new Rectangle(
new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize);
}
else
{
// Reset the rectangle if the mouse is not over an item in the ListBox.
mMinDistanceRectangle = Rectangle.Empty;
}
}

So, in the MouseMove event, you will want to test if the mouse is outside of that rectangle to start a Drag&Drop. Something like this:

if (mMinDistanceRectangle != Rectangle.Empty &&
!mMinDistanceRectangle .Contains(e.X, e.Y))
{
dataGridView1.DoDragDrop(...whatever...);
}

Hope this helps.

Cheers !

Thursday, 8 March 2007

XNA Collision Detection (Part III). Content Processing (code fixed)

[Please NOTE: This article is OBSOLETE. It has been re-written and completed in this newer posts: part 1 and part 2]

Put in the Mesh class all the info wee need

Very much like we did in the Custom Content Processing post, we are going to use the “Tag” property of a mesh to store what we want, which in this case is something like this:



public class MeshData


{


public VertexPositionNormalTexture[] Vertices;


public int[] Indices;


public Vector3[] FaceNormals;



public MeshData(VertexPositionNormalTexture[] Vertices,


int[] Indices,


Vector3[] pFaceNormals)


{


this.Vertices = Vertices;


this.Indices = Indices;


this.FaceNormals = pFaceNormals;


}


}




When VisualStudio passes every model through our ContentProcessor, it will write the model´s data to an XNB file. When it finds a MeshData object, will search for a writer that is able to serialize it, so we have to write our custom ContentTypeWriter for the MeshData class:



[ContentTypeWriter]


public class ModelVertexDataWriter : ContentTypeWriter<MeshData>


{



protected override void Write(


ContentWriter output, MeshData value)


{


output.Write((int)value.Vertices.Length);


for (int x = 0; x < value.Vertices.Length; x++)


{


output.Write(value.Vertices[x].Position);


output.Write(value.Vertices[x].Normal);


output.Write(value.Vertices[x].TextureCoordinate);


}



output.Write(value.Indices.Length);


for (int x = 0; x < value.Indices.Length; x++)


output.Write(value.Indices[x]);



output.Write(value.FaceNormals.Length);


for (int x = 0; x < value.FaceNormals.Length; x++)


output.Write(value.FaceNormals[x]);


}



public override string GetRuntimeType(


TargetPlatform targetPlatform)


{


return typeof(MeshData).AssemblyQualifiedName;


}



public override string GetRuntimeReader(


TargetPlatform targetPlatform)


{


return "ContentProcessors.ModelVertexDataReader, ContentProcessors, Version=1.0.0.0, Culture=neutral";


}


}




In a similar way, when the ContentPipeline tries to read back the XNB file, it will search for a deserializer for the type MeshData, so we have to write our own ContentTypeReader:



public class ModelVertexDataReader : ContentTypeReader<MeshData>


{


protected override MeshData Read(


ContentReader input, MeshData existingInstance)


{


int i;


i = input.ReadInt32();



VertexPositionNormalTexture[] vb = new VertexPositionNormalTexture[i];



for (int x = 0; x < i; x++)


{


vb[x].Position = input.ReadVector3();


vb[x].Normal = input.ReadVector3();


vb[x].TextureCoordinate = input.ReadVector2();


}



i = input.ReadInt32();


int[] ib = new int[i];



for (int x = 0; x < i; x++)


ib[x] = input.ReadInt32();



i = input.ReadInt32();


Vector3[] normals = new Vector3[i];


for (int x = 0; x < i; x++)


normals[x] = input.ReadVector3();



return new MeshData(vb, ib, normals);



}


}




Finally, our Custom Content Processor that fills up the MeshData objects for each model goes through it:

Note: some parts taken from ZiggyWare:

http://www.ziggyware.com/readarticle.php?article_id=74


[ContentProcessor(DisplayName = "Custom Mesh Processor")]


public class PositionNormalTexture : ModelProcessor


{



public override ModelContent Process(


NodeContent input, ContentProcessorContext context)


{


ModelContent model = base.Process(input, context);


foreach (ModelMeshContent mesh in model.Meshes)


{


// Put the data in the tag.


VertexPositionNormalTexture[] vb;


MemoryStream ms =


new MemoryStream(mesh.VertexBuffer.VertexData);


BinaryReader reader = new BinaryReader(ms);



VertexElement[] elems = mesh.MeshParts[0].GetVertexDeclaration();



int num = mesh.VertexBuffer.VertexData.Length /


VertexDeclaration.GetVertexStrideSize(elems, 0);



vb = new VertexPositionNormalTexture[num];



for (int i = 0; i < num; i++)


{


foreach (VertexElement e in elems)


{


switch (e.VertexElementUsage)


{


case VertexElementUsage.Position:


{


vb[i].Position.X =


reader.ReadSingle();


vb[i].Position.Y =


reader.ReadSingle();


vb[i].Position.Z =


reader.ReadSingle();


}


break;


case VertexElementUsage.Normal:


{


vb[i].Normal.X =


reader.ReadSingle();


vb[i].Normal.Y =


reader.ReadSingle();


vb[i].Normal.Z =


reader.ReadSingle();


}


break;


case


VertexElementUsage.TextureCoordinate:


{


if (e.UsageIndex != 0)


continue;


vb[i].TextureCoordinate.X =


reader.ReadSingle();


vb[i].TextureCoordinate.Y =


reader.ReadSingle();


}


break;



default:


{


Console.WriteLine(e.VertexElementFormat.ToString());


switch (e.VertexElementFormat)


{


case VertexElementFormat.Color:


{


reader.ReadUInt32();


}


break;


case VertexElementFormat.Vector3:


{


reader.ReadSingle();


reader.ReadSingle();


reader.ReadSingle();


}


break;


case VertexElementFormat.Vector2:


{


reader.ReadSingle();


reader.ReadSingle();


}


break;


}


}


break;


}


}


} // for i < num




reader.Close();



int[] ib = new int[mesh.IndexBuffer.Count];


mesh.IndexBuffer.CopyTo(ib, 0);



Vector3[] normals = new Vector3[mesh.IndexBuffer.Count / 3];



for (int i = 0, conta = 0; i < mesh.IndexBuffer.Count; i += 3, conta++)


{


Vector3 v0 = vb[mesh.IndexBuffer[i]].Position;


Vector3 v1 = vb[mesh.IndexBuffer[i+1]].Position;


Vector3 v2 = vb[mesh.IndexBuffer[i+2]].Position;


Vector3 edge1 = v1 - v0;


Vector3 edge2 = v2 - v0;


Vector3 normal = Vector3.Cross(edge1, edge2);


normal.Normalize();


normals[conta] = normal;


}



mesh.Tag = new MeshData(vb, ib, normals);


} // foreach mesh



return model;


}


}






In the next chapter will focus on the Collision Detection implementation using all this info. Cheers !




Tuesday, 6 March 2007

XNA Collision Detection (Part II)

[Please NOTE: This article is OBSOLETE. It has been re-written and completed in this newer posts: part 1 and part 2]

Accurate collision detection

( I assume here that you´ve read my post about Custom Content Processing: http://graphicdna.blogspot.com/2007/02/xna-customizing-content-processing.html )

A more accurate collision model is sometimes needed. The best is to develop a library of methods to test between meshes and rays, spheres, boxes, etc. How we do that?

Probably, you already incluye in your engine a system memory copy of your geometry. The problem is that there´s no direct access to content created with the WriteOnly flag in XNA, so you cannot create that sysmem copy at load time.

The solution is to make a custom content processor that stores that copy of the geometry at build time, where there´s still access to it. We made a simple example of something similar in the post mentioned above, but now we need more...

In the next post, I´ll show how to create a Custom Content Processor designed to store all the info needed for collision detection.

Cheers !

Monday, 5 March 2007

XNA Collision Detection (Part I)

[Please NOTE: This article is OBSOLETE. It has been re-written and completed in this newer posts: part 1 and part 2]

Preface:

If you want to see an introductory post to Collision Detection, check out this one: http://graphicdna.blogspot.com/2007/02/3d-intersection-concepts-and.html


XNA collision detection

In D3D there´s a method called Mesh.Intersect that performs a Mesh-Ray intersection test. Many people thinks this method does some kind of optimized "magic" to test for intersection, but in fact it just loops throught all the triangles of the mesh doing a triangle-ray intersect, keeping track of the closest collision point. In XNA, there´s not such a method, and we will have to do it on our own. To do so, we will also have to deal with Custom Content Processing.

Simple Collision Detection

Before we go into a Mesh.Intersect() method, it´s a good idea to point out that XNA does include simple intersection tests for simplification shapes like: Bounding Spheres, AABB (Axis Aligned Bound Box), Planes, Rays, and any combination of them.

Using those tests, almost any kind of game-like intersection can be achieved. You must remember that a Mesh-Whatever intersection is expensive (depending in the number of polygons, of course), and should be left for special cases in which a very high intersection accuracy is needed. So, its usually preferred to aproximate a complex geometry by a bunch of spheres or boxes, than using the real triangles.

There´s a very good post at Sharky´s blog about XNA collisions, specially focused in approximating generic shapes with bounding spheres.

You can find it here: http://sharky.bluecog.co.nz/?p=119

Will continue tomorrow.

Cheers !