English 中文(简体)
Switch between active objects - understanding transform/view
原标题:

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.

问题回答

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)





相关问题
Prerequisite for learning directx

I am from .net C# background and I want to learn DirectX. I have knowledge of C++ but I am fairly new to graphic world. I am little confused about how to start learning directx, should I start ...

How to programmatically disable the auto-focus of a webcam?

I am trying to do computer vision using a webcam (the model is Hercules Dualpix). I know it is not the ideal camera to use, but I have no choice here. The problem is the auto-focus makes it hard/...

Making an object orbit a fixed point in directx?

I am trying to make a very simple object rotate around a fixed point in 3dspace. Basically my object is created from a single D3DXVECTOR3, which indicates the current position of the object, ...

3d Alternative for D3DXSPRITE for billboarding

I am looking to billboard a sun image in my 3d world (directx 9). Creating a D3DXSPRITE is great in some cases, but it is only a 2d object and can not exist in my "world" as a 3d object. What is ...

热门标签