views:

41

answers:

1

Hello,

it is something I don't understand on transforming (meshes). Please take a look at my code (which is in Render() function) first:

            foreach (GeometricObject obj in this.objects)
            {
                if (obj != this.activeObject)
                {
                    obj.Mesh = MeshUtils.ChangeMeshColor(obj.Mesh, Color.Yellow, device);
                }
                else
                {
                    obj.Mesh = MeshUtils.ChangeMeshColor(obj.Mesh, Color.Green, device);
                    obj.GeometryMatrix.Translate(this.move);
                }
                device.Transform.World = obj.GeometryMatrix;
                obj.Mesh.DrawSubset(0);
            } 

Explanation: I have got some yellow gometriObjects (meshes) and one green activeObject (I can switch between them by keyboard 1-4). 'move' is a vector that I change after every arrow is selected on keyboard (so I can move the active objects).

BUT it is not working as I wanted to. ...if I change the position of one of my objects...then after switching to the other (changing activeObject) I got the other view on the screen (after all switches ... all objects are in the same place of the screen;/). Why is that it isn't the same view for all the time? I think...it should, because I have got the same view setted:

            device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 2.0f, -25.0f), // Camera position
                    new Vector3(0.0f, 0.0f, 0.0f),   // Look-at point
                    new Vector3(0.0f, 1.0f, 0.0f));  // Up vector

So what's my problem? Any ideas:)? Aha...the problem isn't connected with that changingMeshColor function...i checked.

A: 

Ech....it started to work after changing:

obj.GeometryMatrix.Translate(this.move);

to:

obj.GeometryMatrix *= Matrix.Translation(this.move);

...but why is that? I really don't know... Translate() should change my matrix, not set as a translation (as it did)

Kamil Hawdziejuk
In the latter code you are transforming a matrix by the translation matrix defined by "move". In the former you are creating a translation matrix. The former overwrites anything that was already in the matrix.
Goz