Everything in viewpoint is backwards

Hi,

  I have been working on a small 3d engine for the last few weeks, no big plans for it or anything just doing it to teach myself.

Everything has been going ok so far, been working off internet tutorials and examples but i have run into a problem, everything in my viewpoint is backwards.

Screen Shot:  www.turnipfan.com/screen_shot.jpg

I have tried changing all the settings but nothing seems to work, i was wondering if someone more experience could have a look at the code and tell me whats wrong.

Source Code (84kb): www.turnipfan.com/testapp.zip 

Thanks for any help,

    -Dave



Answer this question

Everything in viewpoint is backwards

  • A_S_G

    You just have your u,v coordinates wrong for the textures. You have one of them going from 1.0 to 0.0 instead of 0.0 to 1.0 so the texture gets rendered backwards.

  • acangialosi

     

    When you draw in DX your faces have an orientation depending on the order of entry of your vertex

    < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

    a triangle 0,0,0 to 0,1,0 to 1,0,0

    will be facing toward you

    a triangle 0,0,0 to 1,0,0 to 0,1,0

    is the very same triangle but this time it face the back of your screen

     

    the ''normal'' is the direction the face of the triangle is pointing

    In the first triangle the normal point to you

    In the second triangle the normal point to the back of the screen

    So the order you send the vertex to the system will give the orientation of your face (triangles)

     

    Another problem might be that your texture coordinate are not in the good orientation

    The texture coordinate work the same way, the order you send them is important

     

    a triangle 0,0,0 to 0,1,0 to 1,0,0  must have (0,0) (0,1) and (1,0) texture for each respective vertex

     

    Maybe your vertex are in the good order but your texture coordinate are not

     

    If I do this :

    a triangle 0,0,0 to 0,1,0 to 1,0,0  with (0,0) (1,0) and (0,1) texture for each respective vertex

    I will get what you get...the texture will be backward...like seen in a mirror

     

    When you plot those value on a sheet of paper, you can draw a circular arrow on the face

    To show the order you should enter the vertex

    Depending on the order your circular arrow will go clock wise ot not

     

    If you use your left hand over that circular arrow your tumb will show the direction of your faces...

     

    So maybe your vertex are enter in the bad order or it's your texture coodinate order

     


  • MattFunke

    Thanks for the reply Etienne2005 but i think it has to be in the camera or the way my engine is getting declared, you see normally instead of a simple box mesh i have the app loading largers mesh data complete with normals, indices, vertex colors and texture coords and everything is backwards.

    I have tried reversing my vertex data, indices and changind the normals with no luck so i posted the engines code here to see if someone could help.

    Thanks though!


  • Mark Uniacke

    Your matrix view seems a little complicated :-)

    An easier way is to use the LookAt Function...

               device.Transform.View = Matrix.LookAtLH(
                   new Vector3(0.0f, 3.0f, -5.0f),
                   new Vector3(0.0f, 0.0f, 0.0f),
                   new Vector3(0.0f, 1.0f, 0.0f));

    It's a lot easier :-)

            public void Render()
            {
                Matrix view = Matrix.Identity;

                //cameraTarget = Vector3.Normalize(cameraTarget);
                vRight = Vector3.Cross(cameraUp, cameraTarget);
                vRight = Vector3.Normalize(vRight);
                //cameraUp = Vector3.Cross(cameraTarget, vRight);
                //Vector3.Normalize(cameraUp);

                view.M11 = vRight.X;
                view.M12 = cameraUp.X;
                view.M13 = cameraTarget.X;
                view.M14 = 0.0f;

                view.M21 = vRight.Y;
                view.M22 = cameraUp.Y;
                view.M23 = cameraTarget.Y;
                view.M24 = 0.0f;

                view.M31 = vRight.Z;
                view.M32 = cameraUp.Z;
                view.M33 = cameraTarget.Z;
                view.M34 = 0.0f;

                view.M41 = -Vector3.Dot(cameraPos, vRight);
                view.M42 = -Vector3.Dot(cameraPos, cameraUp);
                view.M43 = -Vector3.Dot(cameraPos, cameraTarget);
                view.M44 = 1.0f;

                parentForm.device.Transform.View = view;
            }

     

         private void SetupMatrices()
           {
               // For our world matrix, we will just rotate

    the object about the y-axis.

               // Set up the rotation matrix to generate 1

    full rotation (2*PI radians)
               // every 1000 ms. To avoid the loss of

    precision inherent in very high
               // floating point numbers, the system time is

    modulated by the rotation
               // period before conversion to a radian

    angle.
               //float fangle;
               //int  iTime  = Environment.TickCount % 1000;
               //fangle = iTime * (2.0f * (float)Math.PI) /

    1000.0f;
               //device.Transform.World =

    Matrix.RotationY(fangle);

               device.Transform.World =

    Matrix.RotationX(xRotate);
               //device.Transform.World =

    Matrix.RotationY(yRotate);
               //device.Transform.World =

    Matrix.RotationZ(zRotate);
               // Set up our view matrix. A view matrix can

    be defined given an eye
               // point, a point to lookat, and a direction

    for which way is up. Here,
               // we set the eye five units back along the

    z-axis and up three units,
               // look at the origin, and define "up" to be

    in the y-direction.

               device.Transform.View = Matrix.LookAtLH(
                   new Vector3(0.0f, 3.0f, -5.0f),
                   new Vector3(0.0f, 0.0f, 0.0f),
                   new Vector3(0.0f, 1.0f, 0.0f));

               // For the projection matrix, we set up a

    perspective transform (which
               // transforms geometry from 3D view space to

    2D viewport space, with
               // a perspective divide making objects

    smaller in the distance). To build
               // a perpsective transform, we need the field

    of view (1/4 pi is common),
               // the aspect ratio, and the near and far

    clipping planes (which define
               // at what distances geometry should be no

    longer be rendered).
               device.Transform.Projection =

    Matrix.PerspectiveFovLH(
                   (float)Math.PI / 4,
                   1.0f,
                   0.4f,
                   10000.0f);
           }


  • Everything in viewpoint is backwards