2
\$\begingroup\$

This is probably a stupid question, but I'm trying to simply move a 3D object up, down, left, and right (Not forward or backward).

The Y axis works fine, but when I increment the object's X position, the object moves BOTH right and backwards! when I decrement X, left and forwards!

setPosition(getPosition().X + 2/*times deltatime*/, getPosition().Y, getPosition().Z); 

I was astonished that XNA doesnt have its own setPosition function, so I made a parent class for all objects with a setPosition and Draw function. Setposition simply edits a variable "mPosition" and passes it to the common draw function:

 // Copy any parent transforms. Matrix[] transforms = new Matrix[block.Bones.Count]; block.CopyAbsoluteBoneTransformsTo(transforms); 
 // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in block.Meshes) { // This is where the mesh orientation is set, as well // as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(MathHelper.ToRadians(mOrientation.Y)) * Matrix.CreateTranslation(mPosition); effect.View = game1.getView(); effect.Projection = game1.getProjection(); } // Draw the mesh, using the effects set above. mesh.Draw(); } 

I tried to work it out by attempting to increment and decrement the Z axis, but nothing happens?! So using the X axis changes the objects x and z axis', but changing the Z does nothing. Great. So how do I seperate the X and Z axis movement?

\$\endgroup\$
3
  • \$\begingroup\$ I guess your matrix usage is incorrect. \$\endgroup\$ Commented Oct 28, 2012 at 13:04
  • \$\begingroup\$ I am hoping that you already figured this out on your own but if not then could you please indicate what projection you are using, as well as what the value is for the mOrientation.Y. \$\endgroup\$ Commented Feb 25, 2013 at 19:16
  • \$\begingroup\$ The problem was elsewhere in the code. A really, really dumb error on my part in a different file. Brace yourself, I wrote this: x = getPosition.x y = getPosition.y z = getPosition.x \$\endgroup\$ Commented Feb 25, 2013 at 21:19

1 Answer 1

1
\$\begingroup\$

First..

you can set the translation of matrix easily...

Transform.Translation = yourTranslation; 

Second...

I would render the axis base to see if it´s moving right.. because of your parent rotation or your camera view the behaviuor described maybe is right...

\$\endgroup\$
5
  • \$\begingroup\$ In what library is "Transform"? It's not in any namespace i'm using :( \$\endgroup\$ Commented Oct 29, 2012 at 12:34
  • \$\begingroup\$ Pretty sure that's just a typo - I think he means transforms.Translation. \$\endgroup\$ Commented Oct 29, 2012 at 14:39
  • \$\begingroup\$ Matrix type has a translation property \$\endgroup\$ Commented Oct 29, 2012 at 14:47
  • \$\begingroup\$ Not in matrix, nor any other library, is there transform.translation. I've vhecked the axis and they are correct. \$\endgroup\$ Commented Oct 31, 2012 at 13:28
  • \$\begingroup\$ msdn.microsoft.com/en-us/library/… \$\endgroup\$ Commented Oct 31, 2012 at 16:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.