Busy May with RavenDB
Just a small post to let you know. I’ll be speaking in two conferences this month.
The 26th of May at DDD South West. The topic is Raven DB Day to Day
Closely followed by an Introduction to Raven DB in Progressive.net (London) the 31st of May
If there is a particular topic you want to see there, please let me know
Cheers
Filed under: ravenDB, talk | Leave a Comment
Tags: ravenDB, uk
XNA–A Simple Spring Camera in 2D
Cameras are cool, so lets keep at it and try a spring camera, i.e. one that follows you around.
The initial aspect of the camera and how to use it is on the previous post on cameras, so I ll let you go and have a look there.
The spring camera is very similar to a simple camera, but with Hooke’s Law applied. Hooke’s Law states that the extension of a helical spring is directly proportional to the weight applied, provided the elastic limit of the spring is not exceeded. I read this a few times and couldnt figure how to turn this into code , so I went to Khan Academy and found this video, where the formula F = –k x is explained.
If we use the formula as is, then the spring would be “springing” forever, so when calculating the force we will use some damping. So the new update method in Camera.cs now looks like this
1: public void Update(float elapsedSeconds, float rotation, Vector2 desiredPosition, float zoom)
2: {
3: var delta = _position - desiredPosition;
4: var force = -SpringStiffness * delta - Damping * _velocity;
5:
6: var acceleration = force / Mass;
7: _velocity += acceleration * elapsedSeconds;
8: _position += _velocity * elapsedSeconds;
9:
10: Transform = Matrix.CreateTranslation(-_position.X, -_position.Y, 0) *
11: Matrix.CreateRotationZ(rotation) *
12: Matrix.CreateScale(zoom, zoom, 1)*
13: Matrix.CreateTranslation(_halfScreenSize.X, _halfScreenSize.Y, 0);
14: }
The line
var force = -SpringStiffness * delta – Damping * _velocity;
Is respecting the formula F= –kx, where k is the SpringStiffness and x is the delta(in orange). The second part of this assignment(in green) is applying some damping proportional to the velocity.
Once we have the result of calculating the force, we use the force vector to calculate the acceleration that, in turn that value is used to calculate the velocity and position.
Finally, once we have the position, the matrix transformation is calculated in the same way we calculated this for the simple camera (in previous post).
You can get a complete working sample here.
Filed under: Uncategorized | Leave a Comment
Tags: acceleration force mass, programming
This a very simple walk through to use Mercury on a Windows Phone 7 project.
Get the binaries
As far as I can see, Mercury supports Windows Phone 7 only in version 4.0, if you go to the project page you wont find this on downloads, as it’s not yet released.
So, you have to get the sources from here and build the project and find the correct binaries. An alternative is to download them from here (I forked the repo and added the binary download for WP7 ) If you ask nicely I’ll add all the other binaries.
Once you have the binaries, include ProjectMercury.dll in the project where you want to use the particle engine, and add ProjectMercury.ContentPipeline.dll to the content project.
Code
I am not entirely sure where is the best place for the initialization code, you can probably place it in LoadContent, tho I did create the new instance of SpriteBatchRenderer in the constructor of my game class.
1: // It needs the GraphicsDeviceManager
2: _spriteBatchRenderer = new SpriteBatchRenderer{ GraphicsDeviceService = _graphics };
3:
4: _particleEffect = Content.Load<ParticleEffect>("Demo1");
5:
6: foreach (var emitter in _particleEffect.Emitters)
7: {
8: emitter.ParticleTexture = Content.Load<Texture2D>("Star");
9: emitter.Initialise();
10: }
11: _spriteBatchRenderer.LoadContent(Content);
All you are doing is loading the particle effect through the content pipeline. Then you are iterating over the emitters in the effect to assign the ParticleTexture value, ie a texture you just loaded, and initializing each of the emitters. Finally you need to call LoadContent, calling this method is required because it creates the internal SpriteBatch instance* .
In the update you will need to call
1: //position is a Vector3
2: _particleEffect.Trigger(ref position);
3: _particleEffect.Update((float) gameTime.ElapsedGameTime.TotalSeconds);
You need to Trigger the particle with a position (there are a number of overloads for this method, make sure you check this out) and then Update. If you fail to do either of those calls, no particles will be rendered.
Finally in the Draw function:
1: var matrix = Matrix.Identity;
2: var cameraPosition = Vector3.Zero;
3: _spriteBatchRenderer.Transformation = Matrix.Identity;
4: _spriteBatchRenderer.RenderEffect(_particleEffect, ref matrix, ref matrix, ref matrix, ref cameraPosition);
Please find a full working sample here
And this would be what you see when you run the project ![]()
Some thoughts
I have to admit, I find it strange that the constructor for SpriteBatchRenderer doesn’t require GraphicsDeviceManager, and instead you need to initialize the property, if you don’t set this property before you call LoadContent, then you get a NullReferenceException, as this is where the internal instance of SpriteBatch is created and a GraphicsDevice is required.
My suggestion here would be to have two versions of the constructors, one where you pass the reference of spriteBatch you have, and another one where you pass the instance of GraphicsDevice, as all usages point to only actually consuming that.
These are just some thoughts on the API, and there might be really good reasons for the decisions made this way that I don’t know about. I think that all in all this is a great project, thanks to the creators and maintainers of it.
Filed under: gamedev, xna | 3 Comments
Tags: gamedev, mercury, particle, particle engine, xna
XNA – A Simple 2D Camera
What is a camera? Intuitively we know what a camera is: simply a way to show the action.
A Camera allows us to deal with the display of the action in a detached way from the action.
Implementation
I like to start with what we are trying to achieve. For the purposes of this post, I want to have two cameras showing the same action at different zoom levels, like this:
In this case we want 2 cameras, with each camera having it’s own ViewPort that we assign when creating like this:
int halfScreenWidth = GraphicsDevice.Viewport.Width/2; _camera1 = new Camera(new Viewport(0, 0, halfScreenWidth - 3, GraphicsDevice.Viewport.Height));
What we are saying with that is that the Camera class will have a Viewport that occupies the left side of the screen. The – 3 is there to add a visible gap between the left and right sides of the screen. Lets look at the following portion of the Draw method. Please note you could have all the parameters for _spriteBatch.Begin() null, except for the transform.
1: GraphicsDevice.Viewport = _camera1.Viewport; 2:
3: _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, _camera1.Transform); 4: _level.Draw(_spriteBatch);
5: _spriteBatch.Draw(_tankTexture, _tankPosition, null, Color.White, _rotation, new Vector2(_tankTexture.Width / 2, _tankTexture.Height / 2), 1, SpriteEffects.None, 0); 6: _spriteBatch.End();
Since we have a viewport per camera, the graphics device needs to know which one to use, and that’s what we are doing in line 1 in the code above. The other important part of the code is the last parameter of the _spriteBatch.Begin call, where we are using the transformation matrix from the camera. This transform is calculated on each update.
So finally lets look at the Camera class:
1: public class Camera
2: {
3: public Matrix Transform { get; private set; }
4: public Viewport Viewport { get; private set; }
5:
6: public Camera(Viewport viewport)
7: {
8: Transform = Matrix.Identity;
9: Viewport = viewport;
10: }
11:
12: public void Update(GameTime gameTime, float rotation, Vector2 position, float zoom)
13: {
14: Transform = Matrix.CreateTranslation(-position.X, -position.Y, 0) *
15: Matrix.CreateRotationZ(rotation) *
16: Matrix.CreateScale(new Vector3(zoom, zoom, 1)) *
17: Matrix.CreateTranslation(Viewport.Width / 2, Viewport.Height / 2, 0);
18: }
19: }
The least obvious part of this code lies in the matrix transformation. It is important to understand that we have two coordinate systems in place, the screen and the world. With the transformation matrix we are trying to project the world coordinate system onto the screen system. With that in mind, the first translation matrix (line 14 in the code above) will reposition the world so that point (position.X, position.Y) lines up with the screen’s origin. The result is as follows:
What you see at the top left of the pic is a quarter of the tank. If you change the tank’s position then you will see that the tank remains static at the top left (tho rotation applies) and the world moves underneath it.
The next line, Matrix.CreateRotationZ, creates a matrix representing a rotation around the Z axis. The Z axis points straight out of the screen. In 2D, to perform a rotation, we always rotate around Z.
Then we need to scale, using the parameters that we sent on update. Don’t forget we set different levels of zoom in each of the two cameras. We use the overload of Matrix.CreateScale() that takes a Vector3 to create a scaling matrix. However we could use the overload that just takes a float and pass the zoom value as a parameter with the same result. Unsurprisingly applying the scale, scales
.
Finally we want to center the tank in the middle of each viewport and that’s why you apply the last line (line 17 on the sample above).
And we are done
tho I m sure there are plenty of ways to improve the code, but hopefully it will help as a simple example.
If you want to have a better look at the code, a working sample is available here. If you have any comments, improvements, questions, as always you are very welcome.
UPDATE: I followed up with a post about Spring Camera here.
Other XNA 2d Camera posts
XNA Camera 2d with zoom and rotation
Another one that I read after implementation Terrain, Weather, and more!
Filed under: gamedev, xna | 1 Comment
Tags: 2d, camera, gamedev, xna
I got a Windows Phone 7 to play with for a while and these are some notes about the experiment. I just did a tick-tac-toe based on this blog post changed a few things tho (like the use of extension method for checking for wining and replaced by bit shifting
), but I wanted to have some code to fall back to just in case.
NOTE: I have an android phone, and had an iPhone for a while in the past, so my expectations about this phone are probably based on them.
As soon as I connected the phone to my computer it prompted me to install the Zune software, after installation you get this:
restarting my machine? we are not in 1999, this shouldn’t be a requirement.
Also when I was trying to install some game, the phone displayed a message about the fact that some installations require re starting the phone. Very strange
Rather randomly on an LG –E90099 I get the error that the phone is pin locked (it isn’t
).
If while trying to debug to your phone you get an error, “The application could not be lauched for debugging. Verify that the application is installed on target device” that, for me , meant that the phone was locked (ie dark screen) Make sure you can see the menu and try again
After these initial errors, I pretty much moved pretty quickly.
I am quite surprised by this, but at least for game development (with xna) this little trial has been incredibly painless.
Regarding the phone OS, there are some aspects that I really dislike:
- A lot of screen is wasted, for example if i search online for something, I can only see about 2 to 3 results.
- The facebook integration (I dont want facebook). Probably it can be turned off?
- Figuring out how to un-link the hotmail account to the phone is quite tricky (it might be just me)
- Having to restart your phone after installing an app is just not acceptable.
Things I liked about the phone
- Dealing with text in general is superior at least to the android experience. ie writting texts and email was a good experience
- Generally fast and non cluttered
In general my perception of the phone has improved after trying it . And I have to add I m pretty impressed by the Zune software, it looks good, it worked flawlessly. Comparing to iTunes and Samsung Kies it’s way ahead.
I like XNA, and the fact that it was so transparent to deploy a game to the phone was really nice.
Filed under: gamedev, Uncategorized, xna | Leave a Comment
Tags: ganedev, windows phone 7, xna
Programming Science
So a few Scientists and a few developers met last Wednesday. It was hard to know where we were going to end and thanks so much to everyone that participated. The following is a summary of the tips we (scientist + developers) thought was a good idea
Tips for scientists writing code (1st Round):
- Talk to other scientists that work on similar projects and share a list of your most used functions (I cant remember the name of the person suggestion
- Every now and then meet up with other scientist writing similar code to you to talk specifically about the code you write, after all if you know the tools you are working with better, you are bound to be more productive
- Use source control. There are pretty good open source alternatives and many places that offer free storage. Some source control options: Git, Mercurial, subversion. Some places to host your code: github, bitbucket, google code, codeplex
- Use variable names that indicate what you are talking about.
- Some bad examples: your_cat_name, sss, ttt, etc. Some good examples: portionOfSphere, portion_of_sphere.
- In the case of IDL, avoid for loops and try to use functions
- Try to get used to reading others people code so that you realise where you can improve, or point out things that can be done i na more effective way
Help a scientist day
The above is all well and good, however. We were also thinking about collaboration. So Philippe came up with a great idea: Help a scientist day.
- A scientist submits (somewhere to be discussed) a problem she or he thinks it could be solved with some help of more developers
- people can ask questions about the idea (either technical details or just to check that its a problem similar to theirs)
- People can vote on ideas (no need to sign up )
- The ideas with most votes (that are doable) will be the ones that will be implemented by developer during “Help a Scientist Day”
So, we need to organize this day, please comment on G+ so we can get this going
Cheers
Filed under: Uncategorized | 3 Comments
XNA is the SDK from Microsoft for game development.
- XNA getting started tutorial. Well organized, paced series of XNA tutorials by a guy that teaches this. If you know nothing this is pretty good.
- Xna workshop. Some posts and links to learn XNA Is kinda handy to see other people’s questions
- Riemers XNA Tutorials. I think this is a link you want to keep, every time I search for something XNA related I get a post from this guy
- 2D Camera with parallax scrolling. Does what it said on the tin, very comprehensive article that also links to other interesting articles.
- Mono game. The good news is that there is a port
… “MonoGame is an open source implementation of the XNA APIs that allows developers to build 2D games that run on Android, iPhone, iPad, Mac, Linux and Windows using the same code base, or reusing existing XNA code that runs on Xbox 360 or Windows Phone 7″
Filed under: Uncategorized | Leave a Comment
What an awesome experience to organize and participate in this event.
It was a long day but I think people enjoyed it, learned a lot and got to try a few new things.
At 9, Jose explained how a Code Retreat works and Kevin(below) explained Conway’s Game of Life, the problem to solve during the day.
Sessions
A code retreat has many sessions of 45 minutes each. Below is how most of the sessions looked
Session 1
At 9.10 am we started our first session.
Constraint: To code Conway’s Game of life in pairs.
At the beginning of the session all the pairs were talking to each other, but after 5 min or so we saw a change towards writing code.
Retrospective:
- A few solutions to the problem emerged.
- A healthy discussion about the problem constraints.
Pair count by language:
- Python: 3
- Ruby: 4
- C#: 2
- Php: 1
- Javascript: 1
Session 2
Constraint: To discuss the solution for 10 min, and to test drive or unit test the solution.
Retrospective:
A pair came up with a solution that used 2 lists.
More people using javascript, as it’s a language that most can understand. Jasmine (BDD for Javascript) was a handy tool since you can run it in the browser.
Pair count by language:
- Python: 3
- Ruby: 2
- C#: 2
- Php: 0
- Javascript: 3
- Java: 1
Session 3
Constraint: Avoid the use of primitives.
Retrospective:
In this session we got more feedback:
- As a result of the restriction we got self documenting tests
- Not enough time
- Arriving at a better design
- One of the pairs spent most of the time just analyzing
- Some questions about testing in general. What do you do when tests are just too big? The general answer was around the lines of break it down into smaller tests and skip or remove from code and add to To do list. Another question was about mocking
Pair count by language:
- Python: 2
- Ruby: 1
- C#: 1
- Php: 1
- Javascript: 3
- Java: 3
Session 4
- Python: 1
- Ruby: 2
- C#: 2
- Php: 0
- Javascript: 3
- Java: 1
Session 5
- Python: 2
- Ruby: 1
- C#: 2
- Php: 0
- Javascript: 2
- Java: 2
Session 6
Filed under: code_retreat | Leave a Comment
Tags: code_retreat, dublin, events
TDD tools for .net developers
In the last few years the tooling available to .net developers for unit testing in general has matured, these are some of the tools that I either used or heard of :
Continuous Integration:
- Team City: I use it and really like it, simple to set up and use, if you want to try it they have a free professional edition .
- Cruise Control.net: Open source, used it but didnt find it too friendly, I m aware a lot of people use it
- Hudson. Originally a Java only project but there are some success stories on the .net fence, has some features unavailable in the other two mentioned above.
- there must be something else. ?
- StoryQ: This is what I use. Like it because you write C# code with some constraints and it generates reports on the behaviour. Samples: code report
- Cukes/Cucumber: I remember the first time I saw cucumber in action I was really impressed, however it’s hard to get buy in for a tool that requires another language installed, probably fine for some projects, it depends a lot on the project, the company and the culture.
- SpecFlow: you write features in Gherkin(the cucumber spec language) that are then compiled into c# code. Nice reports, but I find the generated code hard to read… ie a bit too verbose (example feature example generated code) however I wouldnt discard it totally.
- NSpec: You write c# code (very lambda-y) and it generates reports.. like it even less for reasons similar to the above, have a look at it yourself here
- Fit/fitnesse: I haven’t tried it, it supposed to be very good, I ll leave that one to you (would love some feedback on this if anyone reading did try it)
- xUnit: a nice, compact unit test framework, I like it because it has less noise, no setup method (ie it uses the ctor for
- nUnit: The most popular one.
- mbUnit: good support for RowTests.
- _
- msTests: the option by Microsoft. I tried this framework when it came out, so perhaps not valid anymore. My experience with it was that the same set of test ran 20% slower. Also it had poor support for theory tests. Maybe this all changed. I will guess that anyone using this framework does it because they can’t use anything else
- Psake: powershel based DSL for building
- Rake: Ruby based Dsl for builds, nice to use ruby, but sometimes needing the ruby dependency is a deal breaker
- Nant: not something I would choose, but hey if you like xml this is the way to go (if you like Xml you might want to talk to your doctor too
) - MSBuild: I find it non intuitive, I thought I was being unfair so I asked in twitter what ppl thought of it. One supporter and 4 not really happy with it (see below)
- Final Builder : a commercial option, and not a bad one to be honest. Very easy to use (drag drop style) tho not as flexible as we needed.
- NCover: does the job but I think the generated graph could be better. Running the tool was cumbersome too as far as I remember
- dotCover : really nice and integrated with resharper, it a bit rough around the edges with lambdas and other minor things, but a tool I use day to day
Filed under: Uncategorized | 7 Comments
DDD Scotland. Review and Slides
During the past weekend I was at DDD Scotland, it was great to meet all the people there.
I apologize for the amount of lolcalts that I added to my presentation (available below) and any feedback, etc more than welcome.
In many ways it was good to get the presentation out of the way early because it meant I could focus on being out there listening to other folks smarter than me talk and meet some people.
After my talk I was at Gary Short’s presentation on hoe to measure performance, interesting and really well delivered. Some interesting questions too.
Then I was at Seb Rose talk on TDD and unit testing. It was interesting to see that you can test drive a C++ app. His advice was sound. He talked about the importance of setting a structure before starting to test. He talked about the importance of deployment. And how it was important that the tests were also clean and well designed. Link to his slides
After that there was lunch, unfortunately (or not) I couldnt catch any of the grok talks as I was talking to people, one of the ideas we had was to open source a project (not mine :S) that would make using selenium+qunit on CI easier… will see how that goes.
After that I joined a talk by Toby Henderson, The dark parts of Mono. I reallly enoyed this talk. Info about small standalone tools or libraries that you can use, with examples. Such as IKVM, Cecil, SIMD, Compiler and Gendarme.
Finally, I joined the “Ask the Speakers” panel, very relaxed and quite fun. We talked about the news (Mono and its future, other stuff I cant remember – please comment), innovation and community. There is a post of note that goes into some of the stuff we talked about .
All in all a great event, thanks to everyone for making it possible.
Filed under: Uncategorized | Leave a Comment
Search
Recent Entries
- Busy May with RavenDB
- XNA–A Simple Spring Camera in 2D
- Using Mercury Particle Engine with Windows Phone 7
- XNA – A Simple 2D Camera
- Windows Phone 7– Game Development Experience
- Programming Science
- Starting out with XNA? some handy links
- Code Retreat Dublin–17th September
- TDD tools for .net developers
- DDD Scotland. Review and Slides
- DDDScotland… next weekend 7th Of May.
Categories
- .net (8)
- ActiveRecord (2)
- adobe (1)
- agile (1)
- alt.net (7)
- ayende (1)
- bdd (2)
- Best Practices (3)
- blogging (2)
- browser plus (1)
- castle (2)
- code_retreat (1)
- code_shapes (1)
- conference (1)
- couchDB (1)
- cqrs (5)
- ddd (5)
- dlr (1)
- Entity Framework (1)
- events pencil (1)
- ExtJs (4)
- FireBug (1)
- firefox (1)
- foxit (1)
- gamedev (3)
- Girl Geek Dinners (2)
- GWT (6)
- gwt-ext (2)
- ie (2)
- ie debugger (1)
- IIS (1)
- ironruby (1)
- java (1)
- javascript (7)
- jQuery (5)
- Linux (2)
- monorail (7)
- NHibernate (5)
- NVelocity (5)
- openCoffee (2)
- OSS (1)
- pdf (1)
- php (1)
- phyton (1)
- png (1)
- podcast (1)
- principles (1)
- productivity (2)
- ravenDB (1)
- ruby (3)
- silverlight (1)
- speed (1)
- Sql Server (1)
- SSIS (1)
- talk (11)
- technical talks (4)
- time picker (1)
- UI (2)
- umbrella project (1)
- Uncategorized (38)
- unit-testing (4)
- urlhelper (1)
- WALL (1)
- web-development (3)
- web-server (1)
- windsor (2)
- WURFL (1)
- xna (3)
Archives
- May 2012
- April 2012
- December 2011
- November 2011
- September 2011
- July 2011
- May 2011
- April 2011
- January 2011
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008




