Winforms example is drawing Model different from normal XNA app?
In order to get the most of the WinForms example I converted it to XNA3 (which was quite a hassle at first, change all the version occurences to 3.0 instead of 2.0, add the MSbuild 3.5 references to you project, and last but not least, (a very important one) set "msBuildProject.DefaultToolsVersion = "3.5";" in the ContentBuilder class.
Anyway those are just details. The problem I have now is that I have 2 exactly the same model classes, one runs in a standard XNA3.0 environment and the other one in the WinForms environment, however the results are quite different.

The code is litterally exact, word for word but drawing it using the standard control from the winforms example gives me terrible results, is the Zbuffer disabled in the winforms example? (If so how to turn it on in this case))
Any tips would be appreciated.
The code models code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;</p>
<p>namespace UVPainter
{
public class GameModel
{
private Model model;
public Model Model
{
get { return model; }</p>
<p> private set
{
model = value;
boneTransforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(boneTransforms);
CalculateBounds();
}
}
private Effect effect;
public Effect Effect
{
get { return effect; }
set
{
effect = value;
foreach (ModelMesh mesh in Model.Meshes)
{
foreach (ModelMeshPart meshPart
in mesh.MeshParts)
{
meshPart.Effect = effect;
}
}
}
}
private EffectParameter effectParamTexture;
private Texture2D texture;
public Texture2D EffectTexture
{
set
{
this.texture = value;
this.effectParamTexture.SetValue(texture);
}
get
{
return texture;
}
}</p>
<p> private bool upAxisY;
public bool UpAxisY
{
get
{
return upAxisY;
}
set
{
upAxisY = value;
WorldMatrix = worldMatrix;
}
}
private Matrix worldMatrix = Matrix.Identity;
public Matrix WorldMatrix
{
set
{
if (upAxisY) worldMatrix = value;
else worldMatrix = value * Matrix.CreateRotationX(MathHelper.ToRadians(-90f));
}
get
{
if (upAxisY) return worldMatrix;
else return worldMatrix * Matrix.CreateRotationX(MathHelper.ToRadians(90f));
}
}</p>
<p> public Vector3 Position
{
get { return worldMatrix.Translation; }
set { worldMatrix.Translation = value; }
}</p>
<p> private EffectParameter effectParamWorldViewProj;
private Matrix worldViewProjMatrix = Matrix.Identity;
public Matrix EffectWorldViewProj
{
get
{
return worldViewProjMatrix;
}
set
{
worldViewProjMatrix = value;
effectParamWorldViewProj.SetValue(
worldViewProjMatrix);
}
}</p>
<p > private EffectTechnique effectTechnique;
public string EffectTechnique
{
get
{
return effectTechnique.Name;
}
set
{
effectTechnique = Effect.Techniques[value];
}
}</p>
<p> private BoundingSphere boundingSphere = new BoundingSphere();
public BoundingSphere BoundingSphere
{
get
{
return boundingSphere;
}
}</p>
<p> //Calculates a BoundingSphere around the model
private void CalculateBounds()
{
boundingSphere = new BoundingSphere();</p>
<p> for (int x = 0; x < model.Meshes.Count; x++)
{
ModelMesh mesh = model.Meshes[x];</p>
<p> BoundingSphere modelSphere = mesh.BoundingSphere;
Matrix modelBone = boneTransforms[mesh.ParentBone.Index];</p>
<p> boundingSphere =
BoundingSphere.CreateMerged(
boundingSphere,
modelSphere.Transform(modelBone));
}
}
private Matrix[ boneTransforms = null;
public Matrix[ BoneTransforms
{
get { return boneTransforms; }
set { boneTransforms = value; }
}
public GameModel(Model model, Matrix worldMatrix, Effect effect, Texture2D texture, string technique, bool upAxisY)
{
this.Model = model;
this.upAxisY = upAxisY;
this.WorldMatrix = worldMatrix;
this.Effect = effect;
this.EffectTechnique = technique;
this.effectParamWorldViewProj = effect.Parameters["WorldViewProj"];
this.effectParamTexture = effect.Parameters["texture0"];
this.EffectTexture = texture;
boneTransforms = new Matrix[this.model.Bones.Count];
this.model.CopyAbsoluteBoneTransformsTo(boneTransforms);</p>
<p> CalculateBounds();
}</p>
<p > public void Draw(Viewpoint viewpoint)
{
this.Effect.CurrentTechnique = this.effectTechnique;
this.EffectTexture = texture;
foreach (ModelMesh mesh in model.Meshes)
{
this.EffectWorldViewProj =
boneTransforms[mesh.ParentBone.Index] *
this.worldMatrix *
viewpoint.ViewProjMatrix;
mesh.Draw();
}
}
}
}</p>
<p>
(funny part: A while ago I posted a tutorial here on a simple (though apparently dangerous) way of using XNA in a WinForms app.
However Shawn Hargreaves, Ziggy, TheZMan and others pointed out some problems with the code that *could* occur, but now I am stuck with the WinForms example that should be foul proof, hmm I hope I am doing something obvious wrong
)
Comments
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!










