This project is read-only.

My model disappear!

Jul 12, 2009 at 3:41 PM


I tried to display some Model.

Here is my Model Class


class Model
 private Vector3 position;
 Matrix worldMatrix;
 ModelInstance model;
 void Update()
  worldMatrix = Matrix.CreateTranslation(position);
 void Draw()
  state.PushWorldMatrix(ref worldMatrix);


and, I added this model to drawToScreen. and Set Camera to FirstPersonControlledCamera3D.

 and Set camera's property ->

camera.Projection.Aspect = null;
camera.Projection.FieldOfView = MathHelper.ToRadians(30);

Then Model is displayed in center. (near (0, 0, 0) ). very good.

but model's position over (-7.6, 0, 15.8), model disappeared! (when camera's position (-4.5, 5, 6.29) ).

and i set model's position to (7.15, 0, 14.4), model was displayed again. (camera position (-4, 5 , 4.9) ).

I don't know why model disappear. Model's culling is always true.

Please help me.


Jul 13, 2009 at 12:44 AM

Don't take this the wrong way, but there is very little that I can do to help you. 
There are far too many factors involved for anyone to conclusively say 'this is your problem'. It's a case where you will have to debug and reason to find the problem yourself. Sorry to say but there really isn't any other way around it. Welcome to programming :-)

However, with that said, I will give you some pointers.
These are the things I'd look at first (I'm not asking you to tell me these things, I'm suggesting places to start looking):

You say the model's culling is always true, yet you are not performing an obvious cull test in your code there. Look into what happens when you do not perform the culling?
Have you debugged into the model class to see if any geometry is being drawn?

What are your near/far clip plane set to?
Your FOV is very low, so I'd actually expect those values you gave to be off the sides of the screen.

Have you used PIX to see what is being drawn, and where the vertices are being transformed to?

Are you doing anything funky with scaled matrices? (These are known to screw up models a bit, and is something I'm working on)

Have you tried using a CullTestVisualiser to see where cull tests are being performed.

Have you tried one of the generic models such as Tiny? Have you tried not using animation (if you are...)

Etc. There are all sorts of potential reasons why your model is not showing up on screen. And chances are it'll be something really simple or silly. In any case, it is probably very unlikely that we can help you beyond pointing you in the right direction.
I'm sorry I can't be more helpful in telling you exactly why something is wrong - but to be honest with you, this is all part of programming. Some times things go wrong for reasons you cannot explain, and take a lot of work to figure what is going wrong. It's difficult, but it's rewarding and you learn a lot more than being told the answer :-)

If, however, you genuinely feel there is a bug in xen somewhere which is causing this problem for you, I'll gladly take a closer look at it (which would mean looking at your code).

Jul 13, 2009 at 7:58 AM
The problem was resolved. It was completely my fault. I thinked for three hour, for this problem.
The problem was simple.
I  created a Map Class, then Game Object (models) are added to map class.
Map's Size is 10x10, 2D floor. and I setted Map's Culler to { TestBox(new Vector3(-10, 0, -10), new Vector3(10, 0, 10)); }.
In map's draw method, there is Method of Model drawing.
therefore, When Camera moved out 10x10, Map's culling was changed to false, then all Model are not displayed.
then I tried to edit Map's CullTest to
 bool cull;
cull = culler.TestBox(new Vector3(-10, 0, -10), new Vector3(10, 0, 10));
foreach (GameObject obj in objects)
 cull = cull || obj.CullTest(culler);
return cull;
As a result, Model was displayed!
I assume that --------------------
In IDraw Interface,
CullTest = true -> run Draw(DrawState state)
CullTest = false -> not run Draw(DrawState state)
This right?
I am ashamed by this elementary mistake. but I believe that for mistakes, the programming skills will increase.
Always appreciate.
Jul 16, 2009 at 2:38 PM
Edited Jul 16, 2009 at 2:40 PM

"I am ashamed by this elementary mistake. but I believe that for mistakes, the programming skills will increase."

Don't be ashamed! Programming is all about making mistakes. It's how well you learn from them that's important!

And yes, the general logic is:

if (item.CullTest(state))

This is how DrawTargets treat their children, for example.
However, you can get into a trap here,
For example, this wouldn't work:

if (item.CullTest(state))

That could mean the cull test has a different world matrix to the draw call...
The reason they are separated, is because some objects only draw geometry (eg, the Xen.Ex.Geometry classes, such as the sphere). So doing things like setting up shaders can also be skipped in such a case. Quite often you don't just call Draw, you also do a bunch of setup. So it's nice to skip that too.

Jul 16, 2009 at 4:41 PM
Thank you, always a good answer!
I could learn a lot.