Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 13 Aug 2007
Offline Last Active Sep 21 2012 07:45 AM

Topics I've Started

Graphics programming book recommendations

15 September 2012 - 05:02 AM

Hi guys

I'm looking to buy a good, theory heavy, reference book on the fundamentals of computer graphics and the common algorithms used in 2D and 3D graphics programming.

Any recommendations really appreciated.

Working out delta theta to obtain a particular angle.

05 June 2012 - 05:04 AM

Hi guys

I've been spending an embarrassing amount of time on a fairly simple problem. In my 2D world each entity has an orientation (theta) which represents the direction it is facing.

Given its current orientation and a target orientation, I want to find out:

The change in theta required to achieve the target orientation, rotating clockwise.
The change in theta required to acheive the target orientation, rotating counter clockwise.

the closest I got was abs(current - target) for clockwise rotations, and -abs(current - target), for counter clockwise rotations. But that falls apart when you go past 0.

This should be simple, but i can't seem to work it out.

Please help :)

Help with rotations in 2D around a particular point, using a scene graph

19 May 2012 - 09:59 AM

Hi all

I'm getting myself confused with rotations in 2D when rotating about a point about another point. I'm using a simple tree as my scene graph. Each node knows its position relative to its parent, and there is a root node that is the ancestor of all nodes. So when I move a node all of its children move with it.

Rotations of a node about its parent are simple. But how do I rotate a node about another node ?

What I could find on the internet talks about translating the origin to the node being rotated around, rotating it, then translating back. So based on that, I came up with:

  • From the node to be rotated walk up the tree to the root node building a translation matrix (1)
  • From the origin node walk up the tree to the root node building a translation matrix (2)
  • inverse the origin node's translation (2) matrix
  • Form the origin translation matrix by multiplying matrix (1) by matrix (2), forming matrix (3)
  • Multiply the node to be rotated by matrix (3). It's now a vector relative to the rotation origin
  • apply rotation matrix
  • multiply the node by the inverse of matrix (3), its now a vector relative to its parent again.

But that seems somewhat over complicated, which makes me think I'm either doing it wrong, or have found a convoluted way of doing something simple.

Any help greatly appreciated.

Idea: Using Dictionary<enum, animation> vs <string, animation> C#

15 February 2012 - 04:59 AM

Hi guys

Working on a game engine in 2d C# and currently working on the animation and entity classes. An entity has a set of animations can play and I'm tossing up between using enums or using strings as the key, ie

Entity player = new Entity();


Entity player = new Entity();

the latter would ensure at compile time that the call to play always contains a valid animation, while the former is far simpler to implement.

Using the later, each different entity type would need its own enum, but that's not too bad as I can easily parse my sprite's xml metadata and add a bit of code generation as a pre compile step. I'm leaning towards the enum approach as it would eliminate one potential source of fauilts at run-time, but I feel like i'm abusing the concept of an enum, so other peoples opinions would be welcome.

Here's my code if it helps visualise things

Entity class:
	public class Entity
		private Dictionary<int, Animation> AnimationSet;
		public Enum Animations;
		public Entity(Enum animations)
			AnimationSet = new Dictionary<int,Animation>();
			Animations = animations;
		public void AddAnimation(Enum id, Animation a )
			if (id.GetType() == Animations.GetType())
				int idint = Convert.ToInt32(id);
				AnimationSet.Add(idint, a);
				throw new ArgumentException(String.Format("Incorrect Enum used, this entity uses '{0}' but passed in ' {1}'", Animations.GetType(), id.GetType()));

Here's my unit tests - Shows the class in practice.
		public void EntityConstruct()
			Entity myPC = new Entity(new PlayerAnimations());
			myPC.AddAnimation(PlayerAnimations.die, new Animation("afd", null, 1, 1, 1, 1, 1, 1, 1));
		public void EntityConstructFail()
			Entity myPC = new Entity(new PlayerAnimations());
			Assert.Throws(typeof(ArgumentException), delegate() { myPC.AddAnimation(TankAnimations.die, new Animation("afd", null, 1, 1, 1, 1, 1, 1, 1)); });
		enum PlayerAnimations { walk, run, die } // auto generated
		enum TankAnimations { roll, shoot, die } // auto generated

Resolving circular dependencies in C#

09 December 2011 - 03:58 AM

Hi guys

I'm writing a multi-player server for web based flash games. Each game instance has 2-4 players, and each instance is completely independent of other instances. Different game types (ie chess and poker) can be run on the same server. Server uses a worker thread pool that uses application instances for locking; ie only one worker thread may access an instance at a time.

In one project I have the server code that handles networking, scheduling, all the common low level stuff a game instance needs. It provides an abstract Application class that provides the interface* to the low level stuff that I want each different game type to inherent. *declared abstract application, not interface application as I wanted to put in some utility functions in there.

This works fine if each game lives in the same project as the server, but when I tried to refactor a game out into its own separate project I run into circular dependencies, since:
Server needs to be able to construct instances of a particular game type.
Each game type needs to be able to inherent Application.

I've been doing some googling, and it seems the 'standard' solution involves creating a third project that has an interface that both projects use...but that seems kinda hacky to me...is that really the best way to do what I'm trying to do ? Like if this was C++ I'd just make each game instance a static lib and link it in. Inversion of Control also comes up alot, but it seems very overcomplicated for what I'm trying to do. I don't need to be able to swap out server implementations, I just want each different game to live in its own project.

Thanks for any help, Hope I gave enough detail.