I cannot get the orientation of models correct. In this project the user loads 3 DXF files.
- DXF 1 is the model represented by 3dfaces.
- DXF 2 is the 3dpoly representing the path of the camera as driving on the left.
- DXF 3 is the 3dpoly providing a path for oncoming traffic.
The first two data sets are dealt with correctly in the C#/XNA development. The user can drive along the road using up and down keyboard keys. But I fail at the third process. I cannot get the orientation of oncoming traffic correct. The position is ok, one van at every 100 metres, but the orientation is wrong.
The strangest of all is the normal method to transform the models to the correct place and orientation is causing the models to be on top of the camera! Where did I go wrong? I have made the source code available at the following URL, so you can view the code and see where I went wrong (the zip includes the DXF files used for testing):
http://www.4shared.com/zip/Lk3xmCtO
Thanks in advance.. Kevin.
This is the most incorrect part:
Matrix worldMatrix = Matrix.CreateTranslation(VanPos[vi]);
Matrix[] transforms = new Matrix[Van.Bones.Count];
Van.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh modmesh in Van.Meshes)
{
foreach (BasicEffect be1 in modmesh.Effects)
{
be1.World = transforms[modmesh.ParentBone.Index] * worldMatrix;
this results in the models being placed at the camera position.
using just the CreateTranslation is placing the models at the correct place but the orientation is incorrect.
You are never setting an orientation, which means that your stuff is never going to rotate. From some code I have laying around, this is how I draw model meshes.
Key points:
Orientationmatrix needs to be created. There are lots of convenience functions to help you do this likeMatrix.CreateRotationYBeware of ordering when multiplying matrices. I’m sure you’ve noticed this but the order really matters. I tend to mess this up and fiddle around with the multiplication order to make things work 🙂