1
\$\begingroup\$

Let's say we got a little set {S} wich has 4 possible coordinate systems (LH=left handed, RH=right handed):

  1. LH-y_up
  2. LH-z_up
  3. RH-y_up
  4. RH-z_up

Now, let's say my Opengl engine is using a RH-y_up coordinate system and I want to import models from some 3d package which uses a RH-z up coordinate system (like 3ds max). One way to do it would be at the exporting/preprocessing stage flipping the y&z model's components. That solution doesn't seem like a really good idea though... what about if i decided to change eventually on my engine from coordinate system 3) to 1) or 2)?

So, my question would be. Let be A & B 2 coordinate systems from set S. What's the proper way to use models from A onto B?

\$\endgroup\$
1
\$\begingroup\$

You can get things pretty generic by writing a conversion layer, likely using matrix transformations. You're already thinking along these lines with the pre-processing stage.

At a high level, this would look like:

LoadModel(Model modelData)
   CoordinateSystem modelCoordSystem = DetectModelCoordinatesSystem(modelData);
   if(modelCoordSystem != engineCoordSystem)
       modelData = ConvertModelCoordinates(modelCoordSystem, modelData)
   AddModelToDatabase(modelData)

ConvertModelCoordinates(CoordinateSystem current, Model data)
    Transform transform = GetTransform(current, engineCoordSystem)
    return ApplyTransform(transform , data)

Where GetTransform would select the correct Matrix Transform to convert from the current orientation to the desired orientation. This implementation does provide for a change in engine system down the road, but it won't be as simple elsewhere in the engine to switch, or it'll mean considerably more work to code every method that assumes a certain coordinate system to be coordinate system agnostic.

As for what happens if you change your mind later. If you were to change your mind, you'd just modify your conversion layer at the same time.

However, if your design is so up in the air you're thinking your coordinate system might change in the future, you might want to nail some things down before going too much further. Remember that it's very difficult to finish something like a game engine. Worrying about making it flexible enough to accept foundational changes later down the road is going to stretch your development time to infinity.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Yep, there you go, something pretty high level to get you started. \$\endgroup\$ – MichaelHouse May 17 '17 at 9:14
  • \$\begingroup\$ Well, it's your system. I don't know what features you want to provide, what your technical requirements are, or anything else. These are questions only you'll know the answer to. You're free to make a requirement that meshes come in a specific format and ignore the problem entirely. Or you can take care of everything by pre-processing and saving over the original with the modified data. Honestly, I'd make the requirement be that meshes have a specific coordinate system and move on. Come back later to accept more coordinate systems if you finish everything else. \$\endgroup\$ – MichaelHouse May 17 '17 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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