Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Given a shape (any shape) in a 2D world where all positions, locations, and centers are two dimensional vectors, should the shape's center be described in local space or world space?

EXAMPLE:

World Space center of a Rectangle: Position: (100, 100); Dimensions: (200, 200); Center: (200, 200);

Local Space center of a Rectangle: Position: (200, 200); Dimensions: (100, 200); Center: (50, 100);

World Space center of a Circle: Position: (100, 100); Dimensions: (50, 50) (diameter); Center: (100, 100);

Local Space center of a Circle: Position: (50, 50); Dimensions: (200, 200); Center: (0, 0);

share|improve this question
1  
Depends on your use case, good arguments can be made for either. What are you planning to DO with these polygons? –  Patrick Hughes Aug 16 '12 at 6:06
    
It's a general question of common practice, really. It's not what I plan on doing, but what others plan on doing and if going one way or the other will make their life easier during development of a game. –  Casey Aug 16 '12 at 6:32
1  
I think we need to know a bit more about what you need these coordinates for. Dimensions is obvious, but what about position? Is the position the position of the center and the center is an offset to a corner of the rectangle? What point on the rectangle is specified with "position"? And what do you use center for? Some engines (such as cocos2d) use fractions (eg. 0..1) for center coordinates. –  bummzack Aug 16 '12 at 6:35
    
@bummzack It depends on the shape. A circle's position is also its center. In world space these are the same, but in local space the position is the center and the "center" is an offset of (0, 0). –  Casey Aug 16 '12 at 15:39

2 Answers 2

up vote 1 down vote accepted

If at all possible, make a shape's center and its origin in local space be the same point. That is, describe the center in local space, but don't bother storing it—make it always (0, 0).

This is simply an attempt to reduce the number of unique spaces you have to think about. If your shape's center differs from its origin, you will probably at some point have to think about all of these:

  1. world space vector from world origin to object origin;
  2. world space vector from world origin to object center;
  3. local space vector from object origin to object center;
  4. local space vector from object origin to some other point on the object; and
  5. local space vector from object center to some other point on the object.

If you make "object origin" and "object center" be the same thing, you can hopefully reduce that to 2 unique kinds of vectors (vector from world origin to object origin and vector from object origin to some other point on the object).

share|improve this answer

I assume your object's position in the world is not the same as its "center" (otherwise, if you specified the center in local coordinates it would always be the zero vector).

It all depends on your requirements, but I would imagine that specifying the "center" (whatever you define the center to be) in local coordinates would be easier since whenever your object moves you would not need to update its center vector as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.