2 Replies - 5069 Views - Last Post: 12 January 2013 - 04:16 PM

#1 rex64  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 168
  • Joined: 31-January 12

Model Drawing

Posted 22 December 2012 - 02:26 PM

The models are drawing odd. They are either transparent or drawing thing in the wrong order/drawing too much. You are seeing things from the front and the back. Like seeing both sides of a coin at the same time. See attached file for an example. You can see both the front and the back side of the coin :)/>

Here is my drawing function. Sorry it is a little messy, I am STILL learning a lot about drawing, and I actually feel like I know nothing yet :)/>
        /// <summary>
        /// Draw the model. A model can have multiple meshes, so loop.  //Quaternion quaternionRotation  Vector3 rotationVector 
        /// </summary>
        public void drawModel(clsCamera camera, Quaternion quaternionRotation, Vector3 modelPosition, int modelNumber, float scaleRatio, drawType drawMode, bool drawParticles = false)
        {
            // Copy any parent transforms.  Should I be using this here?????? 
            //Matrix[] transforms = new Matrix[myModel.Bones.Count];   
            //myModel.CopyAbsoluteBoneTransformsTo(transforms);

            if (modelSet.ultraResModels[modelNumber] != null)
            {
                Matrix[] transforms = new Matrix[modelSet.ultraResModels[modelNumber].Bones.Count];
                modelSet.ultraResModels[modelNumber].CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh mesh in modelSet.ultraResModels[0].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.LightingEnabled = true; // Turn on the lighting subsystem.

                        if (drawMode == drawType.wireframe)
                        {
                            effect.DiffuseColor = camera.effects.DiffuseColor;
                            effect.FogEnabled = false;
                            effect.AmbientLightColor = new Vector3(.6f, .6f, .6f);
                        }
                        else
                        {
                            effect.DiffuseColor = new Vector3(1, 1, 1); //null;// Color.Transparent.d;// camera.effects.DiffuseColor.;



                            effect.DirectionalLight0.DiffuseColor = new Vector3(100f, 100f, 100f); // a  light color
                            effect.DirectionalLight0.Direction = new Vector3(1f, 0, .2f);  // coming along the x-axis
                            effect.DirectionalLight0.SpecularColor = new Vector3(1, 1, 1); // with green highlights

                            effect.AmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f); // Add some overall ambient light.
                            //effect.EmissiveColor = new Vector3(.5f, 0, 0); // Sets some strange emmissive lighting.  This just looks weird.

                            //effect.FogEnabled = camera.effects.FogEnabled;
                            //effect.FogStart = camera.effects.FogStart;
                            //effect.FogEnd = camera.effects.FogEnd;
                            //effect.FogColor = camera.effects.FogColor;
                        }

                        //if (mesh.Tag != null)
                        //{
                        //    //mesh.MeshParts.
                        //    //effect.Texture = mesh.Tag;
                        //    effect.TextureEnabled = true; //camera.effects.TextureEnabled;
                        //    //effect.Parameters["xTexture"].SetValue(exTextures[i++]); 
                        //    //effect.CommitChanges();
                        //}
                        //else
                        //{
                        //    effect.TextureEnabled = true;
                        //}

                        //effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotationY + MathHelper.ToRadians(-90)) * Matrix.CreateRotationX(modelRotationX) * Matrix.CreateTranslation(modelPosition) * Matrix.CreateScale(scaleRatio, scaleRatio, scaleRatio);

                        //effect.Texture = GridTexture; 

                        effect.World = transforms[mesh.ParentBone.Index] *
                             Matrix.CreateScale(scaleRatio, scaleRatio, scaleRatio) *
                             Matrix.CreateFromQuaternion(quaternionRotation) *
                             Matrix.CreateTranslation(new Vector3(modelPosition.X + adjust.offsetPosition.X, modelPosition.Y + adjust.offsetPosition.Y, modelPosition.Z + adjust.offsetPosition.Z));


                        //Matrix worldMatrix = * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(19, 12, -5));
                        effect.View = camera.view; //Matrix.CreateLookAt(camera.cameraPosition, Vector3.Zero, Vector3.Up);
                        effect.Projection = camera.projection;  //Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
                    }

                    foreach (ModelMeshPart part in mesh.MeshParts)
                    {
                        clsMisc.polygonCount += part.PrimitiveCount;
                    }

                    // Draw the mesh, using the effects set above.
                    mesh.Draw();
                }
            }
        }




The coin has a Y and a 1 on it. Model is copyright 2012 PlazSoft, all rights reserved.

Attached image(s)

  • Attached Image

This post has been edited by rex64: 22 December 2012 - 02:28 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Model Drawing

#2 rex64  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 168
  • Joined: 31-January 12

Re: Model Drawing

Posted 12 January 2013 - 09:27 AM

We found the issue, it was related to some drawing settings, but I can't find the setting right now to paste here.

Also, does this seem like a fast way of displaying things? It seems like we are re-creating everything every frame. Is that normal?
Was This Post Helpful? 0
  • +
  • -

#3 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Model Drawing

Posted 12 January 2013 - 04:16 PM

Well you could set your effects separately, if the effect is going to be used more than once with some of the same settings then you may as well only set those settings once per frame, rather than once per model per frame. So you could set your lights and your camera matrices for any effects that will be used in a method that only runs once per frame.

An easy way to do this would be to create a singleton class to hold all your effects, then have set methods for the different effect variables you may want to set.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1